hotel-datepicker
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -8,3 +8,3 @@ const rollup = require('rollup'); | ||
const banner = `/*! ${packageInfo.name} ${packageInfo.version} - Copyright 2019 ${packageInfo.author} - ${packageInfo.homepage} - ${packageInfo.license} */`; | ||
const banner = `/*! ${packageInfo.name} ${packageInfo.version} - Copyright 2020 ${packageInfo.author} - ${packageInfo.homepage} - ${packageInfo.license} */`; | ||
@@ -11,0 +11,0 @@ rollup.rollup({ |
@@ -1,2 +0,2 @@ | ||
/*! hotel-datepicker 4.0.0 - Copyright 2019 Benito Lopez (http://lopezb.com) - https://github.com/benitolopez/hotel-datepicker - MIT */ | ||
/*! hotel-datepicker 4.0.1 - Copyright 2020 Benito Lopez (http://lopezb.com) - https://github.com/benitolopez/hotel-datepicker - MIT */ | ||
var HotelDatepicker = (function () { | ||
@@ -3,0 +3,0 @@ 'use strict'; |
@@ -1,2 +0,2 @@ | ||
/*! hotel-datepicker 4.0.0 - Copyright 2019 Benito Lopez (http://lopezb.com) - https://github.com/benitolopez/hotel-datepicker - MIT */ | ||
var HotelDatepicker=function(){"use strict";function a(e,t){this._boundedEventHandlers={},this.id=a.getNewId();var s=t||{};this.format=s.format||"YYYY-MM-DD",this.infoFormat=s.infoFormat||this.format,this.separator=s.separator||" - ",this.startOfWeek=s.startOfWeek||"sunday",this.startDate=s.startDate||new Date,this.endDate=s.endDate||!1,this.minNights=s.minNights||1,this.maxNights=s.maxNights||0,this.selectForward=s.selectForward||!1,this.disabledDates=s.disabledDates||[],this.noCheckInDates=s.noCheckInDates||[],this.noCheckOutDates=s.noCheckOutDates||[],this.disabledDaysOfWeek=s.disabledDaysOfWeek||[],this.enableCheckout=s.enableCheckout||!1,this.preventContainerClose=s.preventContainerClose||!1,this.container=s.container||"",this.animationSpeed=s.animationSpeed||".5s",this.hoveringTooltip=s.hoveringTooltip||!0,this.autoClose=void 0===s.autoClose||s.autoClose,this.showTopbar=void 0===s.showTopbar||s.showTopbar,this.moveBothMonths=s.moveBothMonths||!1,this.i18n=s.i18n||{selected:"Your stay:",night:"Night",nights:"Nights",button:"Close","checkin-disabled":"Check-in disabled","checkout-disabled":"Check-out disabled","day-names-short":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"day-names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"month-names-short":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"month-names":["January","February","March","April","May","June","July","August","September","October","November","December"],"error-more":"Date range should not be more than 1 night","error-more-plural":"Date range should not be more than %d nights","error-less":"Date range should not be less than 1 night","error-less-plural":"Date range should not be less than %d nights","info-more":"Please select a date range of at least 1 night","info-more-plural":"Please select a date range of at least %d nights","info-range":"Please select a date range between %d and %d nights","info-default":"Please select a date range"},this.getValue=s.getValue||function(){return e.value},this.setValue=s.setValue||function(t){e.value=t},this.onDayClick=void 0!==s.onDayClick&&s.onDayClick,this.onOpenDatepicker=void 0!==s.onOpenDatepicker&&s.onOpenDatepicker,this.onSelectRange=void 0!==s.onSelectRange&&s.onSelectRange,this.input=e,this.init()}var t=0;return a.prototype.addBoundedListener=function(t,e,s,a){t in this._boundedEventHandlers||(this._boundedEventHandlers[t]={}),e in this._boundedEventHandlers[t]||(this._boundedEventHandlers[t][e]=[]);var i=s.bind(this);this._boundedEventHandlers[t][e].push([i,a]),t.addEventListener(e,i,a)},a.prototype.removeAllBoundedListeners=function(t,e){if(t in this._boundedEventHandlers){var s=this._boundedEventHandlers[t];if(e in s)for(var a=s[e],i=a.length;i--;){var n=a[i];t.removeEventListener(e,n[0],n[1])}}},a.getNewId=function(){return++t},a.prototype.setFechaI18n=function(){fecha.setGlobalDateI18n({dayNamesShort:this.i18n["day-names-short"],dayNames:this.i18n["day-names"],monthNamesShort:this.i18n["month-names-short"],monthNames:this.i18n["month-names"]})},a.prototype.getWeekDayNames=function(){var t="";if("monday"===this.startOfWeek){for(var e=0;e<7;e++)t+='<th class="datepicker__week-name">'+this.lang("day-names-short")[(1+e)%7]+"</th>";return t}for(var s=0;s<7;s++)t+='<th class="datepicker__week-name">'+this.lang("day-names-short")[s]+"</th>";return t},a.prototype.getMonthDom=function(t){return document.getElementById(this.getMonthTableId(t))},a.prototype.getMonthName=function(t){return this.lang("month-names")[t]},a.prototype.getDatepickerId=function(){return"datepicker-"+this.generateId()},a.prototype.getMonthTableId=function(t){return"month-"+t+"-"+this.generateId()},a.prototype.getCloseButtonId=function(){return"close-"+this.generateId()},a.prototype.getTooltipId=function(){return"tooltip-"+this.generateId()},a.prototype.getNextMonth=function(t){var e=new Date(t.valueOf());return new Date(e.setMonth(e.getMonth()+1,1))},a.prototype.getPrevMonth=function(t){var e=new Date(t.valueOf());return new Date(e.setMonth(e.getMonth()-1,1))},a.prototype.getDateString=function(t,e){return void 0===e&&(e=this.format),this.setFechaI18n(),fecha.format(t,e)},a.prototype.parseDate=function(t,e){return void 0===e&&(e=this.format),this.setFechaI18n(),fecha.parse(t,e)},a.prototype.init=function(){this.parent=this.container?this.container:this.input.parentElement,this.start=!1,this.end=!1,this.minDays=1<this.minNights?this.minNights+1:2,this.maxDays=0<this.maxNights?this.maxNights+1:0,this.startDate&&"string"==typeof this.startDate&&(this.startDate=this.parseDate(this.startDate)),this.endDate&&"string"==typeof this.endDate&&(this.endDate=this.parseDate(this.endDate)),this.isTouchDevice()&&(this.hoveringTooltip=!1),this.isOpen=!1,this.changed=!1,this.createDom();var t=new Date;this.startDate&&this.compareMonth(t,this.startDate)<0&&(t=new Date(this.startDate.getTime())),this.endDate&&0<this.compareMonth(this.getNextMonth(t),this.endDate)&&(t=new Date(this.getPrevMonth(this.endDate.getTime()))),0<this.disabledDates.length&&this.parseDisabledDates(),this.showMonth(t,1),this.showMonth(this.getNextMonth(t),2),this.topBarDefaultText(),this.addListeners(),this.isFirstDisabledDate=0,this.lastDisabledDate=!1},a.prototype.addListeners=function(){for(var e=this,t=this.datepicker.getElementsByClassName("datepicker__month-button--next"),s=0;s<t.length;s++)t[s].addEventListener("click",function(t){return e.goToNextMonth(t)});for(var a=this.datepicker.getElementsByClassName("datepicker__month-button--prev"),i=0;i<a.length;i++)a[i].addEventListener("click",function(t){return e.goToPreviousMonth(t)});this.addBoundedListener(this.input,"click",function(t){return e.openDatepicker(t)}),this.showTopbar&&document.getElementById(this.getCloseButtonId()).addEventListener("click",function(t){return e.closeDatepicker(t)}),this.datepicker.addEventListener("mouseover",function(t){return e.datepickerHover(t)}),this.datepicker.addEventListener("mouseout",function(t){return e.datepickerMouseOut(t)}),this.addBoundedListener(this.input,"change",function(){return e.checkAndSetDefaultValue()})},a.prototype.generateId=function(){return this.input.id?this.input.id:this.id},a.prototype.createDom=function(){var t=this.createDatepickerDomString();this.parent.insertAdjacentHTML("beforeend",t),this.datepicker=document.getElementById(this.getDatepickerId())},a.prototype.createDatepickerDomString=function(){var t='<div id="'+this.getDatepickerId()+'" style="display:none" class="datepicker datepicker--closed">';t+='<div class="datepicker__inner">',this.showTopbar&&(t+='<div class="datepicker__topbar"><div class="datepicker__info datepicker__info--selected"><span class="datepicker__info datepicker__info--selected-label">'+this.lang("selected")+' </span> <strong class="datepicker__info-text datepicker__info-text--start-day">...</strong> <span class="datepicker__info-text datepicker__info--separator">'+this.separator+'</span> <strong class="datepicker__info-text datepicker__info-text--end-day">...</strong> <em class="datepicker__info-text datepicker__info-text--selected-days">(<span></span>)</em></div><div class="datepicker__info datepicker__info--feedback"></div><button type="button" id="'+this.getCloseButtonId()+'" class="datepicker__close-button">'+this.lang("button")+"</button></div>"),t+='<div class="datepicker__months">';for(var e=1;e<=2;e++)t+='<table id="'+this.getMonthTableId(e)+'" class="datepicker__month datepicker__month--month'+e+'"><thead><tr class="datepicker__month-caption"><th><span class="datepicker__month-button datepicker__month-button--prev" month="'+e+'"><</span></th><th colspan="5" class="datepicker__month-name"></th><th><span class="datepicker__month-button datepicker__month-button--next" month="'+e+'">></span></th></tr><tr class="datepicker__week-days">'+this.getWeekDayNames(e)+"</tr></thead><tbody></tbody></table>";return t+="</div>",t+='<div style="display:none" id="'+this.getTooltipId()+'" class="datepicker__tooltip"></div>',t+="</div>",t+="</div>"},a.prototype.showMonth=function(t,e){var s=this.getMonthName(t.getMonth()),a=this.getMonthDom(e),i=a.getElementsByClassName("datepicker__month-name")[0],n=a.getElementsByTagName("tbody")[0];i.textContent=s+" "+t.getFullYear(),this.emptyElement(n),n.insertAdjacentHTML("beforeend",this.createMonthDomString(t)),this.updateSelectableRange(),this["month"+e]=t},a.prototype.createMonthDomString=function(t){var e=this,s=[],a="";t.setDate(1);var i=t.getDay(),n=t.getMonth();if(0===i&&"monday"===this.startOfWeek&&(i=7),0<i)for(var o=i;0<o;o--){var r=new Date(t.getTime()-864e5*o),h=e.isValidDate(r.getTime());(e.startDate&&e.compareDay(r,e.startDate)<0||e.endDate&&0<e.compareDay(r,e.endDate))&&(h=!1),s.push({date:r,type:"lastMonth",day:r.getDate(),time:r.getTime(),valid:h})}for(var d=0;d<40;d++){var l=e.addDays(t,d);h=e.isValidDate(l.getTime()),(e.startDate&&e.compareDay(l,e.startDate)<0||e.endDate&&0<e.compareDay(l,e.endDate))&&(h=!1),s.push({date:l,type:l.getMonth()===n?"visibleMonth":"nextMonth",day:l.getDate(),time:l.getTime(),valid:h})}for(var c=0;c<6&&"nextMonth"!==s[7*c].type;c++){a+='<tr class="datepicker__week-row">';for(var p=0;p<7;p++){var m,g,u,y,D=s[7*c+(D="monday"===e.startOfWeek?p+1:p)],f=e.getDateString(D.time)===e.getDateString(new Date),k=e.getDateString(D.time)===e.getDateString(e.startDate),_=!1,v=!1,b=!1,C=!1,M=!1,T=!1;!D.valid&&"visibleMonth"!==D.type||(m=e.getDateString(D.time,"YYYY-MM-DD"),0<e.disabledDates.length&&((g=e.getClosestDates(D.date))[0]&&g[1]&&e.compareDay(D.date,g[0])&&0<e.countDays(g[0],g[1])-2&&(u=e.countDays(g[1],D.date)-1,y=e.countDays(D.date,g[0])-1,(e.selectForward&&u<e.minDays||!e.selectForward&&u<e.minDays&&y<e.minDays)&&(D.valid=!1),!D.valid&&e.enableCheckout&&2==u&&(T=!0)),-1<e.disabledDates.indexOf(m)?(_=!(D.valid=!1),e.isFirstDisabledDate++,e.lastDisabledDate=D.date):e.isFirstDisabledDate=0,D.valid&&e.lastDisabledDate&&0<e.compareDay(D.date,e.lastDisabledDate)&&2===e.countDays(D.date,e.lastDisabledDate)&&(M=!0)),0<e.disabledDaysOfWeek.length&&-1<e.disabledDaysOfWeek.indexOf(fecha.format(D.time,"dddd"))&&(C=!(D.valid=!1)),0<e.noCheckInDates.length&&-1<e.noCheckInDates.indexOf(m)&&(M=!(v=!0)),0<e.noCheckOutDates.length&&-1<e.noCheckOutDates.indexOf(m)&&(b=!0));var w=["datepicker__month-day--"+D.type,"datepicker__month-day--"+(D.valid?"valid":"invalid"),f?"datepicker__month-day--today":"",_?"datepicker__month-day--disabled":"",_&&e.enableCheckout&&1===e.isFirstDisabledDate?"datepicker__month-day--checkout-enabled":"",T?"datepicker__month-day--before-disabled-date":"",k||M?"datepicker__month-day--checkin-only":"",v?"datepicker__month-day--no-checkin":"",b?"datepicker__month-day--no-checkout":"",C?"datepicker__month-day--day-of-week-disabled":""],S="";v&&(S=e.i18n["checkin-disabled"]),b&&(S&&(S+=". "),S+=e.i18n["checkout-disabled"]);var N={time:D.time,class:w.join(" ")};S&&(N.title=S),a+='<td class="datepicker__month-day '+N.class+'" '+e.printAttributes(N)+">"+D.day+"</td>"}a+="</tr>"}return a},a.prototype.openDatepicker=function(){var e=this;this.isOpen||(this.removeClass(this.datepicker,"datepicker--closed"),this.addClass(this.datepicker,"datepicker--open"),this.checkAndSetDefaultValue(),this.slideDown(this.datepicker,this.animationSpeed),this.isOpen=!0,this.showSelectedDays(),this.disableNextPrevButtons(),this.addBoundedListener(document,"click",function(t){return e.documentClick(t)}),this.onOpenDatepicker&&this.onOpenDatepicker())},a.prototype.closeDatepicker=function(){var t;this.isOpen&&(this.removeClass(this.datepicker,"datepicker--open"),this.addClass(this.datepicker,"datepicker--closed"),this.slideUp(this.datepicker,this.animationSpeed),this.isOpen=!1,(t=document.createEvent("Event")).initEvent("afterClose",!0,!0),this.input.dispatchEvent(t),this.removeAllBoundedListeners(document,"click"))},a.prototype.autoclose=function(){this.autoClose&&this.changed&&this.isOpen&&this.start&&this.end&&this.closeDatepicker()},a.prototype.documentClick=function(t){this.parent.contains(t.target)||t.target===this.input?"td"===t.target.tagName.toLowerCase()&&this.dayClicked(t.target):this.preventContainerClose||this.closeDatepicker()},a.prototype.datepickerHover=function(t){t.target.tagName&&"td"===t.target.tagName.toLowerCase()&&this.dayHovering(t.target)},a.prototype.datepickerMouseOut=function(t){t.target.tagName&&"td"===t.target.tagName.toLowerCase()&&(document.getElementById(this.getTooltipId()).style.display="none")},a.prototype.checkAndSetDefaultValue=function(){var t,e=this.getValue(),s=e?e.split(this.separator):"";s&&2<=s.length?(t=this.format,this.changed=!1,this.setDateRange(this.parseDate(s[0],t),this.parseDate(s[1],t)),this.changed=!0):this.showTopbar&&(this.datepicker.getElementsByClassName("datepicker__info--selected")[0].style.display="none")},a.prototype.setDateRange=function(t,e){var s;t.getTime()>e.getTime()&&(s=e,e=t,t=s,s=null);var a=!0;if((this.startDate&&this.compareDay(t,this.startDate)<0||this.endDate&&0<this.compareDay(e,this.endDate))&&(a=!1),!a)return this.showMonth(this.startDate,1),this.showMonth(this.getNextMonth(this.startDate),2),this.showSelectedDays(),void this.disableNextPrevButtons();t.setTime(t.getTime()+432e5),e.setTime(e.getTime()+432e5),this.start=t.getTime(),this.end=e.getTime(),0<this.compareDay(t,e)&&0===this.compareMonth(t,e)&&(e=this.getNextMonth(t)),0===this.compareMonth(t,e)&&(e=this.getNextMonth(t)),this.showMonth(t,1),this.showMonth(e,2),this.showSelectedDays(),this.disableNextPrevButtons(),this.checkSelection(),this.showSelectedInfo(),this.autoclose()},a.prototype.showSelectedDays=function(){var t=this;if(this.start||this.end)for(var e=this.datepicker.getElementsByTagName("td"),s=0;s<e.length;s++){var a=parseInt(e[s].getAttribute("time"),10);t.start&&t.end&&t.end>=a&&t.start<=a||t.start&&!t.end&&t.getDateString(t.start,"YYYY-MM-DD")===t.getDateString(a,"YYYY-MM-DD")?t.addClass(e[s],"datepicker__month-day--selected"):t.removeClass(e[s],"datepicker__month-day--selected"),t.start&&t.getDateString(t.start,"YYYY-MM-DD")===t.getDateString(a,"YYYY-MM-DD")?t.addClass(e[s],"datepicker__month-day--first-day-selected"):t.removeClass(e[s],"datepicker__month-day--first-day-selected"),t.end&&t.getDateString(t.end,"YYYY-MM-DD")===t.getDateString(a,"YYYY-MM-DD")?t.addClass(e[s],"datepicker__month-day--last-day-selected"):t.removeClass(e[s],"datepicker__month-day--last-day-selected")}},a.prototype.showSelectedInfo=function(){var t,e,s,a,i,n,o,r,h;this.showTopbar?(e=(t=this.datepicker.getElementsByClassName("datepicker__info--selected")[0]).getElementsByClassName("datepicker__info-text--start-day")[0],s=t.getElementsByClassName("datepicker__info-text--end-day")[0],a=t.getElementsByClassName("datepicker__info-text--selected-days")[0],i=document.getElementById(this.getCloseButtonId()),e.textContent="...",s.textContent="...",a.style.display="none",this.start&&(t.style.display="",e.textContent=this.getDateString(new Date(parseInt(this.start,10)),this.infoFormat)),this.end&&(s.textContent=this.getDateString(new Date(parseInt(this.end,10)),this.infoFormat)),this.start&&this.end?(o=1==(n=this.countDays(this.end,this.start)-1)?n+" "+this.lang("night"):n+" "+this.lang("nights"),r=this.getDateString(new Date(this.start))+this.separator+this.getDateString(new Date(this.end)),a.style.display="",a.firstElementChild.textContent=o,i.disabled=!1,this.setValue(r,this.getDateString(new Date(this.start)),this.getDateString(new Date(this.end))),this.changed=!0):i.disabled=!0):this.start&&this.end&&(h=this.getDateString(new Date(this.start))+this.separator+this.getDateString(new Date(this.end)),this.setValue(h,this.getDateString(new Date(this.start)),this.getDateString(new Date(this.end))),this.changed=!0)},a.prototype.dayClicked=function(t){if(!this.hasClass(t,"datepicker__month-day--invalid")){var e=this.start&&this.end||!this.start&&!this.end;if(e){if(this.hasClass(t,"datepicker__month-day--no-checkin"))return}else if(this.start&&this.hasClass(t,"datepicker__month-day--no-checkout"))return;var s,a=parseInt(t.getAttribute("time"),10);this.addClass(t,"datepicker__month-day--selected"),e?(this.start=a,this.end=!1):this.start&&(this.end=a),this.start&&this.end&&this.start>this.end&&(s=this.end,this.end=this.start,this.start=s),this.start=parseInt(this.start,10),this.end=parseInt(this.end,10),this.clearHovering(),this.start&&!this.end&&this.dayHovering(t),this.updateSelectableRange(),this.checkSelection(),this.showSelectedInfo(),this.showSelectedDays(),this.autoclose(),this.onDayClick&&this.onDayClick(),this.end&&this.onSelectRange&&this.onSelectRange()}},a.prototype.isValidDate=function(t){if(t=parseInt(t,10),this.startDate&&this.compareDay(t,this.startDate)<0||this.endDate&&0<this.compareDay(t,this.endDate))return!1;if(this.start&&!this.end){if(0<this.maxDays&&this.countDays(t,this.start)>this.maxDays||0<this.minDays&&1<this.countDays(t,this.start)&&this.countDays(t,this.start)<this.minDays)return!1;if(this.selectForward&&t<this.start)return!1;if(0<this.disabledDates.length){var e=this.getClosestDates(new Date(parseInt(this.start,10)));if(e[0]&&this.compareDay(t,e[0])<=0)return!1;if(e[1]&&0<=this.compareDay(t,e[1]))return!1}}return!0},a.prototype.checkSelection=function(){var t=this,e=this.countDays(this.end,this.start),s=!!this.showTopbar&&this.datepicker.getElementsByClassName("datepicker__info--feedback")[0];if(this.maxDays&&e>this.maxDays){this.start=!1,this.end=!1;for(var a,i=this.datepicker.getElementsByTagName("td"),n=0;n<i.length;n++)t.removeClass(i[n],"datepicker__month-day--selected"),t.removeClass(i[n],"datepicker__month-day--first-day-selected"),t.removeClass(i[n],"datepicker__month-day--last-day-selected");this.showTopbar&&(a=this.maxDays-1,this.topBarErrorText(s,"error-more",a))}else if(this.minDays&&e<this.minDays){this.start=!1,this.end=!1;for(var o,r=this.datepicker.getElementsByTagName("td"),h=0;h<r.length;h++)t.removeClass(r[h],"datepicker__month-day--selected"),t.removeClass(r[h],"datepicker__month-day--first-day-selected"),t.removeClass(r[h],"datepicker__month-day--last-day-selected");this.showTopbar&&(o=this.minDays-1,this.topBarErrorText(s,"error-less",o))}else this.start||this.end?this.showTopbar&&(this.removeClass(s,"datepicker__info--error"),this.removeClass(s,"datepicker__info--help")):this.showTopbar&&(this.removeClass(s,"datepicker__info--error"),this.addClass(s,"datepicker__info--help"))},a.prototype.addDays=function(t,e){var s=new Date(t);return s.setDate(s.getDate()+e),s},a.prototype.countDays=function(t,e){return Math.abs(this.daysFrom1970(t)-this.daysFrom1970(e))+1},a.prototype.compareDay=function(t,e){var s=parseInt(this.getDateString(t,"YYYYMMDD"),10)-parseInt(this.getDateString(e,"YYYYMMDD"),10);return 0<s?1:0==s?0:-1},a.prototype.compareMonth=function(t,e){var s=parseInt(this.getDateString(t,"YYYYMM"),10)-parseInt(this.getDateString(e,"YYYYMM"),10);return 0<s?1:0==s?0:-1},a.prototype.daysFrom1970=function(t){return Math.floor(this.toLocalTimestamp(t)/864e5)},a.prototype.toLocalTimestamp=function(t){return"object"==typeof t&&t.getTime&&(t=t.getTime()),"string"!=typeof t||t.match(/\d{13}/)||(t=this.parseDate(t).getTime()),t=parseInt(t,10)-60*(new Date).getTimezoneOffset()*1e3},a.prototype.printAttributes=function(t){var e=t,s="";for(var a in t)Object.prototype.hasOwnProperty.call(e,a)&&(s+=a+'="'+e[a]+'" ');return s},a.prototype.goToNextMonth=function(t){var e=t.target.getAttribute("month"),s=1<e,a=s?this.month2:this.month1,a=this.getNextMonth(a);!this.isSingleMonth()&&!s&&0<=this.compareMonth(a,this.month2)||this.isMonthOutOfRange(a)||(this.moveBothMonths&&s&&this.showMonth(this.month2,1),this.showMonth(a,e),this.showSelectedDays(),this.disableNextPrevButtons())},a.prototype.goToPreviousMonth=function(t){var e=t.target.getAttribute("month"),s=1<e,a=s?this.month2:this.month1,a=this.getPrevMonth(a);s&&this.compareMonth(a,this.month1)<=0||this.isMonthOutOfRange(a)||(this.moveBothMonths&&!s&&this.showMonth(this.month1,2),this.showMonth(a,e),this.showSelectedDays(),this.disableNextPrevButtons())},a.prototype.isSingleMonth=function(){return!this.isVisible(this.getMonthDom(2))},a.prototype.isMonthOutOfRange=function(t){var e=new Date(t.valueOf());return!!(this.startDate&&new Date(e.getFullYear(),e.getMonth()+1,0,23,59,59)<this.startDate||this.endDate&&new Date(e.getFullYear(),e.getMonth(),1)>this.endDate)},a.prototype.disableNextPrevButtons=function(){var t,e,s,a,i;this.isSingleMonth()||(t=parseInt(this.getDateString(this.month1,"YYYYMM"),10),e=parseInt(this.getDateString(this.month2,"YYYYMM"),10),s=Math.abs(t-e),a=this.datepicker.getElementsByClassName("datepicker__month-button--next"),i=this.datepicker.getElementsByClassName("datepicker__month-button--prev"),1<s&&89!==s?(this.removeClass(a[0],"datepicker__month-button--disabled"),this.removeClass(i[1],"datepicker__month-button--disabled")):(this.addClass(a[0],"datepicker__month-button--disabled"),this.addClass(i[1],"datepicker__month-button--disabled")),this.isMonthOutOfRange(this.getPrevMonth(this.month1))?this.addClass(i[0],"datepicker__month-button--disabled"):this.removeClass(i[0],"datepicker__month-button--disabled"),this.isMonthOutOfRange(this.getNextMonth(this.month2))?this.addClass(a[1],"datepicker__month-button--disabled"):this.removeClass(a[1],"datepicker__month-button--disabled"))},a.prototype.topBarDefaultText=function(){var t,e;this.showTopbar&&(t="",t=this.minDays&&this.maxDays?this.lang("info-range"):this.minDays&&2<this.minDays?this.lang("info-more-plural"):this.minDays?this.lang("info-more"):this.lang("info-default"),e=this.datepicker.getElementsByClassName("datepicker__info--feedback")[0],t=t.replace(/%d/,this.minDays-1).replace(/%d/,this.maxDays-1),this.addClass(e,"datepicker__info--help"),this.removeClass(e,"datepicker__info--error"),e.textContent=t)},a.prototype.topBarErrorText=function(t,e,s){this.showTopbar&&(this.addClass(t,"datepicker__info--error"),this.removeClass(t,"datepicker__info--help"),1<s?(e=(e=this.lang(e+"-plural")).replace("%d",s),t.textContent=e):e=this.lang(e),this.datepicker.getElementsByClassName("datepicker__info--selected")[0].style.display="none")},a.prototype.updateSelectableRange=function(){for(var t,e=this,s=this.datepicker.getElementsByTagName("td"),a=this.start&&!this.end,i=0;i<s.length;i++){e.hasClass(s[i],"datepicker__month-day--invalid")&&e.hasClass(s[i],"datepicker__month-day--tmp")&&(e.removeClass(s[i],"datepicker__month-day--tmp"),e.hasClass(s[i],"datepicker__month-day--tmpinvalid")?e.removeClass(s[i],"datepicker__month-day--tmpinvalid"):(e.removeClass(s[i],"datepicker__month-day--invalid"),e.addClass(s[i],"datepicker__month-day--valid"))),a?e.hasClass(s[i],"datepicker__month-day--visibleMonth")&&(e.hasClass(s[i],"datepicker__month-day--valid")||e.hasClass(s[i],"datepicker__month-day--disabled")||e.hasClass(s[i],"datepicker__month-day--before-disabled-date"))&&(t=parseInt(s[i].getAttribute("time"),10),e.isValidDate(t)?(e.addClass(s[i],"datepicker__month-day--valid"),e.addClass(s[i],"datepicker__month-day--tmp"),e.removeClass(s[i],"datepicker__month-day--invalid"),e.removeClass(s[i],"datepicker__month-day--disabled")):(e.hasClass(s[i],"datepicker__month-day--invalid")&&e.addClass(s[i],"datepicker__month-day--tmpinvalid"),e.addClass(s[i],"datepicker__month-day--invalid"),e.addClass(s[i],"datepicker__month-day--tmp"),e.removeClass(s[i],"datepicker__month-day--valid"))):(e.hasClass(s[i],"datepicker__month-day--checkout-enabled")||e.hasClass(s[i],"datepicker__month-day--before-disabled-date"))&&(e.addClass(s[i],"datepicker__month-day--invalid"),e.removeClass(s[i],"datepicker__month-day--valid"),e.hasClass(s[i],"datepicker__month-day--before-disabled-date")||e.addClass(s[i],"datepicker__month-day--disabled"))}return!0},a.prototype.dayHovering=function(t){var e,s,a,i,n,o,r,h=this,d=parseInt(t.getAttribute("time"),10),l="";if(!this.hasClass(t,"datepicker__month-day--invalid")){for(var c,p=this.datepicker.getElementsByTagName("td"),m=0;m<p.length;m++){var g=parseInt(p[m].getAttribute("time"),10);g===d?h.addClass(p[m],"datepicker__month-day--hovering"):h.removeClass(p[m],"datepicker__month-day--hovering"),h.start&&!h.end&&(h.start<g&&g<=d||h.start>g&&d<=g)?h.addClass(p[m],"datepicker__month-day--hovering"):h.removeClass(p[m],"datepicker__month-day--hovering")}this.start&&!this.end&&(c=this.countDays(d,this.start)-1,this.hoveringTooltip&&("function"==typeof this.hoveringTooltip?l=this.hoveringTooltip(c,this.start,d):!0===this.hoveringTooltip&&0<c&&(l=c+" "+(1==c?this.lang("night"):this.lang("nights")))))}l?(e=t.getBoundingClientRect(),s=this.datepicker.getBoundingClientRect(),a=e.left-s.left,i=e.top-s.top,a+=e.width/2,(n=document.getElementById(this.getTooltipId())).style.display="",n.textContent=l,o=n.getBoundingClientRect().width,r=n.getBoundingClientRect().height,a-=o/2,i-=r,setTimeout(function(){n.style.left=a+"px",n.style.top=i+"px"},10)):document.getElementById(this.getTooltipId()).style.display="none"},a.prototype.clearHovering=function(){for(var t=this.datepicker.getElementsByTagName("td"),e=0;e<t.length;e++)this.removeClass(t[e],"datepicker__month-day--hovering");document.getElementById(this.getTooltipId()).style.display="none"},a.prototype.clearSelection=function(){this.start=!1,this.end=!1;for(var t=this.datepicker.getElementsByTagName("td"),e=0;e<t.length;e++)this.removeClass(t[e],"datepicker__month-day--selected"),this.removeClass(t[e],"datepicker__month-day--first-day-selected"),this.removeClass(t[e],"datepicker__month-day--last-day-selected");this.setValue(""),this.checkSelection(),this.showSelectedInfo(),this.showSelectedDays()},a.prototype.parseDisabledDates=function(){var t=[];this.setFechaI18n();for(var e=0;e<this.disabledDates.length;e++)t[e]=fecha.parse(this.disabledDates[e],"YYYY-MM-DD");t.sort(function(t,e){return t-e}),this.disabledDatesTime=t},a.prototype.getClosestDates=function(t){var e=[!1,!1];if(t<this.disabledDatesTime[0])e=this.enableCheckout?[!1,this.addDays(this.disabledDatesTime[0],1)]:[!1,this.disabledDatesTime[0]];else if(t>this.disabledDatesTime[this.disabledDatesTime.length-1])e=[this.disabledDatesTime[this.disabledDatesTime.length-1],!1];else{for(var s=this.disabledDatesTime.length,a=this.disabledDatesTime.length,i=Math.abs(new Date(0,0,0).valueOf()),n=i,o=-i,r=0,h=0;h<this.disabledDatesTime.length;++h)(r=t-this.disabledDatesTime[h])<0&&o<r&&(a=h,o=r),0<r&&r<n&&(s=h,n=r);this.disabledDatesTime[s]&&(e[0]=this.disabledDatesTime[s]),void 0===this.disabledDatesTime[s]?e[1]=!1:this.enableCheckout?e[1]=this.addDays(this.disabledDatesTime[a],1):e[1]=this.disabledDatesTime[a]}return e},a.prototype.lang=function(t){return t in this.i18n?this.i18n[t]:""},a.prototype.emptyElement=function(t){for(;t.firstChild;)t.removeChild(t.firstChild)},a.prototype.classRegex=function(t){return new RegExp("(^|\\s+)"+t+"(\\s+|$)")},a.prototype.hasClass=function(t,e){return this.classRegex(e).test(t.className)},a.prototype.addClass=function(t,e){this.hasClass(t,e)||(t.className=t.className+" "+e)},a.prototype.removeClass=function(t,e){t.className=t.className.replace(this.classRegex(e)," ")},a.prototype.isVisible=function(t){return t.offsetWidth||t.offsetHeight||t.getClientRects().length},a.prototype.slideDown=function(t,e){t.style.display="";var s=t.getBoundingClientRect().height;t.style.height=0,this.recalc(t.offsetHeight),t.style.transition="height "+e,t.style.height=s+"px",t.addEventListener("transitionend",function(){t.style.height=t.style.transition=t.style.display=""})},a.prototype.slideUp=function(t,e){var s=t.getBoundingClientRect().height;t.style.height=s+"px",this.recalc(t.offsetHeight),t.style.transition="height "+e,t.style.height=0,t.addEventListener("transitionend",function(){t.style.display="none"})},a.prototype.recalc=function(t){return t.offsetHeight},a.prototype.isTouchDevice=function(){return"ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch},a.prototype.open=function(){this.openDatepicker()},a.prototype.close=function(){this.closeDatepicker()},a.prototype.getDatePicker=function(){return this.datepicker},a.prototype.setRange=function(t,e){"string"==typeof t&&"string"==typeof e&&(t=this.parseDate(t),e=this.parseDate(e)),this.setDateRange(t,e)},a.prototype.clear=function(){this.clearSelection()},a.prototype.getNights=function(){var t,e,s,a=0;return this.start&&this.end?a=this.countDays(this.end,this.start)-1:(e=(t=this.getValue())?t.split(this.separator):"")&&2<=e.length&&(s=this.format,a=this.countDays(this.parseDate(e[0],s),this.parseDate(e[1],s))-1),a},a.prototype.destroy=function(){document.getElementById(this.getDatepickerId())&&(this.removeAllBoundedListeners(this.input,"click"),this.removeAllBoundedListeners(document,"click"),this.removeAllBoundedListeners(this.input,"change"),this.datepicker.parentNode.removeChild(this.datepicker))},a}(); | ||
/*! hotel-datepicker 4.0.1 - Copyright 2020 Benito Lopez (http://lopezb.com) - https://github.com/benitolopez/hotel-datepicker - MIT */ | ||
var HotelDatepicker=function(){"use strict";var t=0,e=function t(e,s){this._boundedEventHandlers={},this.id=t.getNewId();var a=s||{};this.format=a.format||"YYYY-MM-DD",this.infoFormat=a.infoFormat||this.format,this.separator=a.separator||" - ",this.startOfWeek=a.startOfWeek||"sunday",this.startDate=a.startDate||new Date,this.endDate=a.endDate||!1,this.minNights=a.minNights||1,this.maxNights=a.maxNights||0,this.selectForward=a.selectForward||!1,this.disabledDates=a.disabledDates||[],this.noCheckInDates=a.noCheckInDates||[],this.noCheckOutDates=a.noCheckOutDates||[],this.disabledDaysOfWeek=a.disabledDaysOfWeek||[],this.enableCheckout=a.enableCheckout||!1,this.preventContainerClose=a.preventContainerClose||!1,this.container=a.container||"",this.animationSpeed=a.animationSpeed||".5s",this.hoveringTooltip=a.hoveringTooltip||!0,this.autoClose=void 0===a.autoClose||a.autoClose,this.showTopbar=void 0===a.showTopbar||a.showTopbar,this.moveBothMonths=a.moveBothMonths||!1,this.i18n=a.i18n||{selected:"Your stay:",night:"Night",nights:"Nights",button:"Close","checkin-disabled":"Check-in disabled","checkout-disabled":"Check-out disabled","day-names-short":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"day-names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"month-names-short":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"month-names":["January","February","March","April","May","June","July","August","September","October","November","December"],"error-more":"Date range should not be more than 1 night","error-more-plural":"Date range should not be more than %d nights","error-less":"Date range should not be less than 1 night","error-less-plural":"Date range should not be less than %d nights","info-more":"Please select a date range of at least 1 night","info-more-plural":"Please select a date range of at least %d nights","info-range":"Please select a date range between %d and %d nights","info-default":"Please select a date range"},this.getValue=a.getValue||function(){return e.value},this.setValue=a.setValue||function(t){e.value=t},this.onDayClick=void 0!==a.onDayClick&&a.onDayClick,this.onOpenDatepicker=void 0!==a.onOpenDatepicker&&a.onOpenDatepicker,this.onSelectRange=void 0!==a.onSelectRange&&a.onSelectRange,this.input=e,this.init()};return e.prototype.addBoundedListener=function(t,e,s,a){t in this._boundedEventHandlers||(this._boundedEventHandlers[t]={}),e in this._boundedEventHandlers[t]||(this._boundedEventHandlers[t][e]=[]);var i=s.bind(this);this._boundedEventHandlers[t][e].push([i,a]),t.addEventListener(e,i,a)},e.prototype.removeAllBoundedListeners=function(t,e){if(t in this._boundedEventHandlers){var s=this._boundedEventHandlers[t];if(e in s)for(var a=s[e],i=a.length;i--;){var n=a[i];t.removeEventListener(e,n[0],n[1])}}},e.getNewId=function(){return++t},e.prototype.setFechaI18n=function(){fecha.setGlobalDateI18n({dayNamesShort:this.i18n["day-names-short"],dayNames:this.i18n["day-names"],monthNamesShort:this.i18n["month-names-short"],monthNames:this.i18n["month-names"]})},e.prototype.getWeekDayNames=function(){var t="";if("monday"===this.startOfWeek){for(var e=0;e<7;e++)t+='<th class="datepicker__week-name">'+this.lang("day-names-short")[(1+e)%7]+"</th>";return t}for(var s=0;s<7;s++)t+='<th class="datepicker__week-name">'+this.lang("day-names-short")[s]+"</th>";return t},e.prototype.getMonthDom=function(t){return document.getElementById(this.getMonthTableId(t))},e.prototype.getMonthName=function(t){return this.lang("month-names")[t]},e.prototype.getDatepickerId=function(){return"datepicker-"+this.generateId()},e.prototype.getMonthTableId=function(t){return"month-"+t+"-"+this.generateId()},e.prototype.getCloseButtonId=function(){return"close-"+this.generateId()},e.prototype.getTooltipId=function(){return"tooltip-"+this.generateId()},e.prototype.getNextMonth=function(t){var e=new Date(t.valueOf());return new Date(e.setMonth(e.getMonth()+1,1))},e.prototype.getPrevMonth=function(t){var e=new Date(t.valueOf());return new Date(e.setMonth(e.getMonth()-1,1))},e.prototype.getDateString=function(t,e){return void 0===e&&(e=this.format),this.setFechaI18n(),fecha.format(t,e)},e.prototype.parseDate=function(t,e){return void 0===e&&(e=this.format),this.setFechaI18n(),fecha.parse(t,e)},e.prototype.init=function(){this.parent=this.container?this.container:this.input.parentElement,this.start=!1,this.end=!1,this.minDays=1<this.minNights?this.minNights+1:2,this.maxDays=0<this.maxNights?this.maxNights+1:0,this.startDate&&"string"==typeof this.startDate&&(this.startDate=this.parseDate(this.startDate)),this.endDate&&"string"==typeof this.endDate&&(this.endDate=this.parseDate(this.endDate)),this.isTouchDevice()&&(this.hoveringTooltip=!1),this.isOpen=!1,this.changed=!1,this.createDom();var t=new Date;this.startDate&&this.compareMonth(t,this.startDate)<0&&(t=new Date(this.startDate.getTime())),this.endDate&&0<this.compareMonth(this.getNextMonth(t),this.endDate)&&(t=new Date(this.getPrevMonth(this.endDate.getTime()))),0<this.disabledDates.length&&this.parseDisabledDates(),this.showMonth(t,1),this.showMonth(this.getNextMonth(t),2),this.topBarDefaultText(),this.addListeners(),this.isFirstDisabledDate=0,this.lastDisabledDate=!1},e.prototype.addListeners=function(){for(var e=this,t=this.datepicker.getElementsByClassName("datepicker__month-button--next"),s=0;s<t.length;s++)t[s].addEventListener("click",function(t){return e.goToNextMonth(t)});for(var a=this.datepicker.getElementsByClassName("datepicker__month-button--prev"),i=0;i<a.length;i++)a[i].addEventListener("click",function(t){return e.goToPreviousMonth(t)});this.addBoundedListener(this.input,"click",function(t){return e.openDatepicker(t)}),this.showTopbar&&document.getElementById(this.getCloseButtonId()).addEventListener("click",function(t){return e.closeDatepicker(t)}),this.datepicker.addEventListener("mouseover",function(t){return e.datepickerHover(t)}),this.datepicker.addEventListener("mouseout",function(t){return e.datepickerMouseOut(t)}),this.addBoundedListener(this.input,"change",function(){return e.checkAndSetDefaultValue()})},e.prototype.generateId=function(){return this.input.id?this.input.id:this.id},e.prototype.createDom=function(){var t=this.createDatepickerDomString();this.parent.insertAdjacentHTML("beforeend",t),this.datepicker=document.getElementById(this.getDatepickerId())},e.prototype.createDatepickerDomString=function(){var t='<div id="'+this.getDatepickerId()+'" style="display:none" class="datepicker datepicker--closed">';t+='<div class="datepicker__inner">',this.showTopbar&&(t+='<div class="datepicker__topbar"><div class="datepicker__info datepicker__info--selected"><span class="datepicker__info datepicker__info--selected-label">'+this.lang("selected")+' </span> <strong class="datepicker__info-text datepicker__info-text--start-day">...</strong> <span class="datepicker__info-text datepicker__info--separator">'+this.separator+'</span> <strong class="datepicker__info-text datepicker__info-text--end-day">...</strong> <em class="datepicker__info-text datepicker__info-text--selected-days">(<span></span>)</em></div><div class="datepicker__info datepicker__info--feedback"></div><button type="button" id="'+this.getCloseButtonId()+'" class="datepicker__close-button">'+this.lang("button")+"</button></div>"),t+='<div class="datepicker__months">';for(var e=1;e<=2;e++)t+='<table id="'+this.getMonthTableId(e)+'" class="datepicker__month datepicker__month--month'+e+'"><thead><tr class="datepicker__month-caption"><th><span class="datepicker__month-button datepicker__month-button--prev" month="'+e+'"><</span></th><th colspan="5" class="datepicker__month-name"></th><th><span class="datepicker__month-button datepicker__month-button--next" month="'+e+'">></span></th></tr><tr class="datepicker__week-days">'+this.getWeekDayNames(e)+"</tr></thead><tbody></tbody></table>";return t+="</div>",t+='<div style="display:none" id="'+this.getTooltipId()+'" class="datepicker__tooltip"></div>',t+="</div>",t+="</div>"},e.prototype.showMonth=function(t,e){var s=this.getMonthName(t.getMonth()),a=this.getMonthDom(e),i=a.getElementsByClassName("datepicker__month-name")[0],n=a.getElementsByTagName("tbody")[0];i.textContent=s+" "+t.getFullYear(),this.emptyElement(n),n.insertAdjacentHTML("beforeend",this.createMonthDomString(t)),this.updateSelectableRange(),this["month"+e]=t},e.prototype.createMonthDomString=function(t){var e,s=this,a=[],i="";t.setDate(1);var n=t.getDay(),o=t.getMonth();if(0===n&&"monday"===this.startOfWeek&&(n=7),0<n)for(var r=n;0<r;r--){var h=new Date(t.getTime()-864e5*r);e=s.isValidDate(h.getTime()),(s.startDate&&s.compareDay(h,s.startDate)<0||s.endDate&&0<s.compareDay(h,s.endDate))&&(e=!1),a.push({date:h,type:"lastMonth",day:h.getDate(),time:h.getTime(),valid:e})}for(var d=0;d<40;d++){var l=s.addDays(t,d);e=s.isValidDate(l.getTime()),(s.startDate&&s.compareDay(l,s.startDate)<0||s.endDate&&0<s.compareDay(l,s.endDate))&&(e=!1),a.push({date:l,type:l.getMonth()===o?"visibleMonth":"nextMonth",day:l.getDate(),time:l.getTime(),valid:e})}for(var c=0;c<6&&"nextMonth"!==a[7*c].type;c++){i+='<tr class="datepicker__week-row">';for(var p=0;p<7;p++){var m="monday"===s.startOfWeek?p+1:p;m=a[7*c+m];var g=s.getDateString(m.time)===s.getDateString(new Date),u=s.getDateString(m.time)===s.getDateString(s.startDate),y=!1,D=!1,f=!1,v=!1,k=!1,_=!1;if(m.valid||"visibleMonth"===m.type){var b=s.getDateString(m.time,"YYYY-MM-DD");if(0<s.disabledDates.length){var C=s.getClosestDates(m.date);if(C[0]&&C[1]&&s.compareDay(m.date,C[0])&&0<s.countDays(C[0],C[1])-2){var M=s.countDays(C[1],m.date)-1,T=s.countDays(m.date,C[0])-1;s.selectForward&&M<s.minDays?m.valid=!1:!s.selectForward&&M<s.minDays&&T<s.minDays&&(m.valid=!1),!m.valid&&s.enableCheckout&&2===M&&(_=!0)}-1<s.disabledDates.indexOf(b)?(y=!(m.valid=!1),s.isFirstDisabledDate++,s.lastDisabledDate=m.date):s.isFirstDisabledDate=0,m.valid&&s.lastDisabledDate&&0<s.compareDay(m.date,s.lastDisabledDate)&&2===s.countDays(m.date,s.lastDisabledDate)&&(k=!0)}0<s.disabledDaysOfWeek.length&&-1<s.disabledDaysOfWeek.indexOf(fecha.format(m.time,"dddd"))&&(v=!(m.valid=!1)),0<s.noCheckInDates.length&&-1<s.noCheckInDates.indexOf(b)&&(k=!(D=!0)),0<s.noCheckOutDates.length&&-1<s.noCheckOutDates.indexOf(b)&&(f=!0)}var w=["datepicker__month-day--"+m.type,"datepicker__month-day--"+(m.valid?"valid":"invalid"),g?"datepicker__month-day--today":"",y?"datepicker__month-day--disabled":"",y&&s.enableCheckout&&1===s.isFirstDisabledDate?"datepicker__month-day--checkout-enabled":"",_?"datepicker__month-day--before-disabled-date":"",u||k?"datepicker__month-day--checkin-only":"",D?"datepicker__month-day--no-checkin":"",f?"datepicker__month-day--no-checkout":"",v?"datepicker__month-day--day-of-week-disabled":""],S="";D&&(S=s.i18n["checkin-disabled"]),f&&(S&&(S+=". "),S+=s.i18n["checkout-disabled"]);var N={time:m.time,class:w.join(" ")};S&&(N.title=S),i+='<td class="datepicker__month-day '+N.class+'" '+s.printAttributes(N)+">"+m.day+"</td>"}i+="</tr>"}return i},e.prototype.openDatepicker=function(){var e=this;this.isOpen||(this.removeClass(this.datepicker,"datepicker--closed"),this.addClass(this.datepicker,"datepicker--open"),this.checkAndSetDefaultValue(),this.slideDown(this.datepicker,this.animationSpeed),this.isOpen=!0,this.showSelectedDays(),this.disableNextPrevButtons(),this.addBoundedListener(document,"click",function(t){return e.documentClick(t)}),this.onOpenDatepicker&&this.onOpenDatepicker())},e.prototype.closeDatepicker=function(){if(this.isOpen){this.removeClass(this.datepicker,"datepicker--open"),this.addClass(this.datepicker,"datepicker--closed"),this.slideUp(this.datepicker,this.animationSpeed),this.isOpen=!1;var t=document.createEvent("Event");t.initEvent("afterClose",!0,!0),this.input.dispatchEvent(t),this.removeAllBoundedListeners(document,"click")}},e.prototype.autoclose=function(){this.autoClose&&this.changed&&this.isOpen&&this.start&&this.end&&this.closeDatepicker()},e.prototype.documentClick=function(t){this.parent.contains(t.target)||t.target===this.input?"td"===t.target.tagName.toLowerCase()&&this.dayClicked(t.target):this.preventContainerClose||this.closeDatepicker()},e.prototype.datepickerHover=function(t){t.target.tagName&&"td"===t.target.tagName.toLowerCase()&&this.dayHovering(t.target)},e.prototype.datepickerMouseOut=function(t){t.target.tagName&&"td"===t.target.tagName.toLowerCase()&&(document.getElementById(this.getTooltipId()).style.display="none")},e.prototype.checkAndSetDefaultValue=function(){var t=this.getValue(),e=t?t.split(this.separator):"";if(e&&2<=e.length){var s=this.format;this.changed=!1,this.setDateRange(this.parseDate(e[0],s),this.parseDate(e[1],s)),this.changed=!0}else if(this.showTopbar){this.datepicker.getElementsByClassName("datepicker__info--selected")[0].style.display="none"}},e.prototype.setDateRange=function(t,e){if(t.getTime()>e.getTime()){var s=e;e=t,t=s,s=null}var a=!0;if((this.startDate&&this.compareDay(t,this.startDate)<0||this.endDate&&0<this.compareDay(e,this.endDate))&&(a=!1),!a)return this.showMonth(this.startDate,1),this.showMonth(this.getNextMonth(this.startDate),2),this.showSelectedDays(),void this.disableNextPrevButtons();t.setTime(t.getTime()+432e5),e.setTime(e.getTime()+432e5),this.start=t.getTime(),this.end=e.getTime(),0<this.compareDay(t,e)&&0===this.compareMonth(t,e)&&(e=this.getNextMonth(t)),0===this.compareMonth(t,e)&&(e=this.getNextMonth(t)),this.showMonth(t,1),this.showMonth(e,2),this.showSelectedDays(),this.disableNextPrevButtons(),this.checkSelection(),this.showSelectedInfo(),this.autoclose()},e.prototype.showSelectedDays=function(){var t=this;if(this.start||this.end)for(var e=this.datepicker.getElementsByTagName("td"),s=0;s<e.length;s++){var a=parseInt(e[s].getAttribute("time"),10);t.start&&t.end&&t.end>=a&&t.start<=a||t.start&&!t.end&&t.getDateString(t.start,"YYYY-MM-DD")===t.getDateString(a,"YYYY-MM-DD")?t.addClass(e[s],"datepicker__month-day--selected"):t.removeClass(e[s],"datepicker__month-day--selected"),t.start&&t.getDateString(t.start,"YYYY-MM-DD")===t.getDateString(a,"YYYY-MM-DD")?t.addClass(e[s],"datepicker__month-day--first-day-selected"):t.removeClass(e[s],"datepicker__month-day--first-day-selected"),t.end&&t.getDateString(t.end,"YYYY-MM-DD")===t.getDateString(a,"YYYY-MM-DD")?t.addClass(e[s],"datepicker__month-day--last-day-selected"):t.removeClass(e[s],"datepicker__month-day--last-day-selected")}},e.prototype.showSelectedInfo=function(){if(this.showTopbar){var t=this.datepicker.getElementsByClassName("datepicker__info--selected")[0],e=t.getElementsByClassName("datepicker__info-text--start-day")[0],s=t.getElementsByClassName("datepicker__info-text--end-day")[0],a=t.getElementsByClassName("datepicker__info-text--selected-days")[0],i=document.getElementById(this.getCloseButtonId());if(e.textContent="...",s.textContent="...",a.style.display="none",this.start&&(t.style.display="",e.textContent=this.getDateString(new Date(parseInt(this.start,10)),this.infoFormat)),this.end&&(s.textContent=this.getDateString(new Date(parseInt(this.end,10)),this.infoFormat)),this.start&&this.end){var n=this.countDays(this.end,this.start)-1,o=1===n?n+" "+this.lang("night"):n+" "+this.lang("nights"),r=this.getDateString(new Date(this.start))+this.separator+this.getDateString(new Date(this.end));a.style.display="",a.firstElementChild.textContent=o,i.disabled=!1,this.setValue(r,this.getDateString(new Date(this.start)),this.getDateString(new Date(this.end))),this.changed=!0}else i.disabled=!0}else if(this.start&&this.end){var h=this.getDateString(new Date(this.start))+this.separator+this.getDateString(new Date(this.end));this.setValue(h,this.getDateString(new Date(this.start)),this.getDateString(new Date(this.end))),this.changed=!0}},e.prototype.dayClicked=function(t){if(!this.hasClass(t,"datepicker__month-day--invalid")){var e=this.start&&this.end||!this.start&&!this.end;if(e){if(this.hasClass(t,"datepicker__month-day--no-checkin"))return}else if(this.start&&this.hasClass(t,"datepicker__month-day--no-checkout"))return;var s=parseInt(t.getAttribute("time"),10);if(this.addClass(t,"datepicker__month-day--selected"),e?(this.start=s,this.end=!1):this.start&&(this.end=s),this.start&&this.end&&this.start>this.end){var a=this.end;this.end=this.start,this.start=a}this.start=parseInt(this.start,10),this.end=parseInt(this.end,10),this.clearHovering(),this.start&&!this.end&&this.dayHovering(t),this.updateSelectableRange(),this.checkSelection(),this.showSelectedInfo(),this.showSelectedDays(),this.autoclose(),this.onDayClick&&this.onDayClick(),this.end&&this.onSelectRange&&this.onSelectRange()}},e.prototype.isValidDate=function(t){if(t=parseInt(t,10),this.startDate&&this.compareDay(t,this.startDate)<0||this.endDate&&0<this.compareDay(t,this.endDate))return!1;if(this.start&&!this.end){if(0<this.maxDays&&this.countDays(t,this.start)>this.maxDays||0<this.minDays&&1<this.countDays(t,this.start)&&this.countDays(t,this.start)<this.minDays)return!1;if(this.selectForward&&t<this.start)return!1;if(0<this.disabledDates.length){var e=this.getClosestDates(new Date(parseInt(this.start,10)));if(e[0]&&this.compareDay(t,e[0])<=0)return!1;if(e[1]&&0<=this.compareDay(t,e[1]))return!1}}return!0},e.prototype.checkSelection=function(){var t=this,e=this.countDays(this.end,this.start),s=!!this.showTopbar&&this.datepicker.getElementsByClassName("datepicker__info--feedback")[0];if(this.maxDays&&e>this.maxDays){this.start=!1,this.end=!1;for(var a=this.datepicker.getElementsByTagName("td"),i=0;i<a.length;i++)t.removeClass(a[i],"datepicker__month-day--selected"),t.removeClass(a[i],"datepicker__month-day--first-day-selected"),t.removeClass(a[i],"datepicker__month-day--last-day-selected");if(this.showTopbar){var n=this.maxDays-1;this.topBarErrorText(s,"error-more",n)}}else if(this.minDays&&e<this.minDays){this.start=!1,this.end=!1;for(var o=this.datepicker.getElementsByTagName("td"),r=0;r<o.length;r++)t.removeClass(o[r],"datepicker__month-day--selected"),t.removeClass(o[r],"datepicker__month-day--first-day-selected"),t.removeClass(o[r],"datepicker__month-day--last-day-selected");if(this.showTopbar){var h=this.minDays-1;this.topBarErrorText(s,"error-less",h)}}else this.start||this.end?this.showTopbar&&(this.removeClass(s,"datepicker__info--error"),this.removeClass(s,"datepicker__info--help")):this.showTopbar&&(this.removeClass(s,"datepicker__info--error"),this.addClass(s,"datepicker__info--help"))},e.prototype.addDays=function(t,e){var s=new Date(t);return s.setDate(s.getDate()+e),s},e.prototype.countDays=function(t,e){return Math.abs(this.daysFrom1970(t)-this.daysFrom1970(e))+1},e.prototype.compareDay=function(t,e){var s=parseInt(this.getDateString(t,"YYYYMMDD"),10)-parseInt(this.getDateString(e,"YYYYMMDD"),10);return 0<s?1:0===s?0:-1},e.prototype.compareMonth=function(t,e){var s=parseInt(this.getDateString(t,"YYYYMM"),10)-parseInt(this.getDateString(e,"YYYYMM"),10);return 0<s?1:0===s?0:-1},e.prototype.daysFrom1970=function(t){return Math.floor(this.toLocalTimestamp(t)/864e5)},e.prototype.toLocalTimestamp=function(t){return"object"==typeof t&&t.getTime&&(t=t.getTime()),"string"!=typeof t||t.match(/\d{13}/)||(t=this.parseDate(t).getTime()),t=parseInt(t,10)-60*(new Date).getTimezoneOffset()*1e3},e.prototype.printAttributes=function(t){var e=t,s="";for(var a in t)Object.prototype.hasOwnProperty.call(e,a)&&(s+=a+'="'+e[a]+'" ');return s},e.prototype.goToNextMonth=function(t){var e=t.target.getAttribute("month"),s=1<e,a=s?this.month2:this.month1;a=this.getNextMonth(a),!this.isSingleMonth()&&!s&&0<=this.compareMonth(a,this.month2)||this.isMonthOutOfRange(a)||(this.moveBothMonths&&s&&this.showMonth(this.month2,1),this.showMonth(a,e),this.showSelectedDays(),this.disableNextPrevButtons())},e.prototype.goToPreviousMonth=function(t){var e=t.target.getAttribute("month"),s=1<e,a=s?this.month2:this.month1;a=this.getPrevMonth(a),s&&this.compareMonth(a,this.month1)<=0||this.isMonthOutOfRange(a)||(this.moveBothMonths&&!s&&this.showMonth(this.month1,2),this.showMonth(a,e),this.showSelectedDays(),this.disableNextPrevButtons())},e.prototype.isSingleMonth=function(){return!this.isVisible(this.getMonthDom(2))},e.prototype.isMonthOutOfRange=function(t){var e=new Date(t.valueOf());return!!(this.startDate&&new Date(e.getFullYear(),e.getMonth()+1,0,23,59,59)<this.startDate||this.endDate&&new Date(e.getFullYear(),e.getMonth(),1)>this.endDate)},e.prototype.disableNextPrevButtons=function(){if(!this.isSingleMonth()){var t=parseInt(this.getDateString(this.month1,"YYYYMM"),10),e=parseInt(this.getDateString(this.month2,"YYYYMM"),10),s=Math.abs(t-e),a=this.datepicker.getElementsByClassName("datepicker__month-button--next"),i=this.datepicker.getElementsByClassName("datepicker__month-button--prev");1<s&&89!==s?(this.removeClass(a[0],"datepicker__month-button--disabled"),this.removeClass(i[1],"datepicker__month-button--disabled")):(this.addClass(a[0],"datepicker__month-button--disabled"),this.addClass(i[1],"datepicker__month-button--disabled")),this.isMonthOutOfRange(this.getPrevMonth(this.month1))?this.addClass(i[0],"datepicker__month-button--disabled"):this.removeClass(i[0],"datepicker__month-button--disabled"),this.isMonthOutOfRange(this.getNextMonth(this.month2))?this.addClass(a[1],"datepicker__month-button--disabled"):this.removeClass(a[1],"datepicker__month-button--disabled")}},e.prototype.topBarDefaultText=function(){if(this.showTopbar){var t="";t=this.minDays&&this.maxDays?this.lang("info-range"):this.minDays&&2<this.minDays?this.lang("info-more-plural"):this.minDays?this.lang("info-more"):this.lang("info-default");var e=this.datepicker.getElementsByClassName("datepicker__info--feedback")[0];t=t.replace(/%d/,this.minDays-1).replace(/%d/,this.maxDays-1),this.addClass(e,"datepicker__info--help"),this.removeClass(e,"datepicker__info--error"),e.textContent=t}},e.prototype.topBarErrorText=function(t,e,s){this.showTopbar&&(this.addClass(t,"datepicker__info--error"),this.removeClass(t,"datepicker__info--help"),1<s?(e=(e=this.lang(e+"-plural")).replace("%d",s),t.textContent=e):e=this.lang(e),this.datepicker.getElementsByClassName("datepicker__info--selected")[0].style.display="none")},e.prototype.updateSelectableRange=function(){for(var t=this,e=this.datepicker.getElementsByTagName("td"),s=this.start&&!this.end,a=0;a<e.length;a++)if(t.hasClass(e[a],"datepicker__month-day--invalid")&&t.hasClass(e[a],"datepicker__month-day--tmp")&&(t.removeClass(e[a],"datepicker__month-day--tmp"),t.hasClass(e[a],"datepicker__month-day--tmpinvalid")?t.removeClass(e[a],"datepicker__month-day--tmpinvalid"):(t.removeClass(e[a],"datepicker__month-day--invalid"),t.addClass(e[a],"datepicker__month-day--valid"))),s){if(t.hasClass(e[a],"datepicker__month-day--visibleMonth")&&(t.hasClass(e[a],"datepicker__month-day--valid")||t.hasClass(e[a],"datepicker__month-day--disabled")||t.hasClass(e[a],"datepicker__month-day--before-disabled-date"))){var i=parseInt(e[a].getAttribute("time"),10);t.isValidDate(i)?(t.addClass(e[a],"datepicker__month-day--valid"),t.addClass(e[a],"datepicker__month-day--tmp"),t.removeClass(e[a],"datepicker__month-day--invalid"),t.removeClass(e[a],"datepicker__month-day--disabled")):(t.hasClass(e[a],"datepicker__month-day--invalid")&&t.addClass(e[a],"datepicker__month-day--tmpinvalid"),t.addClass(e[a],"datepicker__month-day--invalid"),t.addClass(e[a],"datepicker__month-day--tmp"),t.removeClass(e[a],"datepicker__month-day--valid"))}}else(t.hasClass(e[a],"datepicker__month-day--checkout-enabled")||t.hasClass(e[a],"datepicker__month-day--before-disabled-date"))&&(t.addClass(e[a],"datepicker__month-day--invalid"),t.removeClass(e[a],"datepicker__month-day--valid"),t.hasClass(e[a],"datepicker__month-day--before-disabled-date")||t.addClass(e[a],"datepicker__month-day--disabled"));return!0},e.prototype.dayHovering=function(t){var e=this,s=parseInt(t.getAttribute("time"),10),a="";if(!this.hasClass(t,"datepicker__month-day--invalid")){for(var i=this.datepicker.getElementsByTagName("td"),n=0;n<i.length;n++){var o=parseInt(i[n].getAttribute("time"),10);o===s?e.addClass(i[n],"datepicker__month-day--hovering"):e.removeClass(i[n],"datepicker__month-day--hovering"),e.start&&!e.end&&(e.start<o&&o<=s||e.start>o&&s<=o)?e.addClass(i[n],"datepicker__month-day--hovering"):e.removeClass(i[n],"datepicker__month-day--hovering")}if(this.start&&!this.end){var r=this.countDays(s,this.start)-1;if(this.hoveringTooltip)if("function"==typeof this.hoveringTooltip)a=this.hoveringTooltip(r,this.start,s);else if(!0===this.hoveringTooltip&&0<r){a=r+" "+(1===r?this.lang("night"):this.lang("nights"))}}}if(a){var h=t.getBoundingClientRect(),d=this.datepicker.getBoundingClientRect(),l=h.left-d.left,c=h.top-d.top;l+=h.width/2;var p=document.getElementById(this.getTooltipId());p.style.display="",p.textContent=a;var m=p.getBoundingClientRect().width,g=p.getBoundingClientRect().height;l-=m/2,c-=g,setTimeout(function(){p.style.left=l+"px",p.style.top=c+"px"},10)}else{document.getElementById(this.getTooltipId()).style.display="none"}},e.prototype.clearHovering=function(){for(var t=this.datepicker.getElementsByTagName("td"),e=0;e<t.length;e++)this.removeClass(t[e],"datepicker__month-day--hovering");document.getElementById(this.getTooltipId()).style.display="none"},e.prototype.clearSelection=function(){this.start=!1,this.end=!1;for(var t=this.datepicker.getElementsByTagName("td"),e=0;e<t.length;e++)this.removeClass(t[e],"datepicker__month-day--selected"),this.removeClass(t[e],"datepicker__month-day--first-day-selected"),this.removeClass(t[e],"datepicker__month-day--last-day-selected");this.setValue(""),this.checkSelection(),this.showSelectedInfo(),this.showSelectedDays()},e.prototype.parseDisabledDates=function(){var t=[];this.setFechaI18n();for(var e=0;e<this.disabledDates.length;e++)t[e]=fecha.parse(this.disabledDates[e],"YYYY-MM-DD");t.sort(function(t,e){return t-e}),this.disabledDatesTime=t},e.prototype.getClosestDates=function(t){var e=[!1,!1];if(t<this.disabledDatesTime[0])e=this.enableCheckout?[!1,this.addDays(this.disabledDatesTime[0],1)]:[!1,this.disabledDatesTime[0]];else if(t>this.disabledDatesTime[this.disabledDatesTime.length-1])e=[this.disabledDatesTime[this.disabledDatesTime.length-1],!1];else{var s,a=this.disabledDatesTime.length,i=this.disabledDatesTime.length,n=Math.abs(new Date(0,0,0).valueOf()),o=n,r=-n,h=0;for(s=0;s<this.disabledDatesTime.length;++s)(h=t-this.disabledDatesTime[s])<0&&r<h&&(i=s,r=h),0<h&&h<o&&(a=s,o=h);this.disabledDatesTime[a]&&(e[0]=this.disabledDatesTime[a]),void 0===this.disabledDatesTime[a]?e[1]=!1:this.enableCheckout?e[1]=this.addDays(this.disabledDatesTime[i],1):e[1]=this.disabledDatesTime[i]}return e},e.prototype.lang=function(t){return t in this.i18n?this.i18n[t]:""},e.prototype.emptyElement=function(t){for(;t.firstChild;)t.removeChild(t.firstChild)},e.prototype.classRegex=function(t){return new RegExp("(^|\\s+)"+t+"(\\s+|$)")},e.prototype.hasClass=function(t,e){return this.classRegex(e).test(t.className)},e.prototype.addClass=function(t,e){this.hasClass(t,e)||(t.className=t.className+" "+e)},e.prototype.removeClass=function(t,e){t.className=t.className.replace(this.classRegex(e)," ")},e.prototype.isVisible=function(t){return t.offsetWidth||t.offsetHeight||t.getClientRects().length},e.prototype.slideDown=function(t,e){t.style.display="";var s=t.getBoundingClientRect().height;t.style.height=0,this.recalc(t.offsetHeight),t.style.transition="height "+e,t.style.height=s+"px",t.addEventListener("transitionend",function(){t.style.height=t.style.transition=t.style.display=""})},e.prototype.slideUp=function(t,e){var s=t.getBoundingClientRect().height;t.style.height=s+"px",this.recalc(t.offsetHeight),t.style.transition="height "+e,t.style.height=0,t.addEventListener("transitionend",function(){t.style.display="none"})},e.prototype.recalc=function(t){return t.offsetHeight},e.prototype.isTouchDevice=function(){return"ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch},e.prototype.open=function(){this.openDatepicker()},e.prototype.close=function(){this.closeDatepicker()},e.prototype.getDatePicker=function(){return this.datepicker},e.prototype.setRange=function(t,e){"string"==typeof t&&"string"==typeof e&&(t=this.parseDate(t),e=this.parseDate(e)),this.setDateRange(t,e)},e.prototype.clear=function(){this.clearSelection()},e.prototype.getNights=function(){var t=0;if(this.start&&this.end)t=this.countDays(this.end,this.start)-1;else{var e=this.getValue(),s=e?e.split(this.separator):"";if(s&&2<=s.length){var a=this.format;t=this.countDays(this.parseDate(s[0],a),this.parseDate(s[1],a))-1}}return t},e.prototype.destroy=function(){document.getElementById(this.getDatepickerId())&&(this.removeAllBoundedListeners(this.input,"click"),this.removeAllBoundedListeners(document,"click"),this.removeAllBoundedListeners(this.input,"change"),this.datepicker.parentNode.removeChild(this.datepicker))},e}(); |
{ | ||
"name": "hotel-datepicker", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"author": "Benito Lopez (http://lopezb.com)", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
189311