mirror of
https://github.com/WerySkok/nativegallery.git
synced 2024-11-15 03:31:19 +03:00
1 line
No EOL
15 KiB
JavaScript
1 line
No EOL
15 KiB
JavaScript
!function (e, t) { "object" == typeof exports && "object" == typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define([], t) : "object" == typeof exports ? exports.notie = t() : e.notie = t() }(this, function () { return function (e) { var t = {}; function n(s) { if (t[s]) return t[s].exports; var a = t[s] = { i: s, l: !1, exports: {} }; return e[s].call(a.exports, a, a.exports, n), a.l = !0, a.exports } return n.m = e, n.c = t, n.i = function (e) { return e }, n.d = function (e, t, s) { n.o(e, t) || Object.defineProperty(e, t, { configurable: !1, enumerable: !0, get: s }) }, n.n = function (e) { var t = e && e.__esModule ? function () { return e.default } : function () { return e }; return n.d(t, "a", t), t }, n.o = function (e, t) { return Object.prototype.hasOwnProperty.call(e, t) }, n.p = "", n(n.s = 0) }([function (e, t, n) { "use strict"; Object.defineProperty(t, "__esModule", { value: !0 }); var s = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) { return typeof e } : function (e) { return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e }, a = Object.assign || function (e) { for (var t = 1; t < arguments.length; t++) { var n = arguments[t]; for (var s in n) Object.prototype.hasOwnProperty.call(n, s) && (e[s] = n[s]) } return e }; var i = "top", c = { alertTime: 3, dateMonths: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], overlayClickDismiss: !0, overlayOpacity: .75, transitionCurve: "ease", transitionDuration: .3, transitionSelector: "all", classes: { container: "notie-container", textbox: "notie-textbox", textboxInner: "notie-textbox-inner", button: "notie-button", element: "notie-element", elementHalf: "notie-element-half", elementThird: "notie-element-third", overlay: "notie-overlay", backgroundSuccess: "notie-background-success", backgroundWarning: "notie-background-warning", backgroundError: "notie-background-error", backgroundInfo: "notie-background-info", backgroundNeutral: "notie-background-neutral", backgroundOverlay: "notie-background-overlay", alert: "notie-alert", inputField: "notie-input-field", selectChoiceRepeated: "notie-select-choice-repeated", dateSelectorInner: "notie-date-selector-inner", dateSelectorUp: "notie-date-selector-up" }, ids: { overlay: "notie-overlay" }, positions: { alert: i, force: i, confirm: i, input: i, select: "bottom", date: i } }, o = t.setOptions = function (e) { c = a({}, c, e, { classes: a({}, c.classes, e.classes), ids: a({}, c.ids, e.ids), positions: a({}, c.positions, e.positions) }) }, l = function () { return new Promise(function (e) { return setTimeout(e, 0) }) }, r = function (e) { return new Promise(function (t) { return setTimeout(t, 1e3 * e) }) }, d = function () { document.activeElement && document.activeElement.blur() }, u = function () { return "notie-" + "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (e) { var t = 16 * Math.random() | 0; return ("x" === e ? t : 3 & t | 8).toString(16) }) }, p = { 1: c.classes.backgroundSuccess, success: c.classes.backgroundSuccess, good: c.classes.backgroundSuccess, 2: c.classes.backgroundWarning, warning: c.classes.backgroundWarning, 3: c.classes.backgroundError, error: c.classes.backgroundError, 4: c.classes.backgroundInfo, info: c.classes.backgroundInfo, 5: c.classes.backgroundNeutral, neutral: c.classes.backgroundNeutral }, m = function () { return c.transitionSelector + " " + c.transitionDuration + "s " + c.transitionCurve }, v = function (e) { return 13 === e.keyCode }, f = function (e) { return 27 === e.keyCode }, b = function (e, t) { e.classList.add(c.classes.container), e.style[t] = "-10000px", document.body.appendChild(e), e.style[t] = "-" + e.offsetHeight + "px", e.listener && window.addEventListener("keydown", e.listener), l().then(function () { e.style.transition = m(), e.style[t] = 0 }) }, x = function (e, t) { var n = document.getElementById(e); n && (n.style[t] = "-" + n.offsetHeight + "px", n.listener && window.removeEventListener("keydown", n.listener), r(c.transitionDuration).then(function () { n.parentNode && n.parentNode.removeChild(n) })) }, L = function (e, t) { var n = document.createElement("div"); n.id = c.ids.overlay, n.classList.add(c.classes.overlay), n.classList.add(c.classes.backgroundOverlay), n.style.opacity = 0, e && c.overlayClickDismiss && (n.onclick = function () { x(e.id, t), g() }), document.body.appendChild(n), l().then(function () { n.style.transition = m(), n.style.opacity = c.overlayOpacity }) }, g = function () { var e = document.getElementById(c.ids.overlay); e.style.opacity = 0, r(c.transitionDuration).then(function () { e.parentNode && e.parentNode.removeChild(e) }) }, h = t.hideAlerts = function (e) { var t = document.getElementsByClassName(c.classes.alert); if (t.length) { for (var n = 0; n < t.length; n++) { var s = t[n]; x(s.id, s.position) } e && r(c.transitionDuration).then(function () { return e() }) } }, y = t.alert = function (e) { var t = e.type, n = void 0 === t ? 4 : t, s = e.text, a = e.time, i = void 0 === a ? c.alertTime : a, o = e.stay, l = void 0 !== o && o, m = e.position, L = void 0 === m ? c.positions.alert || L.top : m; d(), h(); var g = document.createElement("div"), y = u(); g.id = y, g.position = L, g.classList.add(c.classes.textbox), g.classList.add(p[n]), g.classList.add(c.classes.alert), g.innerHTML = '<div class="' + c.classes.textboxInner + '">' + s + "</div>", g.onclick = function () { return x(y, L) }, g.listener = function (e) { (v(e) || f(e)) && h() }, b(g, L), i && i < 1 && (i = 1), !l && i && r(i).then(function () { return x(y, L) }) }, k = t.force = function (e, t) { var n = e.type, s = void 0 === n ? 5 : n, a = e.text, i = e.buttonText, o = void 0 === i ? "OK" : i, l = e.callback, r = e.position, m = void 0 === r ? c.positions.force || m.top : r; d(), h(); var f = document.createElement("div"), y = u(); f.id = y; var k = document.createElement("div"); k.classList.add(c.classes.textbox), k.classList.add(c.classes.backgroundInfo), k.innerHTML = '<div class="' + c.classes.textboxInner + '">' + a + "</div>"; var C = document.createElement("div"); C.classList.add(c.classes.button), C.classList.add(p[s]), C.innerHTML = o, C.onclick = function () { x(y, m), g(), l ? l() : t && t() }, f.appendChild(k), f.appendChild(C), f.listener = function (e) { v(e) && C.click() }, b(f, m), L() }, C = t.confirm = function (e, t, n) { var s = e.text, a = e.submitText, i = void 0 === a ? "Yes" : a, o = e.cancelText, l = void 0 === o ? "Cancel" : o, r = e.submitCallback, p = e.cancelCallback, m = e.position, y = void 0 === m ? c.positions.confirm || y.top : m; d(), h(); var k = document.createElement("div"), C = u(); k.id = C; var E = document.createElement("div"); E.classList.add(c.classes.textbox), E.classList.add(c.classes.backgroundInfo), E.innerHTML = '<div class="' + c.classes.textboxInner + '">' + s + "</div>"; var T = document.createElement("div"); T.classList.add(c.classes.button), T.classList.add(c.classes.elementHalf), T.classList.add(c.classes.backgroundSuccess), T.innerHTML = i, T.onclick = function () { x(C, y), g(), r ? r() : t && t() }; var M = document.createElement("div"); M.classList.add(c.classes.button), M.classList.add(c.classes.elementHalf), M.classList.add(c.classes.backgroundError), M.innerHTML = l, M.onclick = function () { x(C, y), g(), p ? p() : n && n() }, k.appendChild(E), k.appendChild(T), k.appendChild(M), k.listener = function (e) { v(e) ? T.click() : f(e) && M.click() }, b(k, y), L(k, y) }, E = function (e, t, n) { var a = e.text, i = e.submitText, o = void 0 === i ? "Submit" : i, l = e.cancelText, r = void 0 === l ? "Cancel" : l, p = e.submitCallback, m = e.cancelCallback, y = e.position, k = void 0 === y ? c.positions.input || k.top : y, C = function (e, t) { var n = {}; for (var s in e) t.indexOf(s) >= 0 || Object.prototype.hasOwnProperty.call(e, s) && (n[s] = e[s]); return n }(e, ["text", "submitText", "cancelText", "submitCallback", "cancelCallback", "position"]); d(), h(); var E = document.createElement("div"), T = u(); E.id = T; var M = document.createElement("div"); M.classList.add(c.classes.textbox), M.classList.add(c.classes.backgroundInfo), M.innerHTML = '<div class="' + c.classes.textboxInner + '">' + a + "</div>"; var H = document.createElement("input"); H.classList.add(c.classes.inputField), H.setAttribute("autocapitalize", C.autocapitalize || "none"), H.setAttribute("autocomplete", C.autocomplete || "off"), H.setAttribute("autocorrect", C.autocorrect || "off"), H.setAttribute("autofocus", C.autofocus || "true"), H.setAttribute("inputmode", C.inputmode || "verbatim"), H.setAttribute("max", C.max || ""), H.setAttribute("maxlength", C.maxlength || ""), H.setAttribute("min", C.min || ""), H.setAttribute("minlength", C.minlength || ""), H.setAttribute("placeholder", C.placeholder || ""), H.setAttribute("spellcheck", C.spellcheck || "default"), H.setAttribute("step", C.step || "any"), H.setAttribute("type", C.type || "text"), H.value = C.value || "", C.allowed && (H.oninput = function () { var e = void 0; if (Array.isArray(C.allowed)) { for (var t = "", n = C.allowed, a = 0; a < n.length; a++)"an" === n[a] ? t += "0-9a-zA-Z" : "a" === n[a] ? t += "a-zA-Z" : "n" === n[a] && (t += "0-9"), "s" === n[a] && (t += " "); e = new RegExp("[^" + t + "]", "g") } else "object" === s(C.allowed) && (e = C.allowed); H.value = H.value.replace(e, "") }); var S = document.createElement("div"); S.classList.add(c.classes.button), S.classList.add(c.classes.elementHalf), S.classList.add(c.classes.backgroundSuccess), S.innerHTML = o, S.onclick = function () { x(T, k), g(), p ? p(H.value) : t && t(H.value) }; var A = document.createElement("div"); A.classList.add(c.classes.button), A.classList.add(c.classes.elementHalf), A.classList.add(c.classes.backgroundError), A.innerHTML = r, A.onclick = function () { x(T, k), g(), m ? m(H.value) : n && n(H.value) }, E.appendChild(M), E.appendChild(H), E.appendChild(S), E.appendChild(A), E.listener = function (e) { v(e) ? S.click() : f(e) && A.click() }, b(E, k), H.focus(), L(E, k) }; t.input = E; var T = t.select = function (e, t) { var n = e.text, s = e.cancelText, a = void 0 === s ? "Cancel" : s, i = e.cancelCallback, o = e.choices, l = e.position, r = void 0 === l ? c.positions.select || r.top : l; d(), h(); var m = document.createElement("div"), v = u(); m.id = v; var y = document.createElement("div"); y.classList.add(c.classes.textbox), y.classList.add(c.classes.backgroundInfo), y.innerHTML = '<div class="' + c.classes.textboxInner + '">' + n + "</div>", m.appendChild(y), o.forEach(function (e, t) { var n = e.type, s = void 0 === n ? 1 : n, a = e.text, i = e.handler, l = document.createElement("div"); l.classList.add(p[s]), l.classList.add(c.classes.button), l.classList.add(c.classes.selectChoice); var d = o[t + 1]; d && !d.type && (d.type = 1), d && d.type === s && l.classList.add(c.classes.selectChoiceRepeated), l.innerHTML = a, l.onclick = function () { x(v, r), g(), i() }, m.appendChild(l) }); var k = document.createElement("div"); k.classList.add(c.classes.backgroundNeutral), k.classList.add(c.classes.button), k.innerHTML = a, k.onclick = function () { x(v, r), g(), i ? i() : t && t() }, m.appendChild(k), m.listener = function (e) { f(e) && k.click() }, b(m, r), L(m, r) }, M = t.date = function (e, t, n) { var s = e.value, a = void 0 === s ? new Date : s, i = e.submitText, o = void 0 === i ? "OK" : i, l = e.cancelText, r = void 0 === l ? "Cancel" : l, p = e.submitCallback, m = e.cancelCallback, y = e.position, k = void 0 === y ? c.positions.date || k.top : y; d(), h(); var C = "▾", E = document.createElement("div"), T = document.createElement("div"), M = document.createElement("div"), H = function (e) { E.innerHTML = c.dateMonths[e.getMonth()], T.innerHTML = e.getDate(), M.innerHTML = e.getFullYear() }, S = function (e) { H(a) }, A = function (e) { var t = new Date(a.getFullYear(), a.getMonth() + e + 1, 0).getDate(); a.getDate() > t && a.setDate(t), a.setMonth(a.getMonth() + e), H(a) }, w = function (e) { a.setDate(a.getDate() + e), H(a) }, D = function (e) { a.getFullYear() + e < 0 ? a.setFullYear(0) : a.setFullYear(a.getFullYear() + e), H(a) }, O = document.createElement("div"), I = u(); O.id = I; var N = document.createElement("div"); N.classList.add(c.classes.backgroundInfo); var F = document.createElement("div"); F.classList.add(c.classes.dateSelectorInner); var j = document.createElement("div"); j.classList.add(c.classes.button), j.classList.add(c.classes.elementThird), j.classList.add(c.classes.dateSelectorUp), j.innerHTML = C; var Y = document.createElement("div"); Y.classList.add(c.classes.button), Y.classList.add(c.classes.elementThird), Y.classList.add(c.classes.dateSelectorUp), Y.innerHTML = C; var P = document.createElement("div"); P.classList.add(c.classes.button), P.classList.add(c.classes.elementThird), P.classList.add(c.classes.dateSelectorUp), P.innerHTML = C, E.classList.add(c.classes.element), E.classList.add(c.classes.elementThird), E.innerHTML = c.dateMonths[a.getMonth()], T.classList.add(c.classes.element), T.classList.add(c.classes.elementThird), T.setAttribute("contentEditable", !0), T.addEventListener("input", function (e) { var t = new Date(a.getFullYear(), a.getMonth() + 1, 0).getDate(), n = e.target.textContent.replace(/^0+/, "").replace(/[^\d]/g, "").slice(0, 2); Number(n) > t && (n = t.toString()), e.target.textContent = n, Number(n) < 1 && (n = "1"), a.setDate(Number(n)) }), T.addEventListener("blur", S), T.innerHTML = a.getDate(), M.classList.add(c.classes.element), M.classList.add(c.classes.elementThird), M.setAttribute("contentEditable", !0), M.addEventListener("input", function (e) { var t = e.target.textContent.replace(/^0+/, "").replace(/[^\d]/g, "").slice(0, 4); e.target.textContent = t, a.setFullYear(Number(t)) }), M.addEventListener("blur", S), M.innerHTML = a.getFullYear(); var z = document.createElement("div"); z.classList.add(c.classes.button), z.classList.add(c.classes.elementThird), z.innerHTML = C; var U = document.createElement("div"); U.classList.add(c.classes.button), U.classList.add(c.classes.elementThird), U.innerHTML = C; var _ = document.createElement("div"); _.classList.add(c.classes.button), _.classList.add(c.classes.elementThird), _.innerHTML = C, j.onclick = function () { return A(1) }, Y.onclick = function () { return w(1) }, P.onclick = function () { return D(1) }, z.onclick = function () { return A(-1) }, U.onclick = function () { return w(-1) }, _.onclick = function () { return D(-1) }; var B = document.createElement("div"); B.classList.add(c.classes.button), B.classList.add(c.classes.elementHalf), B.classList.add(c.classes.backgroundSuccess), B.innerHTML = o, B.onclick = function () { x(I, k), g(), p ? p(a) : t && t(a) }; var J = document.createElement("div"); J.classList.add(c.classes.button), J.classList.add(c.classes.elementHalf), J.classList.add(c.classes.backgroundError), J.innerHTML = r, J.onclick = function () { x(I, k), g(), m ? m(a) : n && n(a) }, F.appendChild(j), F.appendChild(Y), F.appendChild(P), F.appendChild(E), F.appendChild(T), F.appendChild(M), F.appendChild(z), F.appendChild(U), F.appendChild(_), N.appendChild(F), O.appendChild(N), O.appendChild(B), O.appendChild(J), O.listener = function (e) { v(e) ? B.click() : f(e) && J.click() }, b(O, k), L(O, k) }; t.default = { alert: y, force: k, confirm: C, input: E, select: T, date: M, setOptions: o, hideAlerts: h } }]) }); |