diff --git a/dist/calendar.js b/dist/calendar.js index 59aa736..b30b76f 100644 --- a/dist/calendar.js +++ b/dist/calendar.js @@ -769,7 +769,8 @@ if (!minDate && !maxDate) { var startDate = module.get.startDate(); minDate = startDate && settings.minDate ? new Date(Math.max(startDate, settings.minDate)) : startDate || settings.minDate; - maxDate = settings.maxDate; + var endDate = module.get.endDate(); + maxDate = endDate && settings.maxDate ? new Date(Math.min(endDate, settings.maxDate)) : endDate || settings.maxDate; } minDate = minDate && new Date(minDate.getFullYear(), minDate.getMonth(), minDate.getDate(), minDate.getHours(), 5 * Math.ceil(minDate.getMinutes() / 5)); return !(!date || diff --git a/dist/calendar.min.js b/dist/calendar.min.js index 7cda4b8..edcc243 100644 --- a/dist/calendar.min.js +++ b/dist/calendar.min.js @@ -1 +1 @@ -!function(e,t,a,n){"use strict";t="undefined"!=typeof t&&t.Math==Math?t:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.calendar=function(t){var o,r=e(this),i=r.selector||"",l=(new Date).getTime(),d=[],s=arguments[0],u="string"==typeof s,p=[].slice.call(arguments,1);return r.each(function(){var r,c,f=e.isPlainObject(t)?e.extend(!0,{},e.fn.calendar.settings,t):e.extend({},e.fn.calendar.settings),h=f.className,g=f.namespace,m=f.selector,v=f.formatter,y=f.parser,D=f.metadata,b=f.error,C="."+g,M="module-"+g,w=e(this),x=w.find(m.input),k=w.find(m.popup),T=w.find(m.activator),F=this,H=w.data(M),O=!1,I=!1;c={initialize:function(){c.debug("Initializing calendar for",F),r=c.get.isTouch(),c.setup.popup(),c.setup.inline(),c.setup.input(),c.setup.date(),c.create.calendar(),c.bind.events(),c.instantiate()},instantiate:function(){c.verbose("Storing instance of calendar"),H=c,w.data(M,H)},destroy:function(){c.verbose("Destroying previous calendar for",F),w.removeData(M),c.unbind.events()},setup:{popup:function(){if(!f.inline&&(T.length||(T=w.children().first(),T.length))){if(e.fn.popup===n)return void c.error(b.popup);k.length||(k=e("
").addClass(h.popup).prependTo(T.parent())),k.addClass(h.calendar);var t=f.onVisible,a=f.onHidden;x.length||(k.attr("tabindex","0"),t=function(){return c.focus(),f.onVisible.apply(k,arguments)},a=function(){return c.blur(),f.onHidden.apply(k,arguments)});var o=function(){return c.set.focusDate(c.get.date()),c.set.mode(f.startMode),f.onShow.apply(k,arguments)},r=f.on||(x.length?"focus":"click"),i=e.extend({},f.popupOptions,{popup:k,on:r,hoverable:"hover"===r,onShow:o,onVisible:t,onHide:f.onHide,onHidden:a});c.popup(i)}},inline:function(){T.length&&!f.inline||(k=e("
").addClass(h.calendar).appendTo(w),x.length||k.attr("tabindex","0"))},input:function(){f.touchReadonly&&x.length&&r&&x.prop("readonly",!0)},date:function(){if(x.length){var e=x.val(),t=y.date(e,f);c.set.date(t,f.formatInput,!1)}}},create:{calendar:function(){var t,a,n,o,r,i,l,d=c.get.mode(),s=new Date,u=c.get.date(),p=c.get.focusDate(),g=p||u||f.initialDate||s;g=c.helper.dateInRange(g),p||(p=g,c.set.focusDate(p,!1,!1));var m="year"===d,y="month"===d,b="day"===d,C="hour"===d,M="minute"===d,w="time"===f.type,x=Math.max(f.multiMonth,1),T=b?c.get.monthOffset():0,F=g.getMinutes(),H=g.getHours(),O=g.getDate(),I=g.getMonth()+T,N=g.getFullYear(),Y=b?7:C?4:3,E=7===Y?"seven":4===Y?"four":"three",R=b||C?6:4,j=b?x:1,A=k;for(A.empty(),j>1&&(l=e("
").addClass(h.grid).appendTo(A)),o=0;o1){var S=e("
").addClass(h.column).appendTo(l);A=S}var V=I+o,P=(new Date(N,V,1).getDay()-f.firstDayOfWeek%7+7)%7;if(!f.constantHeight&&b){var q=new Date(N,V+1,0).getDate()+P;R=Math.ceil(q/7)}var K=m?10:y?1:0,J=b?1:0,W=C||M?1:0,z=C||M?O:1,L=new Date(N-K,V-J,z-W,H),B=new Date(N+K,V+J,z+W,H),U=m?new Date(10*Math.ceil(N/10)-9,0,0):y?new Date(N,0,0):b?new Date(N,V,0):new Date(N,V,O,(-1)),Q=m?new Date(10*Math.ceil(N/10)+1,0,1):y?new Date(N+1,0,1):b?new Date(N,V+1,1):new Date(N,V,O+1),Z=e("").addClass(h.table).addClass(E+" column").addClass(d).appendTo(A);if(!w){var G=e("").appendTo(Z);r=e("").appendTo(G),i=e("").appendTo(G),t=0;t").appendTo(r),i.text(v.dayColumnHeader((t+f.firstDayOfWeek)%7,f))}var ae=e("").appendTo(Z);for(t=m?10*Math.ceil(N/10)-9:b?1-P:0,a=0;a").appendTo(ae),n=0;n").addClass(h.cell).appendTo(r),i.text(oe),i.data(D.date,ne);var re=b&&ne.getMonth()!==(V+12)%12,ie=re||!c.helper.isDateInRange(ne,d)||f.isDisabled(ne,d),le=c.helper.dateEqual(ne,u,d),de=c.helper.dateEqual(ne,s,d);i.toggleClass(h.adjacentCell,re),i.toggleClass(h.disabledCell,ie),i.toggleClass(h.activeCell,le&&!re),C||M||i.toggleClass(h.todayCell,!re&&de);var se={mode:d,adjacent:re,disabled:ie,active:le,today:de};v.cell(i,ne,se),c.helper.dateEqual(ne,p,d)&&c.set.focusDate(ne,!1,!1)}if(f.today){var ue=e("").appendTo(ae),pe=e("
").attr("colspan",""+Y).appendTo(r);var X=m||y?new Date(N,0,1):b?new Date(N,V,1):new Date(N,V,O,H,F),$=e("").addClass(h.link).appendTo(i);$.text(v.header(X,d,f));var _=y?f.disableYear?"day":"year":b?f.disableMonth?"year":"month":"day";if($.data(D.mode,_),0===o){var ee=e("").addClass(h.prev).appendTo(i);ee.data(D.focusDate,L),ee.toggleClass(h.disabledCell,!c.helper.isDateInRange(U,d)),e("").addClass(h.prevIcon).appendTo(ee)}if(o===j-1){var te=e("").addClass(h.next).appendTo(i);te.data(D.focusDate,B),te.toggleClass(h.disabledCell,!c.helper.isDateInRange(Q,d)),e("").addClass(h.nextIcon).appendTo(te)}if(b)for(r=e("
").attr("colspan",""+Y).addClass(h.today).appendTo(ue);pe.text(v.today(f)),pe.data(D.date,s)}c.update.focus(!1,Z)}}},update:{focus:function(t,a){a=a||k;var n=c.get.mode(),o=c.get.date(),i=c.get.focusDate(),l=c.get.startDate(),d=c.get.endDate(),s=(t?i:null)||o||(r?null:i);a.find("td").each(function(){var t=e(this),a=t.data(D.date);if(a){var o=t.hasClass(h.disabledCell),u=t.hasClass(h.activeCell),p=t.hasClass(h.adjacentCell),f=c.helper.dateEqual(a,i,n),g=!!s&&(!!l&&c.helper.isDateInRange(a,n,l,s)||!!d&&c.helper.isDateInRange(a,n,s,d));t.toggleClass(h.focusCell,f&&(!r||O)&&!p),t.toggleClass(h.rangeCell,g&&!u&&!o)}})}},refresh:function(){c.create.calendar()},bind:{events:function(){k.on("mousedown"+C,c.event.mousedown),k.on("touchstart"+C,c.event.mousedown),k.on("mouseup"+C,c.event.mouseup),k.on("touchend"+C,c.event.mouseup),k.on("mouseover"+C,c.event.mouseover),x.length?(x.on("input"+C,c.event.inputChange),x.on("focus"+C,c.event.inputFocus),x.on("blur"+C,c.event.inputBlur),x.on("click"+C,c.event.inputClick),x.on("keydown"+C,c.event.keydown)):k.on("keydown"+C,c.event.keydown)}},unbind:{events:function(){k.off(C),x.length&&x.off(C)}},event:{mouseover:function(t){var a=e(t.target),n=a.data(D.date),o=1===t.buttons;n&&c.set.focusDate(n,!1,!0,o)},mousedown:function(t){x.length&&t.preventDefault(),O=t.type.indexOf("touch")>=0;var a=e(t.target),n=a.data(D.date);n&&c.set.focusDate(n,!1,!0,!0)},mouseup:function(t){c.focus(),t.preventDefault(),t.stopPropagation(),O=!1;var a=e(t.target),n=a.parent();(n.data(D.date)||n.data(D.focusDate)||n.data(D.mode))&&(a=n);var o=a.data(D.date),r=a.data(D.focusDate),i=a.data(D.mode);if(o){var l=a.hasClass(h.today);c.selectDate(o,l)}else r?c.set.focusDate(r):i&&c.set.mode(i)},keydown:function(e){if(27!==e.keyCode&&9!==e.keyCode||c.popup("hide"),c.popup("is visible"))if(37===e.keyCode||38===e.keyCode||39===e.keyCode||40===e.keyCode){var t=c.get.mode(),a="day"===t?7:"hour"===t?4:3,n=37===e.keyCode?-1:38===e.keyCode?-a:39==e.keyCode?1:a;n*="minute"===t?5:1;var o=c.get.focusDate()||c.get.date()||new Date,r=o.getFullYear()+("year"===t?n:0),i=o.getMonth()+("month"===t?n:0),l=o.getDate()+("day"===t?n:0),d=o.getHours()+("hour"===t?n:0),s=o.getMinutes()+("minute"===t?n:0),u=new Date(r,i,l,d,s);"time"===f.type&&(u=c.helper.mergeDateTime(o,u)),c.helper.isDateInRange(u,t)&&c.set.focusDate(u)}else if(13===e.keyCode){var t=c.get.mode(),p=c.get.focusDate();p&&!f.isDisabled(p,t)&&c.selectDate(p),e.preventDefault(),e.stopPropagation()}38!==e.keyCode&&40!==e.keyCode||(e.preventDefault(),c.popup("show"))},inputChange:function(){var e=x.val(),t=y.date(e,f);c.set.date(t,!1)},inputFocus:function(){k.addClass(h.active)},inputBlur:function(){if(k.removeClass(h.active),f.formatInput){var e=c.get.date(),t=v.datetime(e,f);x.val(t)}},inputClick:function(){c.popup("show")}},get:{date:function(){return w.data(D.date)||null},focusDate:function(){return w.data(D.focusDate)||null},startDate:function(){var e=c.get.calendarModule(f.startCalendar);return(e?e.get.date():w.data(D.startDate))||null},endDate:function(){var e=c.get.calendarModule(f.endCalendar);return(e?e.get.date():w.data(D.endDate))||null},monthOffset:function(){return w.data(D.monthOffset)||0},mode:function(){var t=w.data(D.mode)||f.startMode,a=c.get.validModes();return e.inArray(t,a)>=0?t:"time"===f.type?"hour":"month"===f.type?"month":"year"===f.type?"year":"day"},validModes:function(){var e=[];return"time"!==f.type&&(f.disableYear&&"year"!==f.type||e.push("year"),(!f.disableMonth&&"year"!==f.type||"month"===f.type)&&e.push("month"),f.type.indexOf("date")>=0&&e.push("day")),f.type.indexOf("time")>=0&&(e.push("hour"),f.disableMinute||e.push("minute")),e},isTouch:function(){try{return a.createEvent("TouchEvent"),!0}catch(e){return!1}},calendarModule:function(t){return t?(t instanceof e||(t=w.parent().children(t).first()),t.data(M)):null}},set:{date:function(e,t,a){t=t!==!1,a=a!==!1,e=c.helper.sanitiseDate(e),e=c.helper.dateInRange(e);var o=c.get.mode(),r=v.datetime(e,f);if(a&&f.onChange.call(F,e,r,o)===!1)return!1;if(c.set.focusDate(e),f.isDisabled(e,o))return!1;var i=c.get.endDate();i&&e&&e>i&&c.set.endDate(n),c.set.dataKeyValue(D.date,e),t&&x.length&&x.val(r)},startDate:function(e,t){e=c.helper.sanitiseDate(e);var a=c.get.calendarModule(f.startCalendar);a&&a.set.date(e),c.set.dataKeyValue(D.startDate,e,t)},endDate:function(e,t){e=c.helper.sanitiseDate(e);var a=c.get.calendarModule(f.endCalendar);a&&a.set.date(e),c.set.dataKeyValue(D.endDate,e,t)},focusDate:function(e,t,a,n){e=c.helper.sanitiseDate(e),e=c.helper.dateInRange(e);var o="day"===c.get.mode(),r=c.get.focusDate();if(o&&e&&r){var i=e.getFullYear()-r.getFullYear(),l=12*i+e.getMonth()-r.getMonth();if(l){var d=c.get.monthOffset()-l;c.set.monthOffset(d,!1)}}var s=c.set.dataKeyValue(D.focusDate,e,t);a=a!==!1&&s&&t===!1||I!=n,I=n,a&&c.update.focus(n)},monthOffset:function(e,t){var a=Math.max(f.multiMonth,1);e=Math.max(1-a,Math.min(0,e)),c.set.dataKeyValue(D.monthOffset,e,t)},mode:function(e,t){c.set.dataKeyValue(D.mode,e,t)},dataKeyValue:function(e,t,a){var n=w.data(e),o=n===t||n<=t&&n>=t;return t?w.data(e,t):w.removeData(e),a=a!==!1&&!o,a&&c.create.calendar(),!o}},selectDate:function(e,t){var a=c.get.mode(),n=t||"minute"===a||f.disableMinute&&"hour"===a||"date"===f.type&&"day"===a||"month"===f.type&&"month"===a||"year"===f.type&&"year"===a;if(n){var o=c.set.date(e)===!1;if(!o&&f.closable){c.popup("hide");var r=c.get.calendarModule(f.endCalendar);r&&(r.popup("show"),r.focus())}}else{var i="year"===a?f.disableMonth?"day":"month":"month"===a?"day":"day"===a?"hour":"minute";c.set.mode(i),"hour"===a||"day"===a&&c.get.date()?c.set.date(e):c.set.focusDate(e)}},changeDate:function(e){c.set.date(e)},clear:function(){c.set.date(n)},popup:function(){return T.popup.apply(T,arguments)},focus:function(){x.length?x.focus():k.focus()},blur:function(){x.length?x.blur():k.blur()},helper:{sanitiseDate:function(e){return e?(e instanceof Date||(e=y.date(""+e,f)),isNaN(e.getTime())?n:e):n},dateDiff:function(e,t,a){a=a||"day";var n="time"===f.type,o="year"===a,r=o||"month"===a,i="minute"===a,l=i||"hour"===a;return e=new Date(n?2e3:e.getFullYear(),n?0:o?0:e.getMonth(),n?1:r?1:e.getDate(),l?e.getHours():0,i?5*Math.floor(e.getMinutes()/5):0),t=new Date(n?2e3:t.getFullYear(),n?0:o?0:t.getMonth(),n?1:r?1:t.getDate(),l?t.getHours():0,i?5*Math.floor(t.getMinutes()/5):0),t.getTime()-e.getTime()},dateEqual:function(e,t,a){return!!e&&!!t&&0===c.helper.dateDiff(e,t,a)},isDateInRange:function(e,t,a,n){if(!a&&!n){var o=c.get.startDate();a=o&&f.minDate?new Date(Math.max(o,f.minDate)):o||f.minDate,n=f.maxDate}return a=a&&new Date(a.getFullYear(),a.getMonth(),a.getDate(),a.getHours(),5*Math.ceil(a.getMinutes()/5)),!(!e||a&&c.helper.dateDiff(e,a,t)>0||n&&c.helper.dateDiff(n,e,t)>0)},dateInRange:function(e,t,a){if(!t&&!a){var n=c.get.startDate();t=n&&f.minDate?new Date(Math.max(n,f.minDate)):n||f.minDate,a=f.maxDate}t=t&&new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),5*Math.ceil(t.getMinutes()/5));var o="time"===f.type;return e?t&&c.helper.dateDiff(e,t,"minute")>0?o?c.helper.mergeDateTime(e,t):t:a&&c.helper.dateDiff(a,e,"minute")>0?o?c.helper.mergeDateTime(e,a):a:e:e},mergeDateTime:function(e,t){return e&&t?new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes()):t}},setting:function(t,a){if(c.debug("Changing setting",t,a),e.isPlainObject(t))e.extend(!0,f,t);else{if(a===n)return f[t];e.isPlainObject(f[t])?e.extend(!0,f[t],a):f[t]=a}},internal:function(t,a){return c.debug("Changing internal",t,a),a===n?c[t]:void(e.isPlainObject(t)?e.extend(!0,c,t):c[t]=a)},debug:function(){!f.silent&&f.debug&&(f.performance?c.performance.log(arguments):(c.debug=Function.prototype.bind.call(console.info,console,f.name+":"),c.debug.apply(console,arguments)))},verbose:function(){!f.silent&&f.verbose&&f.debug&&(f.performance?c.performance.log(arguments):(c.verbose=Function.prototype.bind.call(console.info,console,f.name+":"),c.verbose.apply(console,arguments)))},error:function(){f.silent||(c.error=Function.prototype.bind.call(console.error,console,f.name+":"),c.error.apply(console,arguments))},performance:{log:function(e){var t,a,n;f.performance&&(t=(new Date).getTime(),n=l||t,a=t-n,l=t,d.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:F,"Execution Time":a})),clearTimeout(c.performance.timer),c.performance.timer=setTimeout(c.performance.display,500)},display:function(){var t=f.name+":",a=0;l=!1,clearTimeout(c.performance.timer),e.each(d,function(e,t){a+=t["Execution Time"]}),t+=" "+a+"ms",i&&(t+=" '"+i+"'"),(console.group!==n||console.table!==n)&&d.length>0&&(console.groupCollapsed(t),console.table?console.table(d):e.each(d,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),d=[]}},invoke:function(t,a,r){var i,l,d,s=H;return a=a||p,r=F||r,"string"==typeof t&&s!==n&&(t=t.split(/[\. ]/),i=t.length-1,e.each(t,function(a,o){var r=a!=i?o+t[a+1].charAt(0).toUpperCase()+t[a+1].slice(1):t;if(e.isPlainObject(s[r])&&a!=i)s=s[r];else{if(s[r]!==n)return l=s[r],!1;if(!e.isPlainObject(s[o])||a==i)return s[o]!==n?(l=s[o],!1):(c.error(b.method,t),!1);s=s[o]}})),e.isFunction(l)?d=l.apply(r,a):l!==n&&(d=l),e.isArray(o)?o.push(d):o!==n?o=[o,d]:d!==n&&(o=d),l}},u?(H===n&&c.initialize(),c.invoke(s)):(H!==n&&H.invoke("destroy"),c.initialize())}),o!==n?o:this},e.fn.calendar.settings={name:"Calendar",namespace:"calendar",silent:!1,debug:!1,verbose:!1,performance:!1,type:"datetime",firstDayOfWeek:0,constantHeight:!0,today:!1,closable:!0,monthFirst:!0,touchReadonly:!0,inline:!1,on:null,initialDate:null,startMode:!1,minDate:null,maxDate:null,ampm:!0,disableYear:!1,disableMonth:!1,disableMinute:!1,formatInput:!0,startCalendar:null,endCalendar:null,multiMonth:1,popupOptions:{position:"bottom left",lastResort:"bottom left",prefer:"opposite",hideOnScroll:!1},text:{days:["S","M","T","W","T","F","S"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],today:"Today",now:"Now",am:"AM",pm:"PM"},formatter:{header:function(e,t,a){return"year"===t?a.formatter.yearHeader(e,a):"month"===t?a.formatter.monthHeader(e,a):"day"===t?a.formatter.dayHeader(e,a):"hour"===t?a.formatter.hourHeader(e,a):a.formatter.minuteHeader(e,a)},yearHeader:function(e,t){var a=10*Math.ceil(e.getFullYear()/10);return a-9+" - "+(a+2)},monthHeader:function(e,t){return e.getFullYear()},dayHeader:function(e,t){var a=t.text.months[e.getMonth()],n=e.getFullYear();return a+" "+n},hourHeader:function(e,t){return t.formatter.date(e,t)},minuteHeader:function(e,t){return t.formatter.date(e,t)},dayColumnHeader:function(e,t){return t.text.days[e]},datetime:function(e,t){if(!e)return"";var a="time"===t.type?"":t.formatter.date(e,t),n=t.type.indexOf("time")<0?"":t.formatter.time(e,t,!1),o="datetime"===t.type?" ":"";return a+o+n},date:function(e,t){if(!e)return"";var a=e.getDate(),n=t.text.months[e.getMonth()],o=e.getFullYear();return"year"===t.type?o:"month"===t.type?n+" "+o:(t.monthFirst?n+" "+a:a+" "+n)+", "+o},time:function(e,t,a){if(!e)return"";var n=e.getHours(),o=e.getMinutes(),r="";return t.ampm&&(r=" "+(n<12?t.text.am:t.text.pm),n=0===n?12:n>12?n-12:n),n+":"+(o<10?"0":"")+o+r},today:function(e){return"date"===e.type?e.text.today:e.text.now},cell:function(e,t,a){}},parser:{date:function(t,a){if(!t)return null;if(t=(""+t).trim().toLowerCase(),0===t.length)return null;var o,r,i,l=-1,d=-1,s=-1,u=-1,p=-1,c=n,f="time"===a.type,h=a.type.indexOf("time")<0,g=t.split(a.regExp.dateWords),m=t.split(a.regExp.dateNumbers);if(!h)for(c=e.inArray(a.text.am.toLowerCase(),g)>=0||!(e.inArray(a.text.pm.toLowerCase(),g)>=0)&&n,o=0;o=0){if(d<0||l<0){var y=v.split(":");for(i=0;i=0)break}}for(o=0;o59){p=r,m.splice(o,1);break}if(u<0)for(o=0;o1||a.monthFirst?o:1===o?0:1,r=parseInt(m[i]),!isNaN(r)&&1<=r&&r<=12){u=r,m.splice(i,1);break}for(o=0;o=0;o--)if(r=parseInt(m[o]),!isNaN(r)){r<99&&(r+=2e3),p=r,m.splice(o,1);break}}if(!h){if(d<0)for(o=0;o").addClass(f.popup).prependTo(k.parent())),x.addClass(f.calendar);var t=c.onVisible,a=c.onHidden;w.length||(x.attr("tabindex","0"),t=function(){return p.focus(),c.onVisible.apply(x,arguments)},a=function(){return p.blur(),c.onHidden.apply(x,arguments)});var n=function(){return p.set.focusDate(p.get.date()),p.set.mode(c.startMode),c.onShow.apply(x,arguments)},o=c.on||(w.length?"focus":"click"),r=e.extend({},c.popupOptions,{popup:x,on:o,hoverable:"hover"===o,onShow:n,onVisible:t,onHide:c.onHide,onHidden:a});p.popup(r)}},inline:function(){k.length&&!c.inline||(x=e("
").addClass(f.calendar).appendTo(M),w.length||x.attr("tabindex","0"))},input:function(){c.touchReadonly&&w.length&&o&&w.prop("readonly",!0)},date:function(){if(w.length){var e=w.val(),t=v.date(e,c);p.set.date(t,c.formatInput,!1)}}},create:{calendar:function(){var t,a,n,o,r,i,l,d=p.get.mode(),s=new Date,u=p.get.date(),h=p.get.focusDate(),g=h||u||c.initialDate||s;g=p.helper.dateInRange(g),h||(h=g,p.set.focusDate(h,!1,!1));var v="year"===d,y="month"===d,b="day"===d,C="hour"===d,M="minute"===d,w="time"===c.type,k=Math.max(c.multiMonth,1),T=b?p.get.monthOffset():0,F=g.getMinutes(),H=g.getHours(),O=g.getDate(),I=g.getMonth()+T,N=g.getFullYear(),Y=b?7:C?4:3,E=7===Y?"seven":4===Y?"four":"three",R=b||C?6:4,j=b?k:1,A=x;for(A.empty(),j>1&&(l=e("
").addClass(f.grid).appendTo(A)),o=0;o1){A=e("
").addClass(f.column).appendTo(l)}var S=I+o,V=(new Date(N,S,1).getDay()-c.firstDayOfWeek%7+7)%7;if(!c.constantHeight&&b){var P=new Date(N,S+1,0).getDate()+V;R=Math.ceil(P/7)}var q=v?10:y?1:0,K=b?1:0,J=C||M?1:0,W=C||M?O:1,z=new Date(N-q,S-K,W-J,H),L=new Date(N+q,S+K,W+J,H),B=v?new Date(10*Math.ceil(N/10)-9,0,0):y?new Date(N,0,0):b?new Date(N,S,0):new Date(N,S,O,-1),U=v?new Date(10*Math.ceil(N/10)+1,0,1):y?new Date(N+1,0,1):b?new Date(N,S+1,1):new Date(N,S,O+1),Q=e("").addClass(f.table).addClass(E+" column").addClass(d).appendTo(A);if(!w){var Z=e("").appendTo(Q);r=e("").appendTo(Z),i=e("").appendTo(Z),t=0;t").appendTo(r),i.text(m.dayColumnHeader((t+c.firstDayOfWeek)%7,c))}var te=e("").appendTo(Q);for(t=v?10*Math.ceil(N/10)-9:b?1-V:0,a=0;a").appendTo(te),n=0;n").addClass(f.cell).appendTo(r),i.text(ne),i.data(D.date,ae);var oe=b&&ae.getMonth()!==(S+12)%12,re=oe||!p.helper.isDateInRange(ae,d)||c.isDisabled(ae,d),ie=p.helper.dateEqual(ae,u,d),le=p.helper.dateEqual(ae,s,d);i.toggleClass(f.adjacentCell,oe),i.toggleClass(f.disabledCell,re),i.toggleClass(f.activeCell,ie&&!oe),C||M||i.toggleClass(f.todayCell,!oe&&le);var de={mode:d,adjacent:oe,disabled:re,active:ie,today:le};m.cell(i,ae,de),p.helper.dateEqual(ae,h,d)&&p.set.focusDate(ae,!1,!1)}if(c.today){var se=e("").appendTo(te),ue=e("
").attr("colspan",""+Y).appendTo(r);var G=v||y?new Date(N,0,1):b?new Date(N,S,1):new Date(N,S,O,H,F),X=e("").addClass(f.link).appendTo(i);X.text(m.header(G,d,c));var $=y?c.disableYear?"day":"year":b?c.disableMonth?"year":"month":"day";if(X.data(D.mode,$),0===o){var _=e("").addClass(f.prev).appendTo(i);_.data(D.focusDate,z),_.toggleClass(f.disabledCell,!p.helper.isDateInRange(B,d)),e("").addClass(f.prevIcon).appendTo(_)}if(o===j-1){var ee=e("").addClass(f.next).appendTo(i);ee.data(D.focusDate,L),ee.toggleClass(f.disabledCell,!p.helper.isDateInRange(U,d)),e("").addClass(f.nextIcon).appendTo(ee)}if(b)for(r=e("
").attr("colspan",""+Y).addClass(f.today).appendTo(se);ue.text(m.today(c)),ue.data(D.date,s)}p.update.focus(!1,Q)}}},update:{focus:function(t,a){a=a||x;var n=p.get.mode(),r=p.get.date(),i=p.get.focusDate(),l=p.get.startDate(),d=p.get.endDate(),s=(t?i:null)||r||(o?null:i);a.find("td").each(function(){var t=e(this),a=t.data(D.date);if(a){var r=t.hasClass(f.disabledCell),u=t.hasClass(f.activeCell),c=t.hasClass(f.adjacentCell),h=p.helper.dateEqual(a,i,n),g=!!s&&(!!l&&p.helper.isDateInRange(a,n,l,s)||!!d&&p.helper.isDateInRange(a,n,s,d));t.toggleClass(f.focusCell,h&&(!o||H)&&!c),t.toggleClass(f.rangeCell,g&&!u&&!r)}})}},refresh:function(){p.create.calendar()},bind:{events:function(){x.on("mousedown"+b,p.event.mousedown),x.on("touchstart"+b,p.event.mousedown),x.on("mouseup"+b,p.event.mouseup),x.on("touchend"+b,p.event.mouseup),x.on("mouseover"+b,p.event.mouseover),w.length?(w.on("input"+b,p.event.inputChange),w.on("focus"+b,p.event.inputFocus),w.on("blur"+b,p.event.inputBlur),w.on("click"+b,p.event.inputClick),w.on("keydown"+b,p.event.keydown)):x.on("keydown"+b,p.event.keydown)}},unbind:{events:function(){x.off(b),w.length&&w.off(b)}},event:{mouseover:function(t){var a=e(t.target),n=a.data(D.date),o=1===t.buttons;n&&p.set.focusDate(n,!1,!0,o)},mousedown:function(t){w.length&&t.preventDefault(),H=t.type.indexOf("touch")>=0;var a=e(t.target),n=a.data(D.date);n&&p.set.focusDate(n,!1,!0,!0)},mouseup:function(t){p.focus(),t.preventDefault(),t.stopPropagation(),H=!1;var a=e(t.target),n=a.parent();(n.data(D.date)||n.data(D.focusDate)||n.data(D.mode))&&(a=n);var o=a.data(D.date),r=a.data(D.focusDate),i=a.data(D.mode);if(o){var l=a.hasClass(f.today);p.selectDate(o,l)}else r?p.set.focusDate(r):i&&p.set.mode(i)},keydown:function(e){if(27!==e.keyCode&&9!==e.keyCode||p.popup("hide"),p.popup("is visible"))if(37===e.keyCode||38===e.keyCode||39===e.keyCode||40===e.keyCode){var t=p.get.mode(),a="day"===t?7:"hour"===t?4:3,n=37===e.keyCode?-1:38===e.keyCode?-a:39==e.keyCode?1:a;n*="minute"===t?5:1;var o=p.get.focusDate()||p.get.date()||new Date,r=o.getFullYear()+("year"===t?n:0),i=o.getMonth()+("month"===t?n:0),l=o.getDate()+("day"===t?n:0),d=o.getHours()+("hour"===t?n:0),s=o.getMinutes()+("minute"===t?n:0),u=new Date(r,i,l,d,s);"time"===c.type&&(u=p.helper.mergeDateTime(o,u)),p.helper.isDateInRange(u,t)&&p.set.focusDate(u)}else if(13===e.keyCode){var t=p.get.mode(),f=p.get.focusDate();f&&!c.isDisabled(f,t)&&p.selectDate(f),e.preventDefault(),e.stopPropagation()}38!==e.keyCode&&40!==e.keyCode||(e.preventDefault(),p.popup("show"))},inputChange:function(){var e=w.val(),t=v.date(e,c);p.set.date(t,!1)},inputFocus:function(){x.addClass(f.active)},inputBlur:function(){if(x.removeClass(f.active),c.formatInput){var e=p.get.date(),t=m.datetime(e,c);w.val(t)}},inputClick:function(){p.popup("show")}},get:{date:function(){return M.data(D.date)||null},focusDate:function(){return M.data(D.focusDate)||null},startDate:function(){var e=p.get.calendarModule(c.startCalendar);return(e?e.get.date():M.data(D.startDate))||null},endDate:function(){var e=p.get.calendarModule(c.endCalendar);return(e?e.get.date():M.data(D.endDate))||null},monthOffset:function(){return M.data(D.monthOffset)||0},mode:function(){var t=M.data(D.mode)||c.startMode,a=p.get.validModes();return e.inArray(t,a)>=0?t:"time"===c.type?"hour":"month"===c.type?"month":"year"===c.type?"year":"day"},validModes:function(){var e=[];return"time"!==c.type&&(c.disableYear&&"year"!==c.type||e.push("year"),(!c.disableMonth&&"year"!==c.type||"month"===c.type)&&e.push("month"),c.type.indexOf("date")>=0&&e.push("day")),c.type.indexOf("time")>=0&&(e.push("hour"),c.disableMinute||e.push("minute")),e},isTouch:function(){try{return a.createEvent("TouchEvent"),!0}catch(e){return!1}},calendarModule:function(t){return t?(t instanceof e||(t=M.parent().children(t).first()),t.data(C)):null}},set:{date:function(e,t,a){t=!1!==t,a=!1!==a,e=p.helper.sanitiseDate(e),e=p.helper.dateInRange(e);var n=p.get.mode(),o=m.datetime(e,c);if(a&&!1===c.onChange.call(T,e,o,n))return!1;if(p.set.focusDate(e),c.isDisabled(e,n))return!1;var r=p.get.endDate();r&&e&&e>r&&p.set.endDate(void 0),p.set.dataKeyValue(D.date,e),t&&w.length&&w.val(o)},startDate:function(e,t){e=p.helper.sanitiseDate(e);var a=p.get.calendarModule(c.startCalendar);a&&a.set.date(e),p.set.dataKeyValue(D.startDate,e,t)},endDate:function(e,t){e=p.helper.sanitiseDate(e);var a=p.get.calendarModule(c.endCalendar);a&&a.set.date(e),p.set.dataKeyValue(D.endDate,e,t)},focusDate:function(e,t,a,n){e=p.helper.sanitiseDate(e),e=p.helper.dateInRange(e);var o="day"===p.get.mode(),r=p.get.focusDate();if(o&&e&&r){var i=e.getFullYear()-r.getFullYear(),l=12*i+e.getMonth()-r.getMonth();if(l){var d=p.get.monthOffset()-l;p.set.monthOffset(d,!1)}}var s=p.set.dataKeyValue(D.focusDate,e,t);a=!1!==a&&s&&!1===t||O!=n,O=n,a&&p.update.focus(n)},monthOffset:function(e,t){var a=Math.max(c.multiMonth,1);e=Math.max(1-a,Math.min(0,e)),p.set.dataKeyValue(D.monthOffset,e,t)},mode:function(e,t){p.set.dataKeyValue(D.mode,e,t)},dataKeyValue:function(e,t,a){var n=M.data(e),o=n===t||n<=t&&n>=t;return t?M.data(e,t):M.removeData(e),a=!1!==a&&!o,a&&p.create.calendar(),!o}},selectDate:function(e,t){var a=p.get.mode();if(t||"minute"===a||c.disableMinute&&"hour"===a||"date"===c.type&&"day"===a||"month"===c.type&&"month"===a||"year"===c.type&&"year"===a){if(!1!==p.set.date(e)&&c.closable){p.popup("hide");var n=p.get.calendarModule(c.endCalendar);n&&(n.popup("show"),n.focus())}}else{var o="year"===a?c.disableMonth?"day":"month":"month"===a?"day":"day"===a?"hour":"minute";p.set.mode(o),"hour"===a||"day"===a&&p.get.date()?p.set.date(e):p.set.focusDate(e)}},changeDate:function(e){p.set.date(e)},clear:function(){p.set.date(void 0)},popup:function(){return k.popup.apply(k,arguments)},focus:function(){w.length?w.focus():x.focus()},blur:function(){w.length?w.blur():x.blur()},helper:{sanitiseDate:function(e){if(e&&(e instanceof Date||(e=v.date(""+e,c)),!isNaN(e.getTime())))return e},dateDiff:function(e,t,a){a=a||"day";var n="time"===c.type,o="year"===a,r=o||"month"===a,i="minute"===a,l=i||"hour"===a;return e=new Date(n?2e3:e.getFullYear(),n?0:o?0:e.getMonth(),n?1:r?1:e.getDate(),l?e.getHours():0,i?5*Math.floor(e.getMinutes()/5):0),t=new Date(n?2e3:t.getFullYear(),n?0:o?0:t.getMonth(),n?1:r?1:t.getDate(),l?t.getHours():0,i?5*Math.floor(t.getMinutes()/5):0),t.getTime()-e.getTime()},dateEqual:function(e,t,a){return!!e&&!!t&&0===p.helper.dateDiff(e,t,a)},isDateInRange:function(e,t,a,n){if(!a&&!n){var o=p.get.startDate();a=o&&c.minDate?new Date(Math.max(o,c.minDate)):o||c.minDate;var r=p.get.endDate();n=r&&c.maxDate?new Date(Math.min(r,c.maxDate)):r||c.maxDate}return a=a&&new Date(a.getFullYear(),a.getMonth(),a.getDate(),a.getHours(),5*Math.ceil(a.getMinutes()/5)),!(!e||a&&p.helper.dateDiff(e,a,t)>0||n&&p.helper.dateDiff(n,e,t)>0)},dateInRange:function(e,t,a){if(!t&&!a){var n=p.get.startDate();t=n&&c.minDate?new Date(Math.max(n,c.minDate)):n||c.minDate,a=c.maxDate}t=t&&new Date(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),5*Math.ceil(t.getMinutes()/5));var o="time"===c.type;return e?t&&p.helper.dateDiff(e,t,"minute")>0?o?p.helper.mergeDateTime(e,t):t:a&&p.helper.dateDiff(a,e,"minute")>0?o?p.helper.mergeDateTime(e,a):a:e:e},mergeDateTime:function(e,t){return e&&t?new Date(e.getFullYear(),e.getMonth(),e.getDate(),t.getHours(),t.getMinutes()):t}},setting:function(t,a){if(p.debug("Changing setting",t,a),e.isPlainObject(t))e.extend(!0,c,t);else{if(void 0===a)return c[t];e.isPlainObject(c[t])?e.extend(!0,c[t],a):c[t]=a}},internal:function(t,a){if(p.debug("Changing internal",t,a),void 0===a)return p[t];e.isPlainObject(t)?e.extend(!0,p,t):p[t]=a},debug:function(){!c.silent&&c.debug&&(c.performance?p.performance.log(arguments):(p.debug=Function.prototype.bind.call(console.info,console,c.name+":"),p.debug.apply(console,arguments)))},verbose:function(){!c.silent&&c.verbose&&c.debug&&(c.performance?p.performance.log(arguments):(p.verbose=Function.prototype.bind.call(console.info,console,c.name+":"),p.verbose.apply(console,arguments)))},error:function(){c.silent||(p.error=Function.prototype.bind.call(console.error,console,c.name+":"),p.error.apply(console,arguments))},performance:{log:function(e){var t,a,n;c.performance&&(t=(new Date).getTime(),n=i||t,a=t-n,i=t,l.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:T,"Execution Time":a})),clearTimeout(p.performance.timer),p.performance.timer=setTimeout(p.performance.display,500)},display:function(){var t=c.name+":",a=0;i=!1,clearTimeout(p.performance.timer),e.each(l,function(e,t){a+=t["Execution Time"]}),t+=" "+a+"ms",r&&(t+=" '"+r+"'"),(void 0!==console.group||void 0!==console.table)&&l.length>0&&(console.groupCollapsed(t),console.table?console.table(l):e.each(l,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),l=[]}},invoke:function(t,a,o){var r,i,l,d=F;return a=a||u,o=T||o,"string"==typeof t&&void 0!==d&&(t=t.split(/[\. ]/),r=t.length-1,e.each(t,function(a,n){var o=a!=r?n+t[a+1].charAt(0).toUpperCase()+t[a+1].slice(1):t;if(e.isPlainObject(d[o])&&a!=r)d=d[o];else{if(void 0!==d[o])return i=d[o],!1;if(!e.isPlainObject(d[n])||a==r)return void 0!==d[n]?(i=d[n],!1):(p.error(y.method,t),!1);d=d[n]}})),e.isFunction(i)?l=i.apply(o,a):void 0!==i&&(l=i),e.isArray(n)?n.push(l):void 0!==n?n=[n,l]:void 0!==l&&(n=l),i}},s?(void 0===F&&p.initialize(),p.invoke(d)):(void 0!==F&&F.invoke("destroy"),p.initialize())}),void 0!==n?n:this},e.fn.calendar.settings={name:"Calendar",namespace:"calendar",silent:!1,debug:!1,verbose:!1,performance:!1,type:"datetime",firstDayOfWeek:0,constantHeight:!0,today:!1,closable:!0,monthFirst:!0,touchReadonly:!0,inline:!1,on:null,initialDate:null,startMode:!1,minDate:null,maxDate:null,ampm:!0,disableYear:!1,disableMonth:!1,disableMinute:!1,formatInput:!0,startCalendar:null,endCalendar:null,multiMonth:1,popupOptions:{position:"bottom left",lastResort:"bottom left",prefer:"opposite",hideOnScroll:!1},text:{days:["S","M","T","W","T","F","S"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],today:"Today",now:"Now",am:"AM",pm:"PM"},formatter:{header:function(e,t,a){return"year"===t?a.formatter.yearHeader(e,a):"month"===t?a.formatter.monthHeader(e,a):"day"===t?a.formatter.dayHeader(e,a):"hour"===t?a.formatter.hourHeader(e,a):a.formatter.minuteHeader(e,a)},yearHeader:function(e,t){var a=10*Math.ceil(e.getFullYear()/10);return a-9+" - "+(a+2)},monthHeader:function(e,t){return e.getFullYear()},dayHeader:function(e,t){return t.text.months[e.getMonth()]+" "+e.getFullYear()},hourHeader:function(e,t){return t.formatter.date(e,t)},minuteHeader:function(e,t){return t.formatter.date(e,t)},dayColumnHeader:function(e,t){return t.text.days[e]},datetime:function(e,t){if(!e)return"";var a="time"===t.type?"":t.formatter.date(e,t),n=t.type.indexOf("time")<0?"":t.formatter.time(e,t,!1);return a+("datetime"===t.type?" ":"")+n},date:function(e,t){if(!e)return"";var a=e.getDate(),n=t.text.months[e.getMonth()],o=e.getFullYear();return"year"===t.type?o:"month"===t.type?n+" "+o:(t.monthFirst?n+" "+a:a+" "+n)+", "+o},time:function(e,t,a){if(!e)return"";var n=e.getHours(),o=e.getMinutes(),r="";return t.ampm&&(r=" "+(n<12?t.text.am:t.text.pm),n=0===n?12:n>12?n-12:n),n+":"+(o<10?"0":"")+o+r},today:function(e){return"date"===e.type?e.text.today:e.text.now},cell:function(e,t,a){}},parser:{date:function(t,a){if(!t)return null;if(t=(""+t).trim().toLowerCase(),0===t.length)return null;var n,o,r,i=-1,l=-1,d=-1,s=-1,u=-1,p=void 0,c="time"===a.type,f=a.type.indexOf("time")<0,h=t.split(a.regExp.dateWords),g=t.split(a.regExp.dateNumbers);if(!f)for(p=e.inArray(a.text.am.toLowerCase(),h)>=0||!(e.inArray(a.text.pm.toLowerCase(),h)>=0)&&void 0,n=0;n=0){if(l<0||i<0){var v=m.split(":");for(r=0;r=0)break}}for(n=0;n59){u=o,g.splice(n,1);break}if(s<0)for(n=0;n1||a.monthFirst?n:1===n?0:1,o=parseInt(g[r]),!isNaN(o)&&1<=o&&o<=12){s=o,g.splice(r,1);break}for(n=0;n=0;n--)if(o=parseInt(g[n]),!isNaN(o)){o<99&&(o+=2e3),u=o,g.splice(n,1);break}}if(!f){if(l<0)for(n=0;n