vendor/assets/javascripts/flatpickr.js in flatpickr-2.5.3.0 vs vendor/assets/javascripts/flatpickr.js in flatpickr-2.5.4.0

- old
+ new

@@ -1,10 +1,10 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; -/*! flatpickr v2.5.3, @license MIT */ +/*! flatpickr v2.5.4, @license MIT */ function Flatpickr(element, config) { var self = this; self._ = {}; self._.afterDayAnim = afterDayAnim; @@ -145,22 +145,17 @@ } function bind() { if (self.config.wrap) { ["open", "close", "toggle", "clear"].forEach(function (el) { - var toggles = self.element.querySelectorAll("[data-" + el + "]"); - for (var i = 0; i < toggles.length; i++) { - toggles[i].addEventListener("click", self[el]); + self._toggles = self.element.querySelectorAll("[data-" + el + "]"); + for (var i = self._toggles.length; i--;) { + self._toggles[i].addEventListener("click", self[el]); } }); } - if (window.document.createEvent !== undefined) { - self.changeEvent = window.document.createEvent("HTMLEvents"); - self.changeEvent.initEvent("change", false, true); - } - if (self.isMobile) return setupMobile(); self.debouncedResize = debounce(onResize, 50); self.triggerChange = function () { triggerEvent("Change"); @@ -169,11 +164,11 @@ if (self.config.mode === "range" && self.daysContainer) self.daysContainer.addEventListener("mouseover", function (e) { return onMouseOver(e.target); }); - document.body.addEventListener("keydown", onKeyDown); + window.document.body.addEventListener("keydown", onKeyDown); if (!self.config.static) self._input.addEventListener("keydown", onKeyDown); if (!self.config.inline && !self.config.static) window.addEventListener("resize", self.debouncedResize); @@ -183,14 +178,14 @@ self._input.addEventListener("blur", documentClick); if (self.config.clickOpens) self._input.addEventListener("focus", open); if (!self.config.noCalendar) { - self.prevMonthNav.addEventListener("click", function () { + self.prevMonthNav.addEventListener("click", self.prevMonthFn = function () { return changeMonth(-1); }); - self.nextMonthNav.addEventListener("click", function () { + self.nextMonthNav.addEventListener("click", self.nextMonthFn = function () { return changeMonth(1); }); self.monthNav.addEventListener("wheel", function (e) { e.preventDefault(); @@ -310,21 +305,13 @@ if (~e.target.className.indexOf("arrow")) incrementNumInput(e, e.target.classList.contains("arrowUp") ? 1 : -1); } function incrementNumInput(e, delta, inputElem) { var input = inputElem || e.target.parentNode.childNodes[0]; - var ev = void 0; - - try { - ev = new Event("increment", { "bubbles": true }); - } catch (err) { - ev = window.document.createEvent("CustomEvent"); - ev.initCustomEvent("increment", true, true, {}); - } - - ev.delta = delta; - input.dispatchEvent(ev); + var event = createEvent("increment"); + event.delta = delta; + input.dispatchEvent(event); } function createNumberInput(inputClassName) { var wrapper = createElement("div", "numInputWrapper"), numInput = createElement("input", "numInput " + inputClassName), @@ -343,11 +330,10 @@ function build() { var fragment = window.document.createDocumentFragment(); self.calendarContainer = createElement("div", "flatpickr-calendar"); self.calendarContainer.tabIndex = -1; - self.numInputType = navigator.userAgent.indexOf("MSIE 9.0") > 0 ? "text" : "number"; if (!self.config.noCalendar) { fragment.appendChild(buildMonthNav()); self.innerContainer = createElement("div", "flatpickr-innerContainer"); @@ -788,10 +774,12 @@ window.removeEventListener("resize", instance.debouncedResize); window.document.removeEventListener("click", documentClick); window.document.removeEventListener("touchstart", documentClick); window.document.removeEventListener("blur", documentClick); + window.document.body.removeEventListener("keydown", onKeyDown); + instance._input.removeEventListener("keydown", onKeyDown); if (instance.mobileInput) { if (instance.mobileInput.parentNode) instance.mobileInput.parentNode.removeChild(instance.mobileInput); instance.mobileInput = undefined; } else if (instance.calendarContainer && instance.calendarContainer.parentNode) instance.calendarContainer.parentNode.removeChild(instance.calendarContainer); @@ -1491,23 +1479,25 @@ hooks[i](self.selectedDates, self.input && self.input.value, self, data); } } if (event === "Change") { - if (typeof Event === "function" && Event.constructor) { - self.input.dispatchEvent(new Event("change", { "bubbles": true })); + self.input.dispatchEvent(createEvent("change")); - // many front-end frameworks bind to the input event - self.input.dispatchEvent(new Event("input", { "bubbles": true })); - } + // many front-end frameworks bind to the input event + self.input.dispatchEvent(createEvent("input")); + } + } - /* istanbul ignore next */ - else { - if (window.document.createEvent !== undefined) return self.input.dispatchEvent(self.changeEvent); + function createEvent(name) { + var existing = self._[name + "Event"]; + if (existing !== undefined) return existing; - self.input.fireEvent("onchange"); - } - } + if (self._supportsEvents) return self._[name + "Event"] = new Event(name, { bubbles: true }); + + self._[name + "Event"] = document.createEvent("Event"); + self._[name + "Event"].initEvent(name, true, true); + return self._[name + "Event"]; } function isDateSelected(date) { for (var i = 0; i < self.selectedDates.length; i++) { if (compareDates(self.selectedDates[i], date) === 0) return "" + i; \ No newline at end of file