Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions glDatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@
onHide: function(calendar) { calendar.hide(); },

// First date of the month.
firstDate: null
firstDate: null,

// Callback for additional next-prev click handling
nextPrevCallback: function(){}
};

// Our plugin object
Expand Down Expand Up @@ -383,16 +386,23 @@

var getFirstDate = function(_offset) {
// Create start date as the first date of the month
var _date = new Date(options.firstDate);
var _date = new Date(options.firstDate),
tempDate = new Date(_date.getFullYear(), _date.getMonth(), 1);

// Default to no offset
_offset = _offset || 0;

// Find out which months are selectable
while(true) {
// Adjust date for month offset
_date.setMonth(_date.getMonth() + _offset);
_date.setDate(Math.min(1, _date._max()));
//_date.setMonth(_date.getMonth() + _offset);
//_date.setDate(Math.min(1, _date._max()));

// Set the month first because if number of days are not the same with _date, setMonth() will skip to the month with the same number of days
// e.g. if _date is 31 Mar, _offset + 1 will set it to May instead of April
tempDate.setMonth(_date.getMonth() + _offset);
tempDate.setDate(Math.min(1, _date._max()));
_date = tempDate;

// If not an offset, break out of the loop
if(_offset == 0) { break; }
Expand Down Expand Up @@ -456,6 +466,7 @@

var prevCell = $('<div/>')
.addClass(monyearClass)
.addClass('prev')
.css(
$.extend({}, cellCSS,
{
Expand All @@ -464,14 +475,15 @@
)
.append(
$('<a/>')
.addClass('prev-arrow' + (showPrev ? '' : '-off'))
.addClass('prev-arrow' + (showPrev ? '' : ' off'))
.html(options.prevArrow)
)
.mousedown(function() { return false; })
.click(function(e) {
if(options.prevArrow != '' && showPrev) {
e.stopPropagation();
setFirstDate(prevFirstDate);
options.nextPrevCallback(this);
}
});

Expand All @@ -490,6 +502,7 @@

var nextCell = $('<div/>')
.addClass(monyearClass)
.addClass('next')
.css(
$.extend({}, cellCSS,
{
Expand All @@ -499,14 +512,15 @@
)
.append(
$('<a/>')
.addClass('next-arrow' + (showNext ? '' : '-off'))
.addClass('next-arrow' + (showNext ? '' : ' off'))
.html(options.nextArrow)
)
.mousedown(function() { return false; })
.click(function(e) {
if(options.nextArrow != '' && showNext) {
e.stopPropagation();
setFirstDate(nextFirstDate);
options.nextPrevCallback(this);
}
});

Expand Down