/*! * Pikaday * * Copyright © 2014 David Bushell | BSD & MIT license | https://github.com/dbushell/Pikaday */ !function(t,e){"use strict";var n;if("object"==typeof exports){try{n=require("moment")}catch(i){}module.exports=e(n)}else"function"==typeof define&&define.amd?define(function(t){var i="moment";try{n=t(i)}catch(a){}return e(n)}):t.Pikaday=e(t.moment)}(this,function(t){"use strict";var e="function"==typeof t,n=!!window.addEventListener,i=window.document,a=window.setTimeout,o=function(t,e,i,a){n?t.addEventListener(e,i,!!a):t.attachEvent("on"+e,i)},s=function(t,e,i,a){n?t.removeEventListener(e,i,!!a):t.detachEvent("on"+e,i)},r=function(t,e,n){var a;i.createEvent?(a=i.createEvent("HTMLEvents"),a.initEvent(e,!0,!1),a=D(a,n),t.dispatchEvent(a)):i.createEventObject&&(a=i.createEventObject(),a=D(a,n),t.fireEvent("on"+e,a))},h=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")},l=function(t,e){return-1!==(" "+t.className+" ").indexOf(" "+e+" ")},d=function(t,e){l(t,e)||(t.className=""===t.className?e:t.className+" "+e)},u=function(t,e){t.className=h((" "+t.className+" ").replace(" "+e+" "," "))},c=function(t){return/Array/.test(Object.prototype.toString.call(t))},f=function(t){return/Date/.test(Object.prototype.toString.call(t))&&!isNaN(t.getTime())},g=function(t){var e=t.getDay();return 0===e||6===e},m=function(t){return t%4===0&&t%100!==0||t%400===0},p=function(t,e){return[31,m(t)?29:28,31,30,31,30,31,31,30,31,30,31][e]},y=function(t){f(t)&&t.setHours(0,0,0,0)},_=function(t,e){return t.getTime()===e.getTime()},D=function(t,e,n){var i,a;for(i in e)a=void 0!==t[i],a&&"object"==typeof e[i]&&null!==e[i]&&void 0===e[i].nodeName?f(e[i])?n&&(t[i]=new Date(e[i].getTime())):c(e[i])?n&&(t[i]=e[i].slice(0)):t[i]=D({},e[i],n):(n||!a)&&(t[i]=e[i]);return t},v=function(t){return t.month<0&&(t.year-=Math.ceil(Math.abs(t.month)/12),t.month+=12),t.month>11&&(t.year+=Math.floor(Math.abs(t.month)/12),t.month-=12),t},b={field:null,bound:void 0,position:"bottom left",reposition:!0,format:"YYYY-MM-DD",defaultDate:null,setDefaultDate:!1,firstDay:0,minDate:null,maxDate:null,yearRange:10,showWeekNumber:!1,minYear:0,maxYear:9999,minMonth:void 0,maxMonth:void 0,startRange:null,endRange:null,isRTL:!1,yearSuffix:"",showMonthAfterYear:!1,numberOfMonths:1,mainCalendar:"left",container:void 0,i18n:{previousMonth:nfi18n.previousMonth,nextMonth:nfi18n.nextMonth,months:nfi18n.months,weekdays:nfi18n.weekdays,weekdaysShort:nfi18n.weekdaysShort},theme:null,onSelect:null,onOpen:null,onClose:null,onDraw:null},w=function(t,e,n){for(e+=t.firstDay;e>=7;)e-=7;return n?t.i18n.weekdaysShort[e]:t.i18n.weekdays[e]},M=function(t){if(t.isEmpty)return'';var e=[];return t.isDisabled&&e.push("is-disabled"),t.isToday&&e.push("is-today"),t.isSelected&&e.push("is-selected"),t.isInRange&&e.push("is-inrange"),t.isStartRange&&e.push("is-startrange"),t.isEndRange&&e.push("is-endrange"),'"},k=function(t,e,n){var i=new Date(n,0,1),a=Math.ceil(((new Date(n,e,t)-i)/864e5+i.getDay()+1)/7);return''+a+""},R=function(t,e){return""+(e?t.reverse():t).join("")+""},x=function(t){return""+t.join("")+""},N=function(t){var e,n=[];for(t.showWeekNumber&&n.push(""),e=0;7>e;e++)n.push(''+w(t,e,!0)+"");return""+(t.isRTL?n.reverse():n).join("")+""},C=function(t,e,n,i,a){var o,s,r,h,l,d=t._o,u=n===d.minYear,f=n===d.maxYear,g='
',m=!0,p=!0;for(r=[],o=0;12>o;o++)r.push('");for(h='
'+d.i18n.months[i]+'
",c(d.yearRange)?(o=d.yearRange[0],s=d.yearRange[1]+1):(o=n-d.yearRange,s=1+n+d.yearRange),r=[];s>o&&o<=d.maxYear;o++)o>=d.minYear&&r.push('");return l='
'+n+d.yearSuffix+'
",g+=d.showMonthAfterYear?l+h:h+l,u&&(0===i||d.minMonth>=i)&&(m=!1),f&&(11===i||d.maxMonth<=i)&&(p=!1),0===e&&(g+='"),e===t._o.numberOfMonths-1&&(g+='"),g+="
"},T=function(t,e){return''+N(t)+x(e)+"
"},E=function(s){var r=this,h=r.config(s);r._onMouseDown=function(t){if(r._v){t=t||window.event;var e=t.target||t.srcElement;if(e)if(l(e,"is-disabled")||(l(e,"pika-button")&&!l(e,"is-empty")?(r.setDate(new Date(e.getAttribute("data-pika-year"),e.getAttribute("data-pika-month"),e.getAttribute("data-pika-day"))),h.bound&&a(function(){r.hide(),h.field&&h.field.blur()},100)):l(e,"pika-prev")?r.prevMonth():l(e,"pika-next")&&r.nextMonth()),l(e,"pika-select"))r._c=!0;else{if(!t.preventDefault)return t.returnValue=!1,!1;t.preventDefault()}}},r._onChange=function(t){t=t||window.event;var e=t.target||t.srcElement;e&&(l(e,"pika-select-month")?r.gotoMonth(e.value):l(e,"pika-select-year")&&r.gotoYear(e.value))},r._onInputChange=function(n){var i;n.firedBy!==r&&(e?(i=t(h.field.value,h.format),i=i&&i.isValid()?i.toDate():null):i=new Date(Date.parse(h.field.value)),f(i)&&r.setDate(i),r._v||r.show())},r._onInputFocus=function(){r.show()},r._onInputClick=function(){r.show()},r._onInputBlur=function(){var t=i.activeElement;do if(l(t,"pika-single"))return;while(t=t.parentNode);r._c||(r._b=a(function(){r.hide()},50)),r._c=!1},r._onClick=function(t){t=t||window.event;var e=t.target||t.srcElement,i=e;if(e){!n&&l(e,"pika-select")&&(e.onchange||(e.setAttribute("onchange","return;"),o(e,"change",r._onChange)));do if(l(i,"pika-single")||i===h.trigger)return;while(i=i.parentNode);r._v&&e!==h.trigger&&i!==h.trigger&&r.hide()}},r.el=i.createElement("div"),r.el.className="pika-single"+(h.isRTL?" is-rtl":"")+(h.theme?" "+h.theme:""),o(r.el,"mousedown",r._onMouseDown,!0),o(r.el,"touchend",r._onMouseDown,!0),o(r.el,"change",r._onChange),h.field&&(h.container?h.container.appendChild(r.el):h.bound?i.body.appendChild(r.el):h.field.parentNode.insertBefore(r.el,h.field.nextSibling),o(h.field,"change",r._onInputChange),h.defaultDate||(e&&h.field.value?h.defaultDate=t(h.field.value,h.format).toDate():h.defaultDate=new Date(Date.parse(h.field.value)),h.setDefaultDate=!0));var d=h.defaultDate;f(d)?h.setDefaultDate?r.setDate(d,!0):r.gotoDate(d):r.gotoDate(new Date),h.bound?(this.hide(),r.el.className+=" is-bound",o(h.trigger,"click",r._onInputClick),o(h.trigger,"focus",r._onInputFocus),o(h.trigger,"blur",r._onInputBlur)):this.show()};return E.prototype={config:function(t){this._o||(this._o=D({},b,!0));var e=D(this._o,t,!0);e.isRTL=!!e.isRTL,e.field=e.field&&e.field.nodeName?e.field:null,e.theme="string"==typeof e.theme&&e.theme?e.theme:null,e.bound=!!(void 0!==e.bound?e.field&&e.bound:e.field),e.trigger=e.trigger&&e.trigger.nodeName?e.trigger:e.field,e.disableWeekends=!!e.disableWeekends,e.disableDayFn="function"==typeof e.disableDayFn?e.disableDayFn:null;var n=parseInt(e.numberOfMonths,10)||1;if(e.numberOfMonths=n>4?4:n,f(e.minDate)||(e.minDate=!1),f(e.maxDate)||(e.maxDate=!1),e.minDate&&e.maxDate&&e.maxDate100&&(e.yearRange=100);return e},toString:function(n){return f(this._d)?e?t(this._d).format(n||this._o.format):this._d.toDateString():""},getMoment:function(){return e?t(this._d):null},setMoment:function(n,i){e&&t.isMoment(n)&&this.setDate(n.toDate(),i)},getDate:function(){return f(this._d)?new Date(this._d.getTime()):null},setDate:function(t,e){if(!t)return this._d=null,this._o.field&&(this._o.field.value="",r(this._o.field,"change",{firedBy:this})),this.draw();if("string"==typeof t&&(t=new Date(Date.parse(t))),f(t)){var n=this._o.minDate,i=this._o.maxDate;f(n)&&n>t?t=n:f(i)&&t>i&&(t=i),this._d=new Date(t.getTime()),y(this._d),this.gotoDate(this._d),this._o.field&&(this._o.field.value=this.toString(),r(this._o.field,"change",{firedBy:this})),e||"function"!=typeof this._o.onSelect||this._o.onSelect.call(this,this.getDate())}},gotoDate:function(t){var e=!0;if(f(t)){if(this.calendars){var n=new Date(this.calendars[0].year,this.calendars[0].month,1),i=new Date(this.calendars[this.calendars.length-1].year,this.calendars[this.calendars.length-1].month,1),a=t.getTime();i.setMonth(i.getMonth()+1),i.setDate(i.getDate()-1),e=a=i&&(this._y=i,!isNaN(s)&&this._m>s&&(this._m=s));for(var h=0;h'+C(this,h,this.calendars[h].year,this.calendars[h].month,this.calendars[0].year)+this.render(this.calendars[h].year,this.calendars[h].month)+"";if(this.el.innerHTML=r,e.bound&&"hidden"!==e.field.type&&a(function(){e.trigger.focus()},1),"function"==typeof this._o.onDraw){var l=this;a(function(){l._o.onDraw.call(l)},0)}}},adjustPosition:function(){var t,e,n,a,o,s,r,h,l,d;if(!this._o.container){if(this.el.style.position="absolute",t=this._o.trigger,e=t,n=this.el.offsetWidth,a=this.el.offsetHeight,o=window.innerWidth||i.documentElement.clientWidth,s=window.innerHeight||i.documentElement.clientHeight,r=window.pageYOffset||i.body.scrollTop||i.documentElement.scrollTop,"function"==typeof t.getBoundingClientRect)d=t.getBoundingClientRect(),h=d.left+window.pageXOffset,l=d.bottom+window.pageYOffset;else for(h=e.offsetLeft,l=e.offsetTop+e.offsetHeight;e=e.offsetParent;)h+=e.offsetLeft,l+=e.offsetTop;(this._o.reposition&&h+n>o||this._o.position.indexOf("right")>-1&&h-n+t.offsetWidth>0)&&(h=h-n+t.offsetWidth),(this._o.reposition&&l+a>s+r||this._o.position.indexOf("top")>-1&&l-a-t.offsetHeight>0)&&(l=l-a-t.offsetHeight),this.el.style.left=h+"px",this.el.style.top=l+"px"}},render:function(t,e){var n=this._o,i=new Date,a=p(t,e),o=new Date(t,e,1).getDay(),s=[],r=[];y(i),n.firstDay>0&&(o-=n.firstDay,0>o&&(o+=7));for(var h=a+o,l=h;l>7;)l-=7;h+=7-l;for(var d=0,u=0;h>d;d++){var c=new Date(t,e,1+(d-o)),m=f(this._d)?_(c,this._d):!1,D=_(c,i),v=o>d||d>=a+o,b=n.startRange&&_(n.startRange,c),w=n.endRange&&_(n.endRange,c),x=n.startRange&&n.endRange&&n.startRangen.maxDate||n.disableWeekends&&g(c)||n.disableDayFn&&n.disableDayFn(c),C={day:1+(d-o),month:e,year:t,isSelected:m,isToday:D,isDisabled:N,isEmpty:v,isStartRange:b,isEndRange:w,isInRange:x};r.push(M(C)),7===++u&&(n.showWeekNumber&&r.unshift(k(d-o,e,t)),s.push(R(r,n.isRTL)),r=[],u=0)}return T(n,s)},isVisible:function(){return this._v},show:function(){this._v||(u(this.el,"is-hidden"),this._v=!0,this.draw(),this._o.bound&&(o(i,"click",this._onClick),this.adjustPosition()),"function"==typeof this._o.onOpen&&this._o.onOpen.call(this))},hide:function(){var t=this._v;t!==!1&&(this._o.bound&&s(i,"click",this._onClick),this.el.style.position="static",this.el.style.left="auto",this.el.style.top="auto",d(this.el,"is-hidden"),this._v=!1,void 0!==t&&"function"==typeof this._o.onClose&&this._o.onClose.call(this))},destroy:function(){this.hide(),s(this.el,"mousedown",this._onMouseDown,!0),s(this.el,"touchend",this._onMouseDown,!0),s(this.el,"change",this._onChange),this._o.field&&(s(this._o.field,"change",this._onInputChange),this._o.bound&&(s(this._o.trigger,"click",this._onInputClick),s(this._o.trigger,"focus",this._onInputFocus),s(this._o.trigger,"blur",this._onInputBlur))),this.el.parentNode&&this.el.parentNode.removeChild(this.el)}},E});