DateJust.js is a JavaScript component for calendars. It has powerful controls: drag to select multiple days, and scroll to change month.
A demo of the library in action can be found here.
- Chrome ✅
- Opera ✅
Safariknown issues:- Scroll control isn't as smooth as other browsers.
Firefoxknown issues:- Drag control to select a date range is buggy.
Nothing (not even jQuery)
$ git clone [email protected]:callum-hart/DateJust.js.git
$ cd DateJust.js
$ npm install
$ grunt watch
- Include CSS
- Include JavaScript
- Create an instance:
var instance = new DateJust(element, { options });
element
can be a selector or a DOM element.
- Details Minimum date the calendar can go to.
- Type
<Date>
- Default
January 10 years in the past (from todays date)
- Usage
minDate: new Date(2010, 5, 10)
- Details Maximum date the calendar can go to.
- Type
<Date>
- Default
January 10 years in the future (from todays date)
- Usage
maxDate: new Date(2020, 5, 10)
- Details Initialize the calendar with an active date.
- Type
<Date>
- Usage
existingDate: new Date(2016, 11, 8)
- Details Initialize the calendar with an active date range.
- Type
Array <Date>
- Usage
existingDateRange: [new Date(2016, 11, 8), new Date(2016, 11, 25)]
- Details Allow drag control to select a date range.
- Type
Boolean
- Default
true
- Usage
dragSelection: false
- Details Allow scroll control to change the month.
- Type
Boolean
- Default
true
- Usage
scrollControl: false
onDateSelected: (date) {}
- Details When a date is selected.
- Arguments
(date)
onDateRangeSelected: (startDate, endDate) {}
- Details When a date range is selected.
- Arguments
(startDate, endDate)
- Condition Option
dragSelection
has to be set totrue
.
The HTML generated by DateJust.js is:
<div class="dj-container">
<div class="dj-header">
<div class="dj-month">
<span class="dj-month-name"></span>
<select class="dj-month-select"></select>
</div>
<div class="dj-year">
<span class="dj-year-name"></span>
<select class="dj-year-select"></select>
</div>
<a href="" class="previous-month">▶</a>
<a href="" class="next-month">▶</a>
</div>
<ul class="day-names">
<li>M</li>
<li>T</li>
<li>W</li>
<li>T</li>
<li>F</li>
<li>S</li>
<li>S</li>
</ul>
<ul class="days">
<li>
<a href=""></a>
</li>
</ul>
</div>
Classes that are applied when a certain condition is true.
.todays-date
- Condition Applied to todays date.
- Element
.dj-container ul.days a
.in-previous-month
- Condition Applied to dates in the previous month.
- Element
.dj-container ul.days a
.in-this-month
- Condition Applied to dates in the active month.
- Element
.dj-container ul.days a
.in-next-month
- Condition Applied to dates in the next month.
- Element
.dj-container ul.days a
.active-day
- Condition Applied to the active date.
- Element
.dj-container ul.days a
.day-in-range
- Condition Applied to active dates in a date range.
- Element
.dj-container ul.days a
.disabled-date