diff --git a/dist/flatpickr.min.js b/dist/flatpickr.min.js index fa88b7100..555de36dc 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,r=void 0,i=function(t){return t._flatpickr&&t._flatpickr.destroy(),t._flatpickr=new e.init(t,n),t._flatpickr};return t.nodeName?i(t):/^\#[a-zA-Z0-9\-\_]*$/.test(t)?i(document.getElementById(t.slice(1))):(a=/^\.[a-zA-Z0-9\-\_]*$/.test(t)?document.getElementsByClassName(t.slice(1)):document.querySelectorAll(t),r=[].slice.call(a).map(i),{calendars:r,byID:function(e){for(var t=0;t11?"PM":"AM"},M:function(){return l(n.n()-1,!0)},U:function(){return I.selectedDateObj.getTime()/1e3},Y:function(){return I.selectedDateObj.getFullYear()},d:function(){return i(n.j())},h:function(){return I.selectedDateObj.getHours()%12?I.selectedDateObj.getHours()%12:12},i:function(){return i(I.selectedDateObj.getMinutes())},j:function(){return I.selectedDateObj.getDate()},l:function(){return I.l10n.weekdays.longhand[n.w()]},m:function(){return i(n.n())},n:function(){return I.selectedDateObj.getMonth()+1},w:function(){return I.selectedDateObj.getDay()},y:function(){return String(n.Y()).substring(2)}},a=e.split(""),r=0;rt&&n>e)return!0;return!1},p=function(e){e.preventDefault();var t=Math.max(-1,Math.min(1,e.wheelDelta||-e.deltaY));I.currentYear=e.target.innerHTML=parseInt(e.target.innerHTML,10)+t,I.redraw()},f=function(e){e.preventDefault();var t=parseInt(e.target.min),n=parseInt(e.target.max),a=parseInt(e.target.step),r=a*Math.max(-1,Math.min(1,e.wheelDelta||-e.deltaY)),c=(parseInt(e.target.value)+r)%(n+(0===t));t>c&&(c=n+(0===t)-a*(0===t)),e.target.value=i(c)},g=function(){x.innerHTML=l(I.currentMonth)+" ",F.innerHTML=I.currentYear},v=function(){(I.currentMonth<0||I.currentMonth>11)&&(I.currentYear+=I.currentMonth%11,I.currentMonth=(I.currentMonth+12)%12)},D=function(e){U.classList.contains("open")&&!U.contains(e.target)&&I.close()},k=function(e){I.currentMonth+=e,v(),g(),d()},M=function(e){e.preventDefault(),e.target.classList.contains("slot")&&(I.selectedDateObj=new Date(I.currentYear,I.currentMonth,e.target.innerHTML),m(),d(),I.config.inline||I.config.enableTime||I.close())},b=function(){I.config.noCalendar||(h(),u(),d(),N.appendChild(_)),U.appendChild(N),I.config.enableTime&&s()},h=function(){S.className="flatpickr-month",Y.className="flatpickr-prev-month",Y.innerHTML=I.config.prevArrow,A.className="flatpickr-next-month",A.innerHTML=I.config.nextArrow,x.className="cur_month",F.className="cur_year",F.title="Scroll to increment",H.appendChild(x),H.appendChild(F),S.appendChild(Y),S.appendChild(H),S.appendChild(A),g(),N.appendChild(S)},u=function(){var e=document.createElement("div"),t=I.l10n.firstDayOfWeek,n=I.l10n.weekdays.shorthand.slice();e.className="flatpickr-weekdays",t>0&&t"+n.join("")+"",N.appendChild(e)},d=function(){var e=(new Date(I.currentYear,I.currentMonth,1).getDay()-I.l10n.firstDayOfWeek+7)%7,t=C(),n=C((I.currentMonth-1+12)%12),i=n+1-e,c=void 0,l=void 0,u=void 0,d=void 0;for(_.innerHTML="",I.config.minDate=a("today"===I.config.minDate?new Date:I.config.minDate,!0),I.config.maxDate=a(I.config.maxDate,!0);n>=i;i++){var s=document.createElement("span");s.className="disabled flatpickr-day",s.innerHTML=i,_.appendChild(s)}for(i=1;42-e>=i;i++){t>=i&&(l=new Date(I.currentYear,I.currentMonth,i)),d=I.config.minDate&&lI.config.maxDate,u=i>t||d||o(l),c=u?"disabled flatpickr-day":"slot flatpickr-day",u||I.selectedDateObj||!r(l,q)||(c+=" today"),!u&&I.selectedDateObj&&r(l,I.selectedDateObj)&&(c+=" selected");var f=document.createElement("span");f.className=c,f.innerHTML=i>t?i%t:i,_.appendChild(f)}},s=function(){var e=document.createElement("div"),t=document.createElement("span");e.className="flatpickr-time",w=document.createElement("input"),O=document.createElement("input"),t.className="flatpickr-time-separator",t.innerHTML=":",w.type=O.type="number",w.className="flatpickr-hour",O.className="flatpickr-minute",w.value=I.selectedDateObj?i(I.selectedDateObj.getHours()):12,O.value=I.selectedDateObj?i(I.selectedDateObj.getMinutes()):"00",w.step=I.config.hourIncrement,O.step=I.config.minuteIncrement,w.min=+!I.config.time_24hr,w.max=I.config.time_24hr?23:12,O.min=0,O.max=59,w.title=O.title="Scroll to increment",e.appendChild(w),e.appendChild(t),e.appendChild(O),I.config.time_24hr||(j=document.createElement("span"),j.className="flatpickr-am-pm",j.innerHTML=["AM","PM"][w.value>11|0],j.title="Click to toggle",e.appendChild(j)),I.config.noCalendar&&!I.selectedDateObj&&(I.selectedDateObj=new Date),N.appendChild(e)},y=function(){function e(e){e.preventDefault(),j.innerHTML=["AM","PM"]["AM"===j.innerHTML|0]}"true"===String(I.config.clickOpens)&&(I.input.addEventListener("focus",I.open),I.altInput&&I.altInput.addEventListener("focus",I.open)),I.config.wrap&&I.element.querySelector("[data-open]")&&I.element.querySelector("[data-open]").addEventListener("click",I.open),I.config.wrap&&I.element.querySelector("[data-close]")&&I.element.querySelector("[data-close]").addEventListener("click",I.close),I.config.wrap&&I.element.querySelector("[data-toggle]")&&I.element.querySelector("[data-toggle]").addEventListener("click",I.toggle),I.config.wrap&&I.element.querySelector("[data-clear]")&&I.element.querySelector("[data-clear]").addEventListener("click",I.clear),Y.addEventListener("click",function(){k(-1)}),A.addEventListener("click",function(){k(1)}),F.addEventListener("wheel",p),_.addEventListener("click",M),document.addEventListener("click",D,!0),I.config.enableTime&&(w.addEventListener("wheel",f),O.addEventListener("wheel",f),w.addEventListener("mouseout",m),O.addEventListener("mouseout",m),w.addEventListener("change",m),O.addEventListener("change",m),w.addEventListener("click",function(){w.select()}),O.addEventListener("click",function(){O.select()}),I.config.time_24hr||(j.addEventListener("focus",function(){return j.blur()}),j.addEventListener("click",e),j.addEventListener("wheel",e),j.addEventListener("mouseout",m))),document.createEvent?(T=document.createEvent("MouseEvent"),T.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null)):T=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0})},I.open=function(){I.input.disabled||I.config.inline||(I.input.blur(),I.input.classList.add("active"),I.altInput&&(I.altInput.blur(),I.altInput.classList.add("active")),I.element.parentNode.classList.add("open"),I.config.onOpen&&I.config.onOpen())},I.toggle=function(){I.input.disabled||(I.element.parentNode.classList.toggle("open"),I.altInput&&I.altInput.classList.toggle("active"),I.input.classList.toggle("active"))},I.close=function(){I.element.parentNode.classList.remove("open"),I.input.classList.remove("active"),I.altInput&&I.altInput.classList.remove("active"),I.config.onClose&&I.config.onClose()},I.clear=function(){I.input.value="",I.selectedDateObj=null,I.jumpToDate()},E=function(){I.input.dispatchEvent(T),I.config.onChange&&I.config.onChange(I.selectedDateObj,I.input.value)},I.destroy=function(){var e=I.element.parentNode,t=e.removeChild(I.element);document.removeEventListener("click",D,!1),e.removeChild(N),e.parentNode.replaceChild(t,e)},I.redraw=function(){g(),d()},I.jumpToDate=function(e){e=a(e||I.selectedDateObj||I.config.defaultDate||I.config.minDate||q),I.currentYear=e.getFullYear(),I.currentMonth=e.getMonth(),I.redraw()},I.setDate=function(e,t){I.selectedDateObj=a(e),I.jumpToDate(I.selectedDateObj),m(),t=t||!1,t&&E()},I.set=function(e,t){e in I.config&&(I.config[e]=t,I.jumpToDate())},L(),I},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:{noCalendar:!1,wrap:!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))},"classList"in document.documentElement||!Object.defineProperty||"undefined"==typeof HTMLElement||Object.defineProperty(HTMLElement.prototype,"classList",{get:function(){function e(e){return function(n){var a=t.className.split(/\s+/),r=a.indexOf(n);e(a,r,n),t.className=a.join(" ")}}var t=this,n={add:e(function(e,t,n){~t||e.push(n)}),remove:e(function(e,t){~t&&e.splice(t,1)}),toggle:e(function(e,t,n){~t?e.splice(t,1):e.push(n)}),contains:function(e){return!!~t.className.split(/\s+/).indexOf(e)}};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,r=void 0,i=function(t){return t._flatpickr&&t._flatpickr.destroy(),t._flatpickr=new e.init(t,n),t._flatpickr};return t.nodeName?i(t):/^\#[a-zA-Z0-9\-\_]*$/.test(t)?i(document.getElementById(t.slice(1))):(a=/^\.[a-zA-Z0-9\-\_]*$/.test(t)?document.getElementsByClassName(t.slice(1)):document.querySelectorAll(t),r=[].slice.call(a).map(i),{calendars:r,byID:function(e){for(var t=0;t11?"PM":"AM"},M:function(){return l(n.n()-1,!0)},U:function(){return I.selectedDateObj.getTime()/1e3},Y:function(){return I.selectedDateObj.getFullYear()},d:function(){return i(n.j())},h:function(){return I.selectedDateObj.getHours()%12?I.selectedDateObj.getHours()%12:12},i:function(){return i(I.selectedDateObj.getMinutes())},j:function(){return I.selectedDateObj.getDate()},l:function(){return I.l10n.weekdays.longhand[n.w()]},m:function(){return i(n.n())},n:function(){return I.selectedDateObj.getMonth()+1},w:function(){return I.selectedDateObj.getDay()},y:function(){return String(n.Y()).substring(2)}},a=e.split(""),r=0;rt&&n>e)return!0;return!1},p=function(e){e.preventDefault();var t=Math.max(-1,Math.min(1,e.wheelDelta||-e.deltaY));I.currentYear=e.target.innerHTML=parseInt(e.target.innerHTML,10)+t,I.redraw()},f=function(e){e.preventDefault();var t=parseInt(e.target.min),n=parseInt(e.target.max),a=parseInt(e.target.step),r=a*Math.max(-1,Math.min(1,e.wheelDelta||-e.deltaY)),c=(parseInt(e.target.value)+r)%(n+(0===t));t>c&&(c=n+(0===t)-a*(0===t)),e.target.value=i(c)},g=function(){x.innerHTML=l(I.currentMonth)+" ",F.innerHTML=I.currentYear},v=function(){(I.currentMonth<0||I.currentMonth>11)&&(I.currentYear+=I.currentMonth%11,I.currentMonth=(I.currentMonth+12)%12)},D=function(e){U.classList.contains("open")&&!U.contains(e.target)&&I.close()},k=function(e){I.currentMonth+=e,v(),g(),d()},M=function(e){e.preventDefault(),e.target.classList.contains("slot")&&(I.selectedDateObj=new Date(I.currentYear,I.currentMonth,e.target.innerHTML),m(),d(),I.config.inline||I.config.enableTime||I.close())},b=function(){I.config.noCalendar||(h(),u(),d(),N.appendChild(_)),U.appendChild(N),I.config.enableTime&&s()},h=function(){S.className="flatpickr-month",Y.className="flatpickr-prev-month",Y.innerHTML=I.config.prevArrow,A.className="flatpickr-next-month",A.innerHTML=I.config.nextArrow,x.className="cur_month",F.className="cur_year",F.title="Scroll to increment",H.appendChild(x),H.appendChild(F),S.appendChild(Y),S.appendChild(H),S.appendChild(A),g(),N.appendChild(S)},u=function(){var e=document.createElement("div"),t=I.l10n.firstDayOfWeek,n=I.l10n.weekdays.shorthand.slice();e.className="flatpickr-weekdays",t>0&&t"+n.join("")+"",N.appendChild(e)},d=function(){var e=(new Date(I.currentYear,I.currentMonth,1).getDay()-I.l10n.firstDayOfWeek+7)%7,t=C(),n=C((I.currentMonth-1+12)%12),i=n+1-e,c=void 0,l=void 0,u=void 0,d=void 0;for(_.innerHTML="",I.config.minDate=a(I.config.minDate),I.config.maxDate=a(I.config.maxDate);n>=i;i++){var s=document.createElement("span");s.className="disabled flatpickr-day",s.innerHTML=i,_.appendChild(s)}for(i=1;42-e>=i;i++){t>=i&&(l=new Date(I.currentYear,I.currentMonth,i,0,0,0,0)),d=I.config.minDate&&lI.config.maxDate,u=i>t||d||o(l),c=u?"disabled flatpickr-day":"slot flatpickr-day",u||I.selectedDateObj||!r(l,q)||(c+=" today"),!u&&I.selectedDateObj&&r(l,I.selectedDateObj)&&(c+=" selected");var f=document.createElement("span");f.className=c,f.innerHTML=i>t?i%t:i,_.appendChild(f)}},s=function(){var e=document.createElement("div"),t=document.createElement("span");e.className="flatpickr-time",w=document.createElement("input"),O=document.createElement("input"),t.className="flatpickr-time-separator",t.innerHTML=":",w.type=O.type="number",w.className="flatpickr-hour",O.className="flatpickr-minute",w.value=I.selectedDateObj?i(I.selectedDateObj.getHours()):12,O.value=I.selectedDateObj?i(I.selectedDateObj.getMinutes()):"00",w.step=I.config.hourIncrement,O.step=I.config.minuteIncrement,w.min=+!I.config.time_24hr,w.max=I.config.time_24hr?23:12,O.min=0,O.max=59,w.title=O.title="Scroll to increment",e.appendChild(w),e.appendChild(t),e.appendChild(O),I.config.time_24hr||(j=document.createElement("span"),j.className="flatpickr-am-pm",j.innerHTML=["AM","PM"][w.value>11|0],j.title="Click to toggle",e.appendChild(j)),I.config.noCalendar&&!I.selectedDateObj&&(I.selectedDateObj=new Date),N.appendChild(e)},y=function(){function e(e){e.preventDefault(),j.innerHTML=["AM","PM"]["AM"===j.innerHTML|0]}"true"===String(I.config.clickOpens)&&(I.input.addEventListener("focus",I.open),I.altInput&&I.altInput.addEventListener("focus",I.open)),I.config.wrap&&I.element.querySelector("[data-open]")&&I.element.querySelector("[data-open]").addEventListener("click",I.open),I.config.wrap&&I.element.querySelector("[data-close]")&&I.element.querySelector("[data-close]").addEventListener("click",I.close),I.config.wrap&&I.element.querySelector("[data-toggle]")&&I.element.querySelector("[data-toggle]").addEventListener("click",I.toggle),I.config.wrap&&I.element.querySelector("[data-clear]")&&I.element.querySelector("[data-clear]").addEventListener("click",I.clear),Y.addEventListener("click",function(){k(-1)}),A.addEventListener("click",function(){k(1)}),F.addEventListener("wheel",p),_.addEventListener("click",M),document.addEventListener("click",D,!0),I.config.enableTime&&(w.addEventListener("wheel",f),O.addEventListener("wheel",f),w.addEventListener("mouseout",m),O.addEventListener("mouseout",m),w.addEventListener("change",m),O.addEventListener("change",m),w.addEventListener("click",function(){w.select()}),O.addEventListener("click",function(){O.select()}),I.config.time_24hr||(j.addEventListener("focus",function(){return j.blur()}),j.addEventListener("click",e),j.addEventListener("wheel",e),j.addEventListener("mouseout",m))),document.createEvent?(T=document.createEvent("MouseEvent"),T.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null)):T=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0})},I.open=function(){I.input.disabled||I.config.inline||(I.input.blur(),I.input.classList.add("active"),I.altInput&&(I.altInput.blur(),I.altInput.classList.add("active")),I.element.parentNode.classList.add("open"),I.config.onOpen&&I.config.onOpen())},I.toggle=function(){I.input.disabled||(I.element.parentNode.classList.toggle("open"),I.altInput&&I.altInput.classList.toggle("active"),I.input.classList.toggle("active"))},I.close=function(){I.element.parentNode.classList.remove("open"),I.input.classList.remove("active"),I.altInput&&I.altInput.classList.remove("active"),I.config.onClose&&I.config.onClose()},I.clear=function(){I.input.value="",I.selectedDateObj=null,I.jumpToDate()},E=function(){I.input.dispatchEvent(T),I.config.onChange&&I.config.onChange(I.selectedDateObj,I.input.value)},I.destroy=function(){var e=I.element.parentNode,t=e.removeChild(I.element);document.removeEventListener("click",D,!1),e.removeChild(N),e.parentNode.replaceChild(t,e)},I.redraw=function(){g(),d()},I.jumpToDate=function(e){e=a(e||I.selectedDateObj||I.config.defaultDate||I.config.minDate||q),I.currentYear=e.getFullYear(),I.currentMonth=e.getMonth(),I.redraw()},I.setDate=function(e,t){I.selectedDateObj=a(e),I.jumpToDate(I.selectedDateObj),m(),t=t||!1,t&&E()},I.set=function(e,t){e in I.config&&(I.config[e]=t,I.jumpToDate())},L(),I},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:{noCalendar:!1,wrap:!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))},"classList"in document.documentElement||!Object.defineProperty||"undefined"==typeof HTMLElement||Object.defineProperty(HTMLElement.prototype,"classList",{get:function(){function e(e){return function(n){var a=t.className.split(/\s+/),r=a.indexOf(n);e(a,r,n),t.className=a.join(" ")}}var t=this,n={add:e(function(e,t,n){~t||e.push(n)}),remove:e(function(e,t){~t&&e.splice(t,1)}),toggle:e(function(e,t,n){~t?e.splice(t,1):e.push(n)}),contains:function(e){return!!~t.className.split(/\s+/).indexOf(e)}};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 c63021a60..03d1a00c7 100644 --- a/src/flatpickr.js +++ b/src/flatpickr.js @@ -448,10 +448,8 @@ flatpickr.init = function (element, instanceConfig) { calendar.innerHTML = ''; - self.config.minDate = - uDate(self.config.minDate === "today" ? new Date() : self.config.minDate, true); - - self.config.maxDate = uDate(self.config.maxDate, true); + self.config.minDate = uDate(self.config.minDate); + self.config.maxDate = uDate(self.config.maxDate); // prepend days from the ending of previous month for( ; dayNumber <= prevMonthDays; dayNumber++ ){ @@ -465,7 +463,7 @@ flatpickr.init = function (element, instanceConfig) { for (dayNumber = 1; dayNumber <= 42 - firstOfMonth; dayNumber++) { if (dayNumber <= numDays) // avoids new date objects for appended dates - cur_date = new Date(self.currentYear, self.currentMonth, dayNumber); + cur_date = new Date(self.currentYear, self.currentMonth, dayNumber,0,0,0,0); date_outside_minmax = (self.config.minDate && cur_date < self.config.minDate ) ||