From 83c9234f11ec107b62d109560752b7140b765e8c Mon Sep 17 00:00:00 2001 From: Gregory Petrosyan Date: Thu, 9 Jun 2016 23:41:27 -0400 Subject: [PATCH] Listen to a throttled resize and reposition calendar | #22 #68 --- dist/flatpickr.min.js | 2 +- src/flatpickr.js | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/dist/flatpickr.min.js b/dist/flatpickr.min.js index ae58a349f..1df15bfd7 100644 --- a/dist/flatpickr.min.js +++ b/dist/flatpickr.min.js @@ -1 +1 @@ -"use strict";var flatpickr=function e(t,n){var a=void 0,i=void 0,r=function(t){return t._flatpickr&&t._flatpickr.destroy(),t._flatpickr=new e.init(t,n),t._flatpickr};return t.nodeName?r(t):/^\#[a-zA-Z0-9\-\_]*$/.test(t)?r(document.getElementById(t.slice(1))):(a=/^\.[a-zA-Z0-9\-\_]*$/.test(t)?document.getElementsByClassName(t.slice(1)):document.querySelectorAll(t),i=[].slice.call(a).map(r),{calendars:i,byID:function(e){for(var t=0;t11?"PM":"AM"},M:function(){return c(n.n()-1,!0)},U:function(){return P.selectedDateObj.getTime()/1e3},Y:function(){return P.selectedDateObj.getFullYear()},d:function(){return o(n.j())},h:function(){return P.selectedDateObj.getHours()%12?P.selectedDateObj.getHours()%12:12},i:function(){return o(P.selectedDateObj.getMinutes())},j:function(){return P.selectedDateObj.getDate()},l:function(){return P.l10n.weekdays.longhand[n.w()]},m:function(){return o(n.n())},n:function(){return P.selectedDateObj.getMonth()+1},w:function(){return P.selectedDateObj.getDay()},y:function(){return String(n.Y()).substring(2)}},a=e.split(""),i=0;i=i(t.from)&&e<=i(t.to))return!0}return!1},v=function(e){e.preventDefault();var t=Math.max(-1,Math.min(1,e.wheelDelta||-e.deltaY));P.currentYear=e.target.innerHTML=parseInt(e.target.value,10)+t,P.redraw()},h=function(e){e.preventDefault();var t=parseInt(e.target.min),n=parseInt(e.target.max),a=parseInt(e.target.step),i=a*Math.max(-1,Math.min(1,e.wheelDelta||-e.deltaY)),r=(parseInt(e.target.value)+i)%(n+(0===t));t>r&&(r=n+(0===t)-a*(0===t)),e.target.value=o(r)},b=function(){S.innerHTML=c(P.currentMonth)+" ",_.value=P.currentYear},y=function(){(P.currentMonth<0||P.currentMonth>11)&&(P.currentYear+=P.currentMonth%11,P.currentMonth=(P.currentMonth+12)%12)},w=function(e){F.classList.contains("open")&&!F.contains(e.target)&&e.target!==P.element&&e.target!==P.altInput&&P.close()},k=function(e){P.currentMonth+=e,y(),b(),f()},L=function(e){e.preventDefault(),e.target.classList.contains("slot")&&(P.selectedDateObj=new Date(P.currentYear,P.currentMonth,e.target.innerHTML),D(),j(),f(),P.config.inline||P.config.enableTime||P.close())},p=function(){T=J("div","flatpickr-calendar"),T.id=C(),x=J("div","flatpickr-days"),P.config.noCalendar||(d(),s(),P.config.weekNumbers&&g(),f(),T.appendChild(x)),F.appendChild(T),P.config.enableTime&&m()},d=function(){I=J("div","flatpickr-month"),H=J("span","flatpickr-prev-month",P.config.prevArrow),S=J("span","cur_month"),_=J("input","cur_year"),_.type="number",_.title="Scroll to increment",Y=J("span","flatpickr-next-month",P.config.nextArrow),E=J("span","flatpickr-current-month"),E.appendChild(S),E.appendChild(_),I.appendChild(H),I.appendChild(E),I.appendChild(Y),b(),T.appendChild(I)},s=function(){var e=J("div","flatpickr-weekdays"),t=P.l10n.firstDayOfWeek,n=P.l10n.weekdays.shorthand.slice();t>0&&tWk":"",e.innerHTML+=""+n.join("")+"",T.appendChild(e)},g=function(){T.classList.add("hasWeeks"),N=J("div","flatpickr-weeks"),T.appendChild(N)},f=function(){var e=(new Date(P.currentYear,P.currentMonth,1).getDay()-P.l10n.firstDayOfWeek+7)%7,t=M(),n=M((P.currentMonth-1+12)%12),a=n+1-e,o=void 0,l=void 0,c=void 0,d=void 0;for(P.config.weekNumbers&&N&&(N.innerHTML=""),x.innerHTML="",P.config.minDate=i(P.config.minDate,!0),P.config.maxDate=i(P.config.maxDate,!0);n>=a;a++)x.appendChild(J("span","disabled flatpickr-day",a));for(a=1;42-e>=a;a++)(t>=a||a%7===1)&&(l=new Date(P.currentYear,P.currentMonth,a,0,0,0,0)),P.config.weekNumbers&&N&&a%7===1&&N.appendChild(J("span","disabled flatpickr-day",l.fp_getWeek())),d=P.config.minDate&&lP.config.maxDate,c=a>t||d||u(l),o=c?"disabled flatpickr-day":"slot flatpickr-day",!c&&r(l,U)&&(o+=" today"),!c&&P.selectedDateObj&&r(l,P.selectedDateObj)&&(o+=" selected"),x.appendChild(J("span",o,a>t?a%t:a))},m=function(){var e=J("div","flatpickr-time"),t=J("span","flatpickr-time-separator",":");A=J("input","flatpickr-hour"),q=J("input","flatpickr-minute"),A.type=q.type="number",A.value=P.selectedDateObj?o(P.selectedDateObj.getHours()):12,q.value=P.selectedDateObj?o(P.selectedDateObj.getMinutes()):"00",A.step=P.config.hourIncrement,q.step=P.config.minuteIncrement,A.min=+!P.config.time_24hr,A.max=P.config.time_24hr?23:12,q.min=0,q.max=59,A.title=q.title="Scroll to increment",e.appendChild(A),e.appendChild(t),e.appendChild(q),P.config.time_24hr||(W=J("span","flatpickr-am-pm",["AM","PM"][A.value>11|0]),W.title="Click to toggle",e.appendChild(W)),P.config.noCalendar&&!P.selectedDateObj&&(P.selectedDateObj=new Date),T.appendChild(e)},O=function(){function e(e){e.preventDefault(),W.innerHTML=["AM","PM"]["AM"===W.innerHTML|0]}"true"===String(P.config.clickOpens)&&(P.input.addEventListener("focus",P.open),P.altInput&&P.altInput.addEventListener("focus",P.open)),P.config.wrap&&P.element.querySelector("[data-open]")&&P.element.querySelector("[data-open]").addEventListener("click",P.open),P.config.wrap&&P.element.querySelector("[data-close]")&&P.element.querySelector("[data-close]").addEventListener("click",P.close),P.config.wrap&&P.element.querySelector("[data-toggle]")&&P.element.querySelector("[data-toggle]").addEventListener("click",P.toggle),P.config.wrap&&P.element.querySelector("[data-clear]")&&P.element.querySelector("[data-clear]").addEventListener("click",P.clear),P.config.noCalendar||(H.addEventListener("click",function(){k(-1)}),Y.addEventListener("click",function(){k(1)}),_.addEventListener("wheel",v),_.addEventListener("focus",_.select),_.addEventListener("change",function(e){_.blur(),P.currentYear=e.target.value,P.redraw()}),x.addEventListener("click",L)),document.addEventListener("click",w,!0),P.config.enableTime&&(A.addEventListener("wheel",h),q.addEventListener("wheel",h),A.addEventListener("mouseout",D),q.addEventListener("mouseout",D),A.addEventListener("change",D),q.addEventListener("change",D),A.addEventListener("click",A.select),q.addEventListener("click",q.select),P.config.time_24hr||(W.addEventListener("focus",W.blur),W.addEventListener("click",e),W.addEventListener("wheel",e),W.addEventListener("mouseout",D))),document.createEvent?(B=document.createEvent("MouseEvent"),B.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null)):B=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0})},P.open=function(){P.input.disabled||P.config.inline||(P.positionCalendar(),P.input.blur(),P.input.classList.add("active"),P.altInput&&(P.altInput.blur(),P.altInput.classList.add("active")),F.classList.add("open"),P.config.onOpen&&P.config.onOpen(P.selectedDateObj,P.input.value))},P.positionCalendar=function(){var e=P.altInput?P.altInput:P.input,t=e.getBoundingClientRect(),n=window.pageYOffset+e.offsetHeight+t.top,a=window.pageXOffset+t.left;F.style.top=n+"px",F.style.left=a+"px"},P.toggle=function(){P.input.disabled||(F.classList.toggle("open"),P.positionCalendar(),P.altInput&&P.altInput.classList.toggle("active"),P.input.classList.toggle("active"))},P.close=function(){F.classList.remove("open"),P.input.classList.remove("active"),P.altInput&&P.altInput.classList.remove("active"),P.config.onClose&&P.config.onClose(P.selectedDateObj,P.input.value)},P.clear=function(){P.input.value="",P.selectedDateObj=null,P.jumpToDate()},j=function(){P.input.dispatchEvent(B),P.config.onChange&&P.config.onChange(P.selectedDateObj,P.input.value)},P.destroy=function(){if(document.removeEventListener("click",w,!1),P.config.inline){var e=P.element.parentNode,t=e.removeChild(P.element);e.removeChild(T),e.parentNode.replaceChild(t,e)}else document.getElementsByTagName("body")[0].removeChild(F)},P.redraw=function(){P.config.noCalendar||(b(),f())},P.jumpToDate=function(e){e=i(e||P.selectedDateObj||P.config.defaultDate||P.config.minDate||U),P.currentYear=e.getFullYear(),P.currentMonth=e.getMonth(),P.redraw()},P.setDate=function(e,t){return i(e)instanceof Date?(P.selectedDateObj=i(e),P.jumpToDate(P.selectedDateObj),D(),void(t&&j())):(console.error("flatpickr: setDate() - invalid date: "+e),void console.info(P.element))},P.setTime=function(e,t,n){P.selectedDateObj&&(P.selectedDateObj.setHours(e,t,0,0),D(),n&&j())},P.set=function(e,t){e in P.config&&(P.config[e]=t,P.jumpToDate())};try{n()}catch($){console.error($),console.info(P.element)}return P},flatpickr.init.prototype={l10n:{weekdays:{shorthand:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],longhand:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},months:{shorthand:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],longhand:["January","February","March","April","May","June","July","August","September","October","November","December"]},daysInMonth:[31,28,31,30,31,30,31,31,30,31,30,31],firstDayOfWeek:0},defaultConfig:{utc:!1,noCalendar:!1,wrap:!1,weekNumbers:!1,clickOpens:!0,dateFormat:"Y-m-d",altInput:!1,altFormat:"F j, Y",defaultDate:null,minDate:null,maxDate:null,disable:[],shorthandCurrentMonth:!1,inline:!1,prevArrow:"<",nextArrow:">",enableTime:!1,timeFormat:"h:i K",time_24hr:!1,hourIncrement:1,minuteIncrement:5,onChange:null,onOpen:null,onClose:null}},Date.prototype.fp_incr=function(e){return new Date(this.getFullYear(),this.getMonth(),this.getDate()+parseInt(e,10))},Date.prototype.fp_isUTC=!1,Date.prototype.fp_toUTC=function(){var e=new Date(this.getTime()+6e4*this.getTimezoneOffset());return e.fp_isUTC=!0,e},Date.prototype.fp_getWeek=function(){var e=new Date(this.getTime());e.setHours(0,0,0,0),e.setDate(e.getDate()+3-(e.getDay()+6)%7);var t=new Date(e.getFullYear(),0,4);return 1+Math.round(((e.getTime()-t.getTime())/864e5-3+(t.getDay()+6)%7)/7)},"classList"in document.documentElement||!Object.defineProperty||"undefined"==typeof HTMLElement||Object.defineProperty(HTMLElement.prototype,"classList",{get:function(){var e=this;function t(t){return function(n){var a=e.className.split(/\s+/),i=a.indexOf(n);t(a,i,n),e.className=a.join(" ")}}var n={add:t(function(e,t,n){return~t||e.push(n)}),remove:t(function(e,t){return~t&&e.splice(t,1)}),toggle:t(function(e,t,n){return~t?e.splice(t,1):e.push(n)}),contains:function(t){return!!~e.className.split(/\s+/).indexOf(t)}};return n}}),"undefined"!=typeof module&&(module.exports=flatpickr); \ No newline at end of file +"use strict";var flatpickr=function e(t,n){var a=void 0,i=void 0,r=function(t){return t._flatpickr&&t._flatpickr.destroy(),t._flatpickr=new e.init(t,n),t._flatpickr};return t.nodeName?r(t):/^\#[a-zA-Z0-9\-\_]*$/.test(t)?r(document.getElementById(t.slice(1))):(a=/^\.[a-zA-Z0-9\-\_]*$/.test(t)?document.getElementsByClassName(t.slice(1)):document.querySelectorAll(t),i=[].slice.call(a).map(r),{calendars:i,byID:function(e){for(var t=0;t11?"PM":"AM"},M:function(){return d(n.n()-1,!0)},U:function(){return U.selectedDateObj.getTime()/1e3},Y:function(){return U.selectedDateObj.getFullYear()},d:function(){return c(n.j())},h:function(){return U.selectedDateObj.getHours()%12?U.selectedDateObj.getHours()%12:12},i:function(){return c(U.selectedDateObj.getMinutes())},j:function(){return U.selectedDateObj.getDate()},l:function(){return U.l10n.weekdays.longhand[n.w()]},m:function(){return c(n.n())},n:function(){return U.selectedDateObj.getMonth()+1},w:function(){return U.selectedDateObj.getDay()},y:function(){return String(n.Y()).substring(2)}},a=e.split(""),i=0;i=o(t.from)&&e<=o(t.to))return!0}return!1},b=function(e){e.preventDefault();var t=Math.max(-1,Math.min(1,e.wheelDelta||-e.deltaY));U.currentYear=e.target.innerHTML=parseInt(e.target.value,10)+t,U.redraw()},D=function(e){e.preventDefault();var t=parseInt(e.target.min),n=parseInt(e.target.max),a=parseInt(e.target.step),i=a*Math.max(-1,Math.min(1,e.wheelDelta||-e.deltaY)),r=(parseInt(e.target.value)+i)%(n+(0===t));t>r&&(r=n+(0===t)-a*(0===t)),e.target.value=c(r)},k=function(){x.innerHTML=d(U.currentMonth)+" ",Y.value=U.currentYear},w=function(){(U.currentMonth<0||U.currentMonth>11)&&(U.currentYear+=U.currentMonth%11,U.currentMonth=(U.currentMonth+12)%12)},C=function(e){q.classList.contains("open")&&!q.contains(e.target)&&e.target!==U.element&&e.target!==U.altInput&&U.close()},M=function(e){U.currentMonth+=e,w(),k(),m()},O=function(e){e.preventDefault(),e.target.classList.contains("slot")&&(U.selectedDateObj=new Date(U.currentYear,U.currentMonth,e.target.innerHTML),y(),E(),m(),U.config.inline||U.config.enableTime||U.close())},g=function(){I=n("div","flatpickr-calendar"),I.id=j(),F=n("div","flatpickr-days"),U.config.noCalendar||(p(),f(),U.config.weekNumbers&&h(),m(),I.appendChild(F)),q.appendChild(I),U.config.enableTime&&v()},p=function(){_=n("div","flatpickr-month"),S=n("span","flatpickr-prev-month",U.config.prevArrow),x=n("span","cur_month"),Y=n("input","cur_year"),Y.type="number",Y.title="Scroll to increment",N=n("span","flatpickr-next-month",U.config.nextArrow),H=n("span","flatpickr-current-month"),H.appendChild(x),H.appendChild(Y),_.appendChild(S),_.appendChild(H),_.appendChild(N),k(),I.appendChild(_)},f=function(){var e=n("div","flatpickr-weekdays"),t=U.l10n.firstDayOfWeek,a=U.l10n.weekdays.shorthand.slice();t>0&&tWk":"",e.innerHTML+=""+a.join("")+"",I.appendChild(e)},h=function(){I.classList.add("hasWeeks"),A=n("div","flatpickr-weeks"),I.appendChild(A)},m=function(){var e=(new Date(U.currentYear,U.currentMonth,1).getDay()-U.l10n.firstDayOfWeek+7)%7,t=L(),a=L((U.currentMonth-1+12)%12),i=a+1-e,r=void 0,c=void 0,u=void 0,d=void 0;for(U.config.weekNumbers&&A&&(A.innerHTML=""),F.innerHTML="",U.config.minDate=o(U.config.minDate,!0),U.config.maxDate=o(U.config.maxDate,!0);a>=i;i++)F.appendChild(n("span","disabled flatpickr-day",i));for(i=1;42-e>=i;i++)(t>=i||i%7===1)&&(c=new Date(U.currentYear,U.currentMonth,i,0,0,0,0)),U.config.weekNumbers&&A&&i%7===1&&A.appendChild(n("span","disabled flatpickr-day",c.fp_getWeek())),d=U.config.minDate&&cU.config.maxDate,u=i>t||d||s(c),r=u?"disabled flatpickr-day":"slot flatpickr-day",!u&&l(c,z)&&(r+=" today"),!u&&U.selectedDateObj&&l(c,U.selectedDateObj)&&(r+=" selected"),F.appendChild(n("span",r,i>t?i%t:i))},v=function(){var e=n("div","flatpickr-time"),t=n("span","flatpickr-time-separator",":");W=n("input","flatpickr-hour"),B=n("input","flatpickr-minute"),W.type=B.type="number",W.value=U.selectedDateObj?c(U.selectedDateObj.getHours()):12,B.value=U.selectedDateObj?c(U.selectedDateObj.getMinutes()):"00",W.step=U.config.hourIncrement,B.step=U.config.minuteIncrement,W.min=+!U.config.time_24hr,W.max=U.config.time_24hr?23:12,B.min=0,B.max=59,W.title=B.title="Scroll to increment",e.appendChild(W),e.appendChild(t),e.appendChild(B),U.config.time_24hr||(J=n("span","flatpickr-am-pm",["AM","PM"][W.value>11|0]),J.title="Click to toggle",e.appendChild(J)),U.config.noCalendar&&!U.selectedDateObj&&(U.selectedDateObj=new Date),I.appendChild(e)},T=function(){function e(e){e.preventDefault(),J.innerHTML=["AM","PM"]["AM"===J.innerHTML|0]}"true"===String(U.config.clickOpens)&&(U.input.addEventListener("focus",U.open),U.altInput&&U.altInput.addEventListener("focus",U.open)),U.config.wrap&&U.element.querySelector("[data-open]")&&U.element.querySelector("[data-open]").addEventListener("click",U.open),U.config.wrap&&U.element.querySelector("[data-close]")&&U.element.querySelector("[data-close]").addEventListener("click",U.close),U.config.wrap&&U.element.querySelector("[data-toggle]")&&U.element.querySelector("[data-toggle]").addEventListener("click",U.toggle),U.config.wrap&&U.element.querySelector("[data-clear]")&&U.element.querySelector("[data-clear]").addEventListener("click",U.clear),U.config.noCalendar||(S.addEventListener("click",function(){M(-1)}),N.addEventListener("click",function(){M(1)}),Y.addEventListener("wheel",b),Y.addEventListener("focus",Y.select),Y.addEventListener("change",function(e){Y.blur(),U.currentYear=e.target.value,U.redraw()}),F.addEventListener("click",O)),document.addEventListener("click",C,!0),U.config.enableTime&&(W.addEventListener("wheel",D),B.addEventListener("wheel",D),W.addEventListener("mouseout",y),B.addEventListener("mouseout",y),W.addEventListener("change",y),B.addEventListener("change",y),W.addEventListener("click",W.select),B.addEventListener("click",B.select),U.config.time_24hr||(J.addEventListener("focus",J.blur),J.addEventListener("click",e),J.addEventListener("wheel",e),J.addEventListener("mouseout",y))),document.createEvent?(P=document.createEvent("MouseEvent"),P.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null)):P=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0}),window.addEventListener("resize",a(function(){q.classList.contains("open")&&U.positionCalendar()},150))},U.open=function(){U.input.disabled||U.config.inline||(U.positionCalendar(),q.classList.add("open"),U.input.blur(),U.input.classList.add("active"),U.altInput&&(U.altInput.blur(),U.altInput.classList.add("active")),U.config.onOpen&&U.config.onOpen(U.selectedDateObj,U.input.value))},U.positionCalendar=function(){var e=U.altInput?U.altInput:U.input,t=e.getBoundingClientRect(),n=window.pageYOffset+e.offsetHeight+t.top,a=window.pageXOffset+t.left;q.style.top=n+"px",q.style.left=a+"px"},U.toggle=function(){U.input.disabled||(q.classList.toggle("open"),U.positionCalendar(),U.altInput&&U.altInput.classList.toggle("active"),U.input.classList.toggle("active"))},U.close=function(){q.classList.remove("open"),U.input.classList.remove("active"),U.altInput&&U.altInput.classList.remove("active"),U.config.onClose&&U.config.onClose(U.selectedDateObj,U.input.value)},U.clear=function(){U.input.value="",U.selectedDateObj=null,U.jumpToDate()},E=function(){U.input.dispatchEvent(P),U.config.onChange&&U.config.onChange(U.selectedDateObj,U.input.value)},U.destroy=function(){if(document.removeEventListener("click",C,!1),U.config.inline){var e=U.element.parentNode,t=e.removeChild(U.element);e.removeChild(I),e.parentNode.replaceChild(t,e)}else document.getElementsByTagName("body")[0].removeChild(q)},U.redraw=function(){U.config.noCalendar||(k(),m())},U.jumpToDate=function(e){e=o(e||U.selectedDateObj||U.config.defaultDate||U.config.minDate||z),U.currentYear=e.getFullYear(),U.currentMonth=e.getMonth(),U.redraw()},U.setDate=function(e,t){return o(e)instanceof Date?(U.selectedDateObj=o(e),U.jumpToDate(U.selectedDateObj),y(),void(t&&E())):(console.error("flatpickr: setDate() - invalid date: "+e),void console.info(U.element))},U.setTime=function(e,t,n){U.selectedDateObj&&(U.selectedDateObj.setHours(e,t,0,0),y(),n&&E())},U.set=function(e,t){e in U.config&&(U.config[e]=t,U.jumpToDate())};try{i()}catch($){console.error($),console.info(U.element)}return U},flatpickr.init.prototype={l10n:{weekdays:{shorthand:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],longhand:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},months:{shorthand:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],longhand:["January","February","March","April","May","June","July","August","September","October","November","December"]},daysInMonth:[31,28,31,30,31,30,31,31,30,31,30,31],firstDayOfWeek:0},defaultConfig:{utc:!1,noCalendar:!1,wrap:!1,weekNumbers:!1,clickOpens:!0,dateFormat:"Y-m-d",altInput:!1,altFormat:"F j, Y",defaultDate:null,minDate:null,maxDate:null,disable:[],shorthandCurrentMonth:!1,inline:!1,prevArrow:"<",nextArrow:">",enableTime:!1,timeFormat:"h:i K",time_24hr:!1,hourIncrement:1,minuteIncrement:5,onChange:null,onOpen:null,onClose:null}},Date.prototype.fp_incr=function(e){return new Date(this.getFullYear(),this.getMonth(),this.getDate()+parseInt(e,10))},Date.prototype.fp_isUTC=!1,Date.prototype.fp_toUTC=function(){var e=new Date(this.getTime()+6e4*this.getTimezoneOffset());return e.fp_isUTC=!0,e},Date.prototype.fp_getWeek=function(){var e=new Date(this.getTime());e.setHours(0,0,0,0),e.setDate(e.getDate()+3-(e.getDay()+6)%7);var t=new Date(e.getFullYear(),0,4);return 1+Math.round(((e.getTime()-t.getTime())/864e5-3+(t.getDay()+6)%7)/7)},"classList"in document.documentElement||!Object.defineProperty||"undefined"==typeof HTMLElement||Object.defineProperty(HTMLElement.prototype,"classList",{get:function(){var e=this;function t(t){return function(n){var a=e.className.split(/\s+/),i=a.indexOf(n);t(a,i,n),e.className=a.join(" ")}}var n={add:t(function(e,t,n){return~t||e.push(n)}),remove:t(function(e,t){return~t&&e.splice(t,1)}),toggle:t(function(e,t,n){return~t?e.splice(t,1):e.push(n)}),contains:function(t){return!!~e.className.split(/\s+/).indexOf(t)}};return n}}),"undefined"!=typeof module&&(module.exports=flatpickr); \ No newline at end of file diff --git a/src/flatpickr.js b/src/flatpickr.js index b164756e5..5eca5fd9d 100644 --- a/src/flatpickr.js +++ b/src/flatpickr.js @@ -57,6 +57,17 @@ flatpickr.init = function(element, instanceConfig) { }; + function throttle (callback, limit) { + var wait = false; + return function () { + if (!wait) { + callback.call(); + wait = true; + setTimeout(() => {wait = false}, limit); + } + } + } + // functions var self = this, init, @@ -396,11 +407,9 @@ flatpickr.init = function(element, instanceConfig) { event.target === self.altInput ) return; - // if( - // && - // (!wrapperElement.contains(event.target) && event.target != self.element) - // ) + self.close(); + }; changeMonth = function(offset) { @@ -697,6 +706,10 @@ flatpickr.init = function(element, instanceConfig) { 'cancelable': true }); + window.addEventListener('resize', throttle(() => { + wrapperElement.classList.contains('open') && (self.positionCalendar()); + }, 150)); + }; self.open = function() { @@ -704,6 +717,9 @@ flatpickr.init = function(element, instanceConfig) { return; self.positionCalendar(); + + wrapperElement.classList.add('open'); + self.input.blur(); self.input.classList.add('active'); @@ -712,7 +728,7 @@ flatpickr.init = function(element, instanceConfig) { self.altInput.classList.add('active'); } - wrapperElement.classList.add('open'); + if (self.config.onOpen)