/* http://keith-wood.name/datepick.html
Datepicker extensions for jQuery v4.1.0.
Written by Keith Wood (kbwood{at}iinet.com.au) August 2009.
Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and
MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses.
Please attribute the author if you use it. */
(function($) { // Hide scope, no $ conflict
var themeRollerRenderer = {
picker: '
'
}),
// ThemeRoller template for generating a datepicker.
themeRollerRenderer: themeRollerRenderer,
// ThemeRoller template for generating a datepicker showing week of year.
themeRollerWeekOfYearRenderer: $.extend({}, themeRollerRenderer, {
weekHeader: '
{l10n:weekText}
{days}
',
week: '
{weekOfYear}
{days}
'
}),
/* Don't allow weekends to be selected.
Usage: onDate: $.datepick.noWeekends.
@param date (Date) the current date
@return (object) information about this date */
noWeekends: function(date) {
return {selectable: (date.getDay() || 7) < 6};
},
/* Change the first day of the week by clicking on the day header.
Usage: onShow: $.datepick.changeFirstDay.
@param picker (jQuery) the completed datepicker division
@param inst (object) the current instance settings */
changeFirstDay: function(picker, inst) {
var target = $(this);
picker.find('th span').each(function() {
var parent = $(this).parent();
if (parent.is('.datepick-week') || parent.is('.ui-state-hover')) {
return;
}
$('' + $(this).text() + '').
click(function() {
var dow = parseInt(this.className.replace(/^.*datepick-dow-(\d+).*$/, '$1'), 10);
target.datepick('option', {firstDay: dow});
}).
replaceAll(this);
});
},
/* Add a callback when hovering over dates.
Usage: onShow: $.datepick.hoverCallback(handleHover).
@param onHover (function) the callback when hovering,
it receives the current date and a flag indicating selectability
as parameters on entry, and no parameters on exit,
this refers to the target input or division */
hoverCallback: function(onHover) {
return function(picker, inst) {
if ($.isFunction(onHover)) {
var target = this;
picker.find(inst.options.renderer.daySelector + ' a, ' +
inst.options.renderer.daySelector + ' span').
hover(function() {
onHover.apply(target, [$(target).datepick('retrieveDate', this),
this.nodeName.toLowerCase() == 'a']);
},
function() { onHover.apply(target, []); });
}
};
},
/* Highlight the entire week when hovering over it.
Usage: onShow: $.datepick.highlightWeek.
@param picker (jQuery) the completed datepicker division
@param inst (object) the current instance settings */
highlightWeek: function(picker, inst) {
var target = this;
var renderer = inst.options.renderer;
picker.find(renderer.daySelector + ' a, ' + renderer.daySelector + ' span').
hover(function() {
$(this).parents('tr').find(renderer.daySelector + ' *').
addClass(renderer.highlightedClass);
},
function() {
$(this).parents('tr').find(renderer.daySelector + ' *').
removeClass(renderer.highlightedClass);
});
},
/* Show a status bar with messages.
Usage: onShow: $.datepick.showStatus.
@param picker (jQuery) the completed datepicker division
@param inst (object) the current instance settings */
showStatus: function(picker, inst) {
var isTR = (inst.options.renderer.selectedClass == themeRollerRenderer.selectedClass);
var defaultStatus = inst.options.defaultStatus || ' ';
var status = $('
' +
defaultStatus + '
').
insertAfter(picker.find('.datepick-month-row:last,.ui-datepicker-row-break:last'));
picker.find('*[title]').each(function() {
var title = $(this).attr('title');
$(this).removeAttr('title').hover(
function() { status.text(title || defaultStatus); },
function() { status.text(defaultStatus); });
});
},
/* Allow easier navigation by month/year.
Usage: onShow: $.datepick.monthNavigation.
@param picker (jQuery) the completed datepicker division
@param inst (object) the current instance settings */
monthNavigation: function(picker, inst) {
var target = $(this);
var isTR = (inst.options.renderer.selectedClass == themeRollerRenderer.selectedClass);
var minDate = inst.curMinDate();
var maxDate = inst.get('maxDate');
var month = inst.drawDate.getMonth();
var year = inst.drawDate.getFullYear();
var html = '
';
for (var i = 0; i < inst.options.monthNames.length; i++) {
var inRange = ((!minDate || new Date(year, i + 1, 0).getTime() >= minDate.getTime()) &&
(!maxDate || new Date(year, i, 1).getTime() <= maxDate.getTime()));
html += '
';
}
for (var i = -6; i <= 6; i++) {
if (i == 0) {
continue;
}
var inRange =
((!minDate || new Date(year + i, 12 - 1, 31).getTime() >= minDate.getTime()) &&
(!maxDate || new Date(year + i, 1 - 1, 1).getTime() <= maxDate.getTime()));
html += '