flatpickr_rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/flatpickr_rails.gemspec +1 -1
- data/lib/flatpickr_rails/version.rb +1 -1
- data/vendor/assets/javascripts/flatpickr/core.js +1034 -1
- data/vendor/assets/javascripts/flatpickr/index.js +0 -2
- data/vendor/assets/stylesheets/flatpickr.confetti.css +246 -1
- data/vendor/assets/stylesheets/flatpickr.css +242 -1
- data/vendor/assets/stylesheets/flatpickr.dark.css +243 -1
- data/vendor/assets/stylesheets/flatpickr.material_blue.css +246 -1
- data/vendor/assets/stylesheets/flatpickr.material_green.css +246 -1
- data/vendor/assets/stylesheets/flatpickr.material_orange.css +246 -1
- data/vendor/assets/stylesheets/flatpickr.material_red.css +246 -1
- metadata +2 -23
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.ar.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.bg.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.bn.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.de.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.es.js +0 -17
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.fa.js +0 -15
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.fi.js +0 -17
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.fr.js +0 -19
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.he.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.hi.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.ja.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.ko.js +0 -15
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.nl.js +0 -21
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.no.js +0 -15
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.pa.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.pl.js +0 -15
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.pt.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.ru.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.sq.js +0 -11
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.tr.js +0 -13
- data/vendor/assets/javascripts/flatpickr/locales/flatpickr.l10n.zh.js +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9beb2da6da1caeb4515a09327b6524a41590822
|
4
|
+
data.tar.gz: d02cdf657db34b7becbbb22c8c28690ab1932e83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17837c29c8e131e94165ba9471dff4ca67f72745d9bb76fc366039981b9db8f3ea6f59cab3275b7292016a05f3af786f7fc1d2eb8ce973a1b8339e945cc45ba2
|
7
|
+
data.tar.gz: aa5c6817e1a5c96b05e9f3f2aa71d1d756e4c8d23b41767ecbe91a1a6b97b1ef6db98af9e09d34a1a96a033760f5defe9fc73e824291541cbdf57c87d84c8695
|
data/flatpickr_rails.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["jirenpatel@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{A lightweight & powerful datetimepicker gem }
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{A lightweight & powerful datetimepicker using flatpickr lib https://github.com/chmln/flatpickr }
|
14
14
|
spec.homepage = "https://github.com/jiren/flatpickr_rails"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -1 +1,1034 @@
|
|
1
|
-
"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},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;t<i.length;t++)if(i[t].element.id===e)return i[t]}})};flatpickr.init=function(e,t){var n=function(e,t,n){var a=document.createElement(e);return n&&(a.innerHTML=n),t&&(a.className=t),a};function a(e,t){var n=!1;return function(){n||(e.call(),n=!0,setTimeout(function(){n=!1},t))}}var i,r,o,l,c,u,s,d,f,p,g,m,v,h,D,b,y,w,k,L,M,C,O,I,j,T,E,S,_,H,Y,x,N,A,F,q,W,P,B,J,$,U,z=this,K=new Date;i=function(){t=t||{},z.config={},z.element=e;for(var n in z.defaultConfig)z.config[n]=t[n]||z.element.dataset&&z.element.dataset[n.toLowerCase()]||z.element.getAttribute("data-"+n)||z.defaultConfig[n];z.input=z.config.wrap?e.querySelector("[data-input]"):e,z.input.classList.add("flatpickr-input"),z.config.defaultDate&&(z.config.defaultDate=o(z.config.defaultDate)),(z.input.value||z.config.defaultDate)&&(z.selectedDateObj=o(z.config.defaultDate||z.input.value)),r(),g(),T(),z.uDate=o,z.jumpToDate(),y()},j=function(){var e=void 0,t=void 0;do e=Math.round(Math.random()*Math.pow(10,10)),t="flatpickr-"+e;while(null!==document.getElementById(t));return t},o=function(e,t){if(t=t||!1,"today"===e)e=new Date,t=!0;else if("string"==typeof e)if(e=e.trim(),z.config.parseDate)e=z.config.parseDate(e);else if(/^\d\d\d\d\-\d{1,2}\-\d\d$/.test(e))e=new Date(e.replace(/(\d)-(\d)/g,"$1/$2"));else if(Date.parse(e))e=new Date(e);else if(/^\d\d\d\d\-\d\d\-\d\d/.test(e))e=new Date(e.replace(/(\d)-(\d)/g,"$1/$2"));else if(/^(\d?\d):(\d\d)/.test(e)){var n=e.match(/^(\d?\d):(\d\d)(:(\d\d))?/),a=0;void 0!==n[4]&&(a=n[4]),e=new Date,e.setHours(n[1],n[2],a,0)}else console.error("flatpickr: invalid date string "+e),console.info(z.element);return t&&e&&e.setHours(0,0,0,0),"true"===String(z.config.utc)&&e&&!e.fp_isUTC&&(e=e.fp_toUTC()),e},l=function(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()},r=function(){W=n("div","flatpickr-wrapper"),z.config.inline||z.config["static"]?(z.element.parentNode.insertBefore(W,z.element),W.appendChild(z.element),W.classList.add(z.config.inline?"inline":"static")):document.body.appendChild(W),z.config.altInput&&(z.altInput=n(z.input.nodeName,z.config.altInputClass+" flatpickr-input"),z.altInput.placeholder=z.input.placeholder,z.altInput.type="text",z.input.type="hidden",z.input.parentNode.insertBefore(z.altInput,z.input.nextSibling))},C=function(e){var t=z.currentYear,n=e||z.currentMonth;return 1===n&&t%4===0&&t%100!==0||t%400===0?29:z.l10n.daysInMonth[n]},y=function(){var e=void 0;if(z.selectedDateObj&&z.config.enableTime){e=z.selectedDateObj.getTime();var t,n=parseInt(P.value,10)||0,a=(60+(parseInt(B.value,10)||0))%60;z.config.enableSeconds&&(t=(60+parseInt(J.value,10)||0)%60),z.config.time_24hr||(n=n%12+12*("PM"===$.innerHTML)),z.selectedDateObj.setHours(n,a,void 0===t?z.selectedDateObj.getSeconds():t),P.value=c(z.config.time_24hr?n:(12+n)%12+12*(n%12===0)),B.value=c(a),void 0!==t&&(J.value=c(t))}z.altInput&&z.selectedDateObj&&(z.altInput.value=u(z.config.altFormat)),z.selectedDateObj&&(z.input.value=u(z.config.dateFormat)),e&&z.selectedDateObj.getTime()!==e&&E()},c=function(e){return("0"+e).slice(-2)},u=function(e){z.config.noCalendar&&(e=""),z.config.enableTime&&(e+=" "+z.config.timeFormat);for(var t="",n={D:function(){return z.l10n.weekdays.shorthand[n.w()]},F:function(){return s(n.n()-1,!1)},H:function(){return c(z.selectedDateObj.getHours())},J:function(){return n.j()+z.l10n.ordinal(n.j())},K:function(){return z.selectedDateObj.getHours()>11?"PM":"AM"},M:function(){return s(n.n()-1,!0)},S:function(){return c(z.selectedDateObj.getSeconds())},U:function(){return z.selectedDateObj.getTime()/1e3},Y:function(){return z.selectedDateObj.getFullYear()},d:function(){return c(n.j())},h:function(){return z.selectedDateObj.getHours()%12?z.selectedDateObj.getHours()%12:12},i:function(){return c(z.selectedDateObj.getMinutes())},j:function(){return z.selectedDateObj.getDate()},l:function(){return z.l10n.weekdays.longhand[n.w()]},m:function(){return c(n.n())},n:function(){return z.selectedDateObj.getMonth()+1},s:function(){return z.selectedDateObj.getSeconds()},w:function(){return z.selectedDateObj.getDay()},y:function(){return String(n.Y()).substring(2)}},a=e.split(""),i=0;i<a.length;i++){var r=a[i];n[r]&&"\\"!==a[i-1]?t+=n[r]():"\\"!==r&&(t+=r)}return t},s=function(e,t){return t||z.config.shorthandCurrentMonth?z.l10n.months.shorthand[e]:z.l10n.months.longhand[e]},d=function(e){if(z.config.minDate&&e<z.config.minDate||z.config.maxDate&&e>z.config.maxDate)return!0;e=o(e,!0);for(var t=void 0,n=0;n<z.config.disable.length;n++){if(t=z.config.disable[n],t instanceof Function&&t(e))return!0;if("string"==typeof t&&/^wkd/.test(t)&&e.getDay()===(parseInt(t.slice(-1))+z.l10n.firstDayOfWeek-1)%7)return!0;if((t instanceof Date||"string"==typeof t&&!/^wkd/.test(t))&&o(t,!0).getTime()===e.getTime())return!0;if("object"===("undefined"==typeof t?"undefined":_typeof(t))&&t.hasOwnProperty("from")&&e>=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));z.currentYear=e.target.value=parseInt(e.target.value,10)+t,z.redraw()},D=function(e){e.preventDefault();var t=parseInt(e.target.min,10),n=parseInt(e.target.max,10),a=parseInt(e.target.step,10),i=a*Math.max(-1,Math.min(1,e.wheelDelta||-e.deltaY)),r=(parseInt(e.target.value,10)+i)%(n+(0===t));r<t&&(r=n+(0===t)-a*(0===t)),e.target.value=c(r)},k=function(){N.innerHTML=s(z.currentMonth)+" ",x.value=z.currentYear},L=function(){(z.currentMonth<0||z.currentMonth>11)&&(z.currentYear+=z.currentMonth%11,z.currentMonth=(z.currentMonth+12)%12)},O=function(e){W.classList.contains("open")&&!W.contains(e.target)&&e.target!==z.element&&e.target!==z.altInput&&z.close()},M=function(e){z.currentMonth+=e,L(),k(),m()},I=function(e){e.preventDefault(),e.target.classList.contains("slot")&&(z.selectedDateObj=new Date(z.currentYear,z.currentMonth,e.target.innerHTML),y(),E(),m(),z.config.inline||z.config.enableTime||z.close())},g=function(){S=n("div","flatpickr-calendar"),S.id=j(),F=n("div","flatpickr-days"),z.config.noCalendar||(f(),p(),z.config.weekNumbers&&v(),m(),S.appendChild(F)),W.appendChild(S),z.config.enableTime&&h()},f=function(){H=n("div","flatpickr-month"),Y=n("span","flatpickr-prev-month",z.config.prevArrow),N=n("span","cur_month"),x=n("input","cur_year"),x.type="number",x.title=z.l10n.scrollTitle,A=n("span","flatpickr-next-month",z.config.nextArrow),_=n("span","flatpickr-current-month"),_.appendChild(N),_.appendChild(x),H.appendChild(Y),H.appendChild(_),H.appendChild(A),k(),S.appendChild(H)},p=function(){var e=n("div","flatpickr-weekdays"),t=z.l10n.firstDayOfWeek,a=z.l10n.weekdays.shorthand.slice();t>0&&t<a.length&&(a=[].concat(a.splice(t,a.length),a.splice(0,t))),e.innerHTML=z.config.weekNumbers?"<span>"+z.l10n.weekAbbreviation+"</span>":"",e.innerHTML+="<span>"+a.join("</span><span>")+"</span>",S.appendChild(e)},v=function(){S.classList.add("hasWeeks"),q=n("div","flatpickr-weeks"),S.appendChild(q)},m=function(){var e=(new Date(z.currentYear,z.currentMonth,1).getDay()-z.l10n.firstDayOfWeek+7)%7,t=C(),a=C((z.currentMonth-1+12)%12),i=a+1-e,r=void 0,c=void 0,u=void 0;for(z.config.weekNumbers&&q&&(q.innerHTML=""),F.innerHTML="",z.config.minDate=o(z.config.minDate,!0),z.config.maxDate=o(z.config.maxDate,!0);i<=a;i++)F.appendChild(n("span","disabled flatpickr-day",i));for(i=1;i<=42-e;i++)(i<=t||i%7===1)&&(c=new Date(z.currentYear,z.currentMonth,i,0,0,0,0,0)),z.config.weekNumbers&&q&&i%7===1&&q.appendChild(n("span","disabled flatpickr-day",c.fp_getWeek())),u=i>t||d(c),r=u?"disabled flatpickr-day":"slot flatpickr-day",!u&&l(c,K)&&(r+=" today"),!u&&z.selectedDateObj&&l(c,z.selectedDateObj)&&(r+=" selected"),F.appendChild(n("span",r,i>t?i%t:i))},h=function(){var e=n("div","flatpickr-time"),t=n("span","flatpickr-time-separator",":");P=n("input","flatpickr-hour"),B=n("input","flatpickr-minute"),P.type=B.type="number",P.value=z.selectedDateObj?c(z.selectedDateObj.getHours()):12,B.value=z.selectedDateObj?c(z.selectedDateObj.getMinutes()):"00",P.step=z.config.hourIncrement,B.step=z.config.minuteIncrement,P.min=+!z.config.time_24hr,P.max=z.config.time_24hr?23:12,B.min=0,B.max=59,P.title=B.title=z.l10n.scrollTitle,e.appendChild(P),e.appendChild(t),e.appendChild(B),z.config.enableSeconds&&(e.classList.add("has-seconds"),J=n("input","flatpickr-second"),J.type="number",J.value=z.selectedDateObj?c(z.selectedDateObj.getSeconds()):"00",J.step=5,J.min=0,J.max=59,e.appendChild(n("span","flatpickr-time-separator",":")),e.appendChild(J)),z.config.time_24hr||($=n("span","flatpickr-am-pm",["AM","PM"][P.value>11|0]),$.title=z.l10n.toggleTitle,e.appendChild($)),z.config.noCalendar&&!z.selectedDateObj&&(z.selectedDateObj=new Date),S.appendChild(e)},T=function(){function e(e){e.preventDefault(),$.innerHTML=["AM","PM"]["AM"===$.innerHTML|0]}"true"===String(z.config.clickOpens)&&(z.input.addEventListener("focus",z.open),z.altInput&&z.altInput.addEventListener("focus",z.open)),z.config.allowInput&&(z.altInput?z.altInput.addEventListener("change",w):z.input.addEventListener("change",w)),z.config.wrap&&z.element.querySelector("[data-open]")&&z.element.querySelector("[data-open]").addEventListener("click",z.open),z.config.wrap&&z.element.querySelector("[data-close]")&&z.element.querySelector("[data-close]").addEventListener("click",z.close),z.config.wrap&&z.element.querySelector("[data-toggle]")&&z.element.querySelector("[data-toggle]").addEventListener("click",z.toggle),z.config.wrap&&z.element.querySelector("[data-clear]")&&z.element.querySelector("[data-clear]").addEventListener("click",z.clear),z.config.noCalendar||(Y.addEventListener("click",function(){M(-1)}),A.addEventListener("click",function(){M(1)}),x.addEventListener("wheel",b),x.addEventListener("focus",x.select),x.addEventListener("input",function(e){z.currentYear=parseInt(e.target.value,10),z.redraw()}),F.addEventListener("click",I)),document.addEventListener("click",O,!0),document.addEventListener("focus",O,!0),z.config.enableTime&&(P.addEventListener("wheel",D),B.addEventListener("wheel",D),P.addEventListener("mouseout",y),B.addEventListener("mouseout",y),P.addEventListener("change",y),B.addEventListener("change",y),P.addEventListener("click",P.select),B.addEventListener("click",B.select),z.config.enableSeconds&&(J.addEventListener("wheel",D),J.addEventListener("mouseout",y),J.addEventListener("change",y),J.addEventListener("click",J.select)),z.config.time_24hr||($.addEventListener("focus",$.blur),$.addEventListener("click",e),$.addEventListener("wheel",e),$.addEventListener("mouseout",y))),document.createEvent?(U=document.createEvent("MouseEvent"),U.initMouseEvent("click",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null)):U=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0}),window.addEventListener("resize",a(function(){!W.classList.contains("open")||z.input.disabled||z.config.inline||z.config["static"]||z.positionCalendar()},150))},z.open=function(){z.input.disabled||z.config.inline||(z.config["static"]||z.positionCalendar(),W.classList.add("open"),z.altInput?(z.config.allowInput||z.altInput.blur(),z.altInput.classList.add("active")):(z.config.allowInput||z.input.blur(),z.input.classList.add("active")),z.config.onOpen&&z.config.onOpen(z.selectedDateObj,z.input.value))},z.positionCalendar=function(){var e=z.altInput?z.altInput:z.input,t=e.getBoundingClientRect(),n=window.pageYOffset+e.offsetHeight+t.top,a=window.pageXOffset+t.left;W.style.top=n+"px",W.style.left=a+"px"},z.toggle=function(){z.input.disabled||(W.classList.toggle("open"),z.positionCalendar(),z.altInput&&z.altInput.classList.toggle("active"),z.input.classList.toggle("active"))},z.close=function(){W.classList.remove("open"),z.input.classList.remove("active"),z.altInput&&z.altInput.classList.remove("active"),z.config.onClose&&z.config.onClose(z.selectedDateObj,z.input.value)},z.clear=function(){z.input.value="",z.selectedDateObj=null,z.jumpToDate()},E=function(){z.input.dispatchEvent(U),z.config.onChange&&z.config.onChange(z.selectedDateObj,z.input.value)},w=function(e){z.setDate(z.altInput?z.altInput.value:z.input.value)},z.destroy=function(){if(document.removeEventListener("click",O,!1),z.altInput&&z.altInput.parentNode.removeChild(z.altInput),z.config.inline){var e=z.element.parentNode,t=e.removeChild(z.element);e.removeChild(S),e.parentNode.replaceChild(t,e)}else document.getElementsByTagName("body")[0].removeChild(W)},z.redraw=function(){z.config.noCalendar||(k(),m())},z.jumpToDate=function(e){e=o(e||z.selectedDateObj||z.config.defaultDate||z.config.minDate||K),z.currentYear=e.getFullYear(),z.currentMonth=e.getMonth(),z.redraw()},z.setDate=function(e,t){e=o(e),e instanceof Date&&e.getTime()&&(z.selectedDateObj=o(e),z.jumpToDate(z.selectedDateObj),y(),t&&E())},z.setTime=function(e,t,n){z.selectedDateObj&&(P.value=parseInt(e,10)%24,B.value=parseInt(t||0,10)%60,z.config.time_24hr||($.innerHTML=e>11?"PM":"AM"),y(),n&&E())},z.set=function(e,t){e in z.config&&(z.config[e]=t,z.jumpToDate())};try{i()}catch(Z){console.error(Z),console.info(z.element)}return z},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,ordinal:function(e){var t=e%100;if(t>3&&t<21)return"th";switch(t%10){case 1:return"st";case 2:return"nd";case 3:return"rd";default:return"th"}},weekAbbreviation:"Wk",scrollTitle:"Scroll to increment",toggleTitle:"Click to toggle"},defaultConfig:{utc:!1,noCalendar:!1,wrap:!1,weekNumbers:!1,allowInput:!1,clickOpens:!0,dateFormat:"Y-m-d",altInput:!1,altInputClass:"",altFormat:"F j, Y",defaultDate:null,minDate:null,maxDate:null,parseDate:!1,disable:[],shorthandCurrentMonth:!1,inline:!1,"static":!1,prevArrow:"<",nextArrow:">",enableTime:!1,enableSeconds:!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);
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
|
4
|
+
|
5
|
+
var flatpickr = function flatpickr(selector, config) {
|
6
|
+
'use strict';
|
7
|
+
|
8
|
+
var elements = void 0,
|
9
|
+
instances = void 0,
|
10
|
+
createInstance = function createInstance(element) {
|
11
|
+
if (element._flatpickr) element._flatpickr.destroy();
|
12
|
+
|
13
|
+
element._flatpickr = new flatpickr.init(element, config);
|
14
|
+
return element._flatpickr;
|
15
|
+
};
|
16
|
+
|
17
|
+
if (selector.nodeName) return createInstance(selector);
|
18
|
+
/*
|
19
|
+
Utilize the performance of native getters if applicable
|
20
|
+
https://jsperf.com/getelementsbyclassname-vs-queryselectorall/18
|
21
|
+
https://jsperf.com/jquery-vs-javascript-performance-comparison/22
|
22
|
+
*/
|
23
|
+
else if (/^\#[a-zA-Z0-9\-\_]*$/.test(selector)) return createInstance(document.getElementById(selector.slice(1)));else if (/^\.[a-zA-Z0-9\-\_]*$/.test(selector)) elements = document.getElementsByClassName(selector.slice(1));else elements = document.querySelectorAll(selector);
|
24
|
+
|
25
|
+
instances = [].slice.call(elements).map(createInstance);
|
26
|
+
|
27
|
+
return {
|
28
|
+
calendars: instances,
|
29
|
+
byID: function byID(id) {
|
30
|
+
for (var i = 0; i < instances.length; i++) {
|
31
|
+
if (instances[i].element.id === id) return instances[i];
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
};
|
36
|
+
};
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @constructor
|
40
|
+
*/
|
41
|
+
flatpickr.init = function (element, instanceConfig) {
|
42
|
+
'use strict';
|
43
|
+
|
44
|
+
var createElement = function createElement(tag, className, content) {
|
45
|
+
|
46
|
+
var element = document.createElement(tag);
|
47
|
+
|
48
|
+
if (content) element.innerHTML = content;
|
49
|
+
|
50
|
+
if (className) element.className = className;
|
51
|
+
|
52
|
+
return element;
|
53
|
+
};
|
54
|
+
|
55
|
+
function throttle(callback, limit) {
|
56
|
+
var wait = false;
|
57
|
+
return function () {
|
58
|
+
if (!wait) {
|
59
|
+
callback.call();
|
60
|
+
wait = true;
|
61
|
+
setTimeout(function () {
|
62
|
+
wait = false;
|
63
|
+
}, limit);
|
64
|
+
}
|
65
|
+
};
|
66
|
+
}
|
67
|
+
|
68
|
+
// functions
|
69
|
+
var self = this,
|
70
|
+
init,
|
71
|
+
wrap,
|
72
|
+
uDate,
|
73
|
+
equalDates,
|
74
|
+
pad,
|
75
|
+
formatDate,
|
76
|
+
monthToStr,
|
77
|
+
isDisabled,
|
78
|
+
buildMonthNavigation,
|
79
|
+
buildWeekdays,
|
80
|
+
buildCalendar,
|
81
|
+
buildDays,
|
82
|
+
buildWeeks,
|
83
|
+
buildTime,
|
84
|
+
timeWrapper,
|
85
|
+
yearScroll,
|
86
|
+
updateValue,
|
87
|
+
onInput,
|
88
|
+
updateNavigationCurrentMonth,
|
89
|
+
handleYearChange,
|
90
|
+
changeMonth,
|
91
|
+
getDaysinMonth,
|
92
|
+
documentClick,
|
93
|
+
calendarClick,
|
94
|
+
getRandomCalendarIdStr,
|
95
|
+
bind,
|
96
|
+
triggerChange;
|
97
|
+
|
98
|
+
// elements & variables
|
99
|
+
var calendarContainer,
|
100
|
+
navigationCurrentMonth,
|
101
|
+
monthsNav,
|
102
|
+
prevMonthNav,
|
103
|
+
cur_year,
|
104
|
+
cur_month,
|
105
|
+
nextMonthNav,
|
106
|
+
calendar,
|
107
|
+
weekNumbers,
|
108
|
+
currentDate = new Date(),
|
109
|
+
wrapperElement,
|
110
|
+
hourElement,
|
111
|
+
minuteElement,
|
112
|
+
secondElement,
|
113
|
+
am_pm,
|
114
|
+
clickEvt;
|
115
|
+
|
116
|
+
init = function init() {
|
117
|
+
|
118
|
+
instanceConfig = instanceConfig || {};
|
119
|
+
|
120
|
+
self.config = {};
|
121
|
+
self.element = element;
|
122
|
+
|
123
|
+
for (var config in self.defaultConfig) {
|
124
|
+
self.config[config] = instanceConfig[config] || self.element.dataset && self.element.dataset[config.toLowerCase()] || self.element.getAttribute("data-" + config) || self.defaultConfig[config];
|
125
|
+
}self.input = self.config.wrap ? element.querySelector("[data-input]") : element;
|
126
|
+
self.input.classList.add("flatpickr-input");
|
127
|
+
|
128
|
+
if (self.config.defaultDate) self.config.defaultDate = uDate(self.config.defaultDate);
|
129
|
+
|
130
|
+
if (self.input.value || self.config.defaultDate) self.selectedDateObj = uDate(self.config.defaultDate || self.input.value);
|
131
|
+
|
132
|
+
wrap();
|
133
|
+
buildCalendar();
|
134
|
+
bind();
|
135
|
+
|
136
|
+
self.uDate = uDate;
|
137
|
+
|
138
|
+
self.jumpToDate();
|
139
|
+
updateValue();
|
140
|
+
};
|
141
|
+
|
142
|
+
getRandomCalendarIdStr = function getRandomCalendarIdStr() {
|
143
|
+
var randNum = void 0,
|
144
|
+
idStr = void 0;
|
145
|
+
do {
|
146
|
+
randNum = Math.round(Math.random() * Math.pow(10, 10));
|
147
|
+
idStr = 'flatpickr-' + randNum;
|
148
|
+
} while (document.getElementById(idStr) !== null);
|
149
|
+
return idStr;
|
150
|
+
};
|
151
|
+
|
152
|
+
uDate = function uDate(date, timeless) {
|
153
|
+
|
154
|
+
timeless = timeless || false;
|
155
|
+
|
156
|
+
if (date === 'today') {
|
157
|
+
date = new Date();
|
158
|
+
timeless = true;
|
159
|
+
} else if (typeof date === 'string') {
|
160
|
+
|
161
|
+
date = date.trim();
|
162
|
+
|
163
|
+
if (self.config.parseDate) date = self.config.parseDate(date);else if (/^\d\d\d\d\-\d{1,2}\-\d\d$/.test(date))
|
164
|
+
// this utc datestring gets parsed, but incorrectly by Date.parse
|
165
|
+
date = new Date(date.replace(/(\d)-(\d)/g, "$1/$2"));else if (Date.parse(date)) date = new Date(date);else if (/^\d\d\d\d\-\d\d\-\d\d/.test(date)) // disable special utc datestring
|
166
|
+
date = new Date(date.replace(/(\d)-(\d)/g, "$1/$2"));else if (/^(\d?\d):(\d\d)/.test(date)) {
|
167
|
+
// time-only picker
|
168
|
+
var matches = date.match(/^(\d?\d):(\d\d)(:(\d\d))?/);
|
169
|
+
|
170
|
+
var seconds = 0;
|
171
|
+
if (matches[4] !== undefined) seconds = matches[4];
|
172
|
+
|
173
|
+
date = new Date();
|
174
|
+
date.setHours(matches[1], matches[2], seconds, 0);
|
175
|
+
} else {
|
176
|
+
console.error('flatpickr: invalid date string ' + date);
|
177
|
+
console.info(self.element);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
if (timeless && date) date.setHours(0, 0, 0, 0);
|
182
|
+
|
183
|
+
if (String(self.config.utc) === 'true' && date && !date.fp_isUTC) date = date.fp_toUTC();
|
184
|
+
|
185
|
+
return date;
|
186
|
+
};
|
187
|
+
|
188
|
+
equalDates = function equalDates(date1, date2) {
|
189
|
+
return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate();
|
190
|
+
};
|
191
|
+
|
192
|
+
wrap = function wrap() {
|
193
|
+
|
194
|
+
wrapperElement = createElement("div", "flatpickr-wrapper");
|
195
|
+
|
196
|
+
if (self.config.inline || self.config.static) {
|
197
|
+
// Wrap input and place calendar underneath
|
198
|
+
self.element.parentNode.insertBefore(wrapperElement, self.element);
|
199
|
+
wrapperElement.appendChild(self.element);
|
200
|
+
|
201
|
+
wrapperElement.classList.add(self.config.inline ? 'inline' : 'static');
|
202
|
+
} else
|
203
|
+
// Insert at bottom of BODY tag to display outside
|
204
|
+
// of relative positioned elements with css 'overflow: hidden;'
|
205
|
+
// property set.
|
206
|
+
document.body.appendChild(wrapperElement);
|
207
|
+
|
208
|
+
if (self.config.altInput) {
|
209
|
+
// replicate self.element
|
210
|
+
self.altInput = createElement(self.input.nodeName, self.config.altInputClass + " flatpickr-input");
|
211
|
+
self.altInput.placeholder = self.input.placeholder;
|
212
|
+
self.altInput.type = "text";
|
213
|
+
|
214
|
+
self.input.type = 'hidden';
|
215
|
+
self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
|
216
|
+
}
|
217
|
+
};
|
218
|
+
|
219
|
+
getDaysinMonth = function getDaysinMonth(givenMonth) {
|
220
|
+
|
221
|
+
var yr = self.currentYear,
|
222
|
+
month = givenMonth || self.currentMonth;
|
223
|
+
|
224
|
+
if (month === 1 && yr % 4 === 0 && yr % 100 !== 0 || yr % 400 === 0) return 29;
|
225
|
+
|
226
|
+
return self.l10n.daysInMonth[month];
|
227
|
+
};
|
228
|
+
|
229
|
+
updateValue = function updateValue() {
|
230
|
+
|
231
|
+
var prev_date = void 0;
|
232
|
+
|
233
|
+
if (self.selectedDateObj && self.config.enableTime) {
|
234
|
+
|
235
|
+
prev_date = self.selectedDateObj.getTime();
|
236
|
+
|
237
|
+
// update time
|
238
|
+
var hours = parseInt(hourElement.value, 10) || 0,
|
239
|
+
minutes = (60 + (parseInt(minuteElement.value, 10) || 0)) % 60,
|
240
|
+
seconds;
|
241
|
+
|
242
|
+
if (self.config.enableSeconds) seconds = (60 + parseInt(secondElement.value, 10) || 0) % 60;
|
243
|
+
|
244
|
+
if (!self.config.time_24hr) hours = hours % 12 + 12 * (am_pm.innerHTML === "PM");
|
245
|
+
|
246
|
+
self.selectedDateObj.setHours(hours, minutes, seconds === undefined ? self.selectedDateObj.getSeconds() : seconds);
|
247
|
+
|
248
|
+
hourElement.value = pad(self.config.time_24hr ? hours : (12 + hours) % 12 + 12 * (hours % 12 === 0));
|
249
|
+
|
250
|
+
minuteElement.value = pad(minutes);
|
251
|
+
|
252
|
+
if (seconds !== undefined) secondElement.value = pad(seconds);
|
253
|
+
}
|
254
|
+
|
255
|
+
if (self.altInput && self.selectedDateObj) self.altInput.value = formatDate(self.config.altFormat);
|
256
|
+
|
257
|
+
if (self.selectedDateObj) self.input.value = formatDate(self.config.dateFormat);
|
258
|
+
|
259
|
+
if (prev_date && self.selectedDateObj.getTime() !== prev_date) {
|
260
|
+
triggerChange();
|
261
|
+
}
|
262
|
+
};
|
263
|
+
|
264
|
+
pad = function pad(num) {
|
265
|
+
return ("0" + num).slice(-2);
|
266
|
+
};
|
267
|
+
|
268
|
+
formatDate = function formatDate(dateFormat) {
|
269
|
+
|
270
|
+
if (self.config.noCalendar) dateFormat = "";
|
271
|
+
|
272
|
+
if (self.config.enableTime) dateFormat += " " + self.config.timeFormat;
|
273
|
+
|
274
|
+
var formattedDate = '',
|
275
|
+
formats = {
|
276
|
+
D: function D() {
|
277
|
+
return self.l10n.weekdays.shorthand[formats.w()];
|
278
|
+
}, // weekday name, short, e.g. Thu
|
279
|
+
F: function F() {
|
280
|
+
return monthToStr(formats.n() - 1, false);
|
281
|
+
}, // full month name e.g. January
|
282
|
+
H: function H() {
|
283
|
+
return pad(self.selectedDateObj.getHours());
|
284
|
+
}, // hours with leading zero e.g. 03
|
285
|
+
J: function J() {
|
286
|
+
return formats.j() + self.l10n.ordinal(formats.j());
|
287
|
+
}, // day (1-30) with ordinal suffix e.g. 1st, 2nd
|
288
|
+
K: function K() {
|
289
|
+
return self.selectedDateObj.getHours() > 11 ? "PM" : "AM";
|
290
|
+
}, // AM/PM
|
291
|
+
M: function M() {
|
292
|
+
return monthToStr(formats.n() - 1, true);
|
293
|
+
}, // shorthand month e.g. Jan
|
294
|
+
S: function S() {
|
295
|
+
return pad(self.selectedDateObj.getSeconds());
|
296
|
+
}, // seconds 00-59
|
297
|
+
U: function U() {
|
298
|
+
return self.selectedDateObj.getTime() / 1000;
|
299
|
+
},
|
300
|
+
Y: function Y() {
|
301
|
+
return self.selectedDateObj.getFullYear();
|
302
|
+
}, // 2016
|
303
|
+
d: function d() {
|
304
|
+
return pad(formats.j());
|
305
|
+
}, // day in month, padded (01-30)
|
306
|
+
h: function h() {
|
307
|
+
return self.selectedDateObj.getHours() % 12 ? self.selectedDateObj.getHours() % 12 : 12;
|
308
|
+
}, // hour from 1-12 (am/pm)
|
309
|
+
i: function i() {
|
310
|
+
return pad(self.selectedDateObj.getMinutes());
|
311
|
+
}, // minutes, padded with leading zero e.g. 09
|
312
|
+
j: function j() {
|
313
|
+
return self.selectedDateObj.getDate();
|
314
|
+
}, // day in month (1-30)
|
315
|
+
l: function l() {
|
316
|
+
return self.l10n.weekdays.longhand[formats.w()];
|
317
|
+
}, // weekday name, full, e.g. Thursday
|
318
|
+
m: function m() {
|
319
|
+
return pad(formats.n());
|
320
|
+
}, // padded month number (01-12)
|
321
|
+
n: function n() {
|
322
|
+
return self.selectedDateObj.getMonth() + 1;
|
323
|
+
}, // the month number (1-12)
|
324
|
+
s: function s() {
|
325
|
+
return self.selectedDateObj.getSeconds();
|
326
|
+
}, // seconds 0-59
|
327
|
+
w: function w() {
|
328
|
+
return self.selectedDateObj.getDay();
|
329
|
+
}, // number of the day of the week
|
330
|
+
y: function y() {
|
331
|
+
return String(formats.Y()).substring(2);
|
332
|
+
} // last two digits of full year e.g. 16 for full year 2016
|
333
|
+
},
|
334
|
+
formatPieces = dateFormat.split('');
|
335
|
+
|
336
|
+
for (var i = 0; i < formatPieces.length; i++) {
|
337
|
+
var c = formatPieces[i];
|
338
|
+
if (formats[c] && formatPieces[i - 1] !== '\\') formattedDate += formats[c]();else if (c !== '\\') formattedDate += c;
|
339
|
+
}
|
340
|
+
|
341
|
+
return formattedDate;
|
342
|
+
};
|
343
|
+
|
344
|
+
monthToStr = function monthToStr(date, shorthand) {
|
345
|
+
return shorthand || self.config.shorthandCurrentMonth ? self.l10n.months.shorthand[date] : self.l10n.months.longhand[date];
|
346
|
+
};
|
347
|
+
|
348
|
+
isDisabled = function isDisabled(check_date) {
|
349
|
+
|
350
|
+
if (self.config.minDate && check_date < self.config.minDate || self.config.maxDate && check_date > self.config.maxDate) return true;
|
351
|
+
|
352
|
+
check_date = uDate(check_date, true); //timeless
|
353
|
+
|
354
|
+
var d = void 0;
|
355
|
+
|
356
|
+
for (var i = 0; i < self.config.disable.length; i++) {
|
357
|
+
|
358
|
+
d = self.config.disable[i];
|
359
|
+
|
360
|
+
if (d instanceof Function && d(check_date)) // disabled by function
|
361
|
+
return true;else if ( // disabled weekday
|
362
|
+
typeof d === 'string' && /^wkd/.test(d) && check_date.getDay() === (parseInt(d.slice(-1)) + self.l10n.firstDayOfWeek - 1) % 7) return true;else if ( // disabled by date string
|
363
|
+
(d instanceof Date || typeof d === 'string' && !/^wkd/.test(d)) && uDate(d, true).getTime() === check_date.getTime()) return true;else if ( // disabled by range
|
364
|
+
(typeof d === 'undefined' ? 'undefined' : _typeof(d)) === 'object' && d.hasOwnProperty("from") && check_date >= uDate(d.from) && check_date <= uDate(d.to)) return true;
|
365
|
+
}
|
366
|
+
|
367
|
+
return false;
|
368
|
+
};
|
369
|
+
|
370
|
+
yearScroll = function yearScroll(event) {
|
371
|
+
event.preventDefault();
|
372
|
+
|
373
|
+
var delta = Math.max(-1, Math.min(1, event.wheelDelta || -event.deltaY));
|
374
|
+
self.currentYear = event.target.value = parseInt(event.target.value, 10) + delta;
|
375
|
+
self.redraw();
|
376
|
+
};
|
377
|
+
|
378
|
+
timeWrapper = function timeWrapper(e) {
|
379
|
+
e.preventDefault();
|
380
|
+
|
381
|
+
var min = parseInt(e.target.min, 10),
|
382
|
+
max = parseInt(e.target.max, 10),
|
383
|
+
step = parseInt(e.target.step, 10),
|
384
|
+
delta = step * Math.max(-1, Math.min(1, e.wheelDelta || -e.deltaY)),
|
385
|
+
newValue = (parseInt(e.target.value, 10) + delta) % (max + (min === 0));
|
386
|
+
|
387
|
+
if (newValue < min) newValue = max + (min === 0) - step * (min === 0);
|
388
|
+
|
389
|
+
e.target.value = pad(newValue);
|
390
|
+
};
|
391
|
+
|
392
|
+
updateNavigationCurrentMonth = function updateNavigationCurrentMonth() {
|
393
|
+
|
394
|
+
cur_month.innerHTML = monthToStr(self.currentMonth) + " ";
|
395
|
+
cur_year.value = self.currentYear;
|
396
|
+
};
|
397
|
+
|
398
|
+
handleYearChange = function handleYearChange() {
|
399
|
+
|
400
|
+
if (self.currentMonth < 0 || self.currentMonth > 11) {
|
401
|
+
|
402
|
+
self.currentYear += self.currentMonth % 11;
|
403
|
+
self.currentMonth = (self.currentMonth + 12) % 12;
|
404
|
+
}
|
405
|
+
};
|
406
|
+
|
407
|
+
documentClick = function documentClick(event) {
|
408
|
+
if (!wrapperElement.classList.contains("open") || wrapperElement.contains(event.target) || event.target === self.element || event.target === self.altInput) return;
|
409
|
+
|
410
|
+
self.close();
|
411
|
+
};
|
412
|
+
|
413
|
+
changeMonth = function changeMonth(offset) {
|
414
|
+
self.currentMonth += offset;
|
415
|
+
|
416
|
+
handleYearChange();
|
417
|
+
updateNavigationCurrentMonth();
|
418
|
+
buildDays();
|
419
|
+
};
|
420
|
+
|
421
|
+
calendarClick = function calendarClick(e) {
|
422
|
+
|
423
|
+
e.preventDefault();
|
424
|
+
|
425
|
+
if (e.target.classList.contains('slot')) {
|
426
|
+
|
427
|
+
self.selectedDateObj = new Date(self.currentYear, self.currentMonth, e.target.innerHTML);
|
428
|
+
|
429
|
+
updateValue();
|
430
|
+
triggerChange();
|
431
|
+
buildDays();
|
432
|
+
|
433
|
+
if (!self.config.inline && !self.config.enableTime) self.close();
|
434
|
+
}
|
435
|
+
};
|
436
|
+
|
437
|
+
buildCalendar = function buildCalendar() {
|
438
|
+
|
439
|
+
calendarContainer = createElement('div', 'flatpickr-calendar');
|
440
|
+
calendarContainer.id = getRandomCalendarIdStr();
|
441
|
+
|
442
|
+
calendar = createElement("div", "flatpickr-days");
|
443
|
+
|
444
|
+
if (!self.config.noCalendar) {
|
445
|
+
buildMonthNavigation();
|
446
|
+
buildWeekdays();
|
447
|
+
|
448
|
+
if (self.config.weekNumbers) buildWeeks();
|
449
|
+
|
450
|
+
buildDays();
|
451
|
+
|
452
|
+
calendarContainer.appendChild(calendar);
|
453
|
+
}
|
454
|
+
|
455
|
+
wrapperElement.appendChild(calendarContainer);
|
456
|
+
|
457
|
+
if (self.config.enableTime) buildTime();
|
458
|
+
};
|
459
|
+
|
460
|
+
buildMonthNavigation = function buildMonthNavigation() {
|
461
|
+
|
462
|
+
monthsNav = createElement("div", "flatpickr-month");
|
463
|
+
|
464
|
+
prevMonthNav = createElement("span", "flatpickr-prev-month", self.config.prevArrow);
|
465
|
+
|
466
|
+
cur_month = createElement("span", "cur_month");
|
467
|
+
|
468
|
+
cur_year = createElement("input", "cur_year");
|
469
|
+
cur_year.type = "number";
|
470
|
+
cur_year.title = self.l10n.scrollTitle;
|
471
|
+
|
472
|
+
nextMonthNav = createElement("span", "flatpickr-next-month", self.config.nextArrow);
|
473
|
+
|
474
|
+
navigationCurrentMonth = createElement('span', 'flatpickr-current-month');
|
475
|
+
navigationCurrentMonth.appendChild(cur_month);
|
476
|
+
navigationCurrentMonth.appendChild(cur_year);
|
477
|
+
|
478
|
+
monthsNav.appendChild(prevMonthNav);
|
479
|
+
monthsNav.appendChild(navigationCurrentMonth);
|
480
|
+
monthsNav.appendChild(nextMonthNav);
|
481
|
+
|
482
|
+
updateNavigationCurrentMonth();
|
483
|
+
calendarContainer.appendChild(monthsNav);
|
484
|
+
};
|
485
|
+
|
486
|
+
buildWeekdays = function buildWeekdays() {
|
487
|
+
|
488
|
+
var weekdayContainer = createElement('div', "flatpickr-weekdays"),
|
489
|
+
firstDayOfWeek = self.l10n.firstDayOfWeek,
|
490
|
+
weekdays = self.l10n.weekdays.shorthand.slice();
|
491
|
+
|
492
|
+
if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) {
|
493
|
+
weekdays = [].concat(weekdays.splice(firstDayOfWeek, weekdays.length), weekdays.splice(0, firstDayOfWeek));
|
494
|
+
}
|
495
|
+
|
496
|
+
weekdayContainer.innerHTML = self.config.weekNumbers ? "<span>" + self.l10n.weekAbbreviation + "</span>" : "";
|
497
|
+
weekdayContainer.innerHTML += '<span>' + weekdays.join('</span><span>') + '</span>';
|
498
|
+
|
499
|
+
calendarContainer.appendChild(weekdayContainer);
|
500
|
+
};
|
501
|
+
|
502
|
+
buildWeeks = function buildWeeks() {
|
503
|
+
|
504
|
+
calendarContainer.classList.add("hasWeeks");
|
505
|
+
|
506
|
+
weekNumbers = createElement("div", 'flatpickr-weeks');
|
507
|
+
calendarContainer.appendChild(weekNumbers);
|
508
|
+
};
|
509
|
+
|
510
|
+
buildDays = function buildDays() {
|
511
|
+
|
512
|
+
var firstOfMonth = (new Date(self.currentYear, self.currentMonth, 1).getDay() - self.l10n.firstDayOfWeek + 7) % 7,
|
513
|
+
numDays = getDaysinMonth(),
|
514
|
+
prevMonthDays = getDaysinMonth((self.currentMonth - 1 + 12) % 12),
|
515
|
+
dayNumber = prevMonthDays + 1 - firstOfMonth,
|
516
|
+
className = void 0,
|
517
|
+
cur_date = void 0,
|
518
|
+
date_is_disabled = void 0;
|
519
|
+
|
520
|
+
if (self.config.weekNumbers && weekNumbers) weekNumbers.innerHTML = '';
|
521
|
+
|
522
|
+
calendar.innerHTML = '';
|
523
|
+
|
524
|
+
self.config.minDate = uDate(self.config.minDate, true);
|
525
|
+
self.config.maxDate = uDate(self.config.maxDate, true);
|
526
|
+
|
527
|
+
// prepend days from the ending of previous month
|
528
|
+
for (; dayNumber <= prevMonthDays; dayNumber++) {
|
529
|
+
calendar.appendChild(createElement("span", "disabled flatpickr-day", dayNumber));
|
530
|
+
} // Start at 1 since there is no 0th day
|
531
|
+
for (dayNumber = 1; dayNumber <= 42 - firstOfMonth; dayNumber++) {
|
532
|
+
|
533
|
+
if (dayNumber <= numDays || dayNumber % 7 === 1) // avoids new date objects for appended dates
|
534
|
+
cur_date = new Date(self.currentYear, self.currentMonth, dayNumber, 0, 0, 0, 0, 0);
|
535
|
+
|
536
|
+
if (self.config.weekNumbers && weekNumbers && dayNumber % 7 === 1) weekNumbers.appendChild(createElement("span", "disabled flatpickr-day", cur_date.fp_getWeek()));
|
537
|
+
|
538
|
+
date_is_disabled = dayNumber > numDays || isDisabled(cur_date);
|
539
|
+
|
540
|
+
className = date_is_disabled ? "disabled flatpickr-day" : "slot flatpickr-day";
|
541
|
+
|
542
|
+
if (!date_is_disabled && equalDates(cur_date, currentDate)) className += ' today';
|
543
|
+
|
544
|
+
if (!date_is_disabled && self.selectedDateObj && equalDates(cur_date, self.selectedDateObj)) className += ' selected';
|
545
|
+
|
546
|
+
calendar.appendChild(createElement("span", className, dayNumber > numDays ? dayNumber % numDays : dayNumber));
|
547
|
+
}
|
548
|
+
};
|
549
|
+
|
550
|
+
buildTime = function buildTime() {
|
551
|
+
|
552
|
+
var timeContainer = createElement("div", "flatpickr-time"),
|
553
|
+
separator = createElement("span", "flatpickr-time-separator", ":");
|
554
|
+
|
555
|
+
hourElement = createElement("input", "flatpickr-hour");
|
556
|
+
minuteElement = createElement("input", "flatpickr-minute");
|
557
|
+
|
558
|
+
hourElement.type = minuteElement.type = "number";
|
559
|
+
|
560
|
+
hourElement.value = self.selectedDateObj ? pad(self.selectedDateObj.getHours()) : 12;
|
561
|
+
|
562
|
+
minuteElement.value = self.selectedDateObj ? pad(self.selectedDateObj.getMinutes()) : "00";
|
563
|
+
|
564
|
+
hourElement.step = self.config.hourIncrement;
|
565
|
+
minuteElement.step = self.config.minuteIncrement;
|
566
|
+
|
567
|
+
hourElement.min = +!self.config.time_24hr; // 0 in 24hr mode, 1 in 12hr mode
|
568
|
+
hourElement.max = self.config.time_24hr ? 23 : 12;
|
569
|
+
|
570
|
+
minuteElement.min = 0;
|
571
|
+
minuteElement.max = 59;
|
572
|
+
|
573
|
+
hourElement.title = minuteElement.title = self.l10n.scrollTitle;
|
574
|
+
|
575
|
+
timeContainer.appendChild(hourElement);
|
576
|
+
timeContainer.appendChild(separator);
|
577
|
+
timeContainer.appendChild(minuteElement);
|
578
|
+
|
579
|
+
if (self.config.enableSeconds) {
|
580
|
+
|
581
|
+
timeContainer.classList.add("has-seconds");
|
582
|
+
|
583
|
+
secondElement = createElement("input", "flatpickr-second");
|
584
|
+
secondElement.type = "number";
|
585
|
+
secondElement.value = self.selectedDateObj ? pad(self.selectedDateObj.getSeconds()) : "00";
|
586
|
+
|
587
|
+
secondElement.step = 5;
|
588
|
+
secondElement.min = 0;
|
589
|
+
secondElement.max = 59;
|
590
|
+
|
591
|
+
timeContainer.appendChild(createElement("span", "flatpickr-time-separator", ":"));
|
592
|
+
timeContainer.appendChild(secondElement);
|
593
|
+
}
|
594
|
+
|
595
|
+
if (!self.config.time_24hr) {
|
596
|
+
// add am_pm if appropriate
|
597
|
+
am_pm = createElement("span", "flatpickr-am-pm", ["AM", "PM"][hourElement.value > 11 | 0]);
|
598
|
+
am_pm.title = self.l10n.toggleTitle;
|
599
|
+
timeContainer.appendChild(am_pm);
|
600
|
+
}
|
601
|
+
|
602
|
+
// picking time only
|
603
|
+
if (self.config.noCalendar && !self.selectedDateObj) self.selectedDateObj = new Date();
|
604
|
+
|
605
|
+
calendarContainer.appendChild(timeContainer);
|
606
|
+
};
|
607
|
+
|
608
|
+
bind = function bind() {
|
609
|
+
|
610
|
+
function am_pm_toggle(e) {
|
611
|
+
e.preventDefault();
|
612
|
+
am_pm.innerHTML = ["AM", "PM"][am_pm.innerHTML === "AM" | 0];
|
613
|
+
}
|
614
|
+
|
615
|
+
if (String(self.config.clickOpens) === 'true') {
|
616
|
+
self.input.addEventListener('focus', self.open);
|
617
|
+
|
618
|
+
if (self.altInput) self.altInput.addEventListener('focus', self.open);
|
619
|
+
}
|
620
|
+
|
621
|
+
if (self.config.allowInput) {
|
622
|
+
if (self.altInput) self.altInput.addEventListener('change', onInput);else self.input.addEventListener('change', onInput);
|
623
|
+
}
|
624
|
+
|
625
|
+
if (self.config.wrap && self.element.querySelector("[data-open]")) self.element.querySelector("[data-open]").addEventListener('click', self.open);
|
626
|
+
|
627
|
+
if (self.config.wrap && self.element.querySelector("[data-close]")) self.element.querySelector("[data-close]").addEventListener('click', self.close);
|
628
|
+
|
629
|
+
if (self.config.wrap && self.element.querySelector("[data-toggle]")) self.element.querySelector("[data-toggle]").addEventListener('click', self.toggle);
|
630
|
+
|
631
|
+
if (self.config.wrap && self.element.querySelector("[data-clear]")) self.element.querySelector("[data-clear]").addEventListener('click', self.clear);
|
632
|
+
|
633
|
+
if (!self.config.noCalendar) {
|
634
|
+
|
635
|
+
prevMonthNav.addEventListener('click', function () {
|
636
|
+
changeMonth(-1);
|
637
|
+
});
|
638
|
+
nextMonthNav.addEventListener('click', function () {
|
639
|
+
changeMonth(1);
|
640
|
+
});
|
641
|
+
|
642
|
+
cur_year.addEventListener('wheel', yearScroll);
|
643
|
+
cur_year.addEventListener("focus", cur_year.select);
|
644
|
+
cur_year.addEventListener("input", function (event) {
|
645
|
+
|
646
|
+
self.currentYear = parseInt(event.target.value, 10);
|
647
|
+
self.redraw();
|
648
|
+
});
|
649
|
+
|
650
|
+
calendar.addEventListener('click', calendarClick);
|
651
|
+
}
|
652
|
+
|
653
|
+
document.addEventListener('click', documentClick, true);
|
654
|
+
document.addEventListener('focus', documentClick, true);
|
655
|
+
|
656
|
+
if (self.config.enableTime) {
|
657
|
+
|
658
|
+
hourElement.addEventListener("wheel", timeWrapper);
|
659
|
+
minuteElement.addEventListener("wheel", timeWrapper);
|
660
|
+
|
661
|
+
hourElement.addEventListener("mouseout", updateValue);
|
662
|
+
minuteElement.addEventListener("mouseout", updateValue);
|
663
|
+
|
664
|
+
hourElement.addEventListener("change", updateValue);
|
665
|
+
minuteElement.addEventListener("change", updateValue);
|
666
|
+
|
667
|
+
hourElement.addEventListener("click", hourElement.select);
|
668
|
+
minuteElement.addEventListener("click", minuteElement.select);
|
669
|
+
|
670
|
+
if (self.config.enableSeconds) {
|
671
|
+
secondElement.addEventListener("wheel", timeWrapper);
|
672
|
+
secondElement.addEventListener("mouseout", updateValue);
|
673
|
+
secondElement.addEventListener("change", updateValue);
|
674
|
+
secondElement.addEventListener("click", secondElement.select);
|
675
|
+
}
|
676
|
+
|
677
|
+
if (!self.config.time_24hr) {
|
678
|
+
am_pm.addEventListener("focus", am_pm.blur);
|
679
|
+
am_pm.addEventListener("click", am_pm_toggle);
|
680
|
+
|
681
|
+
am_pm.addEventListener("wheel", am_pm_toggle);
|
682
|
+
am_pm.addEventListener("mouseout", updateValue);
|
683
|
+
}
|
684
|
+
}
|
685
|
+
|
686
|
+
if (document.createEvent) {
|
687
|
+
clickEvt = document.createEvent("MouseEvent");
|
688
|
+
// without all these args ms edge spergs out
|
689
|
+
clickEvt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
690
|
+
} else clickEvt = new MouseEvent('click', {
|
691
|
+
'view': window,
|
692
|
+
'bubbles': true,
|
693
|
+
'cancelable': true
|
694
|
+
});
|
695
|
+
|
696
|
+
window.addEventListener('resize', throttle(function () {
|
697
|
+
|
698
|
+
if (wrapperElement.classList.contains('open') && !self.input.disabled && !self.config.inline && !self.config.static) self.positionCalendar();
|
699
|
+
}, 150));
|
700
|
+
};
|
701
|
+
|
702
|
+
self.open = function () {
|
703
|
+
|
704
|
+
if (self.input.disabled || self.config.inline) return;
|
705
|
+
|
706
|
+
if (!self.config.static) self.positionCalendar();
|
707
|
+
|
708
|
+
wrapperElement.classList.add('open');
|
709
|
+
|
710
|
+
if (self.altInput) {
|
711
|
+
if (!self.config.allowInput) self.altInput.blur();
|
712
|
+
self.altInput.classList.add('active');
|
713
|
+
} else {
|
714
|
+
if (!self.config.allowInput) self.input.blur();
|
715
|
+
self.input.classList.add('active');
|
716
|
+
}
|
717
|
+
|
718
|
+
if (self.config.onOpen) self.config.onOpen(self.selectedDateObj, self.input.value);
|
719
|
+
};
|
720
|
+
|
721
|
+
// For calendars inserted in BODY (as opposed to inline wrapper)
|
722
|
+
// it's necessary to properly calculate top/left position.
|
723
|
+
self.positionCalendar = function () {
|
724
|
+
|
725
|
+
var input = self.altInput ? self.altInput : self.input,
|
726
|
+
bounds = input.getBoundingClientRect(),
|
727
|
+
|
728
|
+
// account for scroll & input height
|
729
|
+
top = window.pageYOffset + input.offsetHeight + bounds.top,
|
730
|
+
left = window.pageXOffset + bounds.left;
|
731
|
+
|
732
|
+
wrapperElement.style.top = top + 'px';
|
733
|
+
wrapperElement.style.left = left + 'px';
|
734
|
+
};
|
735
|
+
|
736
|
+
self.toggle = function () {
|
737
|
+
if (self.input.disabled) return;
|
738
|
+
|
739
|
+
wrapperElement.classList.toggle('open');
|
740
|
+
self.positionCalendar();
|
741
|
+
|
742
|
+
if (self.altInput) self.altInput.classList.toggle('active');
|
743
|
+
|
744
|
+
self.input.classList.toggle('active');
|
745
|
+
};
|
746
|
+
|
747
|
+
self.close = function () {
|
748
|
+
wrapperElement.classList.remove('open');
|
749
|
+
self.input.classList.remove('active');
|
750
|
+
|
751
|
+
if (self.altInput) self.altInput.classList.remove('active');
|
752
|
+
|
753
|
+
if (self.config.onClose) self.config.onClose(self.selectedDateObj, self.input.value);
|
754
|
+
};
|
755
|
+
|
756
|
+
self.clear = function () {
|
757
|
+
self.input.value = "";
|
758
|
+
self.selectedDateObj = null;
|
759
|
+
self.jumpToDate();
|
760
|
+
};
|
761
|
+
|
762
|
+
triggerChange = function triggerChange() {
|
763
|
+
|
764
|
+
self.input.dispatchEvent(clickEvt);
|
765
|
+
|
766
|
+
if (self.config.onChange) self.config.onChange(self.selectedDateObj, self.input.value);
|
767
|
+
};
|
768
|
+
|
769
|
+
onInput = function onInput(event) {
|
770
|
+
|
771
|
+
self.setDate(self.altInput ? self.altInput.value : self.input.value);
|
772
|
+
};
|
773
|
+
|
774
|
+
self.destroy = function () {
|
775
|
+
|
776
|
+
document.removeEventListener('click', documentClick, false);
|
777
|
+
|
778
|
+
if (self.altInput) self.altInput.parentNode.removeChild(self.altInput);
|
779
|
+
|
780
|
+
if (self.config.inline) {
|
781
|
+
|
782
|
+
var parent = self.element.parentNode,
|
783
|
+
_element = parent.removeChild(self.element);
|
784
|
+
|
785
|
+
parent.removeChild(calendarContainer);
|
786
|
+
parent.parentNode.replaceChild(_element, parent);
|
787
|
+
} else document.getElementsByTagName("body")[0].removeChild(wrapperElement);
|
788
|
+
};
|
789
|
+
|
790
|
+
self.redraw = function () {
|
791
|
+
|
792
|
+
if (self.config.noCalendar) return;
|
793
|
+
|
794
|
+
updateNavigationCurrentMonth();
|
795
|
+
buildDays();
|
796
|
+
};
|
797
|
+
|
798
|
+
self.jumpToDate = function (jumpDate) {
|
799
|
+
|
800
|
+
jumpDate = uDate(jumpDate || self.selectedDateObj || self.config.defaultDate || self.config.minDate || currentDate);
|
801
|
+
|
802
|
+
self.currentYear = jumpDate.getFullYear();
|
803
|
+
self.currentMonth = jumpDate.getMonth();
|
804
|
+
self.redraw();
|
805
|
+
};
|
806
|
+
|
807
|
+
self.setDate = function (date, triggerChangeEvent) {
|
808
|
+
|
809
|
+
date = uDate(date);
|
810
|
+
|
811
|
+
if (date instanceof Date && date.getTime()) {
|
812
|
+
|
813
|
+
self.selectedDateObj = uDate(date);
|
814
|
+
self.jumpToDate(self.selectedDateObj);
|
815
|
+
updateValue();
|
816
|
+
|
817
|
+
if (triggerChangeEvent || false) triggerChange();
|
818
|
+
}
|
819
|
+
};
|
820
|
+
|
821
|
+
self.setTime = function (hour, minute, triggerChangeEvent) {
|
822
|
+
|
823
|
+
if (!self.selectedDateObj) return;
|
824
|
+
|
825
|
+
hourElement.value = parseInt(hour, 10) % 24;
|
826
|
+
minuteElement.value = parseInt(minute || 0, 10) % 60;
|
827
|
+
|
828
|
+
if (!self.config.time_24hr) am_pm.innerHTML = hour > 11 ? "PM" : "AM";
|
829
|
+
|
830
|
+
updateValue();
|
831
|
+
|
832
|
+
if (triggerChangeEvent || false) triggerChange();
|
833
|
+
};
|
834
|
+
|
835
|
+
self.set = function (key, value) {
|
836
|
+
|
837
|
+
if (key in self.config) {
|
838
|
+
self.config[key] = value;
|
839
|
+
self.jumpToDate();
|
840
|
+
}
|
841
|
+
};
|
842
|
+
|
843
|
+
try {
|
844
|
+
init();
|
845
|
+
} catch (error) {
|
846
|
+
console.error(error);console.info(self.element);
|
847
|
+
} // skip and carry on
|
848
|
+
|
849
|
+
return self;
|
850
|
+
};
|
851
|
+
|
852
|
+
flatpickr.init.prototype = {
|
853
|
+
|
854
|
+
l10n: {
|
855
|
+
weekdays: {
|
856
|
+
shorthand: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
857
|
+
longhand: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
858
|
+
},
|
859
|
+
months: {
|
860
|
+
shorthand: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
861
|
+
longhand: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
|
862
|
+
},
|
863
|
+
daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
|
864
|
+
firstDayOfWeek: 0,
|
865
|
+
ordinal: function ordinal(nth) {
|
866
|
+
var s = nth % 100;
|
867
|
+
if (s > 3 && s < 21) return "th";
|
868
|
+
switch (s % 10) {
|
869
|
+
case 1:
|
870
|
+
return "st";
|
871
|
+
case 2:
|
872
|
+
return "nd";
|
873
|
+
case 3:
|
874
|
+
return "rd";
|
875
|
+
default:
|
876
|
+
return "th";
|
877
|
+
}
|
878
|
+
},
|
879
|
+
weekAbbreviation: "Wk",
|
880
|
+
scrollTitle: "Scroll to increment",
|
881
|
+
toggleTitle: "Click to toggle"
|
882
|
+
},
|
883
|
+
|
884
|
+
defaultConfig: {
|
885
|
+
/* if true, dates will be parsed, formatted, and displayed in UTC.
|
886
|
+
preloading date strings w/ timezones is recommended but not necessary */
|
887
|
+
utc: false,
|
888
|
+
|
889
|
+
// noCalendar: true will hide the calendar. use for a time picker along w/ enableTime
|
890
|
+
noCalendar: false,
|
891
|
+
|
892
|
+
// wrap: see https://chmln.github.io/flatpickr/#strap
|
893
|
+
wrap: false,
|
894
|
+
|
895
|
+
// enables week numbers
|
896
|
+
weekNumbers: false,
|
897
|
+
|
898
|
+
allowInput: false,
|
899
|
+
|
900
|
+
/* clicking on input opens the date(time)picker. disable if you wish to open the calendar manually with .open() */
|
901
|
+
clickOpens: true,
|
902
|
+
|
903
|
+
// more date format chars at https://chmln.github.io/flatpickr/#dateformat
|
904
|
+
dateFormat: 'Y-m-d',
|
905
|
+
|
906
|
+
// altInput - see https://chmln.github.io/flatpickr/#altinput
|
907
|
+
altInput: false,
|
908
|
+
|
909
|
+
// the created altInput element will have this class.
|
910
|
+
altInputClass: "",
|
911
|
+
|
912
|
+
// same as dateFormat, but for altInput
|
913
|
+
altFormat: "F j, Y", // defaults to e.g. June 10, 2016
|
914
|
+
|
915
|
+
// defaultDate - either a datestring or a date object. used for datetimepicker's initial value
|
916
|
+
defaultDate: null,
|
917
|
+
|
918
|
+
// the minimum date that user can pick (inclusive)
|
919
|
+
minDate: null,
|
920
|
+
|
921
|
+
// the maximum date that user can pick (inclusive)
|
922
|
+
maxDate: null,
|
923
|
+
|
924
|
+
// dateparser that transforms a given string to a date object
|
925
|
+
parseDate: false,
|
926
|
+
|
927
|
+
// see https://chmln.github.io/flatpickr/#disable
|
928
|
+
disable: [],
|
929
|
+
|
930
|
+
// display the short version of month names - e.g. Sep instead of September
|
931
|
+
shorthandCurrentMonth: false,
|
932
|
+
|
933
|
+
// displays calendar inline. see https://chmln.github.io/flatpickr/#inline-calendar
|
934
|
+
inline: false,
|
935
|
+
|
936
|
+
// position calendar inside wrapper and next to the input element
|
937
|
+
// leave at false unless you know what you're doing
|
938
|
+
static: false,
|
939
|
+
|
940
|
+
// code for previous/next icons. this is where you put your custom icon code e.g. fontawesome
|
941
|
+
prevArrow: '<',
|
942
|
+
nextArrow: '>',
|
943
|
+
|
944
|
+
// enables the time picker functionality
|
945
|
+
enableTime: false,
|
946
|
+
|
947
|
+
// enables seconds in the time picker
|
948
|
+
enableSeconds: false,
|
949
|
+
|
950
|
+
// self-explanatory. defaults to e.g. 3:02 PM
|
951
|
+
timeFormat: "h:i K",
|
952
|
+
|
953
|
+
// display time picker in 24 hour mode
|
954
|
+
time_24hr: false,
|
955
|
+
|
956
|
+
// step size used when scrolling/incrementing the hour element
|
957
|
+
hourIncrement: 1,
|
958
|
+
|
959
|
+
// step size used when scrolling/incrementing the minute element
|
960
|
+
minuteIncrement: 5,
|
961
|
+
|
962
|
+
// onChange callback when user selects a date or time
|
963
|
+
onChange: null, //function(dateObj, dateStr){}
|
964
|
+
|
965
|
+
// called every time calendar is opened
|
966
|
+
onOpen: null, // function(dateObj, dateStr){}
|
967
|
+
|
968
|
+
// called every time calendar is closed
|
969
|
+
onClose: null // function(dateObj, dateStr){}
|
970
|
+
}
|
971
|
+
};
|
972
|
+
|
973
|
+
Date.prototype.fp_incr = function (days) {
|
974
|
+
return new Date(this.getFullYear(), this.getMonth(), this.getDate() + parseInt(days, 10));
|
975
|
+
};
|
976
|
+
|
977
|
+
Date.prototype.fp_isUTC = false;
|
978
|
+
Date.prototype.fp_toUTC = function () {
|
979
|
+
|
980
|
+
var new_date = new Date(this.getTime() + this.getTimezoneOffset() * 60000);
|
981
|
+
new_date.fp_isUTC = true;
|
982
|
+
|
983
|
+
return new_date;
|
984
|
+
};
|
985
|
+
|
986
|
+
Date.prototype.fp_getWeek = function () {
|
987
|
+
|
988
|
+
var date = new Date(this.getTime());
|
989
|
+
date.setHours(0, 0, 0, 0);
|
990
|
+
|
991
|
+
// Thursday in current week decides the year.
|
992
|
+
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
|
993
|
+
// January 4 is always in week 1.
|
994
|
+
var week1 = new Date(date.getFullYear(), 0, 4);
|
995
|
+
// Adjust to Thursday in week 1 and count number of weeks from date to week1.
|
996
|
+
return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
|
997
|
+
};
|
998
|
+
|
999
|
+
// classList polyfill
|
1000
|
+
if (!("classList" in document.documentElement) && Object.defineProperty && typeof HTMLElement !== 'undefined') {
|
1001
|
+
Object.defineProperty(HTMLElement.prototype, 'classList', {
|
1002
|
+
get: function get() {
|
1003
|
+
var self = this;
|
1004
|
+
function update(fn) {
|
1005
|
+
return function (value) {
|
1006
|
+
var classes = self.className.split(/\s+/),
|
1007
|
+
index = classes.indexOf(value);
|
1008
|
+
|
1009
|
+
fn(classes, index, value);
|
1010
|
+
self.className = classes.join(" ");
|
1011
|
+
};
|
1012
|
+
}
|
1013
|
+
|
1014
|
+
var ret = {
|
1015
|
+
add: update(function (classes, index, value) {
|
1016
|
+
return ~index || classes.push(value);
|
1017
|
+
}),
|
1018
|
+
remove: update(function (classes, index) {
|
1019
|
+
return ~index && classes.splice(index, 1);
|
1020
|
+
}),
|
1021
|
+
toggle: update(function (classes, index, value) {
|
1022
|
+
return ~index ? classes.splice(index, 1) : classes.push(value);
|
1023
|
+
}),
|
1024
|
+
contains: function contains(value) {
|
1025
|
+
return !!~self.className.split(/\s+/).indexOf(value);
|
1026
|
+
}
|
1027
|
+
};
|
1028
|
+
|
1029
|
+
return ret;
|
1030
|
+
}
|
1031
|
+
});
|
1032
|
+
}
|
1033
|
+
|
1034
|
+
if (typeof module !== 'undefined') module.exports = flatpickr;
|