2 lines
56 KiB
JavaScript
2 lines
56 KiB
JavaScript
!function(c,h,n){"use strict";function s(t,e){this.elem=t,this.options=e,this.metadata=this.elem.getAttribute("data-plugin-options")?JSON.parse(this.elem.getAttribute("data-plugin-options")):{}}s.defaults=(s.prototype={public:function(){return{startDate:moment().startOf("day"),endDate:moment().startOf("day"),format:"L",dateSeparator:" - ",calendarCount:2,mobileBreakpoint:760,isHotelBooking:!1,inline:!1,minDate:null,maxDate:null,showHeader:!0,showFooter:!0,rangeOrientation:"horizontal",verticalRangeWidth:180,showButtons:!1,startOnMonday:!1,container:"body",oneCalendarWidth:230,enableKeyboard:!0,showOn:"bottom",arrowOn:"left",autoAlign:!0,locale:moment.locale(),singleDate:!1,target:null,autoCloseOnSelect:!1,startEmpty:!1,isRTL:!1,ranges:[{title:"Today",startDate:moment(),endDate:moment()},{title:"3 Days",startDate:moment(),endDate:moment().add(2,"days")},{title:"5 Days",startDate:moment(),endDate:moment().add(4,"days")},{title:"1 Week",startDate:moment(),endDate:moment().add(6,"days")},{title:"Till Next Week",startDate:moment(),endDate:moment().endOf("week")},{title:"Till Next Month",startDate:moment(),endDate:moment().endOf("month")}],rangeLabel:"Ranges: ",cancelLabel:"Cancel",applyLabel:"Apply",nextMonthIcon:"<i class='fa fa-arrow-right'></i>",prevMonthIcon:"<i class='fa fa-arrow-left'></i>",rangeIcon:"<i class='fa fa-retweet'></i>",headerSeparator:"<i class='fa fa-chevron-right'></i>",onbeforeselect:function(){return!0},onafterselect:function(){},onbeforeshow:function(){},onbeforehide:function(){},onaftershow:function(){},onafterhide:function(){},onfirstselect:function(){},onrangeselect:function(){},onbeforemonthchange:function(){return!0},onaftermonthchange:function(){},onafteryearchange:function(){},ondraw:function(){},onBeforeInit:function(){},onBeforeDestroy:function(){return!0},oninit:function(){},ondestroy:function(){},validateClick:function(){return!0},onCancel:function(){return!0},disableDays:function(){return!1},disabledRanges:[],continuous:!1,disableOnlyStart:!1,disableOnlyEnd:!1,minSelectedDays:0,enableMonthSwitcher:!0,enableYearSwitcher:!0,enableSwipe:!0,numericMonthSwitcher:!1,monthSwitcherFormat:"MMMM",showWeekNumbers:!1,hideOutOfRange:!1,DOBCalendar:!1}},private:function(){return{startSelected:!1,currentDate:moment().startOf("day"),endSelected:!0,hoverDate:null,keyboardHoverDate:null,headerStartDay:null,headerStartDate:null,headerStartWeekday:null,headerEndDay:null,headerEndDate:null,headerEndWeekday:null,swipeX:0,swipeY:0,swipeStart:0,swipeTimeout:null,isMobile:!1,valElements:["BUTTON","OPTION","INPUT","LI","METER","PROGRESS","PARAM"],dontHideOnce:!1,initiator:null,initComplete:!1,startDateBackup:null,startDateInitial:null,endDateInitial:null,firstValueSelected:!1,throttleTimeout:null,instanceId:null,documentEvent:null,delayInputUpdate:!1,lastScrollX:0,lastScrollY:0,isTicking:!1,parentScrollEventsAttached:!1,rafID:0,disabledDays:{}}},init:function(){return this.config=this.extend(this.extend(this.public(),this.options),this.metadata),this.globals=this.private(),this.globals.isMobile=this.checkMobile(),this.globals.instanceId=Math.round(+new Date+100*Math.random()),this.events=this.eventsPrototype(),this.events.init(this.globals.instanceId),this.config.onBeforeInit(this),this.applyConfig(),this.fetchInputs(),this.drawUserInterface(),this.drawOverlay(),this.addInitialEvents(),this.addKeyboardEvents(),(this.elem.caleran=this).config.oninit(this),this.globals.initComplete=!0,this.globals.lastScrollX=0,this.globals.lastScrollY=0,this.events.dispatch(c,"resize"),this},validateDates:function(){var t;(moment.isMoment(this.config.startDate)&&this.config.startDate.isValid()||moment(this.config.startDate,this.config.format).isValid())&&(moment.isMoment(this.config.endDate)&&this.config.endDate.isValid()||moment(this.config.endDate,this.config.format).isValid())?(this.config.startDate=moment(this.config.startDate,this.config.format).middleOfDay().locale(this.config.locale),this.config.endDate=moment(this.config.endDate,this.config.format).middleOfDay().locale(this.config.locale),this.config.startDate.isAfter(this.config.endDate,"day")&&(t=this.config.startDate.clone(),this.config.startDate=this.config.endDate.clone(),this.config.endDate=t.clone(),t=null)):(this.config.startDate=moment().middleOfDay().locale(this.config.locale),this.config.endDate=moment().middleOfDay().locale(this.config.locale)),this.globals.currentDate=moment(this.config.startDate,this.config.format),null!==this.config.minDate&&moment(this.config.minDate,this.config.format).isValid()?this.config.minDate=moment(this.config.minDate,this.config.format).middleOfDay():this.config.minDate=null,null!==this.config.maxDate&&moment(this.config.maxDate,this.config.format).isValid()?this.config.maxDate=moment(this.config.maxDate,this.config.format).middleOfDay():this.config.maxDate=null,null!==this.config.minDate&&null!==this.config.maxDate&&this.config.minDate.isAfter(this.config.maxDate,"day")&&(t=this.config.minDate.clone(),this.config.minDate=this.config.maxDate.clone(),this.config.maxDate=t.clone(),t=null),null!==this.config.minDate&&null!==this.config.startDate&&this.config.minDate.isAfter(this.config.startDate,"day")&&(this.config.startDate=this.config.minDate.clone()),null!==this.config.minDate&&null!==this.config.endDate&&this.config.minDate.isAfter(this.config.endDate,"day")&&(this.config.endDate=this.config.minDate.clone()),null!==this.config.maxDate&&null!==this.config.startDate&&this.config.maxDate.isBefore(this.config.startDate,"day")&&(this.config.startDate=this.config.maxDate.clone()),null!==this.config.maxDate&&null!==this.config.endDate&&this.config.maxDate.isBefore(this.config.endDate,"day")&&(this.config.endDate=this.config.maxDate.clone()),(!1===this.checkRangeContinuity()||1==this.config.disableOnlyStart&&this.isDisabled(this.config.startDate,this.config.isHotelBooking)||!1===this.config.singleDate&&this.config.disableOnlyEnd&&this.isDisabled(this.config.endDate,this.config.isHotelBooking)||this.config.startEmpty&&0==this.globals.firstValueSelected)&&this.clearInput()},applyConfig:function(){null===this.config.target&&(this.config.target=this.elem),!0===this.config.inline&&(this.config.DOBCalendar=!1),1==this.config.DOBCalendar&&(this.config.singleDate=!0),"string"==typeof this.config.container&&(this.config.container=h.querySelector(this.config.container));for(var t=["startDate","endDate","minDate","maxDate"],e=0;e<t.length;e++){var i=t[e];this.config[i]=this.fixDateTime(this.config[i])}if(this.config.ranges.map(function(t){return t.startDate=this.fixDateTime(t.startDate),t.endDate=this.fixDateTime(t.endDate),t},this),!1===this.globals.isMobile){if(!0===this.config.inline)this.container=h.createElement("div"),this.container.classList.add("caleran-container","caleran-inline"),this.container.tabIndex=1,this.container.onclick="",this.elem.insertAdjacentElement("beforebegin",this.container),this.container.appendChild(this.elem),this.input=h.createElement("div"),this.input.classList.add("caleran-input"),this.container.appendChild(this.input),this.elem.type="hidden",this.config.showButtons=!1,this.setViewport();else{this.container=h.createElement("div"),this.container.classList.add("caleran-container","caleran-popup"),this.container.style.display="none",this.container.setAttribute("onclick","");var a=h.createElement("div");a.classList.add("caleran-box-arrow-top"),this.container.appendChild(a),this.input=h.createElement("div"),this.input.classList.add("caleran-input"),this.container.appendChild(this.input),this.config.container.appendChild(this.container),this.config.showButtons&&(this.globals.delayInputUpdate=!0,this.config.autoCloseOnSelect=!1)}"horizontal"===this.config.rangeOrientation?this.input.style.width=this.config.calendarCount*this.config.oneCalendarWidth+"px":this.input.style.width=this.config.calendarCount*this.config.oneCalendarWidth+this.config.verticalRangeWidth+"px"}else!0===this.config.inline?(this.container=h.createElement("div"),this.container.classList.add("caleran-container-mobile","caleran-inline"),this.container.tabIndex=1,this.container.onclick="",this.elem.parentNode.insertBefore(this.container,this.elem),this.container.appendChild(this.elem),this.input=h.createElement("div"),this.input.classList.add("caleran-input"),this.container.appendChild(this.input),this.elem.type="hidden",this.config.showButtons=!1):(this.container=h.createElement("div"),this.container.classList.add(["caleran-container-mobile"]),this.container.onclick="",this.config.container.appendChild(this.container),this.input=h.createElement("div"),this.input.classList.add("caleran-input"),this.input.style.display="none",this.container.appendChild(this.input),this.config.showButtons&&(this.config.autoCloseOnSelect=!1),this.config.autoCloseOnSelect||(this.globals.delayInputUpdate=!0)),this.elem.onfocus=function(){this.blur()};this.config.isHotelBooking&&this.container.classList.add("caleran-hotel-style"),this.config.isRTL&&(this.container.style.direction="rtl",this.container.classList.add("caleran-rtl")),this.clearRangeSelection()},clearRangeSelection:function(){for(var t=0;t<this.config.ranges.length;t++)this.config.ranges[t].selected=!1;for(var e=this.container.querySelectorAll(".caleran-range"),i=0;i<e.length;i++)e[i].classList.remove("caleran-range-selected")},inArray:function(t,e){return Array.isArray(e)&&0<=e.indexOf(t)},fetchInputs:function(){var t=this.inArray(this.config.target.tagName,this.globals.valElements)?this.config.target.value:this.config.target.innerText;if(!1===this.config.singleDate&&0<t.indexOf(this.config.dateSeparator)){var e=t.split(this.config.dateSeparator);2==e.length&&moment(e[0],this.config.format,this.config.locale).isValid()&&moment(e[1],this.config.format,this.config.locale).isValid()&&(this.config.startDate=moment(e[0],this.config.format,this.config.locale).middleOfDay(),this.config.endDate=moment(e[1],this.config.format,this.config.locale).middleOfDay(),this.globals.firstValueSelected=!0)}else if(!0===this.config.singleDate){var i=t;""!=i&&moment(i,this.config.format,this.config.locale).isValid()&&(this.config.startDate=moment(i,this.config.format,this.config.locale).middleOfDay(),this.config.endDate=moment(i,this.config.format,this.config.locale).middleOfDay(),this.globals.firstValueSelected=!0)}this.config.startEmpty&&!this.globals.firstValueSelected&&this.clearInput(),this.validateDates()},drawUserInterface:function(){this.drawHeader(),this.calendars=this.input.querySelectorAll(".caleran-calendars")[0];var t=this.globals.currentDate.clone().middleOfDay();this.globals.disabledDays={};for(var e=0;e<this.config.calendarCount;e++)this.drawCalendarOfMonth(t),t=t.add(1,"month");var i=this.calendars.querySelectorAll(".caleran-calendar");if(i[i.length-1].classList.add("no-border-right"),this.drawArrows(),this.drawFooter(),!0!==this.globals.isMobile&&!1!==this.config.inline||!this.globals.initComplete||this.setViewport(),!1===this.globals.startSelected)if(this.globals.initComplete)this.updateInput(!1);else{var a=this.globals.delayInputUpdate;this.globals.delayInputUpdate=!1,this.updateInput(!1),this.globals.delayInputUpdate=a}this.reDrawCells()},drawOverlay:function(){if(0!=this.globals.isMobile)if(0==h.querySelectorAll(".caleran-overlay").length){this.overlay=h.createElement("div"),this.overlay.classList.add("caleran-overlay"),h.body.appendChild(this.overlay);var t=function(){var t=h.querySelectorAll("body > .caleran-container-mobile");if(0<t.length)for(var e=0;e<t.length;e++){var i=t[e];"none"!=i.style.display&&i.querySelector(".caleran-cancel").click()}};this.events.add(this.overlay,"click",t,!1),this.events.add(this.overlay,"tap",t,!1)}else this.overlay=h.querySelectorAll(".caleran-overlay")[0]},drawHeader:function(){var t="<div class='caleran-header'><div class='caleran-header-start'><div class='caleran-header-start-day'></div><div class='caleran-header-start-date'></div><div class='caleran-header-start-weekday'></div></div>";if(!1===this.config.singleDate&&(t+="<div class='caleran-header-separator'>"+this.config.headerSeparator+"</div><div class='caleran-header-end'><div class='caleran-header-end-day'></div><div class='caleran-header-end-date'></div><div class='caleran-header-end-weekday'></div></div>"),t+="</div><div class='caleran-calendars'></div>",this.input.insertAdjacentHTML("beforeend",t),!1===this.config.showHeader){t=this.input.querySelectorAll(".caleran-header");for(var e=0;e<t.length;e++)t[e].style.display="none"}this.globals.headerStartDay=this.input.querySelector(".caleran-header-start-day"),this.globals.headerStartDate=this.input.querySelector(".caleran-header-start-date"),this.globals.headerStartWeekday=this.input.querySelector(".caleran-header-start-weekday"),this.globals.headerEndDay=this.input.querySelector(".caleran-header-end-day"),this.globals.headerEndDate=this.input.querySelector(".caleran-header-end-date"),this.globals.headerEndWeekday=this.input.querySelector(".caleran-header-end-weekday"),this.updateHeader()},updateHeader:function(){this.config.startDate&&this.config.startDate.locale(this.config.locale),this.config.endDate&&this.config.endDate.locale(this.config.locale),this.config.startEmpty&&!1===this.globals.firstValueSelected||(null!==this.config.startDate?(this.globals.headerStartDay.innerText=this.localizeNumbers(this.config.startDate.date()),this.globals.isMobile?this.globals.headerStartDate.innerText=this.config.startDate.format("MMM")+" "+this.localizeNumbers(this.config.startDate.year()):this.globals.headerStartDate.innerText=this.config.startDate.format("MMMM")+" "+this.localizeNumbers(this.config.startDate.year()),this.globals.headerStartWeekday.innerText=this.config.startDate.format("dddd")):(this.globals.headerStartDay.innerText="",this.globals.headerStartDate.innerText="",this.globals.headerStartWeekday.innerText=""),!1===this.config.singleDate&&(null!==this.config.endDate?(this.globals.headerEndDay.innerText=this.localizeNumbers(this.config.endDate.date()),this.globals.isMobile?this.globals.headerEndDate.innerText=this.config.endDate.format("MMM")+" "+this.localizeNumbers(this.config.endDate.year()):this.globals.headerEndDate.innerText=this.config.endDate.format("MMMM")+" "+this.localizeNumbers(this.config.endDate.year()),this.globals.headerEndWeekday.innerText=this.config.endDate.format("dddd")):(this.globals.headerEndDay.innerText="",this.globals.headerEndDate.innerText="",this.globals.headerEndWeekday.innerText="")))},isUpdateable:function(){var t=this.globals.delayInputUpdate,e=this.config.startEmpty&&!this.globals.firstValueSelected;return(e=(e=e||!0===this.config.singleDate&&null===this.config.startDate)||!1===this.config.singleDate&&(null===this.config.startDate||null===this.config.endDate))&&this.clearInput(),!e&&!t},updateInput:function(t){this.config.startDate&&this.config.startDate.locale(this.config.locale),this.config.endDate&&this.config.endDate.locale(this.config.locale),this.isUpdateable()&&(this.inArray(this.config.target.tagName,this.globals.valElements)?!1===this.config.singleDate?this.config.target.value=this.config.startDate.format(this.config.format)+this.config.dateSeparator+this.config.endDate.format(this.config.format):this.config.target.value=this.config.startDate.format(this.config.format):!1===this.config.singleDate?this.config.target.innerText=this.config.startDate.format(this.config.format)+this.config.dateSeparator+this.config.endDate.format(this.config.format):this.config.target.innerText=this.config.startDate.format(this.config.format),!0===this.globals.initComplete&&!0===t&&(this.config.onafterselect(this,this.config.startDate.clone(),this.config.endDate.clone()),this.events.dispatch(this.input,"change")))},clearInput:function(t){if(this.inArray(this.config.target.tagName,this.globals.valElements)?(this.config.singleDate,this.config.target.value=""):!1===this.config.singleDate?this.config.target.innerText="":this.config.target.innrtText="",this.config.startDate=null,this.config.endDate=null,t?(this.config.startEmpty=!0,this.globals.firstValueSelected=!1):1==this.config.startEmpty&&(this.globals.firstValueSelected=!1),this.globals.initComplete){this.updateHeader();var e=void 0===this.footer?[]:this.footer.querySelector(".caleran-apply");0<e.length&&e.setAttribute("disabled","disabled")}},drawArrows:function(){var t,e=this.config.hideOutOfRange&&this.config.minDate&&this.globals.currentDate.clone().add(-1,"month").isBefore(this.config.minDate,"month"),i=this.config.hideOutOfRange&&this.config.maxDate&&this.globals.currentDate.clone().add(this.config.calendarCount,"month").isAfter(this.config.maxDate,"month"),a=this.container.querySelectorAll(".caleran-title");if(0<a.length)if(this.globals.isMobile){if(!e)for(t=0;t<a.length;t++)a[t].insertAdjacentHTML("afterbegin","<div class='caleran-prev'>"+this.config.prevMonthIcon+"</div>");if(!i)for(t=0;t<a.length;t++)a[t].insertAdjacentHTML("beforeend","<div class='caleran-next'>"+this.config.nextMonthIcon+"</div>")}else this.config.isRTL?(e||a[a.length-1].insertAdjacentHTML("afterbegin","<div class='caleran-prev'>"+this.config.prevMonthIcon+"</div>"),i||a[0].insertAdjacentHTML("beforeend","<div class='caleran-next'>"+this.config.nextMonthIcon+"</div>")):(e||a[0].insertAdjacentHTML("afterbegin","<div class='caleran-prev'>"+this.config.prevMonthIcon+"</div>"),i||a[a.length-1].insertAdjacentHTML("beforeend","<div class='caleran-next'>"+this.config.nextMonthIcon+"</div>"))},drawCalendarOfMonth:function(t){var e=moment(t).locale(this.config.locale).startOf("month").startOf("isoweek").middleOfDay(),i=e.day();1==i&&!1===this.config.startOnMonday?(e.add(-1,"days"),i=0):0===i&&!0===this.config.startOnMonday&&(e.add(1,"days"),i=1),e.isAfter(moment(t).date(1))&&e.add(-7,"day");var a="<div class='caleran-calendar"+(this.config.showWeekNumbers?" caleran-calendar-weeknumbers":"")+"' data-month='"+t.month()+"'>",n=0,s="",o="";this.config.enableMonthSwitcher&&(s=" class='caleran-month-switch'"),this.config.enableYearSwitcher&&(o=" class='caleran-year-switch'"),a+="<div class='caleran-title'><b"+s+">"+t.locale(this.config.locale).format("MMMM")+"</b> <span"+o+">"+this.localizeNumbers(t.year())+"</span></div>",a+="<div class='caleran-days-container'>";var l=moment.localeData(this.config.locale).weekdaysShort();this.config.showWeekNumbers&&(a+="<div class='caleran-dayofweek'> </div>");for(var r=i;r<i+7;r++)a+="<div class='caleran-dayofweek'>"+l[r%7]+"</div>";for(var c=!0,h=null;n<42;){var d=e.middleOfDay().unix(),f=t.month()==e.month()?"caleran-day":"caleran-disabled";n%7==0&&this.config.showWeekNumbers&&(a+="<div class='caleran-weeknumber'><span>"+e.format("ww")+"</span></div>"),a+="<div class='"+f+"' data-value='"+d+"'><span>"+this.localizeNumbers(e.date())+"</span></div>",this.isDisabledOnDraw(e)?(this.globals.disabledDays[d]=1==c?2:1,c=!0,h=d):(1==c&&null!=h&&(this.globals.disabledDays[h]=3),c=!1),e.add(moment.duration({days:1})),n++}a+="</div>",a+="</div>",this.calendars.insertAdjacentHTML("beforeend",a)},drawFooter:function(){if(!1===this.config.singleDate&&!0===this.config.showFooter){if("horizontal"===this.config.rangeOrientation||this.globals.isMobile)this.input.insertAdjacentHTML("beforeend","<div class='caleran-ranges'></div>");else{this.input.classList.add("caleran-input-vertical-range");var t=h.createElement("div");for(t.classList.add("caleran-left");this.input.firstChild;)t.appendChild(this.input.firstChild);this.input.appendChild(t),t.insertAdjacentHTML("afterend","<div class='caleran-right' style='max-width: "+this.config.verticalRangeWidth+"px; min-width: "+this.config.verticalRangeWidth+"px'><div class='caleran-ranges'></div></div>")}var e=this.input.querySelector(".caleran-ranges");e.insertAdjacentHTML("beforeend","<span class='caleran-range-header-container'>"+this.config.rangeIcon+"<div class='caleran-range-header'>"+this.config.rangeLabel+"</div></span>");for(var i=0;i<this.config.ranges.length;i++)e.insertAdjacentHTML("beforeend","<div class='caleran-range"+(this.config.ranges[i].selected?" caleran-range-selected":"")+"' data-id='"+i+"'>"+this.config.ranges[i].title+"</div>")}this.globals.isMobile&&!this.config.inline&&(!0!==this.config.singleDate&&!1!==this.config.showFooter||this.input.insertAdjacentHTML("beforeend","<div class='caleran-filler'></div>")),(this.globals.isMobile&&!this.config.inline||!this.globals.isMobile&&!this.config.inline&&this.config.showButtons)&&("horizontal"===this.config.rangeOrientation||this.globals.isMobile?this.input.insertAdjacentHTML("beforeend","<div class='caleran-footer'></div>"):this.input.querySelector(".caleran-right").insertAdjacentHTML("beforeend","<div class='caleran-footer'></div>"),this.footer=this.input.querySelector(".caleran-footer"),this.footer.insertAdjacentHTML("beforeend","<button type='button' class='caleran-cancel'>"+this.config.cancelLabel+"</button>"),this.footer.insertAdjacentHTML("beforeend","<button type='button' class='caleran-apply'>"+this.config.applyLabel+"</button>"),!1===this.globals.firstValueSelected&&1==this.config.startEmpty&&this.footer.querySelector(".caleran-apply").setAttribute("disabled","disabled"),this.globals.isMobile&&!1===this.globals.endSelected&&this.footer.querySelector(".caleran-apply").setAttribute("disabled","disabled"))},drawNextMonth:function(t){if(t=t||c.event,1==this.config.hideOutOfRange&&this.config.maxDate&&this.globals.currentDate.clone().add(this.config.calendarCount,"month").isAfter(this.config.maxDate,"month"))return!1;if(null===this.globals.swipeTimeout){var e=this;this.globals.swipeTimeout=setTimeout(function(){if(!0===e.config.onbeforemonthchange(e,e.globals.currentDate.clone().startOfMonth(),"next")){var t=e.calendars.scrollTop;e.globals.currentDate.middleOfDay().add(1,"month"),e.reDrawCalendars(),e.calendars.scrollTop=t,e.config.onaftermonthchange(e,e.globals.currentDate.clone().startOfMonth())}e.globals.swipeTimeout=null},100)}return!!t.isCancellable&&this.stopBubbling(t)},drawPrevMonth:function(t){if(t=t||c.event,1==this.config.hideOutOfRange&&this.config.minDate&&this.globals.currentDate.clone().add(-1,"month").isBefore(this.config.minDate,"month"))return!1;if(null===this.globals.swipeTimeout){var e=this;this.globals.swipeTimeout=setTimeout(function(){if(!0===e.config.onbeforemonthchange(e,e.globals.currentDate.clone().startOfMonth(),"prev")){var t=e.calendars.scrollTop;e.globals.currentDate.middleOfDay().subtract(1,"month"),e.reDrawCalendars(),e.calendars.scrollTop=t,e.config.onaftermonthchange(e,e.globals.currentDate.clone().startOfMonth())}e.globals.swipeTimeout=null},100)}return!!t.isCancellable&&this.stopBubbling(t)},cellClicked:function(t){var e=t||c.event,i=e.target||e.srcElement;!1===i.classList.contains("caleran-day")&&(i=this.closest(i,".caleran-day"));var a=parseInt(i.getAttribute("data-value"),10),n=moment.unix(a).middleOfDay();if(0==this.config.validateClick(n))return!1;if(!1===this.config.singleDate)if(!1===this.globals.startSelected){null!==this.config.startDate&&(this.globals.startDateBackup=this.config.startDate.clone()),this.config.startDate=n,this.config.endDate=null,this.globals.startSelected=!0,this.globals.endSelected=!1;var s=void 0===this.footer?[]:this.footer.querySelector(".caleran-apply");0<s.length&&s.setAttribute("disabled","disabled"),this.config.onfirstselect(this,this.config.startDate.clone())}else{if(n.isBefore(this.config.startDate)){var o=this.config.startDate.clone();this.config.startDate=n.clone(),n=o}n.diff(this.config.startDate,"day")<this.config.minSelectedDays?(this.globals.startSelected=!1,this.fetchInputs()):(this.globals.startDateBackup=null,this.config.endDate=n,this.globals.endSelected=!0,this.globals.startSelected=!1,!(this.globals.hoverDate=null)===this.config.onbeforeselect(this,this.config.startDate.clone(),this.config.endDate.clone())&&!0===this.checkRangeContinuity()?(this.globals.firstValueSelected=!0,this.clearRangeSelection(),this.updateInput(!0)):this.fetchInputs(),this.config.autoCloseOnSelect&&!1===this.config.inline?this.hideDropdown(e):void 0!==this.footer&&null!=this.config.endDate&&this.footer.querySelector(".caleran-apply").removeAttribute("disabled"))}else this.config.startDate=n,this.config.endDate=n,this.globals.endSelected=!0,this.globals.startSelected=!1,!(this.globals.hoverDate=null)===this.config.onbeforeselect(this,this.config.startDate.clone(),this.config.endDate.clone())?(this.globals.firstValueSelected=!0,this.clearRangeSelection(),this.updateInput(!0)):this.fetchInputs(),this.config.autoCloseOnSelect&&!1===this.config.inline?this.hideDropdown(e):void 0!==this.footer&&null!=this.config.endDate&&this.footer.querySelector(".caleran-apply").removeAttribute("disabled");return this.reDrawCells(),this.updateHeader(),this.stopBubbling(e)},checkRangeContinuity:function(){var t=this.config.endDate.diff(this.config.startDate,"days"),e=moment(this.config.startDate).middleOfDay();if(1==this.config.disableOnlyStart)return!1===this.isDisabled(this.config.startDate,this.config.isHotelBooking);if(1==this.config.disableOnlyEnd)return!1===this.isDisabled(this.config.endDate,this.config.isHotelBooking);if(this.config.continuous){var i=e.middleOfDay().unix();if(1==this.isDisabled(i,!1)&&(!this.config.isHotelBooking||1===this.getDisabledLevel(i)))return!1;if(0==e.isSame(this.config.endDate,"day")){e.middleOfDay().add(1,"days");for(var a=0;a<=t-2;a++){if(i=e.middleOfDay().unix(),this.getDisabledLevel(i)!==n)return!1;e.add(1,"days")}}if(i=e.middleOfDay().unix(),1==this.isDisabled(i,!1)&&(!this.config.isHotelBooking||3===this.getDisabledLevel(i)))return!1}return!0},isDisabledOnDraw:function(t){var e=moment(t).middleOfDay();if(!0===this.config.disableDays(e))return!0;for(var i=0;i<this.config.disabledRanges.length;i++){var a=this.config.disabledRanges[i];if(e.isBetween(a.start,a.end,"day","[]"))return!0}},isDisabled:function(t,e){return n===e&&(e=!1),(1!=this.config.disableOnlyStart||1!=this.globals.startSelected)&&((1!=this.config.disableOnlyEnd||0!=this.globals.startSelected)&&("object"==typeof t&&null!==t&&(t=t.middleOfDay().unix()),e&&this.config.isHotelBooking?2===this.globals.disabledDays[t]:this.globals.disabledDays[t]!==n))},getDisabledLevel:function(t){return"object"==typeof t&&null!==t&&(t=t.middleOfDay().unix()),this.globals.disabledDays[t]},cellHovered:function(t){var e=t||c.event,i=e.target||e.srcElement;if(!1===i.classList.contains("caleran-day")&&(i=this.closest(i,".caleran-day")),i){var a=parseInt(i.getAttribute("data-value"),10);return this.globals.hoverDate=moment.unix(a).middleOfDay(),!(this.globals.keyboardHoverDate=null)===this.globals.startSelected&&this.reDrawCells(),this.stopBubbling(e)}},reDrawCalendars:function(){this.input.innerHTML="",this.drawUserInterface(),this.container.focus()},monthSwitchClicked:function(){if(!(0<this.calendars.querySelectorAll(".caleran-month-selector").length)){var e=this;this.calendars.scrollTop=0,this.calendars.insertAdjacentHTML("beforeend","<div class='caleran-month-selector'></div>");for(var t=this.calendars.querySelector(".caleran-month-selector"),i=this.globals.currentDate.get("month"),a=0;a<12;a++)t.insertAdjacentHTML("beforeend","<div class='caleran-ms-month"+(i==a?" current":"")+"' data-month='"+a+"'>"+(this.config.numericMonthSelector?a+1:moment({day:15,hour:12,month:a}).locale(this.config.locale).format(this.config.monthSwitcherFormat))+"</div>");t.style.display="block",this.optimizeFontSize(t.querySelectorAll(".caleran-ms-month")),this.rebindEventEach(t,".caleran-ms-month","click",function(t){return!!e.globals&&(e.globals.currentDate.month(parseInt(t.target.getAttribute("data-month"),10)),e.config.onaftermonthchange(e,e.globals.currentDate.clone().startOfMonth()),e.reDrawCalendars(),e.stopBubbling(t))})}},yearSwitchClicked:function(){if(!(0<this.calendars.querySelectorAll(".caleran-year-selector").length)){var n=this;this.calendars.scrollTop=0,this.calendars.insertAdjacentHTML("beforeend","<div class='caleran-year-selector'></div>");var s=this.calendars.querySelector(".caleran-year-selector"),t=this.globals.currentDate.get("year");s.insertAdjacentHTML("beforeend","<div class='caleran-ys-year-prev'><i class='fa fa-angle-double-left'></i></div>"),s.setAttribute("data-year",t);for(var e=t-6;e<t+7;e++)s.insertAdjacentHTML("beforeend","<div class='caleran-ys-year"+(t==e?" current":"")+"' data-year='"+e+"'>"+this.localizeNumbers(e)+"</div>");s.insertAdjacentHTML("beforeend","<div class='caleran-ys-year-next'><i class='fa fa-angle-double-right'></i></div>"),s.style.display="block",this.optimizeFontSize(s.querySelectorAll(".caleran-ys-year")),this.rebindEventScoped(h,".caleran-ys-year","click.caleranys",function(t){return!!n.globals&&(n.globals.currentDate.year(parseInt(t.target.getAttribute("data-year"))),n.config.onafteryearchange(n,n.globals.currentDate.clone().startOf("year")),n.reDrawCalendars(),1==n.config.DOBCalendar&&n.calendars.querySelectorAll(".caleran-calendar")[0].querySelector(".caleran-month-switch").click(),n.stopBubbling(t))}),this.rebindEventScoped(h,".caleran-ys-year-prev","click.caleranysprev",function(t){if(!n.globals)return!1;var e=parseInt(s.getAttribute("data-year"),10)-13,i=n.globals.currentDate.get("year");s.setAttribute("data-year",e),s.innerHTML="",s.insertAdjacentHTML("beforeend","<div class='caleran-ys-year-prev'><i class='fa fa-angle-double-left'></i></div>");for(var a=e-6;a<7+e;a++)s.insertAdjacentHTML("beforeend","<div class='caleran-ys-year"+(i==a?" current":"")+"' data-year='"+a+"'>"+n.localizeNumbers(a)+"</div>");return s.insertAdjacentHTML("beforeend","<div class='caleran-ys-year-next'><i class='fa fa-angle-double-right'></i></div>"),n.stopBubbling(t)}),this.rebindEventScoped(h,".caleran-ys-year-next","click.caleranysnext",function(t){if(!n.globals)return!1;var e=parseInt(s.getAttribute("data-year"),10)+13,i=n.globals.currentDate.get("year");s.setAttribute("data-year",e),s.innerHTML="",s.insertAdjacentHTML("beforeend","<div class='caleran-ys-year-prev'><i class='fa fa-angle-double-left'></i></div>");for(var a=e-6;a<e+7;a++)s.insertAdjacentHTML("beforeend","<div class='caleran-ys-year"+(i==a?" current":"")+"' data-year='"+a+"'>"+n.localizeNumbers(a)+"</div>");return s.insertAdjacentHTML("beforeend","<div class='caleran-ys-year-next'><i class='fa fa-angle-double-right'></i></div>"),n.stopBubbling(t)})}},optimizeFontSize:function(t){for(var e=0;e<t.length;e++){var i=t[e],a=h.createElement("span"),n=i;for(a.classList.add("adjust-subject");i.firstChild;)a.appendChild(i.firstChild);n.appendChild(a),n.insertAdjacentHTML("beforeend","<span class='font-adjuster'>i</span>");var s=a,o=n.querySelector(".font-adjuster");if(s.offsetHeight===o.offsetHeight){for(o.parentNode.removeChild(o);s.firstChild;)n.appendChild(s.firstChild);s.parentNode.removeChild(s)}else{for(var l=0;s.offsetHeight!==o.offsetHeight&&l<16;){var r=0;if(r=void 0!==c.getComputedStyle?parseFloat(c.getComputedStyle(o,null).getPropertyValue("font-size")):parseFloat(o.style.fontSize.replace(/px$/,"")),s.parentNode.style.fontSize=r-1+"px",o.style.fontSize=r-1+"px",r<2)break;l++}for(o.parentNode.removeChild(o);s.firstChild;)n.appendChild(s.firstChild);s.parentNode.removeChild(s)}}},showDropdown:function(t){var e=t||c.event||jQuery.Event("click",{target:this.elem}),i=e.target||e.srcElement;(!this.globals.isMobile&&"none"==this.container.style.display||this.globals.isMobile&&"none"==this.input.style.display)&&(i!==this.elem&&(this.globals.dontHideOnce=!0,this.globals.initiator=i),this.fetchInputs(),this.reDrawCalendars(),this.globals.startDateInitial=this.config.startDate,this.globals.endDateInitial=this.config.endDate,this.config.onbeforeshow(this),this.globals.isMobile?(this.input.style.display="flex",this.overlay.style.display="block",h.body.classList.add("caleran-open")):this.container.style.display="block",this.setViewport(),1==this.config.DOBCalendar&&this.calendars.querySelectorAll(".caleran-calendar")[0].querySelector(".caleran-year-switch").click(),this.config.onaftershow(this))},hideDropdown:function(t){var e=t||c.event||new Event("click",{target:"body"}),i=e.target||e.srcElement;this.globals.initiator!==i&&!1===this.config.inline&&(!this.globals.isMobile&&"none"!==this.container.style.display||this.globals.isMobile&&"none"!==this.input.style.display)&&(this.config.onbeforehide(this),this.globals.isMobile?(this.input.style.display="none",this.overlay.style.display="none",h.body.classList.remove("caleran-open")):this.container.style.display="none",(this.globals.hoverDate=null)!==this.globals.startDateBackup&&(this.config.startDate=this.globals.startDateBackup,this.globals.startSelected=!1),this.config.onafterhide(this))},reDrawCells:function(){var t=null!=this.config.startDate?this.config.startDate.middleOfDay().unix():null,e=null!=this.config.endDate?this.config.endDate.middleOfDay().unix():null,i=null!=this.config.minDate?this.config.minDate.middleOfDay().unix():null,a=null!=this.config.maxDate?this.config.maxDate.middleOfDay().unix():null,n=null!=this.globals.hoverDate?this.globals.hoverDate.middleOfDay().unix():null,s=null!=this.globals.keyboardHoverDate?this.globals.keyboardHoverDate.middleOfDay().unix():null,o=moment().middleOfDay().unix();this.lastHoverStatus=!1;for(var l=0;l<this.config.calendarCount;l++)for(var r=this.input.querySelectorAll(".caleran-calendar")[l],c=r.querySelectorAll(".caleran-days-container > div:not(.caleran-dayofweek):not(.caleran-weeknumber)"),h=parseInt(r.getAttribute("data-month"),10),d=0;d<c.length;d++){var f=c[d],g=parseInt(f.getAttribute("data-value"),10),u=moment.unix(g).middleOfDay().locale(this.config.locale),p="caleran-day",b=u.day();6!=b&&0!==b||(p+=" caleran-weekend"),g===o&&(p+=" caleran-today"),p=this.addDisabledStyles(f,u,g,p,i,a,h),p=this.addSelectedStyles(g,p,t,e,i,a),p=this.addHoverStyles(f,g,p,this,t,n,s),f.setAttribute("class",p)}this.attachEvents(),this.config.ondraw(this)},addSelectedStyles:function(t,e,i,a,n,s){var o=this;return!1!==o.config.startEmpty&&!o.globals.firstValueSelected||(!1===o.config.singleDate&&null!==i&&i===t&&(e+=" caleran-start"),!1===o.config.singleDate&&null!==a&&a===t&&(e+=" caleran-end"),!1===o.config.singleDate&&null!==i&&null!==a&&t<=a&&i<=t&&(e+=" caleran-selected"),!0===o.config.singleDate&&null!==i&&i===t&&(e+=" caleran-selected caleran-start caleran-end")),e},addHoverStyles:function(t,e,i,a,n,s,o){if(i.replace("caleran-hovered","").replace("caleran-hovered-last","").replace("caleran-hovered-first",""),!0===this.globals.startSelected&&!1===this.globals.endSelected&&null!==s&&(s<=e&&e<=n||e<=s&&n<=e)&&(i+=" caleran-hovered"),1==this.config.enableKeyboard&&null!==o&&(!1===this.globals.startSelected?o==e&&(i+=" caleran-hovered"):(e<=n&&o<=e||n<=e&&e<=o)&&(i+=" caleran-hovered")),!1===this.lastHoverStatus&&0<i.indexOf("caleran-hovered")&&(this.lastHoverStatus=!0,i+=" caleran-hovered-first"),!0===this.lastHoverStatus&&i.indexOf("caleran-hovered")<0){var l=t.previousElementSibling;(l=l&&l.matches(".caleran-day")?l:null)&&l.classList.add("caleran-hovered-last"),this.lastHoverStatus=!1}return i},addDisabledStyles:function(t,e,i,a,n,s,o){if(this.isDisabled(i))if(0==this.config.isHotelBooking)a=a.replace("caleran-day","caleran-disabled caleran-disabled-range");else switch(this.globals.disabledDays[i]){case 1:a=a.replace("caleran-day","caleran-day caleran-disabled-range caleran-disabled-range-start");break;case 2:a=a.replace("caleran-day","caleran-disabled caleran-disabled-range");break;case 3:a=a.replace("caleran-day","caleran-day caleran-disabled-range caleran-disabled-range-end")}else(null!=s&&s<i||null!=n&&i<n)&&(a=a.replace("caleran-day","caleran-disabled"));return e.month()!=o&&(a+=" caleran-not-in-month"),a},localizeNumbers:function(t){return moment.localeData(this.config.locale).postformat(""+t)},rangeClicked:function(t){var e=t||c.event,i=e.target||e.srcElement;if(i.hasAttribute("data-id")){var a=i.getAttribute("data-id");return this.globals.currentDate=this.config.ranges[a].startDate.startOf("day").clone().middleOfDay(),this.config.startDate=this.config.ranges[a].startDate.startOf("day").clone().middleOfDay(),this.config.endDate=this.config.ranges[a].endDate.startOf("day").clone().middleOfDay(),!(this.globals.firstValueSelected=!0)===this.checkRangeContinuity()?this.fetchInputs():(this.clearRangeSelection(),this.config.ranges[a].selected=!0,this.config.onrangeselect(this,this.config.ranges[a]),this.reDrawCalendars(),this.setViewport(),this.config.autoCloseOnSelect&&this.hideDropdown()),this.stopBubbling(e)}},setViewport:function(){if(this.globals)if(!0===this.globals.isMobile)"none"!==this.input.style.display&&this.events.dispatch(this.container,"caleran:resize");else if("none"!==this.container.style.display&&this.globals.initComplete&&!1===this.globals.isMobile&&!1===this.config.inline){var t=this.getViewport();switch(this.config.showOn){case"top":this.config.autoAlign?this.positionOnTopAlign(t):this.positionOnTop(!1,t),this.horizontalAlign(t);break;case"left":this.config.autoAlign?this.positionOnLeftAlign(t):this.positionOnLeft(!1,t),this.verticalAlign(t);break;case"right":this.config.autoAlign?this.positionOnRightAlign(t):this.positionOnRight(!1,t),this.verticalAlign(t);break;case"bottom":this.config.autoAlign?this.positionOnBottomAlign(t):this.positionOnBottom(!1,t),this.horizontalAlign(t);break;case"center":this.positionOnCenter(t);break;default:this.config.autoAlign?this.positionOnBottomAlign(t):this.positionOnBottom(!1,t),this.horizontalAlign(t)}if("horizontal"!==this.config.rangeOrientation){var e=this.input.querySelector(".caleran-header").clientHeight+this.input.querySelector(".caleran-calendars").clientHeight+(0<this.input.querySelectorAll(".caleran-footer").length?this.input.querySelector(".caleran-footer").clientHeight:0);this.input.querySelector(".caleran-right").style.maxHeight=e+"px"}}},verticalAlign:function(t){var e=this.getDimensions(this.container,!0),i=t.top-e.offsetTop,a=e.offsetTop+e.height-t.bottom,n=this.container.querySelector("div[class*='caleran-box-arrow-']");0<i&&Math.abs(i)<e.height?(this.container.style.top=parseFloat(this.container.style.top.replace(/px$/,""))+i+"px",n.style.top=parseFloat(n.style.top.replace(/px$/,""))-i+"px"):0<a&&Math.abs(a)<e.height&&(this.container.style.top=parseFloat(this.container.style.top.replace(/px$/,""))-a+"px",n.style.top=parseFloat(n.style.top.replace(/px$/,""))+a+"px")},horizontalAlign:function(t){var e=this.getDimensions(this.container,!0),i=e.offsetLeft+e.width-t.right,a=this.container.querySelector("div[class*='caleran-box-arrow-']");0<i&&Math.abs(i)<e.width&&(this.container.style.left=parseFloat(this.container.style.left.replace(/px$/,""))-i+"px",a.style.left=parseFloat(a.style.left.replace(/px$/,""))+i)},getDropdownPos:function(t){var e=this.getDimensions(this.elem,!0),i=this.getDimensions(this.container,!0),a=parseInt(this.input.style.marginLeft,10);isNaN(a)&&(a=0);var n=0;switch(0<this.container.querySelectorAll("div[class*='caleran-box-arrow']").length&&(n=parseFloat(this.container.querySelectorAll("div[class*='caleran-box-arrow']")[0].offsetHeight/2)),t){case"left":switch(this.config.arrowOn){case"top":return{top:e.offsetTop-a-n-e.height/2,left:e.offsetLeft-i.width-a,arrow:0};case"center":return{top:e.offsetTop-a-i.height/2,left:e.offsetLeft-i.width-a,arrow:(i.height-2*n)/2-e.height/2};case"bottom":return{top:e.offsetTop-i.height+e.height+2*a+n,left:e.offsetLeft-i.width-a,arrow:i.height-4*n-3*a-e.height/2};default:return{top:e.offsetTop-a-n-e.height/2,left:e.offsetLeft-i.width-a,arrow:0}}break;case"right":switch(this.config.arrowOn){case"top":return{top:e.offsetTop-a-n-e.height/2,left:e.offsetLeft+e.width+a,arrow:0};case"center":return{top:e.offsetTop-a-i.height/2,left:e.offsetLeft+e.width+a,arrow:(i.height-2*n)/2-e.height/2};case"bottom":return{top:e.offsetTop-i.height+e.height+2*a+n,left:e.offsetLeft+e.width+a,arrow:i.height-4*n-3*a-e.height/2};default:return{top:e.offsetTop-a-n-e.height/2,left:e.offsetLeft+e.width+a,arrow:0}}break;case"top":switch(this.config.arrowOn){case"left":return{top:e.offsetTop-i.height-a,left:e.offsetLeft-a,arrow:0};case"center":return{top:e.offsetTop-i.height-a,left:e.offsetLeft-(i.width-2*a-e.width)/2,arrow:(i.width-5*n)/2};case"right":return{top:e.offsetTop-i.height-a,left:e.offsetLeft-(i.width-e.width)+a,arrow:i.width-5*n+a};default:return{top:e.offsetTop-i.height-a,left:e.offsetLeft-a,arrow:0}}break;case"bottom":switch(this.config.arrowOn){case"left":return{top:e.offsetTop+e.height-a+n,left:e.offsetLeft-a,arrow:0};case"center":return{top:e.offsetTop+e.height-a+n,left:e.offsetLeft-(i.width-2*a-e.width)/2,arrow:(i.width-5*n)/2};case"right":return{top:e.offsetTop+e.height-a+n,left:e.offsetLeft-(i.width-e.width)+a,arrow:i.width-5*n+a};default:return{top:e.offsetTop+e.height-a+n,left:e.offsetLeft-a,arrow:0}}break;case"center":switch(this.config.arrowOn){case"center":return{top:e.offsetTop-a-i.height/2,left:e.offsetLeft-(i.width-2*a-e.width)/2}}}},positionOnTop:function(t,e){var i=this.getDropdownPos("top");if(t)return i;this.container.style.left=i.left-5+"px",this.container.style.top=i.top-5+"px";var a=this.container.querySelector("div[class*='caleran-box-arrow-']");a.setAttribute("class","caleran-box-arrow-bottom"),a.style.left=i.arrow+"px"},positionOnBottom:function(t,e){var i=this.getDropdownPos("bottom");if(t)return i;this.container.style.left=i.left-5+"px",this.container.style.top=i.top-5+"px";var a=this.container.querySelector("div[class*='caleran-box-arrow-']");a.setAttribute("class","caleran-box-arrow-top"),a.style.left=i.arrow+"px"},positionOnLeft:function(t,e){var i=this.getDropdownPos("left");if(t)return i;this.container.style.left=i.left-5+"px",this.container.style.top=i.top-5+"px";var a=this.container.querySelector("div[class*='caleran-box-arrow-']");a.setAttribute("class","caleran-box-arrow-right"),a.style.top=i.arrow+"px"},positionOnRight:function(t,e){var i=this.getDropdownPos("right");if(t)return i;this.container.style.left=i.left+5+"px",this.container.style.top=i.top-5+"px";var a=this.container.querySelector("div[class*='caleran-box-arrow-']");a.setAttribute("class","caleran-box-arrow-left"),a.style.top=i.arrow+"px"},positionOnCenter:function(t){var e=this.getDropdownPos("center"),i=Math.max(e.left+this.container.clientWidth-(t.right-30),0),a=Math.max(e.top+this.container.clientHeight-(t.bottom-30),0);this.config.autoAlign||(a=i=0),e.left-=i,e.top-=a,this.container.style.left=e.left,this.container.style.top=e.top;var n=this.container.querySelector("div[class*='caleran-box-arrow-']");n&&n.parentNode.removeChild(n)},positionOnBottomAlign:function(t){var e=this.positionOnBottom(!0,t),i=this.getDimensions(this.container);e.top+i.height<t.bottom?this.positionOnBottom(!1,t):this.positionOnTop(!1,t)},positionOnLeftAlign:function(t){this.positionOnLeft(!0,t).left>t.left-50?this.positionOnLeft(!1,t):this.positionOnRight(!1,t)},positionOnRightAlign:function(t){var e=this.positionOnRight(!0,t),i=this.getDimensions(this.container);e.left+i.width<t.right+50?this.positionOnRight(!1,t):this.positionOnLeft(!1,t)},positionOnTopAlign:function(t){this.positionOnTop(!0,t).top>t.top?this.positionOnTop(!1,t):this.positionOnBottom(!1,t)},getDimensions:function(t,e){var i={left:0,top:0},a=t;for(this.attachScrollEvents(t);null!=a&&a!=h.body;){var n=c.getComputedStyle(a);if("fixed"==n.position){i.top=i.top+c.scrollY+parseInt(n.top,10),i.left=i.left+c.scrollX+parseInt(n.left,10);break}i.left=i.left+a.offsetLeft,i.top=i.top+a.offsetTop,a=a.offsetParent}return{width:t.offsetWidth,height:t.offsetHeight,offsetLeft:i.left,offsetTop:i.top}},attachScrollEvents:function(t){var e=h.body;if(t===this.elem&&0==this.globals.parentScrollEventsAttached){var i=this.proxy(function(){this.globals&&(this.globals.isTicking||(this.globals.isTicking=!0,this.globals.rafID=this.requestAnimFrame(this.proxy(function(){this.setViewport(),this.cancelAnimFrame(this.globals.rafID),this.globals.isTicking=!1},this))))},this);if(t!==e)for(var a=t.parentNode;a!==e&&null!==a;)a.scrollHeight>a.offsetHeight&&this.rebindEvent(a,"scroll",i),a=a.parentNode;this.globals.parentScrollEventsAttached=!0}},getViewport:function(){var t=this.globals.lastScrollY,e=this.globals.lastScrollX,i=t+c.innerHeight;return{top:t,left:e,right:e+c.innerWidth,bottom:i}},debugPosition:function(t,e,i,a,n,s){0<h.body.querySelectorAll("#"+t).length&&h.body.removeChild(h.body.querySelector("#"+t)),h.body.insertAdjacentHTML("beforeend","<div id='"+t+"'>;</div>");var o=h.querySelector("#"+t);o.style.top=e+"px",o.style.left=i+"px",o.style.right=a+"px",o.style.bottom=n+"px",o.style.position="absolute",o.style.backgroundColor=s,o.style.zIndex=1e5,o.style.opacity=.5,o.style.width=a-i+"px",o.style.height=n-e+"px",o.style.pointerEvents="none"},rebindEventEach:function(t,e,i,a,n){for(var s=t.querySelectorAll(e),o=0;o<s.length;o++)this.rebindEvent(s[o],i,a,n)},rebindEvent:function(t,e,i,a){for(var n=e.split(" ").map(function(t){return t.trim()}),s=0,o=n.length;s<o;s++)this.events.remove(t,n[s],i),this.events.add(t,n[s],i,a)},rebindEventScoped:function(t,i,e,a,n){this.rebindEvent(t,e,function(t){var e=t.target||t.srcElement;if(e&&(this.matches(e,i)||this.closest(e,i)))return a.call(e,t)}.bind(this),n)},matches:function(t,e){if(!t||t.matches)return t.matches(e);var i=Object.getPrototypeOf(t);i.matches=i.matchesSelector||i.mozMatchesSelector||i.msMatchesSelector||i.oMatchesSelector||i.webkitMatchesSelector;try{return i.matches(e)}catch(t){return!1}},closest:function(t,e){var i=this;if(!t||t.closest)return t.closest(e);var a=Object.getPrototypeOf(t);a.closest=function(t){var e=this;do{if(i.matches(e,t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null};try{return a.closest(e)}catch(t){return!1}},removeEventEach:function(t,e,i){for(var a=i.split(" ").map(function(t){return t.trim()}),n=0,s=a.length;n<s;n++)for(var o=t.querySelectorAll(e),l=0,r=o.length;l<r;l++)this.events.remove(o[l],a[n])},attachEvents:function(){var e=this.drawNextMonth.bind(this),i=this.drawPrevMonth.bind(this),t=this.cellClicked.bind(this),a=this.cellHovered.bind(this),n=this.rangeClicked.bind(this),s=this.monthSwitchClicked.bind(this),o=this.yearSwitchClicked.bind(this),l="click";this.rebindEventEach(this.container,".caleran-next",l,this.config.isRTL?i:e,!0),this.rebindEventEach(this.container,".caleran-prev",l,this.config.isRTL?e:i,!0),this.rebindEventEach(this.container,".caleran-day",l,t,!1),this.rebindEventEach(this.container,".caleran-day","mouseover",a,!1),this.removeEventEach(this.container,".caleran-disabled:not(.caleran-day)",l),this.rebindEventEach(this.container,".caleran-range",l,n,!1),this.rebindEventEach(this.container,".caleran-month-switch",l,s,!1),this.rebindEventEach(this.container,".caleran-year-switch",l,o,!1),!0===this.globals.isMobile&&1==this.config.enableSwipe&&(this.rebindEvent(this.container,"touchstart",function(t){this.globals&&0<event.changedTouches.length&&(this.globals.swipeX=event.changedTouches[0].screenX,this.globals.swipeY=event.changedTouches[0].screenY,this.globals.swipeStart=+new Date)}.bind(this)),this.rebindEvent(this.container,"touchend",function(t){this.globals&&0<t.changedTouches.length&&Math.abs(this.globals.swipeY-t.changedTouches[0].screenY)<50&&100<Math.abs(this.globals.swipeX-t.changedTouches[0].screenX)&&new Date-this.globals.swipeStart<250&&(this.globals.swipeX<t.changedTouches[0].screenX?e():this.globals.swipeX>=t.changedTouches[0].screenX&&i())}.bind(this))),!this.globals.isMobile&&!this.config.showButtons||this.config.inline||(this.rebindEventEach(this.input,".caleran-cancel","click",this.proxy(function(t){1==this.config.onCancel(this,this.config.startDate,this.config.endDate)&&(this.globals.startDateInitial&&(this.config.startDate=this.globals.startDateInitial.clone()),this.globals.endDateInitial&&(this.config.endDate=this.globals.endDateInitial.clone()),this.hideDropdown(t))},this),!1),this.rebindEventEach(this.input,".caleran-apply","click",this.proxy(function(t){!0===this.config.onbeforeselect(this,this.config.startDate.clone(),this.config.endDate.clone())&&!0===this.checkRangeContinuity()?(this.globals.firstValueSelected=!0,this.globals.delayInputUpdate?(this.globals.delayInputUpdate=!1,this.updateInput(!0),this.globals.delayInputUpdate=!0):this.updateInput(!0)):this.fetchInputs(),this.hideDropdown(t)},this),!1))},isVisible:function(t){return 0<t.offsetWidth&&0<t.offsetHeight},addInitialEvents:function(){var e=this,t="click";this.events.add(h,"click",this.proxy(function(t){if(this.globals&&!1===this.globals.isMobile&&!1===this.config.inline){var e=t||c.event||new Event("click",{target:"body"}),i=e.target||e.srcElement;!1===this.contains(this.container,i)&&this.elem!==i&&this.isVisible(this.container)&&this.hideDropdown(e)}},this)),this.config.enableKeyboard&&(t="click focus"),this.rebindEvent(this.elem,t,this.proxy(this.debounce(function(t){var e=t||c.event||new Event("click",{target:"body"}),i=e.target||e.srcElement;0<this.input.clientHeight&&this.config.target!==i?this.hideDropdown(e):(this.events.dispatch(h,"click"),this.showDropdown(e))},100,!0),this),!1),this.globals.isMobile&&this.events.add(c,"resize",function(){e.events.dispatch(e.container,"caleran:resize")}),this.events.add(this.container,"caleran:resize",function(){e.globals.rafID=e.requestAnimFrame(function(){if(e.globals&&"none"!==e.input.style.display){var t=e.input.querySelector(".caleran-calendar:first-child");t&&e.isVisible(t)&&(t=t.clientHeight,e.input.querySelector(".caleran-calendars").style.height=t+"px",e.input.offsetTop<0&&e.input.classList.add("caleran-input-top-reset"),c.innerWidth>c.innerHeight?e.input.style.height=t+"px":e.input.style.height="auto"),e.cancelAnimFrame(e.globals.rafID)}})}),"none"!==this.input.style.display&&this.globals.isMobile&&this.events.dispatch(this.container,"caleran:resize"),!1===this.globals.isMobile&&this.rebindEvent(c,"resize scroll",function(){e.globals&&(e.globals.isTicking||(e.globals.isTicking=!0,e.globals.lastScrollX=c.scrollX||c.pageXOffset||h.documentElement.scrollLeft,e.globals.lastScrollY=c.scrollY||c.pageYOffset||h.documentElement.scrollTop,e.globals.rafID=e.requestAnimFrame(e.proxy(function(){this.globals&&(this.setViewport(),this.globals.isTicking=!1,this.cancelAnimFrame(this.globals.rafID))},e))))})},contains:function(t,e){return"contains"in t?t.contains(e):t.compareDocumentPosition(e)%16},stopBubbling:function(t){return void 0!==t.stopPropagation?t.stopPropagation():void 0!==t.cancelBubble&&(t.cancelBubble=!0),void 0!==t.preventDefault&&t.preventDefault(),t.returnValue=!1},debounce:function(a,n,s){return function(){var t=this,e=arguments;if(t.globals){var i=s&&!t.globals.throttleTimeout;clearTimeout(t.globals.throttleTimeout),t.globals.throttleTimeout=setTimeout(function(){t.globals&&(t.globals.throttleTimeout=null,s||a.apply(t,e))},n),i&&a.apply(t,e)}}},proxy:function(t,e){return t.bind(e)},extend:function(t,e){var i={};function a(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return a(i,t),a(i,e),i},requestAnimFrame:function(t){return"function"==typeof c.requestAnimationFrame?requestAnimationFrame(t):"function"==typeof c.webkitRequestAnimationFrame?webkitRequestAnimationFrame(t):"function"==typeof c.mozRequestAnimationFrame?mozRequestAnimationFrame(t):setTimeout(t,100/6)},cancelAnimFrame:function(t){return("function"==typeof c.cancelAnimationFrame?cancelAnimationFrame:"function"==typeof c.webkitCancelAnimationFrame?webkitCancelAnimationFrame:"function"==typeof c.mozCancelAnimationFrame?mozCancelAnimationFrame:clearTimeout)(t)},addKeyboardEvents:function(){if(this.config.enableKeyboard){var t=function(t){var e=t.which?t.which:t.keyCode;null===this.globals.keyboardHoverDate?null===this.config.startDate?this.globals.keyboardHoverDate=moment({day:1,month:parseInt(this.calendars.first().getAttribute("data-month"))}).middleOfDay():this.globals.keyboardHoverDate=this.config.startDate.clone().middleOfDay():this.globals.keyboardHoverDate.middleOfDay();var i=!1,a=!1;switch(e){case 37:this.globals.keyboardHoverDate.add(-1,"day"),a=i=!0;break;case 38:this.globals.keyboardHoverDate.add(-1,"week"),a=i=!0;break;case 39:this.globals.keyboardHoverDate.add(1,"day"),a=i=!0;break;case 40:this.globals.keyboardHoverDate.add(1,"week"),a=i=!0;break;case 32:this.input.querySelectorAll(".caleran-day[data-value='"+this.globals.keyboardHoverDate.middleOfDay().unix()+"']")[0].click(),a=!(i=!1);break;case 33:t.shiftKey?this.globals.keyboardHoverDate.add(-1,"years"):this.globals.keyboardHoverDate.add(-1,"months"),a=i=!0;break;case 34:t.shiftKey?this.globals.keyboardHoverDate.add(1,"years"):this.globals.keyboardHoverDate.add(1,"months"),a=i=!0;break;case 27:case 9:this.hideDropdown(t);break;case 36:t.shiftKey&&(this.globals.keyboardHoverDate=moment().middleOfDay(),a=i=!0)}if(i||a){this.globals.keyboardHoverDate=this.globals.keyboardHoverDate.middleOfDay();var n=this.input.querySelectorAll(".caleran-day[data-value]");return(this.globals.keyboardHoverDate.isBefore(moment.unix(n[0].getAttribute("data-value")),"day")||this.globals.keyboardHoverDate.isAfter(moment.unix(n[n.length-1].getAttribute("data-value")),"day"))&&(this.globals.currentDate=this.globals.keyboardHoverDate.clone().startOfMonth(),this.reDrawCalendars(),i=!1),i&&(this.globals.hoverDate=null,this.reDrawCells()),!!a&&this.stopBubbling(t)}}.bind(this);this.rebindEvent(this.elem,"keydown",t,!1),this.rebindEvent(this.container,"keydown",t,!1)}},destroy:function(){if(this.config.onBeforeDestroy(this)){this.events.remove(this.container,"caleran:resize"),this.config.inline?(this.input.parentNode.removeChild(this.input),this.globals.isMobile?this.unwrap(this.elem,"caleran-container-mobile"):this.unwrap(this.elem,"caleran-container"),this.elem.type="text"):this.container.parentNode.removeChild(this.container),this.events.remove(h,this.globals.documentEvent),this.elem.caleran=null,this.config.ondestroy(this);var t=null;for(t in this.config)this.config[t]=null;for(t in this.config=null,this.globals)this.globals[t]=null;this.globals=null}},unwrap:function(t,e){if(t&&t.parentNode&&t.parentNode.classList.contains(e)){t.parentNode.insertAdjacentHTML("beforebegin",t.parentNode.innerHTML);var i=t.parentNode.parentNode.querySelector("."+e);i.parentNode.removeChild(i)}},checkMobile:function(){return c.matchMedia("only screen and (max-width: "+this.config.mobileBreakpoint+"px)").matches},fixDateTime:function(t){return null!=t&&0==moment.isMoment(t)&&(t="string"==typeof t?moment(t,this.config.format).locale(this.config.locale):moment(t).locale(this.config.locale)),t},setStart:function(t){var e=this.fixDateTime(t);!1===this.isDisabled(e)&&moment(e).isValid()&&(this.config.startDate=moment(e),this.refreshValues())},setEnd:function(t){var e=this.fixDateTime(t);!1===this.isDisabled(e)&&moment(e).isValid()&&(this.config.endDate=moment(e),this.refreshValues())},setMinDate:function(t){var e=this.fixDateTime(t);moment(e).isValid()&&(this.config.minDate=moment(e),this.refreshValues())},setMaxDate:function(t){var e=this.fixDateTime(t);moment(e).isValid()&&(this.config.maxDate=moment(e),this.refreshValues())},setDisplayDate:function(t){var e=this.fixDateTime(t);moment(e).isValid()&&(this.globals.currentDate=moment(e),this.reDrawCalendars())},refreshValues:function(){var t=this.globals.delayInputUpdate;this.globals.delayInputUpdate=!1,this.validateDates(),this.updateInput(),this.globals.delayInputUpdate=t,this.reDrawCells()},eventsPrototype:function(){return{instanceId:null,init:function(t){this.instanceId=t},add:function(e,i,a,t){var n=this;e.eventsList=e.eventsList||{};var s=(i+=".caleran_"+this.instanceId)+"__"+Object.keys(e.eventsList).filter(function(t){return 0===t.indexOf(i+"__")}).length;e.eventsList[s]=t?function(t){a(t),n.remove(e,i,a)}:function(t){a(t)};var o=i.split(/\./)[0];e.addEventListener?e.addEventListener(o,e.eventsList[s],!1):e.attachEvent?e.attachEvent("on"+o,e.eventsList[s]):e["on"+o]=e.eventsList[s]},remove:function(t,e,i){if("object"==typeof t.eventsList){var a;e+=".caleran_"+this.instanceId,a=Object.keys(t.eventsList).filter(function(t){return 0===t.indexOf(e+"__")});for(var n=0;n<a.length;n++){var s=a[n],o=e.split(/\./)[0];"function"==typeof t.removeEventListener?t.removeEventListener(o,t.eventsList[s]):t.detachEvent?t.detachEvent("on"+o,t.eventsList[s]):t["on"+o]=null,delete t.eventsList[s]}}else"function"==typeof t.removeEventListener?t.removeEventListener(e,null):t.detachEvent&&t.detachEvent("on"+e,null)},dispatch:function(t,e){if("object"==typeof t.eventsList){e+=".caleran_"+this.instanceId;for(var i=Object.keys(t.eventsList).filter(function(t){return 0==t.indexOf(e+"__")}),a=0;a<i.length;a++){var n=i[a].split(/\./)[0];this.triggerEvent(t,n)}}else this.triggerEvent(t,e)},triggerEvent:function(t,e){var i;h.createEvent?(i=h.createEvent("HTMLEvents")).initEvent(e,!1,!0):h.createEventObject&&((i=h.createEventObject()).eventType=e),i.eventName=e,t.dispatchEvent?t.dispatchEvent(i):t.fireEvent&&htmlEvents["on"+e]?t.fireEvent("on"+i.eventType,i):t[e]?t[e]():t["on"+e]&&t["on"+e]()}}}}).defaults,c.caleran=function(t,e){var i=0;if("string"==typeof t){var a=h.querySelectorAll(t);for(i=0;i<a.length;i++){var n=a[i];n.caleran=new s(n,e).init()}}else if("object"==typeof t)if(NodeList.prototype.isPrototypeOf(t))for(i=0;i<t.length;i++)t[i].caleran=new s(t[i],e).init();else t.caleran=new s(t,e).init()},"function"!=typeof moment.fn.middleOfDay&&(moment.fn.middleOfDay=function(){return this.hours(12).minutes(0).seconds(0),this},moment.fn.startOfMonth=function(){return this.middleOfDay().date(1),this})}(window,document);
|
|
//# sourceMappingURL=caleran.min.js.map
|