Right Calendar

Right Calendar is the standard calendar/datepicker feature for RightJS

Get the latest version right here

All the source code of the project is available under terms of the MIT license

http://github.com/rightjs/rightjs-ui/tree/master/src/calendar/

For some standard usage examples see the demo page

Index

top ↑Features List

Right Calendar has the following features:

  • Dates and times picking
  • Multiple months and greed support
  • Date limits support
  • Inline displaying support
  • Auto-appearance at input elements
  • Auto-initialization by the rel="calendar" attribute
  • Tiny (just 10k) size, no image dependencies, fully css-based design
  • Everything is included in a single file
  • i18n support

top ↑Usage Basics

The usage of Right Calendar is really simple. Just grab the file above, include it on your page and you are good to go. Right Calendar does not require any images and all the styles are inlined inside the javascript file

<script src="/javascripts/right-calendar.js" type="text/javascript"></script>

After that you will have the Calendar unit available

new Calendar({format: 'US'}).insertTo('that-element');

new Calendar({showTime: true}).assignTo('that-input');

top ↑Inputs Auto-Discovery

If you like, you can use the auto-initialization feature. Simply specify the rel="calendar" attribute on your INPUT element and the script will automatically initialize the autocompletion feature on this element when it needed.

<input type="text" rel="calendar" />

You also can use the rel="calendar[input_field_id]" attribute if you want to use a trigger element, like an image, that will show the calendar up.

<input type="text" id="my-input" />
<img src="calendar.png" rel="calendar[my-input]" />

And you can specify custom options for those inputs with the HTML5 style attribute like this

<input type="text" rel="calendar"
data-calendar-options="{format: 'US'}" />

top ↑Options List

There are several options you can pass into the Calendar constructor or use with the auto-discovery feature

NameDefaultDescription
format‘ISO’one of the predefined formats name or a format string
showTimenulla marker if the time picker should be displayed
twentyFourHournulla marker if the 24 or 12 hours time picker should be used
timePeriod1the time picker min time quantity in minutes
showButtonsfalsea marker if the bottom buttons should be displayed
minDatenullthe minimum date you can select
maxDatenullthe maximum date you can select
listYearsfalseshow the year switching buttons
firstDay11 for Monday, 0 for Sunday
numberOfMonths1a number of month to display, or a [x,y] months greed definition
fxName‘fade’the visual effect name, use null if you don’t want any fx
fxDuration‘short’the visual effects duration
hideOnPickfalsea marker if the popup should get hidden when user picks a date
cssRule‘[rel^=calendar]’the auto-discoverable calendar elements css-rule

You also can alter the Calendar.Options object to make the changes global.

The showTime and twentyFourHour options have null value by default, which means that those options will be automatically determined depending on the specified time format option. You also might specify a boolean value to enforce those options.

top ↑Dates Formatting

Right Calendar uses the GNU strftime formatting system and there are the following placeholders available:

KeyDescription
%aThe abbreviated weekday name (‘Sun’)
%AThe full weekday name (‘Sunday’)
%bThe abbreviated month name (‘Jan’)
%BThe full month name (‘January’)
%dDay of the month (01..31)
%eDay of the month without leading zero (1..31)
%mMonth of the year (01..12)
%yYear without a century (00..99)
%YYear with century
%HHour of the day, 24-hour clock (00..23)
%kHour of the day, 24-hour clock without leading zero (0..23)
%IHour of the day, 12-hour clock (01..12)
%lHour of the day, 12-hour clock without leading zero (0..12)
%pMeridian indicator (‘AM’ or ‘PM’)
%PMeridian indicator (‘pm’ or ‘pm’)
%MMinute of the hour (00..59)
%SSecond of the minute (00..59)
%%Literal ’%’ character

There are also few predefined date formats are available:

NameFormatExample
ISO‘%Y-%m-%d’2009-08-18
POSIX‘%Y/%m/%d’2009/08/18
EUR‘%d-%m-%Y’18-08-2009
US‘%m/%d/%Y’08/18/2009

top ↑Events List

Right calendar supports the following list of events

NameDescription
showthe calendar element was shown
hidethe calendar element was hidden
selectuser selects a date or time
doneuser hits the ‘done’ button

You can use any standard Observer methods to process those events. Shortcuts like onSelect, onDone are also available.

top ↑API Reference

Right Calendar has a simple interface:

MethodDescription
setDate(date)sets the date, the date might be a Date instance or a String
getDate()returns the current date
format([String format])returns a string representation of the current date
insertTo(element)makes the calendar inlined into the element
assignTo(element[,trigger])assigns the calendar to auto appear at the element; if the trigger is specified a calendar will appear only by clicking on the trigger element
hide()hides the calendar block
show()shows the calendar block
showAt(Element)assigns the calendar to work with the element and shows it at the bottom of the element

top ↑Internationalization

You might find a translation module for your language at the github repository

http://github.com/rightjs/rightjs-ui/tree/master/i18n/

Or you can translate the interface by simply altering the Calendar.i18n object like that

Calendar.i18n = {
Done: 'Готово',
Now: 'Сейчас',
Next: 'Следующий месяц',
Prev: 'Предыдущий месяц',
NextYear: 'Следующий год',
PrevYear: 'Предыдущий год',

dayNames: $w('Вокскресенье Понедельник Вторник Среда Четверг Пятница Суббота'),
dayNamesShort: $w('Вск Пнд Втр Срд Чтв Птн Сбт'),
dayNamesMin: $w('Вс Пн Вт Ср Чт Пт Сб'),
monthNames: $w('Январь Февраль Март Аперль Май Инюнь Июль Август Сентябрь Октябрь Ноябрь Декабрь'),
monthNamesShort: $w('Янв Фев Мар Апр Май Инь Иль Авг Сен Окт Ноя Дек')
};

top ↑Style Alterations

If you need to alter the calendar view to make it fit your design, please use the following elements structure description as a guidance.

<div class="right-calendar">
<div class="right-ui-button right-calendar-next-button">&lsaquo;</div>
<div class="right-ui-button right-calendar-prev-button">&rsaquo;</div>

<table class="right-calendar-greed">
<tr><td>

<div class="right-calendar-month">
<div class="right-calendar-month-caption"></div>

<table>
<thead>
<tr>
<th>Mo<th>Tu<th>...
</tr>
</thead>
<tbody>
<tr>
<td class="right-calendar-day-blank">
<td class="right-calendar-day-selected">
<td class="right-calendar-day-disabled">
<td><td><td><td>...
</tr>
.....
</tbody>
</table>
</div>

</td></tr>
</table>

<div class="right-calendar-time">
<select></select> : <select></select>
</div>

<div class="right-ui-buttons right-calendar-buttons">
<input type="button" value="Done" class="right-ui-button right-calendar-done-button" />
<input type="button" value="Now" class="right-ui-button right-calendar-now-button" />
</div>
</div>