/* 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: '' + '
' + '{link:prev}{link:today}{link:next}
{months}' + '{popup:start}
{button:clear}{button:close}
{popup:end}' + '
', monthRow: '
{months}
', month: '
' + '
{monthHeader:MM yyyy}
' + '{weekHeader}{weeks}
', weekHeader: '{days}', dayHeader: '{day}', week: '{days}', day: '{day}', monthSelector: '.ui-datepicker-group', daySelector: 'td', rtlClass: 'ui-datepicker-rtl', multiClass: 'ui-datepicker-multi', defaultClass: 'ui-state-default', selectedClass: 'ui-state-active', highlightedClass: 'ui-state-hover', todayClass: 'ui-state-highlight', otherMonthClass: 'ui-datepicker-other-month', weekendClass: 'ui-datepicker-week-end', commandClass: 'ui-datepicker-cmd', commandButtonClass: 'ui-state-default ui-corner-all', commandLinkClass: '', disabledClass: 'ui-datepicker-disabled' }; $.extend($.datepick, { // Template for generating a datepicker showing week of year. weekOfYearRenderer: $.extend({}, $.datepick.defaultRenderer, { weekHeader: '' + '{l10n:weekText}{days}', week: '{weekOfYear}{days}' }), // 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 = ''; html = $(html).insertAfter(picker.find('div.datepick-nav,div.ui-datepicker-header:first')); html.find('a').click(function() { var date = target.datepick('retrieveDate', this); target.datepick('showMonth', date.getFullYear(), date.getMonth() + 1); return false; }); picker.find('div.datepick-month-header,div.ui-datepicker-month-header').click(function() { html.slideToggle(); }).css('cursor', 'pointer'); }, /* Select an entire week when clicking on a week number. Use in conjunction with weekOfYearRenderer or themeRollerWeekOfYearRenderer. Usage: onShow: $.datepick.selectWeek. @param picker (jQuery) the completed datepicker division @param inst (object) the current instance settings */ selectWeek: function(picker, inst) { var target = $(this); picker.find('td.datepick-week span,td.ui-state-hover span').each(function() { $('' + $(this).text() + ''). click(function() { var date = target.datepick('retrieveDate', this); var dates = [date]; for (var i = 1; i < 7; i++) { dates.push(date = $.datepick.add($.datepick.newDate(date), 1, 'd')); } if (inst.options.rangeSelect) { dates.splice(1, dates.length - 2); } target.datepick('setDate', dates).datepick('hide'); }). replaceAll(this); }); }, /* Select an entire month when clicking on the week header. Use in conjunction with weekOfYearRenderer or themeRollerWeekOfYearRenderer. Usage: onShow: $.datepick.selectMonth. @param picker (jQuery) the completed datepicker division @param inst (object) the current instance settings */ selectMonth: function(picker, inst) { var target = $(this); picker.find('th.datepick-week span,th.ui-state-hover span').each(function() { $('' + $(this).text() + ''). click(function() { var date = target.datepick('retrieveDate', $(this).parents('table'). find('td:not(.datepick-week):not(.ui-state-hover) ' + '*:not(.datepick-other-month):not(.ui-datepicker-other-month)')[0]); var dates = [date]; var dim = $.datepick.daysInMonth(date); for (var i = 1; i < dim; i++) { dates.push(date = $.datepick.add($.datepick.newDate(date), 1, 'd')); } if (inst.options.rangeSelect) { dates.splice(1, dates.length - 2); } target.datepick('setDate', dates).datepick('hide'); }). replaceAll(this); }); }, /* Select a month only instead of a single day. Usage: onShow: $.datepick.monthOnly. @param picker (jQuery) the completed datepicker division @param inst (object) the current instance settings */ monthOnly: function(picker, inst) { var target = $(this); var selectMonth = $('
'). insertAfter(picker.find('.datepick-month-row:last,.ui-datepicker-row-break:last')). children().click(function() { var monthYear = picker.find('.datepick-month-year:first').val().split('/'); target.datepick('setDate', $.datepick.newDate( parseInt(monthYear[1], 10), parseInt(monthYear[0], 10), 1)). datepick('hide'); }); picker.find('.datepick-month-row table,.ui-datepicker-row-break table').remove(); } }); })(jQuery);