1 | | /*! jQuery UI - v1.10.4 - 2014-01-17 |
2 | | * http://jqueryui.com |
3 | | * Copyright 2014 jQuery Foundation and other contributors; Licensed MIT */ |
4 | | (function(t,e){function i(){this._curInst=null,this._keyEvent=!1,this._disabledInputs=[],this._datepickerShowing=!1,this._inDialog=!1,this._mainDivId="ui-datepicker-div",this._inlineClass="ui-datepicker-inline",this._appendClass="ui-datepicker-append",this._triggerClass="ui-datepicker-trigger",this._dialogClass="ui-datepicker-dialog",this._disableClass="ui-datepicker-disabled",this._unselectableClass="ui-datepicker-unselectable",this._currentClass="ui-datepicker-current-day",this._dayOverClass="ui-datepicker-days-cell-over",this.regional=[],this.regional[""]={closeText:"Done",prevText:"Prev",nextText:"Next",currentText:"Today",monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthNamesShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayNamesShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],dayNamesMin:["Su","Mo","Tu","We","Th","Fr","Sa"],weekHeader:"Wk",dateFormat:"mm/dd/yy",firstDay:0,isRTL:!1,showMonthAfterYear:!1,yearSuffix:""},this._defaults={showOn:"focus",showAnim:"fadeIn",showOptions:{},defaultDate:null,appendText:"",buttonText:"...",buttonImage:"",buttonImageOnly:!1,hideIfNoPrevNext:!1,navigationAsDateFormat:!1,gotoCurrent:!1,changeMonth:!1,changeYear:!1,yearRange:"c-10:c+10",showOtherMonths:!1,selectOtherMonths:!1,showWeek:!1,calculateWeek:this.iso8601Week,shortYearCutoff:"+10",minDate:null,maxDate:null,duration:"fast",beforeShowDay:null,beforeShow:null,onSelect:null,onChangeMonthYear:null,onClose:null,numberOfMonths:1,showCurrentAtPos:0,stepMonths:1,stepBigMonths:12,altField:"",altFormat:"",constrainInput:!0,showButtonPanel:!1,autoSize:!1,disabled:!1},t.extend(this._defaults,this.regional[""]),this.dpDiv=s(t("<div id='"+this._mainDivId+"' class='ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>"))}function s(e){var i="button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a";return e.delegate(i,"mouseout",function(){t(this).removeClass("ui-state-hover"),-1!==this.className.indexOf("ui-datepicker-prev")&&t(this).removeClass("ui-datepicker-prev-hover"),-1!==this.className.indexOf("ui-datepicker-next")&&t(this).removeClass("ui-datepicker-next-hover")}).delegate(i,"mouseover",function(){t.datepicker._isDisabledDatepicker(a.inline?e.parent()[0]:a.input[0])||(t(this).parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover"),t(this).addClass("ui-state-hover"),-1!==this.className.indexOf("ui-datepicker-prev")&&t(this).addClass("ui-datepicker-prev-hover"),-1!==this.className.indexOf("ui-datepicker-next")&&t(this).addClass("ui-datepicker-next-hover"))})}function n(e,i){t.extend(e,i);for(var s in i)null==i[s]&&(e[s]=i[s]);return e}t.extend(t.ui,{datepicker:{version:"1.10.4"}});var a,r="datepicker";t.extend(i.prototype,{markerClassName:"hasDatepicker",maxRows:4,_widgetDatepicker:function(){return this.dpDiv},setDefaults:function(t){return n(this._defaults,t||{}),this},_attachDatepicker:function(e,i){var s,n,a;s=e.nodeName.toLowerCase(),n="div"===s||"span"===s,e.id||(this.uuid+=1,e.id="dp"+this.uuid),a=this._newInst(t(e),n),a.settings=t.extend({},i||{}),"input"===s?this._connectDatepicker(e,a):n&&this._inlineDatepicker(e,a)},_newInst:function(e,i){var n=e[0].id.replace(/([^A-Za-z0-9_\-])/g,"\\\\$1");return{id:n,input:e,selectedDay:0,selectedMonth:0,selectedYear:0,drawMonth:0,drawYear:0,inline:i,dpDiv:i?s(t("<div class='"+this._inlineClass+" ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>")):this.dpDiv}},_connectDatepicker:function(e,i){var s=t(e);i.append=t([]),i.trigger=t([]),s.hasClass(this.markerClassName)||(this._attachments(s,i),s.addClass(this.markerClassName).keydown(this._doKeyDown).keypress(this._doKeyPress).keyup(this._doKeyUp),this._autoSize(i),t.data(e,r,i),i.settings.disabled&&this._disableDatepicker(e))},_attachments:function(e,i){var s,n,a,r=this._get(i,"appendText"),o=this._get(i,"isRTL");i.append&&i.append.remove(),r&&(i.append=t("<span class='"+this._appendClass+"'>"+r+"</span>"),e[o?"before":"after"](i.append)),e.unbind("focus",this._showDatepicker),i.trigger&&i.trigger.remove(),s=this._get(i,"showOn"),("focus"===s||"both"===s)&&e.focus(this._showDatepicker),("button"===s||"both"===s)&&(n=this._get(i,"buttonText"),a=this._get(i,"buttonImage"),i.trigger=t(this._get(i,"buttonImageOnly")?t("<img/>").addClass(this._triggerClass).attr({src:a,alt:n,title:n}):t("<button type='button'></button>").addClass(this._triggerClass).html(a?t("<img/>").attr({src:a,alt:n,title:n}):n)),e[o?"before":"after"](i.trigger),i.trigger.click(function(){return t.datepicker._datepickerShowing&&t.datepicker._lastInput===e[0]?t.datepicker._hideDatepicker():t.datepicker._datepickerShowing&&t.datepicker._lastInput!==e[0]?(t.datepicker._hideDatepicker(),t.datepicker._showDatepicker(e[0])):t.datepicker._showDatepicker(e[0]),!1}))},_autoSize:function(t){if(this._get(t,"autoSize")&&!t.inline){var e,i,s,n,a=new Date(2009,11,20),r=this._get(t,"dateFormat");r.match(/[DM]/)&&(e=function(t){for(i=0,s=0,n=0;t.length>n;n++)t[n].length>i&&(i=t[n].length,s=n);return s},a.setMonth(e(this._get(t,r.match(/MM/)?"monthNames":"monthNamesShort"))),a.setDate(e(this._get(t,r.match(/DD/)?"dayNames":"dayNamesShort"))+20-a.getDay())),t.input.attr("size",this._formatDate(t,a).length)}},_inlineDatepicker:function(e,i){var s=t(e);s.hasClass(this.markerClassName)||(s.addClass(this.markerClassName).append(i.dpDiv),t.data(e,r,i),this._setDate(i,this._getDefaultDate(i),!0),this._updateDatepicker(i),this._updateAlternate(i),i.settings.disabled&&this._disableDatepicker(e),i.dpDiv.css("display","block"))},_dialogDatepicker:function(e,i,s,a,o){var h,l,c,u,d,p=this._dialogInst;return p||(this.uuid+=1,h="dp"+this.uuid,this._dialogInput=t("<input type='text' id='"+h+"' style='position: absolute; top: -100px; width: 0px;'/>"),this._dialogInput.keydown(this._doKeyDown),t("body").append(this._dialogInput),p=this._dialogInst=this._newInst(this._dialogInput,!1),p.settings={},t.data(this._dialogInput[0],r,p)),n(p.settings,a||{}),i=i&&i.constructor===Date?this._formatDate(p,i):i,this._dialogInput.val(i),this._pos=o?o.length?o:[o.pageX,o.pageY]:null,this._pos||(l=document.documentElement.clientWidth,c=document.documentElement.clientHeight,u=document.documentElement.scrollLeft||document.body.scrollLeft,d=document.documentElement.scrollTop||document.body.scrollTop,this._pos=[l/2-100+u,c/2-150+d]),this._dialogInput.css("left",this._pos[0]+20+"px").css("top",this._pos[1]+"px"),p.settings.onSelect=s,this._inDialog=!0,this.dpDiv.addClass(this._dialogClass),this._showDatepicker(this._dialogInput[0]),t.blockUI&&t.blockUI(this.dpDiv),t.data(this._dialogInput[0],r,p),this},_destroyDatepicker:function(e){var i,s=t(e),n=t.data(e,r);s.hasClass(this.markerClassName)&&(i=e.nodeName.toLowerCase(),t.removeData(e,r),"input"===i?(n.append.remove(),n.trigger.remove(),s.removeClass(this.markerClassName).unbind("focus",this._showDatepicker).unbind("keydown",this._doKeyDown).unbind("keypress",this._doKeyPress).unbind("keyup",this._doKeyUp)):("div"===i||"span"===i)&&s.removeClass(this.markerClassName).empty())},_enableDatepicker:function(e){var i,s,n=t(e),a=t.data(e,r);n.hasClass(this.markerClassName)&&(i=e.nodeName.toLowerCase(),"input"===i?(e.disabled=!1,a.trigger.filter("button").each(function(){this.disabled=!1}).end().filter("img").css({opacity:"1.0",cursor:""})):("div"===i||"span"===i)&&(s=n.children("."+this._inlineClass),s.children().removeClass("ui-state-disabled"),s.find("select.ui-datepicker-month, select.ui-datepicker-year").prop("disabled",!1)),this._disabledInputs=t.map(this._disabledInputs,function(t){return t===e?null:t}))},_disableDatepicker:function(e){var i,s,n=t(e),a=t.data(e,r);n.hasClass(this.markerClassName)&&(i=e.nodeName.toLowerCase(),"input"===i?(e.disabled=!0,a.trigger.filter("button").each(function(){this.disabled=!0}).end().filter("img").css({opacity:"0.5",cursor:"default"})):("div"===i||"span"===i)&&(s=n.children("."+this._inlineClass),s.children().addClass("ui-state-disabled"),s.find("select.ui-datepicker-month, select.ui-datepicker-year").prop("disabled",!0)),this._disabledInputs=t.map(this._disabledInputs,function(t){return t===e?null:t}),this._disabledInputs[this._disabledInputs.length]=e)},_isDisabledDatepicker:function(t){if(!t)return!1;for(var e=0;this._disabledInputs.length>e;e++)if(this._disabledInputs[e]===t)return!0;return!1},_getInst:function(e){try{return t.data(e,r)}catch(i){throw"Missing instance data for this datepicker"}},_optionDatepicker:function(i,s,a){var r,o,h,l,c=this._getInst(i);return 2===arguments.length&&"string"==typeof s?"defaults"===s?t.extend({},t.datepicker._defaults):c?"all"===s?t.extend({},c.settings):this._get(c,s):null:(r=s||{},"string"==typeof s&&(r={},r[s]=a),c&&(this._curInst===c&&this._hideDatepicker(),o=this._getDateDatepicker(i,!0),h=this._getMinMaxDate(c,"min"),l=this._getMinMaxDate(c,"max"),n(c.settings,r),null!==h&&r.dateFormat!==e&&r.minDate===e&&(c.settings.minDate=this._formatDate(c,h)),null!==l&&r.dateFormat!==e&&r.maxDate===e&&(c.settings.maxDate=this._formatDate(c,l)),"disabled"in r&&(r.disabled?this._disableDatepicker(i):this._enableDatepicker(i)),this._attachments(t(i),c),this._autoSize(c),this._setDate(c,o),this._updateAlternate(c),this._updateDatepicker(c)),e)},_changeDatepicker:function(t,e,i){this._optionDatepicker(t,e,i)},_refreshDatepicker:function(t){var e=this._getInst(t);e&&this._updateDatepicker(e)},_setDateDatepicker:function(t,e){var i=this._getInst(t);i&&(this._setDate(i,e),this._updateDatepicker(i),this._updateAlternate(i))},_getDateDatepicker:function(t,e){var i=this._getInst(t);return i&&!i.inline&&this._setDateFromField(i,e),i?this._getDate(i):null},_doKeyDown:function(e){var i,s,n,a=t.datepicker._getInst(e.target),r=!0,o=a.dpDiv.is(".ui-datepicker-rtl");if(a._keyEvent=!0,t.datepicker._datepickerShowing)switch(e.keyCode){case 9:t.datepicker._hideDatepicker(),r=!1;break;case 13:return n=t("td."+t.datepicker._dayOverClass+":not(."+t.datepicker._currentClass+")",a.dpDiv),n[0]&&t.datepicker._selectDay(e.target,a.selectedMonth,a.selectedYear,n[0]),i=t.datepicker._get(a,"onSelect"),i?(s=t.datepicker._formatDate(a),i.apply(a.input?a.input[0]:null,[s,a])):t.datepicker._hideDatepicker(),!1;case 27:t.datepicker._hideDatepicker();break;case 33:t.datepicker._adjustDate(e.target,e.ctrlKey?-t.datepicker._get(a,"stepBigMonths"):-t.datepicker._get(a,"stepMonths"),"M");break;case 34:t.datepicker._adjustDate(e.target,e.ctrlKey?+t.datepicker._get(a,"stepBigMonths"):+t.datepicker._get(a,"stepMonths"),"M");break;case 35:(e.ctrlKey||e.metaKey)&&t.datepicker._clearDate(e.target),r=e.ctrlKey||e.metaKey;break;case 36:(e.ctrlKey||e.metaKey)&&t.datepicker._gotoToday(e.target),r=e.ctrlKey||e.metaKey;break;case 37:(e.ctrlKey||e.metaKey)&&t.datepicker._adjustDate(e.target,o?1:-1,"D"),r=e.ctrlKey||e.metaKey,e.originalEvent.altKey&&t.datepicker._adjustDate(e.target,e.ctrlKey?-t.datepicker._get(a,"stepBigMonths"):-t.datepicker._get(a,"stepMonths"),"M");break;case 38:(e.ctrlKey||e.metaKey)&&t.datepicker._adjustDate(e.target,-7,"D"),r=e.ctrlKey||e.metaKey;break;case 39:(e.ctrlKey||e.metaKey)&&t.datepicker._adjustDate(e.target,o?-1:1,"D"),r=e.ctrlKey||e.metaKey,e.originalEvent.altKey&&t.datepicker._adjustDate(e.target,e.ctrlKey?+t.datepicker._get(a,"stepBigMonths"):+t.datepicker._get(a,"stepMonths"),"M");break;case 40:(e.ctrlKey||e.metaKey)&&t.datepicker._adjustDate(e.target,7,"D"),r=e.ctrlKey||e.metaKey;break;default:r=!1}else 36===e.keyCode&&e.ctrlKey?t.datepicker._showDatepicker(this):r=!1;r&&(e.preventDefault(),e.stopPropagation())},_doKeyPress:function(i){var s,n,a=t.datepicker._getInst(i.target);return t.datepicker._get(a,"constrainInput")?(s=t.datepicker._possibleChars(t.datepicker._get(a,"dateFormat")),n=String.fromCharCode(null==i.charCode?i.keyCode:i.charCode),i.ctrlKey||i.metaKey||" ">n||!s||s.indexOf(n)>-1):e},_doKeyUp:function(e){var i,s=t.datepicker._getInst(e.target);if(s.input.val()!==s.lastVal)try{i=t.datepicker.parseDate(t.datepicker._get(s,"dateFormat"),s.input?s.input.val():null,t.datepicker._getFormatConfig(s)),i&&(t.datepicker._setDateFromField(s),t.datepicker._updateAlternate(s),t.datepicker._updateDatepicker(s))}catch(n){}return!0},_showDatepicker:function(e){if(e=e.target||e,"input"!==e.nodeName.toLowerCase()&&(e=t("input",e.parentNode)[0]),!t.datepicker._isDisabledDatepicker(e)&&t.datepicker._lastInput!==e){var i,s,a,r,o,h,l;i=t.datepicker._getInst(e),t.datepicker._curInst&&t.datepicker._curInst!==i&&(t.datepicker._curInst.dpDiv.stop(!0,!0),i&&t.datepicker._datepickerShowing&&t.datepicker._hideDatepicker(t.datepicker._curInst.input[0])),s=t.datepicker._get(i,"beforeShow"),a=s?s.apply(e,[e,i]):{},a!==!1&&(n(i.settings,a),i.lastVal=null,t.datepicker._lastInput=e,t.datepicker._setDateFromField(i),t.datepicker._inDialog&&(e.value=""),t.datepicker._pos||(t.datepicker._pos=t.datepicker._findPos(e),t.datepicker._pos[1]+=e.offsetHeight),r=!1,t(e).parents().each(function(){return r|="fixed"===t(this).css("position"),!r}),o={left:t.datepicker._pos[0],top:t.datepicker._pos[1]},t.datepicker._pos=null,i.dpDiv.empty(),i.dpDiv.css({position:"absolute",display:"block",top:"-1000px"}),t.datepicker._updateDatepicker(i),o=t.datepicker._checkOffset(i,o,r),i.dpDiv.css({position:t.datepicker._inDialog&&t.blockUI?"static":r?"fixed":"absolute",display:"none",left:o.left+"px",top:o.top+"px"}),i.inline||(h=t.datepicker._get(i,"showAnim"),l=t.datepicker._get(i,"duration"),i.dpDiv.zIndex(t(e).zIndex()+1),t.datepicker._datepickerShowing=!0,t.effects&&t.effects.effect[h]?i.dpDiv.show(h,t.datepicker._get(i,"showOptions"),l):i.dpDiv[h||"show"](h?l:null),t.datepicker._shouldFocusInput(i)&&i.input.focus(),t.datepicker._curInst=i))}},_updateDatepicker:function(e){this.maxRows=4,a=e,e.dpDiv.empty().append(this._generateHTML(e)),this._attachHandlers(e),e.dpDiv.find("."+this._dayOverClass+" a").mouseover();var i,s=this._getNumberOfMonths(e),n=s[1],r=17;e.dpDiv.removeClass("ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4").width(""),n>1&&e.dpDiv.addClass("ui-datepicker-multi-"+n).css("width",r*n+"em"),e.dpDiv[(1!==s[0]||1!==s[1]?"add":"remove")+"Class"]("ui-datepicker-multi"),e.dpDiv[(this._get(e,"isRTL")?"add":"remove")+"Class"]("ui-datepicker-rtl"),e===t.datepicker._curInst&&t.datepicker._datepickerShowing&&t.datepicker._shouldFocusInput(e)&&e.input.focus(),e.yearshtml&&(i=e.yearshtml,setTimeout(function(){i===e.yearshtml&&e.yearshtml&&e.dpDiv.find("select.ui-datepicker-year:first").replaceWith(e.yearshtml),i=e.yearshtml=null},0))},_shouldFocusInput:function(t){return t.input&&t.input.is(":visible")&&!t.input.is(":disabled")&&!t.input.is(":focus")},_checkOffset:function(e,i,s){var n=e.dpDiv.outerWidth(),a=e.dpDiv.outerHeight(),r=e.input?e.input.outerWidth():0,o=e.input?e.input.outerHeight():0,h=document.documentElement.clientWidth+(s?0:t(document).scrollLeft()),l=document.documentElement.clientHeight+(s?0:t(document).scrollTop());return i.left-=this._get(e,"isRTL")?n-r:0,i.left-=s&&i.left===e.input.offset().left?t(document).scrollLeft():0,i.top-=s&&i.top===e.input.offset().top+o?t(document).scrollTop():0,i.left-=Math.min(i.left,i.left+n>h&&h>n?Math.abs(i.left+n-h):0),i.top-=Math.min(i.top,i.top+a>l&&l>a?Math.abs(a+o):0),i},_findPos:function(e){for(var i,s=this._getInst(e),n=this._get(s,"isRTL");e&&("hidden"===e.type||1!==e.nodeType||t.expr.filters.hidden(e));)e=e[n?"previousSibling":"nextSibling"];return i=t(e).offset(),[i.left,i.top]},_hideDatepicker:function(e){var i,s,n,a,o=this._curInst;!o||e&&o!==t.data(e,r)||this._datepickerShowing&&(i=this._get(o,"showAnim"),s=this._get(o,"duration"),n=function(){t.datepicker._tidyDialog(o)},t.effects&&(t.effects.effect[i]||t.effects[i])?o.dpDiv.hide(i,t.datepicker._get(o,"showOptions"),s,n):o.dpDiv["slideDown"===i?"slideUp":"fadeIn"===i?"fadeOut":"hide"](i?s:null,n),i||n(),this._datepickerShowing=!1,a=this._get(o,"onClose"),a&&a.apply(o.input?o.input[0]:null,[o.input?o.input.val():"",o]),this._lastInput=null,this._inDialog&&(this._dialogInput.css({position:"absolute",left:"0",top:"-100px"}),t.blockUI&&(t.unblockUI(),t("body").append(this.dpDiv))),this._inDialog=!1)},_tidyDialog:function(t){t.dpDiv.removeClass(this._dialogClass).unbind(".ui-datepicker-calendar")},_checkExternalClick:function(e){if(t.datepicker._curInst){var i=t(e.target),s=t.datepicker._getInst(i[0]);(i[0].id!==t.datepicker._mainDivId&&0===i.parents("#"+t.datepicker._mainDivId).length&&!i.hasClass(t.datepicker.markerClassName)&&!i.closest("."+t.datepicker._triggerClass).length&&t.datepicker._datepickerShowing&&(!t.datepicker._inDialog||!t.blockUI)||i.hasClass(t.datepicker.markerClassName)&&t.datepicker._curInst!==s)&&t.datepicker._hideDatepicker()}},_adjustDate:function(e,i,s){var n=t(e),a=this._getInst(n[0]);this._isDisabledDatepicker(n[0])||(this._adjustInstDate(a,i+("M"===s?this._get(a,"showCurrentAtPos"):0),s),this._updateDatepicker(a))},_gotoToday:function(e){var i,s=t(e),n=this._getInst(s[0]);this._get(n,"gotoCurrent")&&n.currentDay?(n.selectedDay=n.currentDay,n.drawMonth=n.selectedMonth=n.currentMonth,n.drawYear=n.selectedYear=n.currentYear):(i=new Date,n.selectedDay=i.getDate(),n.drawMonth=n.selectedMonth=i.getMonth(),n.drawYear=n.selectedYear=i.getFullYear()),this._notifyChange(n),this._adjustDate(s)},_selectMonthYear:function(e,i,s){var n=t(e),a=this._getInst(n[0]);a["selected"+("M"===s?"Month":"Year")]=a["draw"+("M"===s?"Month":"Year")]=parseInt(i.options[i.selectedIndex].value,10),this._notifyChange(a),this._adjustDate(n)},_selectDay:function(e,i,s,n){var a,r=t(e);t(n).hasClass(this._unselectableClass)||this._isDisabledDatepicker(r[0])||(a=this._getInst(r[0]),a.selectedDay=a.currentDay=t("a",n).html(),a.selectedMonth=a.currentMonth=i,a.selectedYear=a.currentYear=s,this._selectDate(e,this._formatDate(a,a.currentDay,a.currentMonth,a.currentYear)))},_clearDate:function(e){var i=t(e);this._selectDate(i,"")},_selectDate:function(e,i){var s,n=t(e),a=this._getInst(n[0]);i=null!=i?i:this._formatDate(a),a.input&&a.input.val(i),this._updateAlternate(a),s=this._get(a,"onSelect"),s?s.apply(a.input?a.input[0]:null,[i,a]):a.input&&a.input.trigger("change"),a.inline?this._updateDatepicker(a):(this._hideDatepicker(),this._lastInput=a.input[0],"object"!=typeof a.input[0]&&a.input.focus(),this._lastInput=null)},_updateAlternate:function(e){var i,s,n,a=this._get(e,"altField");a&&(i=this._get(e,"altFormat")||this._get(e,"dateFormat"),s=this._getDate(e),n=this.formatDate(i,s,this._getFormatConfig(e)),t(a).each(function(){t(this).val(n)}))},noWeekends:function(t){var e=t.getDay();return[e>0&&6>e,""]},iso8601Week:function(t){var e,i=new Date(t.getTime());return i.setDate(i.getDate()+4-(i.getDay()||7)),e=i.getTime(),i.setMonth(0),i.setDate(1),Math.floor(Math.round((e-i)/864e5)/7)+1},parseDate:function(i,s,n){if(null==i||null==s)throw"Invalid arguments";if(s="object"==typeof s?""+s:s+"",""===s)return null;var a,r,o,h,l=0,c=(n?n.shortYearCutoff:null)||this._defaults.shortYearCutoff,u="string"!=typeof c?c:(new Date).getFullYear()%100+parseInt(c,10),d=(n?n.dayNamesShort:null)||this._defaults.dayNamesShort,p=(n?n.dayNames:null)||this._defaults.dayNames,f=(n?n.monthNamesShort:null)||this._defaults.monthNamesShort,m=(n?n.monthNames:null)||this._defaults.monthNames,g=-1,v=-1,_=-1,b=-1,y=!1,x=function(t){var e=i.length>a+1&&i.charAt(a+1)===t;return e&&a++,e},k=function(t){var e=x(t),i="@"===t?14:"!"===t?20:"y"===t&&e?4:"o"===t?3:2,n=RegExp("^\\d{1,"+i+"}"),a=s.substring(l).match(n);if(!a)throw"Missing number at position "+l;return l+=a[0].length,parseInt(a[0],10)},w=function(i,n,a){var r=-1,o=t.map(x(i)?a:n,function(t,e){return[[e,t]]}).sort(function(t,e){return-(t[1].length-e[1].length)});if(t.each(o,function(t,i){var n=i[1];return s.substr(l,n.length).toLowerCase()===n.toLowerCase()?(r=i[0],l+=n.length,!1):e}),-1!==r)return r+1;throw"Unknown name at position "+l},D=function(){if(s.charAt(l)!==i.charAt(a))throw"Unexpected literal at position "+l;l++};for(a=0;i.length>a;a++)if(y)"'"!==i.charAt(a)||x("'")?D():y=!1;else switch(i.charAt(a)){case"d":_=k("d");break;case"D":w("D",d,p);break;case"o":b=k("o");break;case"m":v=k("m");break;case"M":v=w("M",f,m);break;case"y":g=k("y");break;case"@":h=new Date(k("@")),g=h.getFullYear(),v=h.getMonth()+1,_=h.getDate();break;case"!":h=new Date((k("!")-this._ticksTo1970)/1e4),g=h.getFullYear(),v=h.getMonth()+1,_=h.getDate();break;case"'":x("'")?D():y=!0;break;default:D()}if(s.length>l&&(o=s.substr(l),!/^\s+/.test(o)))throw"Extra/unparsed characters found in date: "+o;if(-1===g?g=(new Date).getFullYear():100>g&&(g+=(new Date).getFullYear()-(new Date).getFullYear()%100+(u>=g?0:-100)),b>-1)for(v=1,_=b;;){if(r=this._getDaysInMonth(g,v-1),r>=_)break;v++,_-=r}if(h=this._daylightSavingAdjust(new Date(g,v-1,_)),h.getFullYear()!==g||h.getMonth()+1!==v||h.getDate()!==_)throw"Invalid date";return h},ATOM:"yy-mm-dd",COOKIE:"D, dd M yy",ISO_8601:"yy-mm-dd",RFC_822:"D, d M y",RFC_850:"DD, dd-M-y",RFC_1036:"D, d M y",RFC_1123:"D, d M yy",RFC_2822:"D, d M yy",RSS:"D, d M y",TICKS:"!",TIMESTAMP:"@",W3C:"yy-mm-dd",_ticksTo1970:1e7*60*60*24*(718685+Math.floor(492.5)-Math.floor(19.7)+Math.floor(4.925)),formatDate:function(t,e,i){if(!e)return"";var s,n=(i?i.dayNamesShort:null)||this._defaults.dayNamesShort,a=(i?i.dayNames:null)||this._defaults.dayNames,r=(i?i.monthNamesShort:null)||this._defaults.monthNamesShort,o=(i?i.monthNames:null)||this._defaults.monthNames,h=function(e){var i=t.length>s+1&&t.charAt(s+1)===e;return i&&s++,i},l=function(t,e,i){var s=""+e;if(h(t))for(;i>s.length;)s="0"+s;return s},c=function(t,e,i,s){return h(t)?s[e]:i[e]},u="",d=!1;if(e)for(s=0;t.length>s;s++)if(d)"'"!==t.charAt(s)||h("'")?u+=t.charAt(s):d=!1;else switch(t.charAt(s)){case"d":u+=l("d",e.getDate(),2);break;case"D":u+=c("D",e.getDay(),n,a);break;case"o":u+=l("o",Math.round((new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()-new Date(e.getFullYear(),0,0).getTime())/864e5),3);break;case"m":u+=l("m",e.getMonth()+1,2);break;case"M":u+=c("M",e.getMonth(),r,o);break;case"y":u+=h("y")?e.getFullYear():(10>e.getYear()%100?"0":"")+e.getYear()%100;break;case"@":u+=e.getTime();break;case"!":u+=1e4*e.getTime()+this._ticksTo1970;break;case"'":h("'")?u+="'":d=!0;break;default:u+=t.charAt(s)}return u},_possibleChars:function(t){var e,i="",s=!1,n=function(i){var s=t.length>e+1&&t.charAt(e+1)===i;return s&&e++,s};for(e=0;t.length>e;e++)if(s)"'"!==t.charAt(e)||n("'")?i+=t.charAt(e):s=!1;else switch(t.charAt(e)){case"d":case"m":case"y":case"@":i+="0123456789";break;case"D":case"M":return null;case"'":n("'")?i+="'":s=!0;break;default:i+=t.charAt(e)}return i},_get:function(t,i){return t.settings[i]!==e?t.settings[i]:this._defaults[i]},_setDateFromField:function(t,e){if(t.input.val()!==t.lastVal){var i=this._get(t,"dateFormat"),s=t.lastVal=t.input?t.input.val():null,n=this._getDefaultDate(t),a=n,r=this._getFormatConfig(t);try{a=this.parseDate(i,s,r)||n}catch(o){s=e?"":s}t.selectedDay=a.getDate(),t.drawMonth=t.selectedMonth=a.getMonth(),t.drawYear=t.selectedYear=a.getFullYear(),t.currentDay=s?a.getDate():0,t.currentMonth=s?a.getMonth():0,t.currentYear=s?a.getFullYear():0,this._adjustInstDate(t)}},_getDefaultDate:function(t){return this._restrictMinMax(t,this._determineDate(t,this._get(t,"defaultDate"),new Date))},_determineDate:function(e,i,s){var n=function(t){var e=new Date;return e.setDate(e.getDate()+t),e},a=function(i){try{return t.datepicker.parseDate(t.datepicker._get(e,"dateFormat"),i,t.datepicker._getFormatConfig(e))}catch(s){}for(var n=(i.toLowerCase().match(/^c/)?t.datepicker._getDate(e):null)||new Date,a=n.getFullYear(),r=n.getMonth(),o=n.getDate(),h=/([+\-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g,l=h.exec(i);l;){switch(l[2]||"d"){case"d":case"D":o+=parseInt(l[1],10);break;case"w":case"W":o+=7*parseInt(l[1],10);break;case"m":case"M":r+=parseInt(l[1],10),o=Math.min(o,t.datepicker._getDaysInMonth(a,r));break;case"y":case"Y":a+=parseInt(l[1],10),o=Math.min(o,t.datepicker._getDaysInMonth(a,r))}l=h.exec(i)}return new Date(a,r,o)},r=null==i||""===i?s:"string"==typeof i?a(i):"number"==typeof i?isNaN(i)?s:n(i):new Date(i.getTime());return r=r&&"Invalid Date"==""+r?s:r,r&&(r.setHours(0),r.setMinutes(0),r.setSeconds(0),r.setMilliseconds(0)),this._daylightSavingAdjust(r)},_daylightSavingAdjust:function(t){return t?(t.setHours(t.getHours()>12?t.getHours()+2:0),t):null},_setDate:function(t,e,i){var s=!e,n=t.selectedMonth,a=t.selectedYear,r=this._restrictMinMax(t,this._determineDate(t,e,new Date));t.selectedDay=t.currentDay=r.getDate(),t.drawMonth=t.selectedMonth=t.currentMonth=r.getMonth(),t.drawYear=t.selectedYear=t.currentYear=r.getFullYear(),n===t.selectedMonth&&a===t.selectedYear||i||this._notifyChange(t),this._adjustInstDate(t),t.input&&t.input.val(s?"":this._formatDate(t))},_getDate:function(t){var e=!t.currentYear||t.input&&""===t.input.val()?null:this._daylightSavingAdjust(new Date(t.currentYear,t.currentMonth,t.currentDay));return e},_attachHandlers:function(e){var i=this._get(e,"stepMonths"),s="#"+e.id.replace(/\\\\/g,"\\");e.dpDiv.find("[data-handler]").map(function(){var e={prev:function(){t.datepicker._adjustDate(s,-i,"M")},next:function(){t.datepicker._adjustDate(s,+i,"M")},hide:function(){t.datepicker._hideDatepicker()},today:function(){t.datepicker._gotoToday(s)},selectDay:function(){return t.datepicker._selectDay(s,+this.getAttribute("data-month"),+this.getAttribute("data-year"),this),!1},selectMonth:function(){return t.datepicker._selectMonthYear(s,this,"M"),!1},selectYear:function(){return t.datepicker._selectMonthYear(s,this,"Y"),!1}};t(this).bind(this.getAttribute("data-event"),e[this.getAttribute("data-handler")])})},_generateHTML:function(t){var e,i,s,n,a,r,o,h,l,c,u,d,p,f,m,g,v,_,b,y,x,k,w,D,T,C,S,M,N,I,P,A,z,H,E,F,O,j,W,R=new Date,L=this._daylightSavingAdjust(new Date(R.getFullYear(),R.getMonth(),R.getDate())),Y=this._get(t,"isRTL"),B=this._get(t,"showButtonPanel"),K=this._get(t,"hideIfNoPrevNext"),J=this._get(t,"navigationAsDateFormat"),Q=this._getNumberOfMonths(t),V=this._get(t,"showCurrentAtPos"),U=this._get(t,"stepMonths"),q=1!==Q[0]||1!==Q[1],X=this._daylightSavingAdjust(t.currentDay?new Date(t.currentYear,t.currentMonth,t.currentDay):new Date(9999,9,9)),G=this._getMinMaxDate(t,"min"),$=this._getMinMaxDate(t,"max"),Z=t.drawMonth-V,te=t.drawYear;if(0>Z&&(Z+=12,te--),$)for(e=this._daylightSavingAdjust(new Date($.getFullYear(),$.getMonth()-Q[0]*Q[1]+1,$.getDate())),e=G&&G>e?G:e;this._daylightSavingAdjust(new Date(te,Z,1))>e;)Z--,0>Z&&(Z=11,te--);for(t.drawMonth=Z,t.drawYear=te,i=this._get(t,"prevText"),i=J?this.formatDate(i,this._daylightSavingAdjust(new Date(te,Z-U,1)),this._getFormatConfig(t)):i,s=this._canAdjustMonth(t,-1,te,Z)?"<a class='ui-datepicker-prev ui-corner-all' data-handler='prev' data-event='click' title='"+i+"'><span class='ui-icon ui-icon-circle-triangle-"+(Y?"e":"w")+"'>"+i+"</span></a>":K?"":"<a class='ui-datepicker-prev ui-corner-all ui-state-disabled' title='"+i+"'><span class='ui-icon ui-icon-circle-triangle-"+(Y?"e":"w")+"'>"+i+"</span></a>",n=this._get(t,"nextText"),n=J?this.formatDate(n,this._daylightSavingAdjust(new Date(te,Z+U,1)),this._getFormatConfig(t)):n,a=this._canAdjustMonth(t,1,te,Z)?"<a class='ui-datepicker-next ui-corner-all' data-handler='next' data-event='click' title='"+n+"'><span class='ui-icon ui-icon-circle-triangle-"+(Y?"w":"e")+"'>"+n+"</span></a>":K?"":"<a class='ui-datepicker-next ui-corner-all ui-state-disabled' title='"+n+"'><span class='ui-icon ui-icon-circle-triangle-"+(Y?"w":"e")+"'>"+n+"</span></a>",r=this._get(t,"currentText"),o=this._get(t,"gotoCurrent")&&t.currentDay?X:L,r=J?this.formatDate(r,o,this._getFormatConfig(t)):r,h=t.inline?"":"<button type='button' class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all' data-handler='hide' data-event='click'>"+this._get(t,"closeText")+"</button>",l=B?"<div class='ui-datepicker-buttonpane ui-widget-content'>"+(Y?h:"")+(this._isInRange(t,o)?"<button type='button' class='ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all' data-handler='today' data-event='click'>"+r+"</button>":"")+(Y?"":h)+"</div>":"",c=parseInt(this._get(t,"firstDay"),10),c=isNaN(c)?0:c,u=this._get(t,"showWeek"),d=this._get(t,"dayNames"),p=this._get(t,"dayNamesMin"),f=this._get(t,"monthNames"),m=this._get(t,"monthNamesShort"),g=this._get(t,"beforeShowDay"),v=this._get(t,"showOtherMonths"),_=this._get(t,"selectOtherMonths"),b=this._getDefaultDate(t),y="",k=0;Q[0]>k;k++){for(w="",this.maxRows=4,D=0;Q[1]>D;D++){if(T=this._daylightSavingAdjust(new Date(te,Z,t.selectedDay)),C=" ui-corner-all",S="",q){if(S+="<div class='ui-datepicker-group",Q[1]>1)switch(D){case 0:S+=" ui-datepicker-group-first",C=" ui-corner-"+(Y?"right":"left");break;case Q[1]-1:S+=" ui-datepicker-group-last",C=" ui-corner-"+(Y?"left":"right");break;default:S+=" ui-datepicker-group-middle",C=""}S+="'>"}for(S+="<div class='ui-datepicker-header ui-widget-header ui-helper-clearfix"+C+"'>"+(/all|left/.test(C)&&0===k?Y?a:s:"")+(/all|right/.test(C)&&0===k?Y?s:a:"")+this._generateMonthYearHeader(t,Z,te,G,$,k>0||D>0,f,m)+"</div><table class='ui-datepicker-calendar'><thead>"+"<tr>",M=u?"<th class='ui-datepicker-week-col'>"+this._get(t,"weekHeader")+"</th>":"",x=0;7>x;x++)N=(x+c)%7,M+="<th"+((x+c+6)%7>=5?" class='ui-datepicker-week-end'":"")+">"+"<span title='"+d[N]+"'>"+p[N]+"</span></th>";for(S+=M+"</tr></thead><tbody>",I=this._getDaysInMonth(te,Z),te===t.selectedYear&&Z===t.selectedMonth&&(t.selectedDay=Math.min(t.selectedDay,I)),P=(this._getFirstDayOfMonth(te,Z)-c+7)%7,A=Math.ceil((P+I)/7),z=q?this.maxRows>A?this.maxRows:A:A,this.maxRows=z,H=this._daylightSavingAdjust(new Date(te,Z,1-P)),E=0;z>E;E++){for(S+="<tr>",F=u?"<td class='ui-datepicker-week-col'>"+this._get(t,"calculateWeek")(H)+"</td>":"",x=0;7>x;x++)O=g?g.apply(t.input?t.input[0]:null,[H]):[!0,""],j=H.getMonth()!==Z,W=j&&!_||!O[0]||G&&G>H||$&&H>$,F+="<td class='"+((x+c+6)%7>=5?" ui-datepicker-week-end":"")+(j?" ui-datepicker-other-month":"")+(H.getTime()===T.getTime()&&Z===t.selectedMonth&&t._keyEvent||b.getTime()===H.getTime()&&b.getTime()===T.getTime()?" "+this._dayOverClass:"")+(W?" "+this._unselectableClass+" ui-state-disabled":"")+(j&&!v?"":" "+O[1]+(H.getTime()===X.getTime()?" "+this._currentClass:"")+(H.getTime()===L.getTime()?" ui-datepicker-today":""))+"'"+(j&&!v||!O[2]?"":" title='"+O[2].replace(/'/g,"'")+"'")+(W?"":" data-handler='selectDay' data-event='click' data-month='"+H.getMonth()+"' data-year='"+H.getFullYear()+"'")+">"+(j&&!v?" ":W?"<span class='ui-state-default'>"+H.getDate()+"</span>":"<a class='ui-state-default"+(H.getTime()===L.getTime()?" ui-state-highlight":"")+(H.getTime()===X.getTime()?" ui-state-active":"")+(j?" ui-priority-secondary":"")+"' href='#'>"+H.getDate()+"</a>")+"</td>",H.setDate(H.getDate()+1),H=this._daylightSavingAdjust(H);S+=F+"</tr>"}Z++,Z>11&&(Z=0,te++),S+="</tbody></table>"+(q?"</div>"+(Q[0]>0&&D===Q[1]-1?"<div class='ui-datepicker-row-break'></div>":""):""),w+=S}y+=w}return y+=l,t._keyEvent=!1,y},_generateMonthYearHeader:function(t,e,i,s,n,a,r,o){var h,l,c,u,d,p,f,m,g=this._get(t,"changeMonth"),v=this._get(t,"changeYear"),_=this._get(t,"showMonthAfterYear"),b="<div class='ui-datepicker-title'>",y="";if(a||!g)y+="<span class='ui-datepicker-month'>"+r[e]+"</span>";else{for(h=s&&s.getFullYear()===i,l=n&&n.getFullYear()===i,y+="<select class='ui-datepicker-month' data-handler='selectMonth' data-event='change'>",c=0;12>c;c++)(!h||c>=s.getMonth())&&(!l||n.getMonth()>=c)&&(y+="<option value='"+c+"'"+(c===e?" selected='selected'":"")+">"+o[c]+"</option>");y+="</select>"}if(_||(b+=y+(!a&&g&&v?"":" ")),!t.yearshtml)if(t.yearshtml="",a||!v)b+="<span class='ui-datepicker-year'>"+i+"</span>";else{for(u=this._get(t,"yearRange").split(":"),d=(new Date).getFullYear(),p=function(t){var e=t.match(/c[+\-].*/)?i+parseInt(t.substring(1),10):t.match(/[+\-].*/)?d+parseInt(t,10):parseInt(t,10); |
5 | | return isNaN(e)?d:e},f=p(u[0]),m=Math.max(f,p(u[1]||"")),f=s?Math.max(f,s.getFullYear()):f,m=n?Math.min(m,n.getFullYear()):m,t.yearshtml+="<select class='ui-datepicker-year' data-handler='selectYear' data-event='change'>";m>=f;f++)t.yearshtml+="<option value='"+f+"'"+(f===i?" selected='selected'":"")+">"+f+"</option>";t.yearshtml+="</select>",b+=t.yearshtml,t.yearshtml=null}return b+=this._get(t,"yearSuffix"),_&&(b+=(!a&&g&&v?"":" ")+y),b+="</div>"},_adjustInstDate:function(t,e,i){var s=t.drawYear+("Y"===i?e:0),n=t.drawMonth+("M"===i?e:0),a=Math.min(t.selectedDay,this._getDaysInMonth(s,n))+("D"===i?e:0),r=this._restrictMinMax(t,this._daylightSavingAdjust(new Date(s,n,a)));t.selectedDay=r.getDate(),t.drawMonth=t.selectedMonth=r.getMonth(),t.drawYear=t.selectedYear=r.getFullYear(),("M"===i||"Y"===i)&&this._notifyChange(t)},_restrictMinMax:function(t,e){var i=this._getMinMaxDate(t,"min"),s=this._getMinMaxDate(t,"max"),n=i&&i>e?i:e;return s&&n>s?s:n},_notifyChange:function(t){var e=this._get(t,"onChangeMonthYear");e&&e.apply(t.input?t.input[0]:null,[t.selectedYear,t.selectedMonth+1,t])},_getNumberOfMonths:function(t){var e=this._get(t,"numberOfMonths");return null==e?[1,1]:"number"==typeof e?[1,e]:e},_getMinMaxDate:function(t,e){return this._determineDate(t,this._get(t,e+"Date"),null)},_getDaysInMonth:function(t,e){return 32-this._daylightSavingAdjust(new Date(t,e,32)).getDate()},_getFirstDayOfMonth:function(t,e){return new Date(t,e,1).getDay()},_canAdjustMonth:function(t,e,i,s){var n=this._getNumberOfMonths(t),a=this._daylightSavingAdjust(new Date(i,s+(0>e?e:n[0]*n[1]),1));return 0>e&&a.setDate(this._getDaysInMonth(a.getFullYear(),a.getMonth())),this._isInRange(t,a)},_isInRange:function(t,e){var i,s,n=this._getMinMaxDate(t,"min"),a=this._getMinMaxDate(t,"max"),r=null,o=null,h=this._get(t,"yearRange");return h&&(i=h.split(":"),s=(new Date).getFullYear(),r=parseInt(i[0],10),o=parseInt(i[1],10),i[0].match(/[+\-].*/)&&(r+=s),i[1].match(/[+\-].*/)&&(o+=s)),(!n||e.getTime()>=n.getTime())&&(!a||e.getTime()<=a.getTime())&&(!r||e.getFullYear()>=r)&&(!o||o>=e.getFullYear())},_getFormatConfig:function(t){var e=this._get(t,"shortYearCutoff");return e="string"!=typeof e?e:(new Date).getFullYear()%100+parseInt(e,10),{shortYearCutoff:e,dayNamesShort:this._get(t,"dayNamesShort"),dayNames:this._get(t,"dayNames"),monthNamesShort:this._get(t,"monthNamesShort"),monthNames:this._get(t,"monthNames")}},_formatDate:function(t,e,i,s){e||(t.currentDay=t.selectedDay,t.currentMonth=t.selectedMonth,t.currentYear=t.selectedYear);var n=e?"object"==typeof e?e:this._daylightSavingAdjust(new Date(s,i,e)):this._daylightSavingAdjust(new Date(t.currentYear,t.currentMonth,t.currentDay));return this.formatDate(this._get(t,"dateFormat"),n,this._getFormatConfig(t))}}),t.fn.datepicker=function(e){if(!this.length)return this;t.datepicker.initialized||(t(document).mousedown(t.datepicker._checkExternalClick),t.datepicker.initialized=!0),0===t("#"+t.datepicker._mainDivId).length&&t("body").append(t.datepicker.dpDiv);var i=Array.prototype.slice.call(arguments,1);return"string"!=typeof e||"isDisabled"!==e&&"getDate"!==e&&"widget"!==e?"option"===e&&2===arguments.length&&"string"==typeof arguments[1]?t.datepicker["_"+e+"Datepicker"].apply(t.datepicker,[this[0]].concat(i)):this.each(function(){"string"==typeof e?t.datepicker["_"+e+"Datepicker"].apply(t.datepicker,[this].concat(i)):t.datepicker._attachDatepicker(this,e)}):t.datepicker["_"+e+"Datepicker"].apply(t.datepicker,[this[0]].concat(i))},t.datepicker=new i,t.datepicker.initialized=!1,t.datepicker.uuid=(new Date).getTime(),t.datepicker.version="1.10.4"})(jQuery); |
6 | | No newline at end of file |
| 1 | /*! |
| 2 | * jQuery UI Datepicker 1.11.1 |
| 3 | * http://jqueryui.com |
| 4 | * |
| 5 | * Copyright 2014 jQuery Foundation and other contributors |
| 6 | * Released under the MIT license. |
| 7 | * http://jquery.org/license |
| 8 | * |
| 9 | * http://api.jqueryui.com/datepicker/ |
| 10 | */ |
| 11 | (function( factory ) { |
| 12 | if ( typeof define === "function" && define.amd ) { |
| 13 | |
| 14 | // AMD. Register as an anonymous module. |
| 15 | define([ |
| 16 | "jquery", |
| 17 | "./core" |
| 18 | ], factory ); |
| 19 | } else { |
| 20 | |
| 21 | // Browser globals |
| 22 | factory( jQuery ); |
| 23 | } |
| 24 | }(function( $ ) { |
| 25 | |
| 26 | $.extend($.ui, { datepicker: { version: "1.11.1" } }); |
| 27 | |
| 28 | var datepicker_instActive; |
| 29 | |
| 30 | function datepicker_getZindex( elem ) { |
| 31 | var position, value; |
| 32 | while ( elem.length && elem[ 0 ] !== document ) { |
| 33 | // Ignore z-index if position is set to a value where z-index is ignored by the browser |
| 34 | // This makes behavior of this function consistent across browsers |
| 35 | // WebKit always returns auto if the element is positioned |
| 36 | position = elem.css( "position" ); |
| 37 | if ( position === "absolute" || position === "relative" || position === "fixed" ) { |
| 38 | // IE returns 0 when zIndex is not specified |
| 39 | // other browsers return a string |
| 40 | // we ignore the case of nested elements with an explicit value of 0 |
| 41 | // <div style="z-index: -10;"><div style="z-index: 0;"></div></div> |
| 42 | value = parseInt( elem.css( "zIndex" ), 10 ); |
| 43 | if ( !isNaN( value ) && value !== 0 ) { |
| 44 | return value; |
| 45 | } |
| 46 | } |
| 47 | elem = elem.parent(); |
| 48 | } |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | /* Date picker manager. |
| 53 | Use the singleton instance of this class, $.datepicker, to interact with the date picker. |
| 54 | Settings for (groups of) date pickers are maintained in an instance object, |
| 55 | allowing multiple different settings on the same page. */ |
| 56 | |
| 57 | function Datepicker() { |
| 58 | this._curInst = null; // The current instance in use |
| 59 | this._keyEvent = false; // If the last event was a key event |
| 60 | this._disabledInputs = []; // List of date picker inputs that have been disabled |
| 61 | this._datepickerShowing = false; // True if the popup picker is showing , false if not |
| 62 | this._inDialog = false; // True if showing within a "dialog", false if not |
| 63 | this._mainDivId = "ui-datepicker-div"; // The ID of the main datepicker division |
| 64 | this._inlineClass = "ui-datepicker-inline"; // The name of the inline marker class |
| 65 | this._appendClass = "ui-datepicker-append"; // The name of the append marker class |
| 66 | this._triggerClass = "ui-datepicker-trigger"; // The name of the trigger marker class |
| 67 | this._dialogClass = "ui-datepicker-dialog"; // The name of the dialog marker class |
| 68 | this._disableClass = "ui-datepicker-disabled"; // The name of the disabled covering marker class |
| 69 | this._unselectableClass = "ui-datepicker-unselectable"; // The name of the unselectable cell marker class |
| 70 | this._currentClass = "ui-datepicker-current-day"; // The name of the current day marker class |
| 71 | this._dayOverClass = "ui-datepicker-days-cell-over"; // The name of the day hover marker class |
| 72 | this.regional = []; // Available regional settings, indexed by language code |
| 73 | this.regional[""] = { // Default regional settings |
| 74 | closeText: "Done", // Display text for close link |
| 75 | prevText: "Prev", // Display text for previous month link |
| 76 | nextText: "Next", // Display text for next month link |
| 77 | currentText: "Today", // Display text for current month link |
| 78 | monthNames: ["January","February","March","April","May","June", |
| 79 | "July","August","September","October","November","December"], // Names of months for drop-down and formatting |
| 80 | monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], // For formatting |
| 81 | dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], // For formatting |
| 82 | dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], // For formatting |
| 83 | dayNamesMin: ["Su","Mo","Tu","We","Th","Fr","Sa"], // Column headings for days starting at Sunday |
| 84 | weekHeader: "Wk", // Column header for week of the year |
| 85 | dateFormat: "mm/dd/yy", // See format options on parseDate |
| 86 | firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ... |
| 87 | isRTL: false, // True if right-to-left language, false if left-to-right |
| 88 | showMonthAfterYear: false, // True if the year select precedes month, false for month then year |
| 89 | yearSuffix: "" // Additional text to append to the year in the month headers |
| 90 | }; |
| 91 | this._defaults = { // Global defaults for all the date picker instances |
| 92 | showOn: "focus", // "focus" for popup on focus, |
| 93 | // "button" for trigger button, or "both" for either |
| 94 | showAnim: "fadeIn", // Name of jQuery animation for popup |
| 95 | showOptions: {}, // Options for enhanced animations |
| 96 | defaultDate: null, // Used when field is blank: actual date, |
| 97 | // +/-number for offset from today, null for today |
| 98 | appendText: "", // Display text following the input box, e.g. showing the format |
| 99 | buttonText: "...", // Text for trigger button |
| 100 | buttonImage: "", // URL for trigger button image |
| 101 | buttonImageOnly: false, // True if the image appears alone, false if it appears on a button |
| 102 | hideIfNoPrevNext: false, // True to hide next/previous month links |
| 103 | // if not applicable, false to just disable them |
| 104 | navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links |
| 105 | gotoCurrent: false, // True if today link goes back to current selection instead |
| 106 | changeMonth: false, // True if month can be selected directly, false if only prev/next |
| 107 | changeYear: false, // True if year can be selected directly, false if only prev/next |
| 108 | yearRange: "c-10:c+10", // Range of years to display in drop-down, |
| 109 | // either relative to today's year (-nn:+nn), relative to currently displayed year |
| 110 | // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n) |
| 111 | showOtherMonths: false, // True to show dates in other months, false to leave blank |
| 112 | selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable |
| 113 | showWeek: false, // True to show week of the year, false to not show it |
| 114 | calculateWeek: this.iso8601Week, // How to calculate the week of the year, |
| 115 | // takes a Date and returns the number of the week for it |
| 116 | shortYearCutoff: "+10", // Short year values < this are in the current century, |
| 117 | // > this are in the previous century, |
| 118 | // string value starting with "+" for current year + value |
| 119 | minDate: null, // The earliest selectable date, or null for no limit |
| 120 | maxDate: null, // The latest selectable date, or null for no limit |
| 121 | duration: "fast", // Duration of display/closure |
| 122 | beforeShowDay: null, // Function that takes a date and returns an array with |
| 123 | // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or "", |
| 124 | // [2] = cell title (optional), e.g. $.datepicker.noWeekends |
| 125 | beforeShow: null, // Function that takes an input field and |
| 126 | // returns a set of custom settings for the date picker |
| 127 | onSelect: null, // Define a callback function when a date is selected |
| 128 | onChangeMonthYear: null, // Define a callback function when the month or year is changed |
| 129 | onClose: null, // Define a callback function when the datepicker is closed |
| 130 | numberOfMonths: 1, // Number of months to show at a time |
| 131 | showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0) |
| 132 | stepMonths: 1, // Number of months to step back/forward |
| 133 | stepBigMonths: 12, // Number of months to step back/forward for the big links |
| 134 | altField: "", // Selector for an alternate field to store selected dates into |
| 135 | altFormat: "", // The date format to use for the alternate field |
| 136 | constrainInput: true, // The input is constrained by the current date format |
| 137 | showButtonPanel: false, // True to show button panel, false to not show it |
| 138 | autoSize: false, // True to size the input for the date format, false to leave as is |
| 139 | disabled: false // The initial disabled state |
| 140 | }; |
| 141 | $.extend(this._defaults, this.regional[""]); |
| 142 | this.regional.en = $.extend( true, {}, this.regional[ "" ]); |
| 143 | this.regional[ "en-US" ] = $.extend( true, {}, this.regional.en ); |
| 144 | this.dpDiv = datepicker_bindHover($("<div id='" + this._mainDivId + "' class='ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>")); |
| 145 | } |
| 146 | |
| 147 | $.extend(Datepicker.prototype, { |
| 148 | /* Class name added to elements to indicate already configured with a date picker. */ |
| 149 | markerClassName: "hasDatepicker", |
| 150 | |
| 151 | //Keep track of the maximum number of rows displayed (see #7043) |
| 152 | maxRows: 4, |
| 153 | |
| 154 | // TODO rename to "widget" when switching to widget factory |
| 155 | _widgetDatepicker: function() { |
| 156 | return this.dpDiv; |
| 157 | }, |
| 158 | |
| 159 | /* Override the default settings for all instances of the date picker. |
| 160 | * @param settings object - the new settings to use as defaults (anonymous object) |
| 161 | * @return the manager object |
| 162 | */ |
| 163 | setDefaults: function(settings) { |
| 164 | datepicker_extendRemove(this._defaults, settings || {}); |
| 165 | return this; |
| 166 | }, |
| 167 | |
| 168 | /* Attach the date picker to a jQuery selection. |
| 169 | * @param target element - the target input field or division or span |
| 170 | * @param settings object - the new settings to use for this date picker instance (anonymous) |
| 171 | */ |
| 172 | _attachDatepicker: function(target, settings) { |
| 173 | var nodeName, inline, inst; |
| 174 | nodeName = target.nodeName.toLowerCase(); |
| 175 | inline = (nodeName === "div" || nodeName === "span"); |
| 176 | if (!target.id) { |
| 177 | this.uuid += 1; |
| 178 | target.id = "dp" + this.uuid; |
| 179 | } |
| 180 | inst = this._newInst($(target), inline); |
| 181 | inst.settings = $.extend({}, settings || {}); |
| 182 | if (nodeName === "input") { |
| 183 | this._connectDatepicker(target, inst); |
| 184 | } else if (inline) { |
| 185 | this._inlineDatepicker(target, inst); |
| 186 | } |
| 187 | }, |
| 188 | |
| 189 | /* Create a new instance object. */ |
| 190 | _newInst: function(target, inline) { |
| 191 | var id = target[0].id.replace(/([^A-Za-z0-9_\-])/g, "\\\\$1"); // escape jQuery meta chars |
| 192 | return {id: id, input: target, // associated target |
| 193 | selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection |
| 194 | drawMonth: 0, drawYear: 0, // month being drawn |
| 195 | inline: inline, // is datepicker inline or not |
| 196 | dpDiv: (!inline ? this.dpDiv : // presentation div |
| 197 | datepicker_bindHover($("<div class='" + this._inlineClass + " ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>")))}; |
| 198 | }, |
| 199 | |
| 200 | /* Attach the date picker to an input field. */ |
| 201 | _connectDatepicker: function(target, inst) { |
| 202 | var input = $(target); |
| 203 | inst.append = $([]); |
| 204 | inst.trigger = $([]); |
| 205 | if (input.hasClass(this.markerClassName)) { |
| 206 | return; |
| 207 | } |
| 208 | this._attachments(input, inst); |
| 209 | input.addClass(this.markerClassName).keydown(this._doKeyDown). |
| 210 | keypress(this._doKeyPress).keyup(this._doKeyUp); |
| 211 | this._autoSize(inst); |
| 212 | $.data(target, "datepicker", inst); |
| 213 | //If disabled option is true, disable the datepicker once it has been attached to the input (see ticket #5665) |
| 214 | if( inst.settings.disabled ) { |
| 215 | this._disableDatepicker( target ); |
| 216 | } |
| 217 | }, |
| 218 | |
| 219 | /* Make attachments based on settings. */ |
| 220 | _attachments: function(input, inst) { |
| 221 | var showOn, buttonText, buttonImage, |
| 222 | appendText = this._get(inst, "appendText"), |
| 223 | isRTL = this._get(inst, "isRTL"); |
| 224 | |
| 225 | if (inst.append) { |
| 226 | inst.append.remove(); |
| 227 | } |
| 228 | if (appendText) { |
| 229 | inst.append = $("<span class='" + this._appendClass + "'>" + appendText + "</span>"); |
| 230 | input[isRTL ? "before" : "after"](inst.append); |
| 231 | } |
| 232 | |
| 233 | input.unbind("focus", this._showDatepicker); |
| 234 | |
| 235 | if (inst.trigger) { |
| 236 | inst.trigger.remove(); |
| 237 | } |
| 238 | |
| 239 | showOn = this._get(inst, "showOn"); |
| 240 | if (showOn === "focus" || showOn === "both") { // pop-up date picker when in the marked field |
| 241 | input.focus(this._showDatepicker); |
| 242 | } |
| 243 | if (showOn === "button" || showOn === "both") { // pop-up date picker when button clicked |
| 244 | buttonText = this._get(inst, "buttonText"); |
| 245 | buttonImage = this._get(inst, "buttonImage"); |
| 246 | inst.trigger = $(this._get(inst, "buttonImageOnly") ? |
| 247 | $("<img/>").addClass(this._triggerClass). |
| 248 | attr({ src: buttonImage, alt: buttonText, title: buttonText }) : |
| 249 | $("<button type='button'></button>").addClass(this._triggerClass). |
| 250 | html(!buttonImage ? buttonText : $("<img/>").attr( |
| 251 | { src:buttonImage, alt:buttonText, title:buttonText }))); |
| 252 | input[isRTL ? "before" : "after"](inst.trigger); |
| 253 | inst.trigger.click(function() { |
| 254 | if ($.datepicker._datepickerShowing && $.datepicker._lastInput === input[0]) { |
| 255 | $.datepicker._hideDatepicker(); |
| 256 | } else if ($.datepicker._datepickerShowing && $.datepicker._lastInput !== input[0]) { |
| 257 | $.datepicker._hideDatepicker(); |
| 258 | $.datepicker._showDatepicker(input[0]); |
| 259 | } else { |
| 260 | $.datepicker._showDatepicker(input[0]); |
| 261 | } |
| 262 | return false; |
| 263 | }); |
| 264 | } |
| 265 | }, |
| 266 | |
| 267 | /* Apply the maximum length for the date format. */ |
| 268 | _autoSize: function(inst) { |
| 269 | if (this._get(inst, "autoSize") && !inst.inline) { |
| 270 | var findMax, max, maxI, i, |
| 271 | date = new Date(2009, 12 - 1, 20), // Ensure double digits |
| 272 | dateFormat = this._get(inst, "dateFormat"); |
| 273 | |
| 274 | if (dateFormat.match(/[DM]/)) { |
| 275 | findMax = function(names) { |
| 276 | max = 0; |
| 277 | maxI = 0; |
| 278 | for (i = 0; i < names.length; i++) { |
| 279 | if (names[i].length > max) { |
| 280 | max = names[i].length; |
| 281 | maxI = i; |
| 282 | } |
| 283 | } |
| 284 | return maxI; |
| 285 | }; |
| 286 | date.setMonth(findMax(this._get(inst, (dateFormat.match(/MM/) ? |
| 287 | "monthNames" : "monthNamesShort")))); |
| 288 | date.setDate(findMax(this._get(inst, (dateFormat.match(/DD/) ? |
| 289 | "dayNames" : "dayNamesShort"))) + 20 - date.getDay()); |
| 290 | } |
| 291 | inst.input.attr("size", this._formatDate(inst, date).length); |
| 292 | } |
| 293 | }, |
| 294 | |
| 295 | /* Attach an inline date picker to a div. */ |
| 296 | _inlineDatepicker: function(target, inst) { |
| 297 | var divSpan = $(target); |
| 298 | if (divSpan.hasClass(this.markerClassName)) { |
| 299 | return; |
| 300 | } |
| 301 | divSpan.addClass(this.markerClassName).append(inst.dpDiv); |
| 302 | $.data(target, "datepicker", inst); |
| 303 | this._setDate(inst, this._getDefaultDate(inst), true); |
| 304 | this._updateDatepicker(inst); |
| 305 | this._updateAlternate(inst); |
| 306 | //If disabled option is true, disable the datepicker before showing it (see ticket #5665) |
| 307 | if( inst.settings.disabled ) { |
| 308 | this._disableDatepicker( target ); |
| 309 | } |
| 310 | // Set display:block in place of inst.dpDiv.show() which won't work on disconnected elements |
| 311 | // http://bugs.jqueryui.com/ticket/7552 - A Datepicker created on a detached div has zero height |
| 312 | inst.dpDiv.css( "display", "block" ); |
| 313 | }, |
| 314 | |
| 315 | /* Pop-up the date picker in a "dialog" box. |
| 316 | * @param input element - ignored |
| 317 | * @param date string or Date - the initial date to display |
| 318 | * @param onSelect function - the function to call when a date is selected |
| 319 | * @param settings object - update the dialog date picker instance's settings (anonymous object) |
| 320 | * @param pos int[2] - coordinates for the dialog's position within the screen or |
| 321 | * event - with x/y coordinates or |
| 322 | * leave empty for default (screen centre) |
| 323 | * @return the manager object |
| 324 | */ |
| 325 | _dialogDatepicker: function(input, date, onSelect, settings, pos) { |
| 326 | var id, browserWidth, browserHeight, scrollX, scrollY, |
| 327 | inst = this._dialogInst; // internal instance |
| 328 | |
| 329 | if (!inst) { |
| 330 | this.uuid += 1; |
| 331 | id = "dp" + this.uuid; |
| 332 | this._dialogInput = $("<input type='text' id='" + id + |
| 333 | "' style='position: absolute; top: -100px; width: 0px;'/>"); |
| 334 | this._dialogInput.keydown(this._doKeyDown); |
| 335 | $("body").append(this._dialogInput); |
| 336 | inst = this._dialogInst = this._newInst(this._dialogInput, false); |
| 337 | inst.settings = {}; |
| 338 | $.data(this._dialogInput[0], "datepicker", inst); |
| 339 | } |
| 340 | datepicker_extendRemove(inst.settings, settings || {}); |
| 341 | date = (date && date.constructor === Date ? this._formatDate(inst, date) : date); |
| 342 | this._dialogInput.val(date); |
| 343 | |
| 344 | this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null); |
| 345 | if (!this._pos) { |
| 346 | browserWidth = document.documentElement.clientWidth; |
| 347 | browserHeight = document.documentElement.clientHeight; |
| 348 | scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; |
| 349 | scrollY = document.documentElement.scrollTop || document.body.scrollTop; |
| 350 | this._pos = // should use actual width/height below |
| 351 | [(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY]; |
| 352 | } |
| 353 | |
| 354 | // move input on screen for focus, but hidden behind dialog |
| 355 | this._dialogInput.css("left", (this._pos[0] + 20) + "px").css("top", this._pos[1] + "px"); |
| 356 | inst.settings.onSelect = onSelect; |
| 357 | this._inDialog = true; |
| 358 | this.dpDiv.addClass(this._dialogClass); |
| 359 | this._showDatepicker(this._dialogInput[0]); |
| 360 | if ($.blockUI) { |
| 361 | $.blockUI(this.dpDiv); |
| 362 | } |
| 363 | $.data(this._dialogInput[0], "datepicker", inst); |
| 364 | return this; |
| 365 | }, |
| 366 | |
| 367 | /* Detach a datepicker from its control. |
| 368 | * @param target element - the target input field or division or span |
| 369 | */ |
| 370 | _destroyDatepicker: function(target) { |
| 371 | var nodeName, |
| 372 | $target = $(target), |
| 373 | inst = $.data(target, "datepicker"); |
| 374 | |
| 375 | if (!$target.hasClass(this.markerClassName)) { |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | nodeName = target.nodeName.toLowerCase(); |
| 380 | $.removeData(target, "datepicker"); |
| 381 | if (nodeName === "input") { |
| 382 | inst.append.remove(); |
| 383 | inst.trigger.remove(); |
| 384 | $target.removeClass(this.markerClassName). |
| 385 | unbind("focus", this._showDatepicker). |
| 386 | unbind("keydown", this._doKeyDown). |
| 387 | unbind("keypress", this._doKeyPress). |
| 388 | unbind("keyup", this._doKeyUp); |
| 389 | } else if (nodeName === "div" || nodeName === "span") { |
| 390 | $target.removeClass(this.markerClassName).empty(); |
| 391 | } |
| 392 | }, |
| 393 | |
| 394 | /* Enable the date picker to a jQuery selection. |
| 395 | * @param target element - the target input field or division or span |
| 396 | */ |
| 397 | _enableDatepicker: function(target) { |
| 398 | var nodeName, inline, |
| 399 | $target = $(target), |
| 400 | inst = $.data(target, "datepicker"); |
| 401 | |
| 402 | if (!$target.hasClass(this.markerClassName)) { |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | nodeName = target.nodeName.toLowerCase(); |
| 407 | if (nodeName === "input") { |
| 408 | target.disabled = false; |
| 409 | inst.trigger.filter("button"). |
| 410 | each(function() { this.disabled = false; }).end(). |
| 411 | filter("img").css({opacity: "1.0", cursor: ""}); |
| 412 | } else if (nodeName === "div" || nodeName === "span") { |
| 413 | inline = $target.children("." + this._inlineClass); |
| 414 | inline.children().removeClass("ui-state-disabled"); |
| 415 | inline.find("select.ui-datepicker-month, select.ui-datepicker-year"). |
| 416 | prop("disabled", false); |
| 417 | } |
| 418 | this._disabledInputs = $.map(this._disabledInputs, |
| 419 | function(value) { return (value === target ? null : value); }); // delete entry |
| 420 | }, |
| 421 | |
| 422 | /* Disable the date picker to a jQuery selection. |
| 423 | * @param target element - the target input field or division or span |
| 424 | */ |
| 425 | _disableDatepicker: function(target) { |
| 426 | var nodeName, inline, |
| 427 | $target = $(target), |
| 428 | inst = $.data(target, "datepicker"); |
| 429 | |
| 430 | if (!$target.hasClass(this.markerClassName)) { |
| 431 | return; |
| 432 | } |
| 433 | |
| 434 | nodeName = target.nodeName.toLowerCase(); |
| 435 | if (nodeName === "input") { |
| 436 | target.disabled = true; |
| 437 | inst.trigger.filter("button"). |
| 438 | each(function() { this.disabled = true; }).end(). |
| 439 | filter("img").css({opacity: "0.5", cursor: "default"}); |
| 440 | } else if (nodeName === "div" || nodeName === "span") { |
| 441 | inline = $target.children("." + this._inlineClass); |
| 442 | inline.children().addClass("ui-state-disabled"); |
| 443 | inline.find("select.ui-datepicker-month, select.ui-datepicker-year"). |
| 444 | prop("disabled", true); |
| 445 | } |
| 446 | this._disabledInputs = $.map(this._disabledInputs, |
| 447 | function(value) { return (value === target ? null : value); }); // delete entry |
| 448 | this._disabledInputs[this._disabledInputs.length] = target; |
| 449 | }, |
| 450 | |
| 451 | /* Is the first field in a jQuery collection disabled as a datepicker? |
| 452 | * @param target element - the target input field or division or span |
| 453 | * @return boolean - true if disabled, false if enabled |
| 454 | */ |
| 455 | _isDisabledDatepicker: function(target) { |
| 456 | if (!target) { |
| 457 | return false; |
| 458 | } |
| 459 | for (var i = 0; i < this._disabledInputs.length; i++) { |
| 460 | if (this._disabledInputs[i] === target) { |
| 461 | return true; |
| 462 | } |
| 463 | } |
| 464 | return false; |
| 465 | }, |
| 466 | |
| 467 | /* Retrieve the instance data for the target control. |
| 468 | * @param target element - the target input field or division or span |
| 469 | * @return object - the associated instance data |
| 470 | * @throws error if a jQuery problem getting data |
| 471 | */ |
| 472 | _getInst: function(target) { |
| 473 | try { |
| 474 | return $.data(target, "datepicker"); |
| 475 | } |
| 476 | catch (err) { |
| 477 | throw "Missing instance data for this datepicker"; |
| 478 | } |
| 479 | }, |
| 480 | |
| 481 | /* Update or retrieve the settings for a date picker attached to an input field or division. |
| 482 | * @param target element - the target input field or division or span |
| 483 | * @param name object - the new settings to update or |
| 484 | * string - the name of the setting to change or retrieve, |
| 485 | * when retrieving also "all" for all instance settings or |
| 486 | * "defaults" for all global defaults |
| 487 | * @param value any - the new value for the setting |
| 488 | * (omit if above is an object or to retrieve a value) |
| 489 | */ |
| 490 | _optionDatepicker: function(target, name, value) { |
| 491 | var settings, date, minDate, maxDate, |
| 492 | inst = this._getInst(target); |
| 493 | |
| 494 | if (arguments.length === 2 && typeof name === "string") { |
| 495 | return (name === "defaults" ? $.extend({}, $.datepicker._defaults) : |
| 496 | (inst ? (name === "all" ? $.extend({}, inst.settings) : |
| 497 | this._get(inst, name)) : null)); |
| 498 | } |
| 499 | |
| 500 | settings = name || {}; |
| 501 | if (typeof name === "string") { |
| 502 | settings = {}; |
| 503 | settings[name] = value; |
| 504 | } |
| 505 | |
| 506 | if (inst) { |
| 507 | if (this._curInst === inst) { |
| 508 | this._hideDatepicker(); |
| 509 | } |
| 510 | |
| 511 | date = this._getDateDatepicker(target, true); |
| 512 | minDate = this._getMinMaxDate(inst, "min"); |
| 513 | maxDate = this._getMinMaxDate(inst, "max"); |
| 514 | datepicker_extendRemove(inst.settings, settings); |
| 515 | // reformat the old minDate/maxDate values if dateFormat changes and a new minDate/maxDate isn't provided |
| 516 | if (minDate !== null && settings.dateFormat !== undefined && settings.minDate === undefined) { |
| 517 | inst.settings.minDate = this._formatDate(inst, minDate); |
| 518 | } |
| 519 | if (maxDate !== null && settings.dateFormat !== undefined && settings.maxDate === undefined) { |
| 520 | inst.settings.maxDate = this._formatDate(inst, maxDate); |
| 521 | } |
| 522 | if ( "disabled" in settings ) { |
| 523 | if ( settings.disabled ) { |
| 524 | this._disableDatepicker(target); |
| 525 | } else { |
| 526 | this._enableDatepicker(target); |
| 527 | } |
| 528 | } |
| 529 | this._attachments($(target), inst); |
| 530 | this._autoSize(inst); |
| 531 | this._setDate(inst, date); |
| 532 | this._updateAlternate(inst); |
| 533 | this._updateDatepicker(inst); |
| 534 | } |
| 535 | }, |
| 536 | |
| 537 | // change method deprecated |
| 538 | _changeDatepicker: function(target, name, value) { |
| 539 | this._optionDatepicker(target, name, value); |
| 540 | }, |
| 541 | |
| 542 | /* Redraw the date picker attached to an input field or division. |
| 543 | * @param target element - the target input field or division or span |
| 544 | */ |
| 545 | _refreshDatepicker: function(target) { |
| 546 | var inst = this._getInst(target); |
| 547 | if (inst) { |
| 548 | this._updateDatepicker(inst); |
| 549 | } |
| 550 | }, |
| 551 | |
| 552 | /* Set the dates for a jQuery selection. |
| 553 | * @param target element - the target input field or division or span |
| 554 | * @param date Date - the new date |
| 555 | */ |
| 556 | _setDateDatepicker: function(target, date) { |
| 557 | var inst = this._getInst(target); |
| 558 | if (inst) { |
| 559 | this._setDate(inst, date); |
| 560 | this._updateDatepicker(inst); |
| 561 | this._updateAlternate(inst); |
| 562 | } |
| 563 | }, |
| 564 | |
| 565 | /* Get the date(s) for the first entry in a jQuery selection. |
| 566 | * @param target element - the target input field or division or span |
| 567 | * @param noDefault boolean - true if no default date is to be used |
| 568 | * @return Date - the current date |
| 569 | */ |
| 570 | _getDateDatepicker: function(target, noDefault) { |
| 571 | var inst = this._getInst(target); |
| 572 | if (inst && !inst.inline) { |
| 573 | this._setDateFromField(inst, noDefault); |
| 574 | } |
| 575 | return (inst ? this._getDate(inst) : null); |
| 576 | }, |
| 577 | |
| 578 | /* Handle keystrokes. */ |
| 579 | _doKeyDown: function(event) { |
| 580 | var onSelect, dateStr, sel, |
| 581 | inst = $.datepicker._getInst(event.target), |
| 582 | handled = true, |
| 583 | isRTL = inst.dpDiv.is(".ui-datepicker-rtl"); |
| 584 | |
| 585 | inst._keyEvent = true; |
| 586 | if ($.datepicker._datepickerShowing) { |
| 587 | switch (event.keyCode) { |
| 588 | case 9: $.datepicker._hideDatepicker(); |
| 589 | handled = false; |
| 590 | break; // hide on tab out |
| 591 | case 13: sel = $("td." + $.datepicker._dayOverClass + ":not(." + |
| 592 | $.datepicker._currentClass + ")", inst.dpDiv); |
| 593 | if (sel[0]) { |
| 594 | $.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]); |
| 595 | } |
| 596 | |
| 597 | onSelect = $.datepicker._get(inst, "onSelect"); |
| 598 | if (onSelect) { |
| 599 | dateStr = $.datepicker._formatDate(inst); |
| 600 | |
| 601 | // trigger custom callback |
| 602 | onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); |
| 603 | } else { |
| 604 | $.datepicker._hideDatepicker(); |
| 605 | } |
| 606 | |
| 607 | return false; // don't submit the form |
| 608 | case 27: $.datepicker._hideDatepicker(); |
| 609 | break; // hide on escape |
| 610 | case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ? |
| 611 | -$.datepicker._get(inst, "stepBigMonths") : |
| 612 | -$.datepicker._get(inst, "stepMonths")), "M"); |
| 613 | break; // previous month/year on page up/+ ctrl |
| 614 | case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ? |
| 615 | +$.datepicker._get(inst, "stepBigMonths") : |
| 616 | +$.datepicker._get(inst, "stepMonths")), "M"); |
| 617 | break; // next month/year on page down/+ ctrl |
| 618 | case 35: if (event.ctrlKey || event.metaKey) { |
| 619 | $.datepicker._clearDate(event.target); |
| 620 | } |
| 621 | handled = event.ctrlKey || event.metaKey; |
| 622 | break; // clear on ctrl or command +end |
| 623 | case 36: if (event.ctrlKey || event.metaKey) { |
| 624 | $.datepicker._gotoToday(event.target); |
| 625 | } |
| 626 | handled = event.ctrlKey || event.metaKey; |
| 627 | break; // current on ctrl or command +home |
| 628 | case 37: if (event.ctrlKey || event.metaKey) { |
| 629 | $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), "D"); |
| 630 | } |
| 631 | handled = event.ctrlKey || event.metaKey; |
| 632 | // -1 day on ctrl or command +left |
| 633 | if (event.originalEvent.altKey) { |
| 634 | $.datepicker._adjustDate(event.target, (event.ctrlKey ? |
| 635 | -$.datepicker._get(inst, "stepBigMonths") : |
| 636 | -$.datepicker._get(inst, "stepMonths")), "M"); |
| 637 | } |
| 638 | // next month/year on alt +left on Mac |
| 639 | break; |
| 640 | case 38: if (event.ctrlKey || event.metaKey) { |
| 641 | $.datepicker._adjustDate(event.target, -7, "D"); |
| 642 | } |
| 643 | handled = event.ctrlKey || event.metaKey; |
| 644 | break; // -1 week on ctrl or command +up |
| 645 | case 39: if (event.ctrlKey || event.metaKey) { |
| 646 | $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), "D"); |
| 647 | } |
| 648 | handled = event.ctrlKey || event.metaKey; |
| 649 | // +1 day on ctrl or command +right |
| 650 | if (event.originalEvent.altKey) { |
| 651 | $.datepicker._adjustDate(event.target, (event.ctrlKey ? |
| 652 | +$.datepicker._get(inst, "stepBigMonths") : |
| 653 | +$.datepicker._get(inst, "stepMonths")), "M"); |
| 654 | } |
| 655 | // next month/year on alt +right |
| 656 | break; |
| 657 | case 40: if (event.ctrlKey || event.metaKey) { |
| 658 | $.datepicker._adjustDate(event.target, +7, "D"); |
| 659 | } |
| 660 | handled = event.ctrlKey || event.metaKey; |
| 661 | break; // +1 week on ctrl or command +down |
| 662 | default: handled = false; |
| 663 | } |
| 664 | } else if (event.keyCode === 36 && event.ctrlKey) { // display the date picker on ctrl+home |
| 665 | $.datepicker._showDatepicker(this); |
| 666 | } else { |
| 667 | handled = false; |
| 668 | } |
| 669 | |
| 670 | if (handled) { |
| 671 | event.preventDefault(); |
| 672 | event.stopPropagation(); |
| 673 | } |
| 674 | }, |
| 675 | |
| 676 | /* Filter entered characters - based on date format. */ |
| 677 | _doKeyPress: function(event) { |
| 678 | var chars, chr, |
| 679 | inst = $.datepicker._getInst(event.target); |
| 680 | |
| 681 | if ($.datepicker._get(inst, "constrainInput")) { |
| 682 | chars = $.datepicker._possibleChars($.datepicker._get(inst, "dateFormat")); |
| 683 | chr = String.fromCharCode(event.charCode == null ? event.keyCode : event.charCode); |
| 684 | return event.ctrlKey || event.metaKey || (chr < " " || !chars || chars.indexOf(chr) > -1); |
| 685 | } |
| 686 | }, |
| 687 | |
| 688 | /* Synchronise manual entry and field/alternate field. */ |
| 689 | _doKeyUp: function(event) { |
| 690 | var date, |
| 691 | inst = $.datepicker._getInst(event.target); |
| 692 | |
| 693 | if (inst.input.val() !== inst.lastVal) { |
| 694 | try { |
| 695 | date = $.datepicker.parseDate($.datepicker._get(inst, "dateFormat"), |
| 696 | (inst.input ? inst.input.val() : null), |
| 697 | $.datepicker._getFormatConfig(inst)); |
| 698 | |
| 699 | if (date) { // only if valid |
| 700 | $.datepicker._setDateFromField(inst); |
| 701 | $.datepicker._updateAlternate(inst); |
| 702 | $.datepicker._updateDatepicker(inst); |
| 703 | } |
| 704 | } |
| 705 | catch (err) { |
| 706 | } |
| 707 | } |
| 708 | return true; |
| 709 | }, |
| 710 | |
| 711 | /* Pop-up the date picker for a given input field. |
| 712 | * If false returned from beforeShow event handler do not show. |
| 713 | * @param input element - the input field attached to the date picker or |
| 714 | * event - if triggered by focus |
| 715 | */ |
| 716 | _showDatepicker: function(input) { |
| 717 | input = input.target || input; |
| 718 | if (input.nodeName.toLowerCase() !== "input") { // find from button/image trigger |
| 719 | input = $("input", input.parentNode)[0]; |
| 720 | } |
| 721 | |
| 722 | if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput === input) { // already here |
| 723 | return; |
| 724 | } |
| 725 | |
| 726 | var inst, beforeShow, beforeShowSettings, isFixed, |
| 727 | offset, showAnim, duration; |
| 728 | |
| 729 | inst = $.datepicker._getInst(input); |
| 730 | if ($.datepicker._curInst && $.datepicker._curInst !== inst) { |
| 731 | $.datepicker._curInst.dpDiv.stop(true, true); |
| 732 | if ( inst && $.datepicker._datepickerShowing ) { |
| 733 | $.datepicker._hideDatepicker( $.datepicker._curInst.input[0] ); |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | beforeShow = $.datepicker._get(inst, "beforeShow"); |
| 738 | beforeShowSettings = beforeShow ? beforeShow.apply(input, [input, inst]) : {}; |
| 739 | if(beforeShowSettings === false){ |
| 740 | return; |
| 741 | } |
| 742 | datepicker_extendRemove(inst.settings, beforeShowSettings); |
| 743 | |
| 744 | inst.lastVal = null; |
| 745 | $.datepicker._lastInput = input; |
| 746 | $.datepicker._setDateFromField(inst); |
| 747 | |
| 748 | if ($.datepicker._inDialog) { // hide cursor |
| 749 | input.value = ""; |
| 750 | } |
| 751 | if (!$.datepicker._pos) { // position below input |
| 752 | $.datepicker._pos = $.datepicker._findPos(input); |
| 753 | $.datepicker._pos[1] += input.offsetHeight; // add the height |
| 754 | } |
| 755 | |
| 756 | isFixed = false; |
| 757 | $(input).parents().each(function() { |
| 758 | isFixed |= $(this).css("position") === "fixed"; |
| 759 | return !isFixed; |
| 760 | }); |
| 761 | |
| 762 | offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]}; |
| 763 | $.datepicker._pos = null; |
| 764 | //to avoid flashes on Firefox |
| 765 | inst.dpDiv.empty(); |
| 766 | // determine sizing offscreen |
| 767 | inst.dpDiv.css({position: "absolute", display: "block", top: "-1000px"}); |
| 768 | $.datepicker._updateDatepicker(inst); |
| 769 | // fix width for dynamic number of date pickers |
| 770 | // and adjust position before showing |
| 771 | offset = $.datepicker._checkOffset(inst, offset, isFixed); |
| 772 | inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ? |
| 773 | "static" : (isFixed ? "fixed" : "absolute")), display: "none", |
| 774 | left: offset.left + "px", top: offset.top + "px"}); |
| 775 | |
| 776 | if (!inst.inline) { |
| 777 | showAnim = $.datepicker._get(inst, "showAnim"); |
| 778 | duration = $.datepicker._get(inst, "duration"); |
| 779 | inst.dpDiv.css( "z-index", datepicker_getZindex( $( input ) ) + 1 ); |
| 780 | $.datepicker._datepickerShowing = true; |
| 781 | |
| 782 | if ( $.effects && $.effects.effect[ showAnim ] ) { |
| 783 | inst.dpDiv.show(showAnim, $.datepicker._get(inst, "showOptions"), duration); |
| 784 | } else { |
| 785 | inst.dpDiv[showAnim || "show"](showAnim ? duration : null); |
| 786 | } |
| 787 | |
| 788 | if ( $.datepicker._shouldFocusInput( inst ) ) { |
| 789 | inst.input.focus(); |
| 790 | } |
| 791 | |
| 792 | $.datepicker._curInst = inst; |
| 793 | } |
| 794 | }, |
| 795 | |
| 796 | /* Generate the date picker content. */ |
| 797 | _updateDatepicker: function(inst) { |
| 798 | this.maxRows = 4; //Reset the max number of rows being displayed (see #7043) |
| 799 | datepicker_instActive = inst; // for delegate hover events |
| 800 | inst.dpDiv.empty().append(this._generateHTML(inst)); |
| 801 | this._attachHandlers(inst); |
| 802 | |
| 803 | var origyearshtml, |
| 804 | numMonths = this._getNumberOfMonths(inst), |
| 805 | cols = numMonths[1], |
| 806 | width = 17, |
| 807 | activeCell = inst.dpDiv.find( "." + this._dayOverClass + " a" ); |
| 808 | |
| 809 | if ( activeCell.length > 0 ) { |
| 810 | datepicker_handleMouseover.apply( activeCell.get( 0 ) ); |
| 811 | } |
| 812 | |
| 813 | inst.dpDiv.removeClass("ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4").width(""); |
| 814 | if (cols > 1) { |
| 815 | inst.dpDiv.addClass("ui-datepicker-multi-" + cols).css("width", (width * cols) + "em"); |
| 816 | } |
| 817 | inst.dpDiv[(numMonths[0] !== 1 || numMonths[1] !== 1 ? "add" : "remove") + |
| 818 | "Class"]("ui-datepicker-multi"); |
| 819 | inst.dpDiv[(this._get(inst, "isRTL") ? "add" : "remove") + |
| 820 | "Class"]("ui-datepicker-rtl"); |
| 821 | |
| 822 | if (inst === $.datepicker._curInst && $.datepicker._datepickerShowing && $.datepicker._shouldFocusInput( inst ) ) { |
| 823 | inst.input.focus(); |
| 824 | } |
| 825 | |
| 826 | // deffered render of the years select (to avoid flashes on Firefox) |
| 827 | if( inst.yearshtml ){ |
| 828 | origyearshtml = inst.yearshtml; |
| 829 | setTimeout(function(){ |
| 830 | //assure that inst.yearshtml didn't change. |
| 831 | if( origyearshtml === inst.yearshtml && inst.yearshtml ){ |
| 832 | inst.dpDiv.find("select.ui-datepicker-year:first").replaceWith(inst.yearshtml); |
| 833 | } |
| 834 | origyearshtml = inst.yearshtml = null; |
| 835 | }, 0); |
| 836 | } |
| 837 | }, |
| 838 | |
| 839 | // #6694 - don't focus the input if it's already focused |
| 840 | // this breaks the change event in IE |
| 841 | // Support: IE and jQuery <1.9 |
| 842 | _shouldFocusInput: function( inst ) { |
| 843 | return inst.input && inst.input.is( ":visible" ) && !inst.input.is( ":disabled" ) && !inst.input.is( ":focus" ); |
| 844 | }, |
| 845 | |
| 846 | /* Check positioning to remain on screen. */ |
| 847 | _checkOffset: function(inst, offset, isFixed) { |
| 848 | var dpWidth = inst.dpDiv.outerWidth(), |
| 849 | dpHeight = inst.dpDiv.outerHeight(), |
| 850 | inputWidth = inst.input ? inst.input.outerWidth() : 0, |
| 851 | inputHeight = inst.input ? inst.input.outerHeight() : 0, |
| 852 | viewWidth = document.documentElement.clientWidth + (isFixed ? 0 : $(document).scrollLeft()), |
| 853 | viewHeight = document.documentElement.clientHeight + (isFixed ? 0 : $(document).scrollTop()); |
| 854 | |
| 855 | offset.left -= (this._get(inst, "isRTL") ? (dpWidth - inputWidth) : 0); |
| 856 | offset.left -= (isFixed && offset.left === inst.input.offset().left) ? $(document).scrollLeft() : 0; |
| 857 | offset.top -= (isFixed && offset.top === (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0; |
| 858 | |
| 859 | // now check if datepicker is showing outside window viewport - move to a better place if so. |
| 860 | offset.left -= Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? |
| 861 | Math.abs(offset.left + dpWidth - viewWidth) : 0); |
| 862 | offset.top -= Math.min(offset.top, (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? |
| 863 | Math.abs(dpHeight + inputHeight) : 0); |
| 864 | |
| 865 | return offset; |
| 866 | }, |
| 867 | |
| 868 | /* Find an object's position on the screen. */ |
| 869 | _findPos: function(obj) { |
| 870 | var position, |
| 871 | inst = this._getInst(obj), |
| 872 | isRTL = this._get(inst, "isRTL"); |
| 873 | |
| 874 | while (obj && (obj.type === "hidden" || obj.nodeType !== 1 || $.expr.filters.hidden(obj))) { |
| 875 | obj = obj[isRTL ? "previousSibling" : "nextSibling"]; |
| 876 | } |
| 877 | |
| 878 | position = $(obj).offset(); |
| 879 | return [position.left, position.top]; |
| 880 | }, |
| 881 | |
| 882 | /* Hide the date picker from view. |
| 883 | * @param input element - the input field attached to the date picker |
| 884 | */ |
| 885 | _hideDatepicker: function(input) { |
| 886 | var showAnim, duration, postProcess, onClose, |
| 887 | inst = this._curInst; |
| 888 | |
| 889 | if (!inst || (input && inst !== $.data(input, "datepicker"))) { |
| 890 | return; |
| 891 | } |
| 892 | |
| 893 | if (this._datepickerShowing) { |
| 894 | showAnim = this._get(inst, "showAnim"); |
| 895 | duration = this._get(inst, "duration"); |
| 896 | postProcess = function() { |
| 897 | $.datepicker._tidyDialog(inst); |
| 898 | }; |
| 899 | |
| 900 | // DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed |
| 901 | if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) ) { |
| 902 | inst.dpDiv.hide(showAnim, $.datepicker._get(inst, "showOptions"), duration, postProcess); |
| 903 | } else { |
| 904 | inst.dpDiv[(showAnim === "slideDown" ? "slideUp" : |
| 905 | (showAnim === "fadeIn" ? "fadeOut" : "hide"))]((showAnim ? duration : null), postProcess); |
| 906 | } |
| 907 | |
| 908 | if (!showAnim) { |
| 909 | postProcess(); |
| 910 | } |
| 911 | this._datepickerShowing = false; |
| 912 | |
| 913 | onClose = this._get(inst, "onClose"); |
| 914 | if (onClose) { |
| 915 | onClose.apply((inst.input ? inst.input[0] : null), [(inst.input ? inst.input.val() : ""), inst]); |
| 916 | } |
| 917 | |
| 918 | this._lastInput = null; |
| 919 | if (this._inDialog) { |
| 920 | this._dialogInput.css({ position: "absolute", left: "0", top: "-100px" }); |
| 921 | if ($.blockUI) { |
| 922 | $.unblockUI(); |
| 923 | $("body").append(this.dpDiv); |
| 924 | } |
| 925 | } |
| 926 | this._inDialog = false; |
| 927 | } |
| 928 | }, |
| 929 | |
| 930 | /* Tidy up after a dialog display. */ |
| 931 | _tidyDialog: function(inst) { |
| 932 | inst.dpDiv.removeClass(this._dialogClass).unbind(".ui-datepicker-calendar"); |
| 933 | }, |
| 934 | |
| 935 | /* Close date picker if clicked elsewhere. */ |
| 936 | _checkExternalClick: function(event) { |
| 937 | if (!$.datepicker._curInst) { |
| 938 | return; |
| 939 | } |
| 940 | |
| 941 | var $target = $(event.target), |
| 942 | inst = $.datepicker._getInst($target[0]); |
| 943 | |
| 944 | if ( ( ( $target[0].id !== $.datepicker._mainDivId && |
| 945 | $target.parents("#" + $.datepicker._mainDivId).length === 0 && |
| 946 | !$target.hasClass($.datepicker.markerClassName) && |
| 947 | !$target.closest("." + $.datepicker._triggerClass).length && |
| 948 | $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI) ) ) || |
| 949 | ( $target.hasClass($.datepicker.markerClassName) && $.datepicker._curInst !== inst ) ) { |
| 950 | $.datepicker._hideDatepicker(); |
| 951 | } |
| 952 | }, |
| 953 | |
| 954 | /* Adjust one of the date sub-fields. */ |
| 955 | _adjustDate: function(id, offset, period) { |
| 956 | var target = $(id), |
| 957 | inst = this._getInst(target[0]); |
| 958 | |
| 959 | if (this._isDisabledDatepicker(target[0])) { |
| 960 | return; |
| 961 | } |
| 962 | this._adjustInstDate(inst, offset + |
| 963 | (period === "M" ? this._get(inst, "showCurrentAtPos") : 0), // undo positioning |
| 964 | period); |
| 965 | this._updateDatepicker(inst); |
| 966 | }, |
| 967 | |
| 968 | /* Action for current link. */ |
| 969 | _gotoToday: function(id) { |
| 970 | var date, |
| 971 | target = $(id), |
| 972 | inst = this._getInst(target[0]); |
| 973 | |
| 974 | if (this._get(inst, "gotoCurrent") && inst.currentDay) { |
| 975 | inst.selectedDay = inst.currentDay; |
| 976 | inst.drawMonth = inst.selectedMonth = inst.currentMonth; |
| 977 | inst.drawYear = inst.selectedYear = inst.currentYear; |
| 978 | } else { |
| 979 | date = new Date(); |
| 980 | inst.selectedDay = date.getDate(); |
| 981 | inst.drawMonth = inst.selectedMonth = date.getMonth(); |
| 982 | inst.drawYear = inst.selectedYear = date.getFullYear(); |
| 983 | } |
| 984 | this._notifyChange(inst); |
| 985 | this._adjustDate(target); |
| 986 | }, |
| 987 | |
| 988 | /* Action for selecting a new month/year. */ |
| 989 | _selectMonthYear: function(id, select, period) { |
| 990 | var target = $(id), |
| 991 | inst = this._getInst(target[0]); |
| 992 | |
| 993 | inst["selected" + (period === "M" ? "Month" : "Year")] = |
| 994 | inst["draw" + (period === "M" ? "Month" : "Year")] = |
| 995 | parseInt(select.options[select.selectedIndex].value,10); |
| 996 | |
| 997 | this._notifyChange(inst); |
| 998 | this._adjustDate(target); |
| 999 | }, |
| 1000 | |
| 1001 | /* Action for selecting a day. */ |
| 1002 | _selectDay: function(id, month, year, td) { |
| 1003 | var inst, |
| 1004 | target = $(id); |
| 1005 | |
| 1006 | if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) { |
| 1007 | return; |
| 1008 | } |
| 1009 | |
| 1010 | inst = this._getInst(target[0]); |
| 1011 | inst.selectedDay = inst.currentDay = $("a", td).html(); |
| 1012 | inst.selectedMonth = inst.currentMonth = month; |
| 1013 | inst.selectedYear = inst.currentYear = year; |
| 1014 | this._selectDate(id, this._formatDate(inst, |
| 1015 | inst.currentDay, inst.currentMonth, inst.currentYear)); |
| 1016 | }, |
| 1017 | |
| 1018 | /* Erase the input field and hide the date picker. */ |
| 1019 | _clearDate: function(id) { |
| 1020 | var target = $(id); |
| 1021 | this._selectDate(target, ""); |
| 1022 | }, |
| 1023 | |
| 1024 | /* Update the input field with the selected date. */ |
| 1025 | _selectDate: function(id, dateStr) { |
| 1026 | var onSelect, |
| 1027 | target = $(id), |
| 1028 | inst = this._getInst(target[0]); |
| 1029 | |
| 1030 | dateStr = (dateStr != null ? dateStr : this._formatDate(inst)); |
| 1031 | if (inst.input) { |
| 1032 | inst.input.val(dateStr); |
| 1033 | } |
| 1034 | this._updateAlternate(inst); |
| 1035 | |
| 1036 | onSelect = this._get(inst, "onSelect"); |
| 1037 | if (onSelect) { |
| 1038 | onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callback |
| 1039 | } else if (inst.input) { |
| 1040 | inst.input.trigger("change"); // fire the change event |
| 1041 | } |
| 1042 | |
| 1043 | if (inst.inline){ |
| 1044 | this._updateDatepicker(inst); |
| 1045 | } else { |
| 1046 | this._hideDatepicker(); |
| 1047 | this._lastInput = inst.input[0]; |
| 1048 | if (typeof(inst.input[0]) !== "object") { |
| 1049 | inst.input.focus(); // restore focus |
| 1050 | } |
| 1051 | this._lastInput = null; |
| 1052 | } |
| 1053 | }, |
| 1054 | |
| 1055 | /* Update any alternate field to synchronise with the main field. */ |
| 1056 | _updateAlternate: function(inst) { |
| 1057 | var altFormat, date, dateStr, |
| 1058 | altField = this._get(inst, "altField"); |
| 1059 | |
| 1060 | if (altField) { // update alternate field too |
| 1061 | altFormat = this._get(inst, "altFormat") || this._get(inst, "dateFormat"); |
| 1062 | date = this._getDate(inst); |
| 1063 | dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst)); |
| 1064 | $(altField).each(function() { $(this).val(dateStr); }); |
| 1065 | } |
| 1066 | }, |
| 1067 | |
| 1068 | /* Set as beforeShowDay function to prevent selection of weekends. |
| 1069 | * @param date Date - the date to customise |
| 1070 | * @return [boolean, string] - is this date selectable?, what is its CSS class? |
| 1071 | */ |
| 1072 | noWeekends: function(date) { |
| 1073 | var day = date.getDay(); |
| 1074 | return [(day > 0 && day < 6), ""]; |
| 1075 | }, |
| 1076 | |
| 1077 | /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition. |
| 1078 | * @param date Date - the date to get the week for |
| 1079 | * @return number - the number of the week within the year that contains this date |
| 1080 | */ |
| 1081 | iso8601Week: function(date) { |
| 1082 | var time, |
| 1083 | checkDate = new Date(date.getTime()); |
| 1084 | |
| 1085 | // Find Thursday of this week starting on Monday |
| 1086 | checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7)); |
| 1087 | |
| 1088 | time = checkDate.getTime(); |
| 1089 | checkDate.setMonth(0); // Compare with Jan 1 |
| 1090 | checkDate.setDate(1); |
| 1091 | return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1; |
| 1092 | }, |
| 1093 | |
| 1094 | /* Parse a string value into a date object. |
| 1095 | * See formatDate below for the possible formats. |
| 1096 | * |
| 1097 | * @param format string - the expected format of the date |
| 1098 | * @param value string - the date in the above format |
| 1099 | * @param settings Object - attributes include: |
| 1100 | * shortYearCutoff number - the cutoff year for determining the century (optional) |
| 1101 | * dayNamesShort string[7] - abbreviated names of the days from Sunday (optional) |
| 1102 | * dayNames string[7] - names of the days from Sunday (optional) |
| 1103 | * monthNamesShort string[12] - abbreviated names of the months (optional) |
| 1104 | * monthNames string[12] - names of the months (optional) |
| 1105 | * @return Date - the extracted date value or null if value is blank |
| 1106 | */ |
| 1107 | parseDate: function (format, value, settings) { |
| 1108 | if (format == null || value == null) { |
| 1109 | throw "Invalid arguments"; |
| 1110 | } |
| 1111 | |
| 1112 | value = (typeof value === "object" ? value.toString() : value + ""); |
| 1113 | if (value === "") { |
| 1114 | return null; |
| 1115 | } |
| 1116 | |
| 1117 | var iFormat, dim, extra, |
| 1118 | iValue = 0, |
| 1119 | shortYearCutoffTemp = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff, |
| 1120 | shortYearCutoff = (typeof shortYearCutoffTemp !== "string" ? shortYearCutoffTemp : |
| 1121 | new Date().getFullYear() % 100 + parseInt(shortYearCutoffTemp, 10)), |
| 1122 | dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort, |
| 1123 | dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames, |
| 1124 | monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort, |
| 1125 | monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames, |
| 1126 | year = -1, |
| 1127 | month = -1, |
| 1128 | day = -1, |
| 1129 | doy = -1, |
| 1130 | literal = false, |
| 1131 | date, |
| 1132 | // Check whether a format character is doubled |
| 1133 | lookAhead = function(match) { |
| 1134 | var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match); |
| 1135 | if (matches) { |
| 1136 | iFormat++; |
| 1137 | } |
| 1138 | return matches; |
| 1139 | }, |
| 1140 | // Extract a number from the string value |
| 1141 | getNumber = function(match) { |
| 1142 | var isDoubled = lookAhead(match), |
| 1143 | size = (match === "@" ? 14 : (match === "!" ? 20 : |
| 1144 | (match === "y" && isDoubled ? 4 : (match === "o" ? 3 : 2)))), |
| 1145 | minSize = (match === "y" ? size : 1), |
| 1146 | digits = new RegExp("^\\d{" + minSize + "," + size + "}"), |
| 1147 | num = value.substring(iValue).match(digits); |
| 1148 | if (!num) { |
| 1149 | throw "Missing number at position " + iValue; |
| 1150 | } |
| 1151 | iValue += num[0].length; |
| 1152 | return parseInt(num[0], 10); |
| 1153 | }, |
| 1154 | // Extract a name from the string value and convert to an index |
| 1155 | getName = function(match, shortNames, longNames) { |
| 1156 | var index = -1, |
| 1157 | names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) { |
| 1158 | return [ [k, v] ]; |
| 1159 | }).sort(function (a, b) { |
| 1160 | return -(a[1].length - b[1].length); |
| 1161 | }); |
| 1162 | |
| 1163 | $.each(names, function (i, pair) { |
| 1164 | var name = pair[1]; |
| 1165 | if (value.substr(iValue, name.length).toLowerCase() === name.toLowerCase()) { |
| 1166 | index = pair[0]; |
| 1167 | iValue += name.length; |
| 1168 | return false; |
| 1169 | } |
| 1170 | }); |
| 1171 | if (index !== -1) { |
| 1172 | return index + 1; |
| 1173 | } else { |
| 1174 | throw "Unknown name at position " + iValue; |
| 1175 | } |
| 1176 | }, |
| 1177 | // Confirm that a literal character matches the string value |
| 1178 | checkLiteral = function() { |
| 1179 | if (value.charAt(iValue) !== format.charAt(iFormat)) { |
| 1180 | throw "Unexpected literal at position " + iValue; |
| 1181 | } |
| 1182 | iValue++; |
| 1183 | }; |
| 1184 | |
| 1185 | for (iFormat = 0; iFormat < format.length; iFormat++) { |
| 1186 | if (literal) { |
| 1187 | if (format.charAt(iFormat) === "'" && !lookAhead("'")) { |
| 1188 | literal = false; |
| 1189 | } else { |
| 1190 | checkLiteral(); |
| 1191 | } |
| 1192 | } else { |
| 1193 | switch (format.charAt(iFormat)) { |
| 1194 | case "d": |
| 1195 | day = getNumber("d"); |
| 1196 | break; |
| 1197 | case "D": |
| 1198 | getName("D", dayNamesShort, dayNames); |
| 1199 | break; |
| 1200 | case "o": |
| 1201 | doy = getNumber("o"); |
| 1202 | break; |
| 1203 | case "m": |
| 1204 | month = getNumber("m"); |
| 1205 | break; |
| 1206 | case "M": |
| 1207 | month = getName("M", monthNamesShort, monthNames); |
| 1208 | break; |
| 1209 | case "y": |
| 1210 | year = getNumber("y"); |
| 1211 | break; |
| 1212 | case "@": |
| 1213 | date = new Date(getNumber("@")); |
| 1214 | year = date.getFullYear(); |
| 1215 | month = date.getMonth() + 1; |
| 1216 | day = date.getDate(); |
| 1217 | break; |
| 1218 | case "!": |
| 1219 | date = new Date((getNumber("!") - this._ticksTo1970) / 10000); |
| 1220 | year = date.getFullYear(); |
| 1221 | month = date.getMonth() + 1; |
| 1222 | day = date.getDate(); |
| 1223 | break; |
| 1224 | case "'": |
| 1225 | if (lookAhead("'")){ |
| 1226 | checkLiteral(); |
| 1227 | } else { |
| 1228 | literal = true; |
| 1229 | } |
| 1230 | break; |
| 1231 | default: |
| 1232 | checkLiteral(); |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | if (iValue < value.length){ |
| 1238 | extra = value.substr(iValue); |
| 1239 | if (!/^\s+/.test(extra)) { |
| 1240 | throw "Extra/unparsed characters found in date: " + extra; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | if (year === -1) { |
| 1245 | year = new Date().getFullYear(); |
| 1246 | } else if (year < 100) { |
| 1247 | year += new Date().getFullYear() - new Date().getFullYear() % 100 + |
| 1248 | (year <= shortYearCutoff ? 0 : -100); |
| 1249 | } |
| 1250 | |
| 1251 | if (doy > -1) { |
| 1252 | month = 1; |
| 1253 | day = doy; |
| 1254 | do { |
| 1255 | dim = this._getDaysInMonth(year, month - 1); |
| 1256 | if (day <= dim) { |
| 1257 | break; |
| 1258 | } |
| 1259 | month++; |
| 1260 | day -= dim; |
| 1261 | } while (true); |
| 1262 | } |
| 1263 | |
| 1264 | date = this._daylightSavingAdjust(new Date(year, month - 1, day)); |
| 1265 | if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) { |
| 1266 | throw "Invalid date"; // E.g. 31/02/00 |
| 1267 | } |
| 1268 | return date; |
| 1269 | }, |
| 1270 | |
| 1271 | /* Standard date formats. */ |
| 1272 | ATOM: "yy-mm-dd", // RFC 3339 (ISO 8601) |
| 1273 | COOKIE: "D, dd M yy", |
| 1274 | ISO_8601: "yy-mm-dd", |
| 1275 | RFC_822: "D, d M y", |
| 1276 | RFC_850: "DD, dd-M-y", |
| 1277 | RFC_1036: "D, d M y", |
| 1278 | RFC_1123: "D, d M yy", |
| 1279 | RFC_2822: "D, d M yy", |
| 1280 | RSS: "D, d M y", // RFC 822 |
| 1281 | TICKS: "!", |
| 1282 | TIMESTAMP: "@", |
| 1283 | W3C: "yy-mm-dd", // ISO 8601 |
| 1284 | |
| 1285 | _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) + |
| 1286 | Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000), |
| 1287 | |
| 1288 | /* Format a date object into a string value. |
| 1289 | * The format can be combinations of the following: |
| 1290 | * d - day of month (no leading zero) |
| 1291 | * dd - day of month (two digit) |
| 1292 | * o - day of year (no leading zeros) |
| 1293 | * oo - day of year (three digit) |
| 1294 | * D - day name short |
| 1295 | * DD - day name long |
| 1296 | * m - month of year (no leading zero) |
| 1297 | * mm - month of year (two digit) |
| 1298 | * M - month name short |
| 1299 | * MM - month name long |
| 1300 | * y - year (two digit) |
| 1301 | * yy - year (four digit) |
| 1302 | * @ - Unix timestamp (ms since 01/01/1970) |
| 1303 | * ! - Windows ticks (100ns since 01/01/0001) |
| 1304 | * "..." - literal text |
| 1305 | * '' - single quote |
| 1306 | * |
| 1307 | * @param format string - the desired format of the date |
| 1308 | * @param date Date - the date value to format |
| 1309 | * @param settings Object - attributes include: |
| 1310 | * dayNamesShort string[7] - abbreviated names of the days from Sunday (optional) |
| 1311 | * dayNames string[7] - names of the days from Sunday (optional) |
| 1312 | * monthNamesShort string[12] - abbreviated names of the months (optional) |
| 1313 | * monthNames string[12] - names of the months (optional) |
| 1314 | * @return string - the date in the above format |
| 1315 | */ |
| 1316 | formatDate: function (format, date, settings) { |
| 1317 | if (!date) { |
| 1318 | return ""; |
| 1319 | } |
| 1320 | |
| 1321 | var iFormat, |
| 1322 | dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort, |
| 1323 | dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames, |
| 1324 | monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort, |
| 1325 | monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames, |
| 1326 | // Check whether a format character is doubled |
| 1327 | lookAhead = function(match) { |
| 1328 | var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match); |
| 1329 | if (matches) { |
| 1330 | iFormat++; |
| 1331 | } |
| 1332 | return matches; |
| 1333 | }, |
| 1334 | // Format a number, with leading zero if necessary |
| 1335 | formatNumber = function(match, value, len) { |
| 1336 | var num = "" + value; |
| 1337 | if (lookAhead(match)) { |
| 1338 | while (num.length < len) { |
| 1339 | num = "0" + num; |
| 1340 | } |
| 1341 | } |
| 1342 | return num; |
| 1343 | }, |
| 1344 | // Format a name, short or long as requested |
| 1345 | formatName = function(match, value, shortNames, longNames) { |
| 1346 | return (lookAhead(match) ? longNames[value] : shortNames[value]); |
| 1347 | }, |
| 1348 | output = "", |
| 1349 | literal = false; |
| 1350 | |
| 1351 | if (date) { |
| 1352 | for (iFormat = 0; iFormat < format.length; iFormat++) { |
| 1353 | if (literal) { |
| 1354 | if (format.charAt(iFormat) === "'" && !lookAhead("'")) { |
| 1355 | literal = false; |
| 1356 | } else { |
| 1357 | output += format.charAt(iFormat); |
| 1358 | } |
| 1359 | } else { |
| 1360 | switch (format.charAt(iFormat)) { |
| 1361 | case "d": |
| 1362 | output += formatNumber("d", date.getDate(), 2); |
| 1363 | break; |
| 1364 | case "D": |
| 1365 | output += formatName("D", date.getDay(), dayNamesShort, dayNames); |
| 1366 | break; |
| 1367 | case "o": |
| 1368 | output += formatNumber("o", |
| 1369 | Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3); |
| 1370 | break; |
| 1371 | case "m": |
| 1372 | output += formatNumber("m", date.getMonth() + 1, 2); |
| 1373 | break; |
| 1374 | case "M": |
| 1375 | output += formatName("M", date.getMonth(), monthNamesShort, monthNames); |
| 1376 | break; |
| 1377 | case "y": |
| 1378 | output += (lookAhead("y") ? date.getFullYear() : |
| 1379 | (date.getYear() % 100 < 10 ? "0" : "") + date.getYear() % 100); |
| 1380 | break; |
| 1381 | case "@": |
| 1382 | output += date.getTime(); |
| 1383 | break; |
| 1384 | case "!": |
| 1385 | output += date.getTime() * 10000 + this._ticksTo1970; |
| 1386 | break; |
| 1387 | case "'": |
| 1388 | if (lookAhead("'")) { |
| 1389 | output += "'"; |
| 1390 | } else { |
| 1391 | literal = true; |
| 1392 | } |
| 1393 | break; |
| 1394 | default: |
| 1395 | output += format.charAt(iFormat); |
| 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | } |
| 1400 | return output; |
| 1401 | }, |
| 1402 | |
| 1403 | /* Extract all possible characters from the date format. */ |
| 1404 | _possibleChars: function (format) { |
| 1405 | var iFormat, |
| 1406 | chars = "", |
| 1407 | literal = false, |
| 1408 | // Check whether a format character is doubled |
| 1409 | lookAhead = function(match) { |
| 1410 | var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match); |
| 1411 | if (matches) { |
| 1412 | iFormat++; |
| 1413 | } |
| 1414 | return matches; |
| 1415 | }; |
| 1416 | |
| 1417 | for (iFormat = 0; iFormat < format.length; iFormat++) { |
| 1418 | if (literal) { |
| 1419 | if (format.charAt(iFormat) === "'" && !lookAhead("'")) { |
| 1420 | literal = false; |
| 1421 | } else { |
| 1422 | chars += format.charAt(iFormat); |
| 1423 | } |
| 1424 | } else { |
| 1425 | switch (format.charAt(iFormat)) { |
| 1426 | case "d": case "m": case "y": case "@": |
| 1427 | chars += "0123456789"; |
| 1428 | break; |
| 1429 | case "D": case "M": |
| 1430 | return null; // Accept anything |
| 1431 | case "'": |
| 1432 | if (lookAhead("'")) { |
| 1433 | chars += "'"; |
| 1434 | } else { |
| 1435 | literal = true; |
| 1436 | } |
| 1437 | break; |
| 1438 | default: |
| 1439 | chars += format.charAt(iFormat); |
| 1440 | } |
| 1441 | } |
| 1442 | } |
| 1443 | return chars; |
| 1444 | }, |
| 1445 | |
| 1446 | /* Get a setting value, defaulting if necessary. */ |
| 1447 | _get: function(inst, name) { |
| 1448 | return inst.settings[name] !== undefined ? |
| 1449 | inst.settings[name] : this._defaults[name]; |
| 1450 | }, |
| 1451 | |
| 1452 | /* Parse existing date and initialise date picker. */ |
| 1453 | _setDateFromField: function(inst, noDefault) { |
| 1454 | if (inst.input.val() === inst.lastVal) { |
| 1455 | return; |
| 1456 | } |
| 1457 | |
| 1458 | var dateFormat = this._get(inst, "dateFormat"), |
| 1459 | dates = inst.lastVal = inst.input ? inst.input.val() : null, |
| 1460 | defaultDate = this._getDefaultDate(inst), |
| 1461 | date = defaultDate, |
| 1462 | settings = this._getFormatConfig(inst); |
| 1463 | |
| 1464 | try { |
| 1465 | date = this.parseDate(dateFormat, dates, settings) || defaultDate; |
| 1466 | } catch (event) { |
| 1467 | dates = (noDefault ? "" : dates); |
| 1468 | } |
| 1469 | inst.selectedDay = date.getDate(); |
| 1470 | inst.drawMonth = inst.selectedMonth = date.getMonth(); |
| 1471 | inst.drawYear = inst.selectedYear = date.getFullYear(); |
| 1472 | inst.currentDay = (dates ? date.getDate() : 0); |
| 1473 | inst.currentMonth = (dates ? date.getMonth() : 0); |
| 1474 | inst.currentYear = (dates ? date.getFullYear() : 0); |
| 1475 | this._adjustInstDate(inst); |
| 1476 | }, |
| 1477 | |
| 1478 | /* Retrieve the default date shown on opening. */ |
| 1479 | _getDefaultDate: function(inst) { |
| 1480 | return this._restrictMinMax(inst, |
| 1481 | this._determineDate(inst, this._get(inst, "defaultDate"), new Date())); |
| 1482 | }, |
| 1483 | |
| 1484 | /* A date may be specified as an exact value or a relative one. */ |
| 1485 | _determineDate: function(inst, date, defaultDate) { |
| 1486 | var offsetNumeric = function(offset) { |
| 1487 | var date = new Date(); |
| 1488 | date.setDate(date.getDate() + offset); |
| 1489 | return date; |
| 1490 | }, |
| 1491 | offsetString = function(offset) { |
| 1492 | try { |
| 1493 | return $.datepicker.parseDate($.datepicker._get(inst, "dateFormat"), |
| 1494 | offset, $.datepicker._getFormatConfig(inst)); |
| 1495 | } |
| 1496 | catch (e) { |
| 1497 | // Ignore |
| 1498 | } |
| 1499 | |
| 1500 | var date = (offset.toLowerCase().match(/^c/) ? |
| 1501 | $.datepicker._getDate(inst) : null) || new Date(), |
| 1502 | year = date.getFullYear(), |
| 1503 | month = date.getMonth(), |
| 1504 | day = date.getDate(), |
| 1505 | pattern = /([+\-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g, |
| 1506 | matches = pattern.exec(offset); |
| 1507 | |
| 1508 | while (matches) { |
| 1509 | switch (matches[2] || "d") { |
| 1510 | case "d" : case "D" : |
| 1511 | day += parseInt(matches[1],10); break; |
| 1512 | case "w" : case "W" : |
| 1513 | day += parseInt(matches[1],10) * 7; break; |
| 1514 | case "m" : case "M" : |
| 1515 | month += parseInt(matches[1],10); |
| 1516 | day = Math.min(day, $.datepicker._getDaysInMonth(year, month)); |
| 1517 | break; |
| 1518 | case "y": case "Y" : |
| 1519 | year += parseInt(matches[1],10); |
| 1520 | day = Math.min(day, $.datepicker._getDaysInMonth(year, month)); |
| 1521 | break; |
| 1522 | } |
| 1523 | matches = pattern.exec(offset); |
| 1524 | } |
| 1525 | return new Date(year, month, day); |
| 1526 | }, |
| 1527 | newDate = (date == null || date === "" ? defaultDate : (typeof date === "string" ? offsetString(date) : |
| 1528 | (typeof date === "number" ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : new Date(date.getTime())))); |
| 1529 | |
| 1530 | newDate = (newDate && newDate.toString() === "Invalid Date" ? defaultDate : newDate); |
| 1531 | if (newDate) { |
| 1532 | newDate.setHours(0); |
| 1533 | newDate.setMinutes(0); |
| 1534 | newDate.setSeconds(0); |
| 1535 | newDate.setMilliseconds(0); |
| 1536 | } |
| 1537 | return this._daylightSavingAdjust(newDate); |
| 1538 | }, |
| 1539 | |
| 1540 | /* Handle switch to/from daylight saving. |
| 1541 | * Hours may be non-zero on daylight saving cut-over: |
| 1542 | * > 12 when midnight changeover, but then cannot generate |
| 1543 | * midnight datetime, so jump to 1AM, otherwise reset. |
| 1544 | * @param date (Date) the date to check |
| 1545 | * @return (Date) the corrected date |
| 1546 | */ |
| 1547 | _daylightSavingAdjust: function(date) { |
| 1548 | if (!date) { |
| 1549 | return null; |
| 1550 | } |
| 1551 | date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0); |
| 1552 | return date; |
| 1553 | }, |
| 1554 | |
| 1555 | /* Set the date(s) directly. */ |
| 1556 | _setDate: function(inst, date, noChange) { |
| 1557 | var clear = !date, |
| 1558 | origMonth = inst.selectedMonth, |
| 1559 | origYear = inst.selectedYear, |
| 1560 | newDate = this._restrictMinMax(inst, this._determineDate(inst, date, new Date())); |
| 1561 | |
| 1562 | inst.selectedDay = inst.currentDay = newDate.getDate(); |
| 1563 | inst.drawMonth = inst.selectedMonth = inst.currentMonth = newDate.getMonth(); |
| 1564 | inst.drawYear = inst.selectedYear = inst.currentYear = newDate.getFullYear(); |
| 1565 | if ((origMonth !== inst.selectedMonth || origYear !== inst.selectedYear) && !noChange) { |
| 1566 | this._notifyChange(inst); |
| 1567 | } |
| 1568 | this._adjustInstDate(inst); |
| 1569 | if (inst.input) { |
| 1570 | inst.input.val(clear ? "" : this._formatDate(inst)); |
| 1571 | } |
| 1572 | }, |
| 1573 | |
| 1574 | /* Retrieve the date(s) directly. */ |
| 1575 | _getDate: function(inst) { |
| 1576 | var startDate = (!inst.currentYear || (inst.input && inst.input.val() === "") ? null : |
| 1577 | this._daylightSavingAdjust(new Date( |
| 1578 | inst.currentYear, inst.currentMonth, inst.currentDay))); |
| 1579 | return startDate; |
| 1580 | }, |
| 1581 | |
| 1582 | /* Attach the onxxx handlers. These are declared statically so |
| 1583 | * they work with static code transformers like Caja. |
| 1584 | */ |
| 1585 | _attachHandlers: function(inst) { |
| 1586 | var stepMonths = this._get(inst, "stepMonths"), |
| 1587 | id = "#" + inst.id.replace( /\\\\/g, "\\" ); |
| 1588 | inst.dpDiv.find("[data-handler]").map(function () { |
| 1589 | var handler = { |
| 1590 | prev: function () { |
| 1591 | $.datepicker._adjustDate(id, -stepMonths, "M"); |
| 1592 | }, |
| 1593 | next: function () { |
| 1594 | $.datepicker._adjustDate(id, +stepMonths, "M"); |
| 1595 | }, |
| 1596 | hide: function () { |
| 1597 | $.datepicker._hideDatepicker(); |
| 1598 | }, |
| 1599 | today: function () { |
| 1600 | $.datepicker._gotoToday(id); |
| 1601 | }, |
| 1602 | selectDay: function () { |
| 1603 | $.datepicker._selectDay(id, +this.getAttribute("data-month"), +this.getAttribute("data-year"), this); |
| 1604 | return false; |
| 1605 | }, |
| 1606 | selectMonth: function () { |
| 1607 | $.datepicker._selectMonthYear(id, this, "M"); |
| 1608 | return false; |
| 1609 | }, |
| 1610 | selectYear: function () { |
| 1611 | $.datepicker._selectMonthYear(id, this, "Y"); |
| 1612 | return false; |
| 1613 | } |
| 1614 | }; |
| 1615 | $(this).bind(this.getAttribute("data-event"), handler[this.getAttribute("data-handler")]); |
| 1616 | }); |
| 1617 | }, |
| 1618 | |
| 1619 | /* Generate the HTML for the current state of the date picker. */ |
| 1620 | _generateHTML: function(inst) { |
| 1621 | var maxDraw, prevText, prev, nextText, next, currentText, gotoDate, |
| 1622 | controls, buttonPanel, firstDay, showWeek, dayNames, dayNamesMin, |
| 1623 | monthNames, monthNamesShort, beforeShowDay, showOtherMonths, |
| 1624 | selectOtherMonths, defaultDate, html, dow, row, group, col, selectedDate, |
| 1625 | cornerClass, calender, thead, day, daysInMonth, leadDays, curRows, numRows, |
| 1626 | printDate, dRow, tbody, daySettings, otherMonth, unselectable, |
| 1627 | tempDate = new Date(), |
| 1628 | today = this._daylightSavingAdjust( |
| 1629 | new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())), // clear time |
| 1630 | isRTL = this._get(inst, "isRTL"), |
| 1631 | showButtonPanel = this._get(inst, "showButtonPanel"), |
| 1632 | hideIfNoPrevNext = this._get(inst, "hideIfNoPrevNext"), |
| 1633 | navigationAsDateFormat = this._get(inst, "navigationAsDateFormat"), |
| 1634 | numMonths = this._getNumberOfMonths(inst), |
| 1635 | showCurrentAtPos = this._get(inst, "showCurrentAtPos"), |
| 1636 | stepMonths = this._get(inst, "stepMonths"), |
| 1637 | isMultiMonth = (numMonths[0] !== 1 || numMonths[1] !== 1), |
| 1638 | currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) : |
| 1639 | new Date(inst.currentYear, inst.currentMonth, inst.currentDay))), |
| 1640 | minDate = this._getMinMaxDate(inst, "min"), |
| 1641 | maxDate = this._getMinMaxDate(inst, "max"), |
| 1642 | drawMonth = inst.drawMonth - showCurrentAtPos, |
| 1643 | drawYear = inst.drawYear; |
| 1644 | |
| 1645 | if (drawMonth < 0) { |
| 1646 | drawMonth += 12; |
| 1647 | drawYear--; |
| 1648 | } |
| 1649 | if (maxDate) { |
| 1650 | maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(), |
| 1651 | maxDate.getMonth() - (numMonths[0] * numMonths[1]) + 1, maxDate.getDate())); |
| 1652 | maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw); |
| 1653 | while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) { |
| 1654 | drawMonth--; |
| 1655 | if (drawMonth < 0) { |
| 1656 | drawMonth = 11; |
| 1657 | drawYear--; |
| 1658 | } |
| 1659 | } |
| 1660 | } |
| 1661 | inst.drawMonth = drawMonth; |
| 1662 | inst.drawYear = drawYear; |
| 1663 | |
| 1664 | prevText = this._get(inst, "prevText"); |
| 1665 | prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText, |
| 1666 | this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)), |
| 1667 | this._getFormatConfig(inst))); |
| 1668 | |
| 1669 | prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ? |
| 1670 | "<a class='ui-datepicker-prev ui-corner-all' data-handler='prev' data-event='click'" + |
| 1671 | " title='" + prevText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "e" : "w") + "'>" + prevText + "</span></a>" : |
| 1672 | (hideIfNoPrevNext ? "" : "<a class='ui-datepicker-prev ui-corner-all ui-state-disabled' title='"+ prevText +"'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "e" : "w") + "'>" + prevText + "</span></a>")); |
| 1673 | |
| 1674 | nextText = this._get(inst, "nextText"); |
| 1675 | nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText, |
| 1676 | this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)), |
| 1677 | this._getFormatConfig(inst))); |
| 1678 | |
| 1679 | next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ? |
| 1680 | "<a class='ui-datepicker-next ui-corner-all' data-handler='next' data-event='click'" + |
| 1681 | " title='" + nextText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "w" : "e") + "'>" + nextText + "</span></a>" : |
| 1682 | (hideIfNoPrevNext ? "" : "<a class='ui-datepicker-next ui-corner-all ui-state-disabled' title='"+ nextText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "w" : "e") + "'>" + nextText + "</span></a>")); |
| 1683 | |
| 1684 | currentText = this._get(inst, "currentText"); |
| 1685 | gotoDate = (this._get(inst, "gotoCurrent") && inst.currentDay ? currentDate : today); |
| 1686 | currentText = (!navigationAsDateFormat ? currentText : |
| 1687 | this.formatDate(currentText, gotoDate, this._getFormatConfig(inst))); |
| 1688 | |
| 1689 | controls = (!inst.inline ? "<button type='button' class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all' data-handler='hide' data-event='click'>" + |
| 1690 | this._get(inst, "closeText") + "</button>" : ""); |
| 1691 | |
| 1692 | buttonPanel = (showButtonPanel) ? "<div class='ui-datepicker-buttonpane ui-widget-content'>" + (isRTL ? controls : "") + |
| 1693 | (this._isInRange(inst, gotoDate) ? "<button type='button' class='ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all' data-handler='today' data-event='click'" + |
| 1694 | ">" + currentText + "</button>" : "") + (isRTL ? "" : controls) + "</div>" : ""; |
| 1695 | |
| 1696 | firstDay = parseInt(this._get(inst, "firstDay"),10); |
| 1697 | firstDay = (isNaN(firstDay) ? 0 : firstDay); |
| 1698 | |
| 1699 | showWeek = this._get(inst, "showWeek"); |
| 1700 | dayNames = this._get(inst, "dayNames"); |
| 1701 | dayNamesMin = this._get(inst, "dayNamesMin"); |
| 1702 | monthNames = this._get(inst, "monthNames"); |
| 1703 | monthNamesShort = this._get(inst, "monthNamesShort"); |
| 1704 | beforeShowDay = this._get(inst, "beforeShowDay"); |
| 1705 | showOtherMonths = this._get(inst, "showOtherMonths"); |
| 1706 | selectOtherMonths = this._get(inst, "selectOtherMonths"); |
| 1707 | defaultDate = this._getDefaultDate(inst); |
| 1708 | html = ""; |
| 1709 | dow; |
| 1710 | for (row = 0; row < numMonths[0]; row++) { |
| 1711 | group = ""; |
| 1712 | this.maxRows = 4; |
| 1713 | for (col = 0; col < numMonths[1]; col++) { |
| 1714 | selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay)); |
| 1715 | cornerClass = " ui-corner-all"; |
| 1716 | calender = ""; |
| 1717 | if (isMultiMonth) { |
| 1718 | calender += "<div class='ui-datepicker-group"; |
| 1719 | if (numMonths[1] > 1) { |
| 1720 | switch (col) { |
| 1721 | case 0: calender += " ui-datepicker-group-first"; |
| 1722 | cornerClass = " ui-corner-" + (isRTL ? "right" : "left"); break; |
| 1723 | case numMonths[1]-1: calender += " ui-datepicker-group-last"; |
| 1724 | cornerClass = " ui-corner-" + (isRTL ? "left" : "right"); break; |
| 1725 | default: calender += " ui-datepicker-group-middle"; cornerClass = ""; break; |
| 1726 | } |
| 1727 | } |
| 1728 | calender += "'>"; |
| 1729 | } |
| 1730 | calender += "<div class='ui-datepicker-header ui-widget-header ui-helper-clearfix" + cornerClass + "'>" + |
| 1731 | (/all|left/.test(cornerClass) && row === 0 ? (isRTL ? next : prev) : "") + |
| 1732 | (/all|right/.test(cornerClass) && row === 0 ? (isRTL ? prev : next) : "") + |
| 1733 | this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate, |
| 1734 | row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers |
| 1735 | "</div><table class='ui-datepicker-calendar'><thead>" + |
| 1736 | "<tr>"; |
| 1737 | thead = (showWeek ? "<th class='ui-datepicker-week-col'>" + this._get(inst, "weekHeader") + "</th>" : ""); |
| 1738 | for (dow = 0; dow < 7; dow++) { // days of the week |
| 1739 | day = (dow + firstDay) % 7; |
| 1740 | thead += "<th scope='col'" + ((dow + firstDay + 6) % 7 >= 5 ? " class='ui-datepicker-week-end'" : "") + ">" + |
| 1741 | "<span title='" + dayNames[day] + "'>" + dayNamesMin[day] + "</span></th>"; |
| 1742 | } |
| 1743 | calender += thead + "</tr></thead><tbody>"; |
| 1744 | daysInMonth = this._getDaysInMonth(drawYear, drawMonth); |
| 1745 | if (drawYear === inst.selectedYear && drawMonth === inst.selectedMonth) { |
| 1746 | inst.selectedDay = Math.min(inst.selectedDay, daysInMonth); |
| 1747 | } |
| 1748 | leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7; |
| 1749 | curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate |
| 1750 | numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043) |
| 1751 | this.maxRows = numRows; |
| 1752 | printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays)); |
| 1753 | for (dRow = 0; dRow < numRows; dRow++) { // create date picker rows |
| 1754 | calender += "<tr>"; |
| 1755 | tbody = (!showWeek ? "" : "<td class='ui-datepicker-week-col'>" + |
| 1756 | this._get(inst, "calculateWeek")(printDate) + "</td>"); |
| 1757 | for (dow = 0; dow < 7; dow++) { // create date picker days |
| 1758 | daySettings = (beforeShowDay ? |
| 1759 | beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, ""]); |
| 1760 | otherMonth = (printDate.getMonth() !== drawMonth); |
| 1761 | unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] || |
| 1762 | (minDate && printDate < minDate) || (maxDate && printDate > maxDate); |
| 1763 | tbody += "<td class='" + |
| 1764 | ((dow + firstDay + 6) % 7 >= 5 ? " ui-datepicker-week-end" : "") + // highlight weekends |
| 1765 | (otherMonth ? " ui-datepicker-other-month" : "") + // highlight days from other months |
| 1766 | ((printDate.getTime() === selectedDate.getTime() && drawMonth === inst.selectedMonth && inst._keyEvent) || // user pressed key |
| 1767 | (defaultDate.getTime() === printDate.getTime() && defaultDate.getTime() === selectedDate.getTime()) ? |
| 1768 | // or defaultDate is current printedDate and defaultDate is selectedDate |
| 1769 | " " + this._dayOverClass : "") + // highlight selected day |
| 1770 | (unselectable ? " " + this._unselectableClass + " ui-state-disabled": "") + // highlight unselectable days |
| 1771 | (otherMonth && !showOtherMonths ? "" : " " + daySettings[1] + // highlight custom dates |
| 1772 | (printDate.getTime() === currentDate.getTime() ? " " + this._currentClass : "") + // highlight selected day |
| 1773 | (printDate.getTime() === today.getTime() ? " ui-datepicker-today" : "")) + "'" + // highlight today (if different) |
| 1774 | ((!otherMonth || showOtherMonths) && daySettings[2] ? " title='" + daySettings[2].replace(/'/g, "'") + "'" : "") + // cell title |
| 1775 | (unselectable ? "" : " data-handler='selectDay' data-event='click' data-month='" + printDate.getMonth() + "' data-year='" + printDate.getFullYear() + "'") + ">" + // actions |
| 1776 | (otherMonth && !showOtherMonths ? " " : // display for other months |
| 1777 | (unselectable ? "<span class='ui-state-default'>" + printDate.getDate() + "</span>" : "<a class='ui-state-default" + |
| 1778 | (printDate.getTime() === today.getTime() ? " ui-state-highlight" : "") + |
| 1779 | (printDate.getTime() === currentDate.getTime() ? " ui-state-active" : "") + // highlight selected day |
| 1780 | (otherMonth ? " ui-priority-secondary" : "") + // distinguish dates from other months |
| 1781 | "' href='#'>" + printDate.getDate() + "</a>")) + "</td>"; // display selectable date |
| 1782 | printDate.setDate(printDate.getDate() + 1); |
| 1783 | printDate = this._daylightSavingAdjust(printDate); |
| 1784 | } |
| 1785 | calender += tbody + "</tr>"; |
| 1786 | } |
| 1787 | drawMonth++; |
| 1788 | if (drawMonth > 11) { |
| 1789 | drawMonth = 0; |
| 1790 | drawYear++; |
| 1791 | } |
| 1792 | calender += "</tbody></table>" + (isMultiMonth ? "</div>" + |
| 1793 | ((numMonths[0] > 0 && col === numMonths[1]-1) ? "<div class='ui-datepicker-row-break'></div>" : "") : ""); |
| 1794 | group += calender; |
| 1795 | } |
| 1796 | html += group; |
| 1797 | } |
| 1798 | html += buttonPanel; |
| 1799 | inst._keyEvent = false; |
| 1800 | return html; |
| 1801 | }, |
| 1802 | |
| 1803 | /* Generate the month and year header. */ |
| 1804 | _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate, |
| 1805 | secondary, monthNames, monthNamesShort) { |
| 1806 | |
| 1807 | var inMinYear, inMaxYear, month, years, thisYear, determineYear, year, endYear, |
| 1808 | changeMonth = this._get(inst, "changeMonth"), |
| 1809 | changeYear = this._get(inst, "changeYear"), |
| 1810 | showMonthAfterYear = this._get(inst, "showMonthAfterYear"), |
| 1811 | html = "<div class='ui-datepicker-title'>", |
| 1812 | monthHtml = ""; |
| 1813 | |
| 1814 | // month selection |
| 1815 | if (secondary || !changeMonth) { |
| 1816 | monthHtml += "<span class='ui-datepicker-month'>" + monthNames[drawMonth] + "</span>"; |
| 1817 | } else { |
| 1818 | inMinYear = (minDate && minDate.getFullYear() === drawYear); |
| 1819 | inMaxYear = (maxDate && maxDate.getFullYear() === drawYear); |
| 1820 | monthHtml += "<select class='ui-datepicker-month' data-handler='selectMonth' data-event='change'>"; |
| 1821 | for ( month = 0; month < 12; month++) { |
| 1822 | if ((!inMinYear || month >= minDate.getMonth()) && (!inMaxYear || month <= maxDate.getMonth())) { |
| 1823 | monthHtml += "<option value='" + month + "'" + |
| 1824 | (month === drawMonth ? " selected='selected'" : "") + |
| 1825 | ">" + monthNamesShort[month] + "</option>"; |
| 1826 | } |
| 1827 | } |
| 1828 | monthHtml += "</select>"; |
| 1829 | } |
| 1830 | |
| 1831 | if (!showMonthAfterYear) { |
| 1832 | html += monthHtml + (secondary || !(changeMonth && changeYear) ? " " : ""); |
| 1833 | } |
| 1834 | |
| 1835 | // year selection |
| 1836 | if ( !inst.yearshtml ) { |
| 1837 | inst.yearshtml = ""; |
| 1838 | if (secondary || !changeYear) { |
| 1839 | html += "<span class='ui-datepicker-year'>" + drawYear + "</span>"; |
| 1840 | } else { |
| 1841 | // determine range of years to display |
| 1842 | years = this._get(inst, "yearRange").split(":"); |
| 1843 | thisYear = new Date().getFullYear(); |
| 1844 | determineYear = function(value) { |
| 1845 | var year = (value.match(/c[+\-].*/) ? drawYear + parseInt(value.substring(1), 10) : |
| 1846 | (value.match(/[+\-].*/) ? thisYear + parseInt(value, 10) : |
| 1847 | parseInt(value, 10))); |
| 1848 | return (isNaN(year) ? thisYear : year); |
| 1849 | }; |
| 1850 | year = determineYear(years[0]); |
| 1851 | endYear = Math.max(year, determineYear(years[1] || "")); |
| 1852 | year = (minDate ? Math.max(year, minDate.getFullYear()) : year); |
| 1853 | endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear); |
| 1854 | inst.yearshtml += "<select class='ui-datepicker-year' data-handler='selectYear' data-event='change'>"; |
| 1855 | for (; year <= endYear; year++) { |
| 1856 | inst.yearshtml += "<option value='" + year + "'" + |
| 1857 | (year === drawYear ? " selected='selected'" : "") + |
| 1858 | ">" + year + "</option>"; |
| 1859 | } |
| 1860 | inst.yearshtml += "</select>"; |
| 1861 | |
| 1862 | html += inst.yearshtml; |
| 1863 | inst.yearshtml = null; |
| 1864 | } |
| 1865 | } |
| 1866 | |
| 1867 | html += this._get(inst, "yearSuffix"); |
| 1868 | if (showMonthAfterYear) { |
| 1869 | html += (secondary || !(changeMonth && changeYear) ? " " : "") + monthHtml; |
| 1870 | } |
| 1871 | html += "</div>"; // Close datepicker_header |
| 1872 | return html; |
| 1873 | }, |
| 1874 | |
| 1875 | /* Adjust one of the date sub-fields. */ |
| 1876 | _adjustInstDate: function(inst, offset, period) { |
| 1877 | var year = inst.drawYear + (period === "Y" ? offset : 0), |
| 1878 | month = inst.drawMonth + (period === "M" ? offset : 0), |
| 1879 | day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) + (period === "D" ? offset : 0), |
| 1880 | date = this._restrictMinMax(inst, this._daylightSavingAdjust(new Date(year, month, day))); |
| 1881 | |
| 1882 | inst.selectedDay = date.getDate(); |
| 1883 | inst.drawMonth = inst.selectedMonth = date.getMonth(); |
| 1884 | inst.drawYear = inst.selectedYear = date.getFullYear(); |
| 1885 | if (period === "M" || period === "Y") { |
| 1886 | this._notifyChange(inst); |
| 1887 | } |
| 1888 | }, |
| 1889 | |
| 1890 | /* Ensure a date is within any min/max bounds. */ |
| 1891 | _restrictMinMax: function(inst, date) { |
| 1892 | var minDate = this._getMinMaxDate(inst, "min"), |
| 1893 | maxDate = this._getMinMaxDate(inst, "max"), |
| 1894 | newDate = (minDate && date < minDate ? minDate : date); |
| 1895 | return (maxDate && newDate > maxDate ? maxDate : newDate); |
| 1896 | }, |
| 1897 | |
| 1898 | /* Notify change of month/year. */ |
| 1899 | _notifyChange: function(inst) { |
| 1900 | var onChange = this._get(inst, "onChangeMonthYear"); |
| 1901 | if (onChange) { |
| 1902 | onChange.apply((inst.input ? inst.input[0] : null), |
| 1903 | [inst.selectedYear, inst.selectedMonth + 1, inst]); |
| 1904 | } |
| 1905 | }, |
| 1906 | |
| 1907 | /* Determine the number of months to show. */ |
| 1908 | _getNumberOfMonths: function(inst) { |
| 1909 | var numMonths = this._get(inst, "numberOfMonths"); |
| 1910 | return (numMonths == null ? [1, 1] : (typeof numMonths === "number" ? [1, numMonths] : numMonths)); |
| 1911 | }, |
| 1912 | |
| 1913 | /* Determine the current maximum date - ensure no time components are set. */ |
| 1914 | _getMinMaxDate: function(inst, minMax) { |
| 1915 | return this._determineDate(inst, this._get(inst, minMax + "Date"), null); |
| 1916 | }, |
| 1917 | |
| 1918 | /* Find the number of days in a given month. */ |
| 1919 | _getDaysInMonth: function(year, month) { |
| 1920 | return 32 - this._daylightSavingAdjust(new Date(year, month, 32)).getDate(); |
| 1921 | }, |
| 1922 | |
| 1923 | /* Find the day of the week of the first of a month. */ |
| 1924 | _getFirstDayOfMonth: function(year, month) { |
| 1925 | return new Date(year, month, 1).getDay(); |
| 1926 | }, |
| 1927 | |
| 1928 | /* Determines if we should allow a "next/prev" month display change. */ |
| 1929 | _canAdjustMonth: function(inst, offset, curYear, curMonth) { |
| 1930 | var numMonths = this._getNumberOfMonths(inst), |
| 1931 | date = this._daylightSavingAdjust(new Date(curYear, |
| 1932 | curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1)); |
| 1933 | |
| 1934 | if (offset < 0) { |
| 1935 | date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth())); |
| 1936 | } |
| 1937 | return this._isInRange(inst, date); |
| 1938 | }, |
| 1939 | |
| 1940 | /* Is the given date in the accepted range? */ |
| 1941 | _isInRange: function(inst, date) { |
| 1942 | var yearSplit, currentYear, |
| 1943 | minDate = this._getMinMaxDate(inst, "min"), |
| 1944 | maxDate = this._getMinMaxDate(inst, "max"), |
| 1945 | minYear = null, |
| 1946 | maxYear = null, |
| 1947 | years = this._get(inst, "yearRange"); |
| 1948 | if (years){ |
| 1949 | yearSplit = years.split(":"); |
| 1950 | currentYear = new Date().getFullYear(); |
| 1951 | minYear = parseInt(yearSplit[0], 10); |
| 1952 | maxYear = parseInt(yearSplit[1], 10); |
| 1953 | if ( yearSplit[0].match(/[+\-].*/) ) { |
| 1954 | minYear += currentYear; |
| 1955 | } |
| 1956 | if ( yearSplit[1].match(/[+\-].*/) ) { |
| 1957 | maxYear += currentYear; |
| 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | return ((!minDate || date.getTime() >= minDate.getTime()) && |
| 1962 | (!maxDate || date.getTime() <= maxDate.getTime()) && |
| 1963 | (!minYear || date.getFullYear() >= minYear) && |
| 1964 | (!maxYear || date.getFullYear() <= maxYear)); |
| 1965 | }, |
| 1966 | |
| 1967 | /* Provide the configuration settings for formatting/parsing. */ |
| 1968 | _getFormatConfig: function(inst) { |
| 1969 | var shortYearCutoff = this._get(inst, "shortYearCutoff"); |
| 1970 | shortYearCutoff = (typeof shortYearCutoff !== "string" ? shortYearCutoff : |
| 1971 | new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10)); |
| 1972 | return {shortYearCutoff: shortYearCutoff, |
| 1973 | dayNamesShort: this._get(inst, "dayNamesShort"), dayNames: this._get(inst, "dayNames"), |
| 1974 | monthNamesShort: this._get(inst, "monthNamesShort"), monthNames: this._get(inst, "monthNames")}; |
| 1975 | }, |
| 1976 | |
| 1977 | /* Format the given date for display. */ |
| 1978 | _formatDate: function(inst, day, month, year) { |
| 1979 | if (!day) { |
| 1980 | inst.currentDay = inst.selectedDay; |
| 1981 | inst.currentMonth = inst.selectedMonth; |
| 1982 | inst.currentYear = inst.selectedYear; |
| 1983 | } |
| 1984 | var date = (day ? (typeof day === "object" ? day : |
| 1985 | this._daylightSavingAdjust(new Date(year, month, day))) : |
| 1986 | this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay))); |
| 1987 | return this.formatDate(this._get(inst, "dateFormat"), date, this._getFormatConfig(inst)); |
| 1988 | } |
| 1989 | }); |
| 1990 | |
| 1991 | /* |
| 1992 | * Bind hover events for datepicker elements. |
| 1993 | * Done via delegate so the binding only occurs once in the lifetime of the parent div. |
| 1994 | * Global datepicker_instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker. |
| 1995 | */ |
| 1996 | function datepicker_bindHover(dpDiv) { |
| 1997 | var selector = "button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a"; |
| 1998 | return dpDiv.delegate(selector, "mouseout", function() { |
| 1999 | $(this).removeClass("ui-state-hover"); |
| 2000 | if (this.className.indexOf("ui-datepicker-prev") !== -1) { |
| 2001 | $(this).removeClass("ui-datepicker-prev-hover"); |
| 2002 | } |
| 2003 | if (this.className.indexOf("ui-datepicker-next") !== -1) { |
| 2004 | $(this).removeClass("ui-datepicker-next-hover"); |
| 2005 | } |
| 2006 | }) |
| 2007 | .delegate( selector, "mouseover", datepicker_handleMouseover ); |
| 2008 | } |
| 2009 | |
| 2010 | function datepicker_handleMouseover() { |
| 2011 | if (!$.datepicker._isDisabledDatepicker( datepicker_instActive.inline? datepicker_instActive.dpDiv.parent()[0] : datepicker_instActive.input[0])) { |
| 2012 | $(this).parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover"); |
| 2013 | $(this).addClass("ui-state-hover"); |
| 2014 | if (this.className.indexOf("ui-datepicker-prev") !== -1) { |
| 2015 | $(this).addClass("ui-datepicker-prev-hover"); |
| 2016 | } |
| 2017 | if (this.className.indexOf("ui-datepicker-next") !== -1) { |
| 2018 | $(this).addClass("ui-datepicker-next-hover"); |
| 2019 | } |
| 2020 | } |
| 2021 | } |
| 2022 | |
| 2023 | /* jQuery extend now ignores nulls! */ |
| 2024 | function datepicker_extendRemove(target, props) { |
| 2025 | $.extend(target, props); |
| 2026 | for (var name in props) { |
| 2027 | if (props[name] == null) { |
| 2028 | target[name] = props[name]; |
| 2029 | } |
| 2030 | } |
| 2031 | return target; |
| 2032 | } |
| 2033 | |
| 2034 | /* Invoke the datepicker functionality. |
| 2035 | @param options string - a command, optionally followed by additional parameters or |
| 2036 | Object - settings for attaching new datepicker functionality |
| 2037 | @return jQuery object */ |
| 2038 | $.fn.datepicker = function(options){ |
| 2039 | |
| 2040 | /* Verify an empty collection wasn't passed - Fixes #6976 */ |
| 2041 | if ( !this.length ) { |
| 2042 | return this; |
| 2043 | } |
| 2044 | |
| 2045 | /* Initialise the date picker. */ |
| 2046 | if (!$.datepicker.initialized) { |
| 2047 | $(document).mousedown($.datepicker._checkExternalClick); |
| 2048 | $.datepicker.initialized = true; |
| 2049 | } |
| 2050 | |
| 2051 | /* Append datepicker main container to body if not exist. */ |
| 2052 | if ($("#"+$.datepicker._mainDivId).length === 0) { |
| 2053 | $("body").append($.datepicker.dpDiv); |
| 2054 | } |
| 2055 | |
| 2056 | var otherArgs = Array.prototype.slice.call(arguments, 1); |
| 2057 | if (typeof options === "string" && (options === "isDisabled" || options === "getDate" || options === "widget")) { |
| 2058 | return $.datepicker["_" + options + "Datepicker"]. |
| 2059 | apply($.datepicker, [this[0]].concat(otherArgs)); |
| 2060 | } |
| 2061 | if (options === "option" && arguments.length === 2 && typeof arguments[1] === "string") { |
| 2062 | return $.datepicker["_" + options + "Datepicker"]. |
| 2063 | apply($.datepicker, [this[0]].concat(otherArgs)); |
| 2064 | } |
| 2065 | return this.each(function() { |
| 2066 | typeof options === "string" ? |
| 2067 | $.datepicker["_" + options + "Datepicker"]. |
| 2068 | apply($.datepicker, [this].concat(otherArgs)) : |
| 2069 | $.datepicker._attachDatepicker(this, options); |
| 2070 | }); |
| 2071 | }; |
| 2072 | |
| 2073 | $.datepicker = new Datepicker(); // singleton instance |
| 2074 | $.datepicker.initialized = false; |
| 2075 | $.datepicker.uuid = new Date().getTime(); |
| 2076 | $.datepicker.version = "1.11.1"; |
| 2077 | |
| 2078 | return $.datepicker; |
| 2079 | |
| 2080 | })); |