diff --git a/dist/notie.js b/dist/notie.js index 0b1d1f4..a161b50 100644 --- a/dist/notie.js +++ b/dist/notie.js @@ -205,6 +205,16 @@ var escapeClicked = function escapeClicked(event) { return event.keyCode === 27; }; +var makeElement = function makeElement(elemType, classes) { + var element = document.createElement(elemType); + if (classes) { + classes.forEach(function (c) { + return element.classList.add(c); + }); + } + return element; +}; + var addToDocument = function addToDocument(element, position) { element.classList.add(options.classes.container); element.style[position] = '-10000px'; @@ -232,10 +242,8 @@ var removeFromDocument = function removeFromDocument(id, position) { }; var addOverlayToDocument = function addOverlayToDocument(owner, position) { - var element = document.createElement('div'); + var element = makeElement('div', [options.classes.overlay, options.classes.backgroundOverlay]); element.id = options.ids.overlay; - element.classList.add(options.classes.overlay); - element.classList.add(options.classes.backgroundOverlay); element.style.opacity = 0; if (owner && options.overlayClickDismiss) { element.onclick = function () { @@ -273,6 +281,29 @@ var hideAlerts = exports.hideAlerts = function hideAlerts(callback) { } }; +// ==================== +// shared elements +// ==================== + +var div = function div(classes) { + var element = makeElement('div', classes); + element.id = generateRandomId(); + return element; +}; + +var button = function button(innerHTML, classes, onclick) { + var element = makeElement('div', classes); + element.innerHTML = innerHTML; + element.onclick = onclick; + return element; +}; + +var textbox = function textbox(text, classes) { + var element = div(classes); + element.innerHTML = '
' + text + '
'; + return element; +}; + // ==================== // exports // ==================== @@ -291,16 +322,10 @@ var alert = exports.alert = function alert(_ref) { blur(); hideAlerts(); - var element = document.createElement('div'); - var id = generateRandomId(); - element.id = id; + var element = textbox(text, [options.classes.textbox, typeToClassLookup[type], options.classes.alert]); element.position = position; - element.classList.add(options.classes.textbox); - element.classList.add(typeToClassLookup[type]); - element.classList.add(options.classes.alert); - element.innerHTML = '
' + text + '
'; element.onclick = function () { - return removeFromDocument(id, position); + return removeFromDocument(element.id, position); }; element.listener = function (event) { @@ -311,7 +336,7 @@ var alert = exports.alert = function alert(_ref) { if (time && time < 1) time = 1; if (!stay && time) wait(time).then(function () { - return removeFromDocument(id, position); + return removeFromDocument(element.id, position); }); }; @@ -328,24 +353,15 @@ var force = exports.force = function force(_ref2, callbackArg) { blur(); hideAlerts(); - var element = document.createElement('div'); - var id = generateRandomId(); - element.id = id; - - var elementText = document.createElement('div'); - elementText.classList.add(options.classes.textbox); - elementText.classList.add(options.classes.backgroundInfo); - elementText.innerHTML = '
' + text + '
'; - - var elementButton = document.createElement('div'); - elementButton.classList.add(options.classes.button); - elementButton.classList.add(typeToClassLookup[type]); - elementButton.innerHTML = buttonText; - elementButton.onclick = function () { - removeFromDocument(id, position); + var element = div(); + + var elementText = textbox(text, [options.classes.textbox, options.classes.backgroundInfo]); + + var elementButton = button(buttonText, [options.classes.button, typeToClassLookup[type]], function () { + removeFromDocument(element.id, position); removeOverlayFromDocument(); if (callback) callback();else if (callbackArg) callbackArg(); - }; + }); element.appendChild(elementText); element.appendChild(elementButton); @@ -373,36 +389,21 @@ var confirm = exports.confirm = function confirm(_ref3, submitCallbackArg, cance blur(); hideAlerts(); - var element = document.createElement('div'); - var id = generateRandomId(); - element.id = id; - - var elementText = document.createElement('div'); - elementText.classList.add(options.classes.textbox); - elementText.classList.add(options.classes.backgroundInfo); - elementText.innerHTML = '
' + text + '
'; - - var elementButtonLeft = document.createElement('div'); - elementButtonLeft.classList.add(options.classes.button); - elementButtonLeft.classList.add(options.classes.elementHalf); - elementButtonLeft.classList.add(options.classes.backgroundSuccess); - elementButtonLeft.innerHTML = submitText; - elementButtonLeft.onclick = function () { - removeFromDocument(id, position); + var element = div(); + + var elementText = textbox(text, [options.classes.textbox, options.classes.backgroundInfo]); + + var elementButtonLeft = button(submitText, [options.classes.button, options.classes.elementHalf, options.classes.backgroundSuccess], function () { + removeFromDocument(element.id, position); removeOverlayFromDocument(); if (submitCallback) submitCallback();else if (submitCallbackArg) submitCallbackArg(); - }; + }); - var elementButtonRight = document.createElement('div'); - elementButtonRight.classList.add(options.classes.button); - elementButtonRight.classList.add(options.classes.elementHalf); - elementButtonRight.classList.add(options.classes.backgroundError); - elementButtonRight.innerHTML = cancelText; - elementButtonRight.onclick = function () { - removeFromDocument(id, position); + var elementButtonRight = button(cancelText, [options.classes.button, options.classes.elementHalf, options.classes.backgroundError], function () { + removeFromDocument(element.id, position); removeOverlayFromDocument(); if (cancelCallback) cancelCallback();else if (cancelCallbackArg) cancelCallbackArg(); - }; + }); element.appendChild(elementText); element.appendChild(elementButtonLeft); @@ -432,17 +433,11 @@ var input = function input(_ref4, submitCallbackArg, cancelCallbackArg) { blur(); hideAlerts(); - var element = document.createElement('div'); - var id = generateRandomId(); - element.id = id; + var element = div(); - var elementText = document.createElement('div'); - elementText.classList.add(options.classes.textbox); - elementText.classList.add(options.classes.backgroundInfo); - elementText.innerHTML = '
' + text + '
'; + var elementText = textbox(text, [options.classes.textbox, options.classes.backgroundInfo]); - var elementInput = document.createElement('input'); - elementInput.classList.add(options.classes.inputField); + var elementInput = makeElement('input', [options.classes.inputField]); elementInput.setAttribute('autocapitalize', settings.autocapitalize || 'none'); elementInput.setAttribute('autocomplete', settings.autocomplete || 'off'); @@ -479,27 +474,17 @@ var input = function input(_ref4, submitCallbackArg, cancelCallbackArg) { }; } - var elementButtonLeft = document.createElement('div'); - elementButtonLeft.classList.add(options.classes.button); - elementButtonLeft.classList.add(options.classes.elementHalf); - elementButtonLeft.classList.add(options.classes.backgroundSuccess); - elementButtonLeft.innerHTML = submitText; - elementButtonLeft.onclick = function () { - removeFromDocument(id, position); + var elementButtonLeft = button(submitText, [options.classes.button, options.classes.elementHalf, options.classes.backgroundSuccess], function () { + removeFromDocument(element.id, position); removeOverlayFromDocument(); if (submitCallback) submitCallback(elementInput.value);else if (submitCallbackArg) submitCallbackArg(elementInput.value); - }; + }); - var elementButtonRight = document.createElement('div'); - elementButtonRight.classList.add(options.classes.button); - elementButtonRight.classList.add(options.classes.elementHalf); - elementButtonRight.classList.add(options.classes.backgroundError); - elementButtonRight.innerHTML = cancelText; - elementButtonRight.onclick = function () { - removeFromDocument(id, position); + var elementButtonRight = button(cancelText, [options.classes.button, options.classes.elementHalf, options.classes.backgroundError], function () { + removeFromDocument(element.id, position); removeOverlayFromDocument(); if (cancelCallback) cancelCallback(elementInput.value);else if (cancelCallbackArg) cancelCallbackArg(elementInput.value); - }; + }); element.appendChild(elementText); element.appendChild(elementInput); @@ -530,14 +515,9 @@ var select = exports.select = function select(_ref5, cancelCallbackArg) { blur(); hideAlerts(); - var element = document.createElement('div'); - var id = generateRandomId(); - element.id = id; + var element = div(); - var elementText = document.createElement('div'); - elementText.classList.add(options.classes.textbox); - elementText.classList.add(options.classes.backgroundInfo); - elementText.innerHTML = '
' + text + '
'; + var elementText = textbox(text, [options.classes.textbox, options.classes.backgroundInfo]); element.appendChild(elementText); @@ -547,10 +527,7 @@ var select = exports.select = function select(_ref5, cancelCallbackArg) { text = _ref6.text, handler = _ref6.handler; - var elementChoice = document.createElement('div'); - elementChoice.classList.add(typeToClassLookup[type]); - elementChoice.classList.add(options.classes.button); - elementChoice.classList.add(options.classes.selectChoice); + var elementChoice = div([typeToClassLookup[type], options.classes.button, options.classes.selectChoice]); var nextChoice = choices[index + 1]; if (nextChoice && !nextChoice.type) nextChoice.type = 1; @@ -560,7 +537,7 @@ var select = exports.select = function select(_ref5, cancelCallbackArg) { elementChoice.innerHTML = text; elementChoice.onclick = function () { - removeFromDocument(id, position); + removeFromDocument(element.id, position); removeOverlayFromDocument(); handler(); }; @@ -568,15 +545,11 @@ var select = exports.select = function select(_ref5, cancelCallbackArg) { element.appendChild(elementChoice); }); - var elementCancel = document.createElement('div'); - elementCancel.classList.add(options.classes.backgroundNeutral); - elementCancel.classList.add(options.classes.button); - elementCancel.innerHTML = cancelText; - elementCancel.onclick = function () { - removeFromDocument(id, position); + var elementCancel = button(cancelText, [options.classes.backgroundNeutral, options.classes.button], function () { + removeFromDocument(element.id, position); removeOverlayFromDocument(); if (cancelCallback) cancelCallback();else if (cancelCallbackArg) cancelCallbackArg(); - }; + }); element.appendChild(elementCancel); @@ -606,9 +579,13 @@ var date = exports.date = function date(_ref7, submitCallbackArg, cancelCallback var arrow = '▾'; - var elementDateMonth = document.createElement('div'); - var elementDateDay = document.createElement('div'); - var elementDateYear = document.createElement('div'); + var elementDateThird = function elementDateThird() { + return div([options.classes.element, options.classes.elementThird]); + }; + + var elementDateMonth = elementDateThird(); + var elementDateDay = elementDateThird(); + var elementDateYear = elementDateThird(); var setValueHTML = function setValueHTML(date) { elementDateMonth.innerHTML = options.dateMonths[date.getMonth()]; @@ -653,107 +630,63 @@ var date = exports.date = function date(_ref7, submitCallbackArg, cancelCallback setValueHTML(value); }; - var element = document.createElement('div'); - var id = generateRandomId(); - element.id = id; - - var elementDateSelector = document.createElement('div'); - elementDateSelector.classList.add(options.classes.backgroundInfo); - - var elementDateSelectorInner = document.createElement('div'); - elementDateSelectorInner.classList.add(options.classes.dateSelectorInner); + var element = div(); + var elementDateSelector = div([options.classes.backgroundInfo]); + var elementDateSelectorInner = div([options.classes.dateSelectorInner]); - var elementDateUpMonth = document.createElement('div'); - elementDateUpMonth.classList.add(options.classes.button); - elementDateUpMonth.classList.add(options.classes.elementThird); - elementDateUpMonth.classList.add(options.classes.dateSelectorUp); - elementDateUpMonth.innerHTML = arrow; + var downButton = function downButton(onclick) { + return button(arrow, [options.classes.button, options.classes.elementThird], onclick); + }; - var elementDateUpDay = document.createElement('div'); - elementDateUpDay.classList.add(options.classes.button); - elementDateUpDay.classList.add(options.classes.elementThird); - elementDateUpDay.classList.add(options.classes.dateSelectorUp); - elementDateUpDay.innerHTML = arrow; + var upButton = function upButton(onclick) { + var element = downButton(onclick); + element.classList.add(options.classes.dateSelectorUp); + return element; + }; - var elementDateUpYear = document.createElement('div'); - elementDateUpYear.classList.add(options.classes.button); - elementDateUpYear.classList.add(options.classes.elementThird); - elementDateUpYear.classList.add(options.classes.dateSelectorUp); - elementDateUpYear.innerHTML = arrow; + var elementDateUpMonth = upButton(function () { + return updateMonth(1); + }); + var elementDateUpDay = upButton(function () { + return updateDay(1); + }); + var elementDateUpYear = upButton(function () { + return updateYear(1); + }); - elementDateMonth.classList.add(options.classes.element); - elementDateMonth.classList.add(options.classes.elementThird); elementDateMonth.innerHTML = options.dateMonths[value.getMonth()]; - elementDateDay.classList.add(options.classes.element); - elementDateDay.classList.add(options.classes.elementThird); elementDateDay.setAttribute('contentEditable', true); elementDateDay.addEventListener('input', handleDayInput); elementDateDay.addEventListener('blur', handleBlur); elementDateDay.innerHTML = value.getDate(); - elementDateYear.classList.add(options.classes.element); - elementDateYear.classList.add(options.classes.elementThird); elementDateYear.setAttribute('contentEditable', true); elementDateYear.addEventListener('input', handleYearInput); elementDateYear.addEventListener('blur', handleBlur); elementDateYear.innerHTML = value.getFullYear(); - var elementDateDownMonth = document.createElement('div'); - elementDateDownMonth.classList.add(options.classes.button); - elementDateDownMonth.classList.add(options.classes.elementThird); - elementDateDownMonth.innerHTML = arrow; - - var elementDateDownDay = document.createElement('div'); - elementDateDownDay.classList.add(options.classes.button); - elementDateDownDay.classList.add(options.classes.elementThird); - elementDateDownDay.innerHTML = arrow; - - var elementDateDownYear = document.createElement('div'); - elementDateDownYear.classList.add(options.classes.button); - elementDateDownYear.classList.add(options.classes.elementThird); - elementDateDownYear.innerHTML = arrow; - - elementDateUpMonth.onclick = function () { - return updateMonth(1); - }; - elementDateUpDay.onclick = function () { - return updateDay(1); - }; - elementDateUpYear.onclick = function () { - return updateYear(1); - }; - elementDateDownMonth.onclick = function () { + var elementDateDownMonth = downButton(function () { return updateMonth(-1); - }; - elementDateDownDay.onclick = function () { + }); + var elementDateDownDay = downButton(function () { return updateDay(-1); - }; - elementDateDownYear.onclick = function () { + }); + var elementDateDownYear = downButton(function () { return updateYear(-1); - }; + }); - var elementButtonLeft = document.createElement('div'); - elementButtonLeft.classList.add(options.classes.button); - elementButtonLeft.classList.add(options.classes.elementHalf); - elementButtonLeft.classList.add(options.classes.backgroundSuccess); - elementButtonLeft.innerHTML = submitText; - elementButtonLeft.onclick = function () { - removeFromDocument(id, position); + var elementButtonLeft = button(submitText, [options.classes.button, options.classes.elementHalf, options.classes.backgroundSuccess], function () { + removeFromDocument(element.id, position); removeOverlayFromDocument(); if (submitCallback) submitCallback(value);else if (submitCallbackArg) submitCallbackArg(value); - }; + }); - var elementButtonRight = document.createElement('div'); - elementButtonRight.classList.add(options.classes.button); - elementButtonRight.classList.add(options.classes.elementHalf); - elementButtonRight.classList.add(options.classes.backgroundError); - elementButtonRight.innerHTML = cancelText; - elementButtonRight.onclick = function () { - removeFromDocument(id, position); + var elementButtonRight = button(cancelText, [options.classes.button, options.classes.elementHalf, options.classes.backgroundError], function () { + removeFromDocument(element.id, position); removeOverlayFromDocument(); if (cancelCallback) cancelCallback(value);else if (cancelCallbackArg) cancelCallbackArg(value); - }; + }); elementDateSelectorInner.appendChild(elementDateUpMonth); elementDateSelectorInner.appendChild(elementDateUpDay); diff --git a/dist/notie.min.js b/dist/notie.min.js index 1f6cd08..44731ba 100644 --- a/dist/notie.min.js +++ b/dist/notie.min.js @@ -1 +1 @@ -!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){function t(s){if(n[s])return n[s].exports;var a=n[s]={i:s,l:!1,exports:{}};return e[s].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,s){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:s})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";(function(e){var n,s,a,i="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};!function(c,o){"object"===i(t)&&"object"===i(e)?e.exports=o():(s=[],n=o,a="function"==typeof n?n.apply(t,s):n,!(void 0!==a&&(e.exports=a)))}(void 0,function(){return function(e){function t(s){if(n[s])return n[s].exports;var a=n[s]={i:s,l:!1,exports:{}};return e[s].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,s){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:s})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){function s(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}Object.defineProperty(t,"__esModule",{value:!0});var a="function"==typeof Symbol&&"symbol"===i(Symbol.iterator)?function(e){return"undefined"==typeof e?"undefined":i(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":"undefined"==typeof e?"undefined":i(e)},c=Object.assign||function(e){for(var t=1;t'+s+"",v.onclick=function(){return L(g,d)},v.listener=function(e){(b(e)||x(e))&&k()},y(v,d),i&&i<1&&(i=1),!o&&i&&u(i).then(function(){return L(g,d)})},E=t.force=function(e,t){var n=e.type,s=void 0===n?5:n,a=e.text,i=e.buttonText,c=void 0===i?"OK":i,o=e.callback,l=e.position,d=void 0===l?r.positions.force||d.top:l;p(),k();var u=document.createElement("div"),v=f();u.id=v;var x=document.createElement("div");x.classList.add(r.classes.textbox),x.classList.add(r.classes.backgroundInfo),x.innerHTML='
'+a+"
";var C=document.createElement("div");C.classList.add(r.classes.button),C.classList.add(m[s]),C.innerHTML=c,C.onclick=function(){L(v,d),h(),o?o():t&&t()},u.appendChild(x),u.appendChild(C),u.listener=function(e){b(e)&&C.click()},y(u,d),g()},T=t.confirm=function(e,t,n){var s=e.text,a=e.submitText,i=void 0===a?"Yes":a,c=e.cancelText,o=void 0===c?"Cancel":c,l=e.submitCallback,d=e.cancelCallback,u=e.position,m=void 0===u?r.positions.confirm||m.top:u;p(),k();var v=document.createElement("div"),C=f();v.id=C;var E=document.createElement("div");E.classList.add(r.classes.textbox),E.classList.add(r.classes.backgroundInfo),E.innerHTML='
'+s+"
";var T=document.createElement("div");T.classList.add(r.classes.button),T.classList.add(r.classes.elementHalf),T.classList.add(r.classes.backgroundSuccess),T.innerHTML=i,T.onclick=function(){L(C,m),h(),l?l():t&&t()};var M=document.createElement("div");M.classList.add(r.classes.button),M.classList.add(r.classes.elementHalf),M.classList.add(r.classes.backgroundError),M.innerHTML=o,M.onclick=function(){L(C,m),h(),d?d():n&&n()},v.appendChild(E),v.appendChild(T),v.appendChild(M),v.listener=function(e){b(e)?T.click():x(e)&&M.click()},y(v,m),g(v,m)},M=function(e,t,n){var i=e.text,c=e.submitText,o=void 0===c?"Submit":c,l=e.cancelText,d=void 0===l?"Cancel":l,u=e.submitCallback,m=e.cancelCallback,v=e.position,C=void 0===v?r.positions.input||C.top:v,E=s(e,["text","submitText","cancelText","submitCallback","cancelCallback","position"]);p(),k();var T=document.createElement("div"),M=f();T.id=M;var H=document.createElement("div");H.classList.add(r.classes.textbox),H.classList.add(r.classes.backgroundInfo),H.innerHTML='
'+i+"
";var S=document.createElement("input");S.classList.add(r.classes.inputField),S.setAttribute("autocapitalize",E.autocapitalize||"none"),S.setAttribute("autocomplete",E.autocomplete||"off"),S.setAttribute("autocorrect",E.autocorrect||"off"),S.setAttribute("autofocus",E.autofocus||"true"),S.setAttribute("inputmode",E.inputmode||"verbatim"),S.setAttribute("max",E.max||""),S.setAttribute("maxlength",E.maxlength||""),S.setAttribute("min",E.min||""),S.setAttribute("minlength",E.minlength||""),S.setAttribute("placeholder",E.placeholder||""),S.setAttribute("spellcheck",E.spellcheck||"default"),S.setAttribute("step",E.step||"any"),S.setAttribute("type",E.type||"text"),S.value=E.value||"",E.allowed&&(S.oninput=function(){var e=void 0;if(Array.isArray(E.allowed)){for(var t="",n=E.allowed,s=0;s'+n+"",d.appendChild(v),c.forEach(function(e,t){var n=e.type,s=void 0===n?1:n,a=e.text,i=e.handler,o=document.createElement("div");o.classList.add(m[s]),o.classList.add(r.classes.button),o.classList.add(r.classes.selectChoice);var p=c[t+1];p&&!p.type&&(p.type=1),p&&p.type===s&&o.classList.add(r.classes.selectChoiceRepeated),o.innerHTML=a,o.onclick=function(){L(u,l),h(),i()},d.appendChild(o)});var b=document.createElement("div");b.classList.add(r.classes.backgroundNeutral),b.classList.add(r.classes.button),b.innerHTML=a,b.onclick=function(){L(u,l),h(),i?i():t&&t()},d.appendChild(b),d.listener=function(e){x(e)&&b.click()},y(d,l),g(d,l)},S=t.date=function(e,t,n){var s=e.value,a=void 0===s?new Date:s,i=e.submitText,c=void 0===i?"OK":i,o=e.cancelText,l=void 0===o?"Cancel":o,d=e.submitCallback,u=e.cancelCallback,m=e.position,v=void 0===m?r.positions.date||v.top:m;p(),k();var C="▾",E=document.createElement("div"),T=document.createElement("div"),M=document.createElement("div"),H=function(e){E.innerHTML=r.dateMonths[e.getMonth()],T.innerHTML=e.getDate(),M.innerHTML=e.getFullYear()},S=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))},w=function(e){var t=e.target.textContent.replace(/^0+/,"").replace(/[^\d]/g,"").slice(0,4);e.target.textContent=t,a.setFullYear(Number(t))},O=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)},D=function(e){a.setDate(a.getDate()+e),H(a)},I=function(e){var t=a.getFullYear()+e;t<0?a.setFullYear(0):a.setFullYear(a.getFullYear()+e),H(a)},j=document.createElement("div"),N=f();j.id=N;var P=document.createElement("div");P.classList.add(r.classes.backgroundInfo);var F=document.createElement("div");F.classList.add(r.classes.dateSelectorInner);var Y=document.createElement("div");Y.classList.add(r.classes.button),Y.classList.add(r.classes.elementThird),Y.classList.add(r.classes.dateSelectorUp),Y.innerHTML=C;var _=document.createElement("div");_.classList.add(r.classes.button),_.classList.add(r.classes.elementThird),_.classList.add(r.classes.dateSelectorUp),_.innerHTML=C;var z=document.createElement("div");z.classList.add(r.classes.button),z.classList.add(r.classes.elementThird),z.classList.add(r.classes.dateSelectorUp),z.innerHTML=C,E.classList.add(r.classes.element),E.classList.add(r.classes.elementThird),E.innerHTML=r.dateMonths[a.getMonth()],T.classList.add(r.classes.element),T.classList.add(r.classes.elementThird),T.setAttribute("contentEditable",!0),T.addEventListener("input",S),T.addEventListener("blur",O),T.innerHTML=a.getDate(),M.classList.add(r.classes.element),M.classList.add(r.classes.elementThird),M.setAttribute("contentEditable",!0),M.addEventListener("input",w),M.addEventListener("blur",O),M.innerHTML=a.getFullYear();var U=document.createElement("div");U.classList.add(r.classes.button),U.classList.add(r.classes.elementThird),U.innerHTML=C;var B=document.createElement("div");B.classList.add(r.classes.button),B.classList.add(r.classes.elementThird),B.innerHTML=C;var J=document.createElement("div");J.classList.add(r.classes.button),J.classList.add(r.classes.elementThird),J.innerHTML=C,Y.onclick=function(){return A(1)},_.onclick=function(){return D(1)},z.onclick=function(){return I(1)},U.onclick=function(){return A(-1)},B.onclick=function(){return D(-1)},J.onclick=function(){return I(-1)};var R=document.createElement("div");R.classList.add(r.classes.button),R.classList.add(r.classes.elementHalf),R.classList.add(r.classes.backgroundSuccess),R.innerHTML=c,R.onclick=function(){L(N,v),h(),d?d(a):t&&t(a)};var W=document.createElement("div");W.classList.add(r.classes.button),W.classList.add(r.classes.elementHalf),W.classList.add(r.classes.backgroundError),W.innerHTML=l,W.onclick=function(){L(N,v),h(),u?u(a):n&&n(a)},F.appendChild(Y),F.appendChild(_),F.appendChild(z),F.appendChild(E),F.appendChild(T),F.appendChild(M),F.appendChild(U),F.appendChild(B),F.appendChild(J),P.appendChild(F),j.appendChild(P),j.appendChild(R),j.appendChild(W),j.listener=function(e){b(e)?R.click():x(e)&&W.click()},y(j,v),g(j,v)};t.default={alert:C,force:E,confirm:T,input:M,select:H,date:S,setOptions:l,hideAlerts:k}}])})}).call(t,n(0)(e))}])}); \ No newline at end of file +!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){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";(function(e){var n,o,r,i="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};!function(a,s){"object"===i(t)&&"object"===i(e)?e.exports=s():(o=[],n=s,r="function"==typeof n?n.apply(t,o):n,!(void 0!==r&&(e.exports=r)))}(void 0,function(){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){function o(e,t){var n={};for(var o in e)t.indexOf(o)>=0||Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n}Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"===i(Symbol.iterator)?function(e){return"undefined"==typeof e?"undefined":i(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":"undefined"==typeof e?"undefined":i(e)},a=Object.assign||function(e){for(var t=1;t'+e+"",n},O=t.alert=function(e){var t=e.type,n=void 0===t?4:t,o=e.text,r=e.time,i=void 0===r?c.alertTime:r,a=e.stay,s=void 0!==a&&a,l=e.position,u=void 0===l?c.positions.alert||u.top:l;p(),S();var f=M(o,[c.classes.textbox,b[n],c.classes.alert]);f.position=u,f.onclick=function(){return h(f.id,u)},f.listener=function(e){(m(e)||y(e))&&S()},g(f,u),i&&i<1&&(i=1),!s&&i&&d(i).then(function(){return h(f.id,u)})},A=t.force=function(e,t){var n=e.type,o=void 0===n?5:n,r=e.text,i=e.buttonText,a=void 0===i?"OK":i,s=e.callback,l=e.position,u=void 0===l?c.positions.force||u.top:l;p(),S();var d=T(),f=M(r,[c.classes.textbox,c.classes.backgroundInfo]),v=w(a,[c.classes.button,b[o]],function(){h(d.id,u),C(),s?s():t&&t()});d.appendChild(f),d.appendChild(v),d.listener=function(e){m(e)&&v.click()},g(d,u),k()},E=t.confirm=function(e,t,n){var o=e.text,r=e.submitText,i=void 0===r?"Yes":r,a=e.cancelText,s=void 0===a?"Cancel":a,l=e.submitCallback,u=e.cancelCallback,d=e.position,f=void 0===d?c.positions.confirm||f.top:d;p(),S();var b=T(),v=M(o,[c.classes.textbox,c.classes.backgroundInfo]),x=w(i,[c.classes.button,c.classes.elementHalf,c.classes.backgroundSuccess],function(){h(b.id,f),C(),l?l():t&&t()}),O=w(s,[c.classes.button,c.classes.elementHalf,c.classes.backgroundError],function(){h(b.id,f),C(),u?u():n&&n()});b.appendChild(v),b.appendChild(x),b.appendChild(O),b.listener=function(e){m(e)?x.click():y(e)&&O.click()},g(b,f),k(b,f)},D=function(e,t,n){var i=e.text,a=e.submitText,s=void 0===a?"Submit":a,l=e.cancelText,u=void 0===l?"Cancel":l,d=e.submitCallback,f=e.cancelCallback,b=e.position,v=void 0===b?c.positions.input||v.top:b,O=o(e,["text","submitText","cancelText","submitCallback","cancelCallback","position"]);p(),S();var A=T(),E=M(i,[c.classes.textbox,c.classes.backgroundInfo]),D=x("input",[c.classes.inputField]);D.setAttribute("autocapitalize",O.autocapitalize||"none"),D.setAttribute("autocomplete",O.autocomplete||"off"),D.setAttribute("autocorrect",O.autocorrect||"off"),D.setAttribute("autofocus",O.autofocus||"true"),D.setAttribute("inputmode",O.inputmode||"verbatim"),D.setAttribute("max",O.max||""),D.setAttribute("maxlength",O.maxlength||""),D.setAttribute("min",O.min||""),D.setAttribute("minlength",O.minlength||""),D.setAttribute("placeholder",O.placeholder||""),D.setAttribute("spellcheck",O.spellcheck||"default"),D.setAttribute("step",O.step||"any"),D.setAttribute("type",O.type||"text"),D.value=O.value||"",O.allowed&&(D.oninput=function(){var e=void 0;if(Array.isArray(O.allowed)){for(var t="",n=O.allowed,o=0;ot&&(n=t.toString()),e.target.textContent=n,Number(n)<1&&(n="1"),r.setDate(Number(n))},L=function(e){var t=e.target.textContent.replace(/^0+/,"").replace(/[^\d]/g,"").slice(0,4);e.target.textContent=t,r.setFullYear(Number(t))},H=function(e){E(r)},j=function(e){var t=new Date(r.getFullYear(),r.getMonth()+e+1,0).getDate();r.getDate()>t&&r.setDate(t),r.setMonth(r.getMonth()+e),E(r)},I=function(e){r.setDate(r.getDate()+e),E(r)},N=function(e){var t=r.getFullYear()+e;t<0?r.setFullYear(0):r.setFullYear(r.getFullYear()+e),E(r)},P=T(),F=T([c.classes.backgroundInfo]),Y=T([c.classes.dateSelectorInner]),_=function(e){return w(v,[c.classes.button,c.classes.elementThird],e)},z=function(e){var t=_(e);return t.classList.add(c.classes.dateSelectorUp),t},B=z(function(){return j(1)}),J=z(function(){return I(1)}),R=z(function(){return N(1)});M.innerHTML=c.dateMonths[r.getMonth()],O.setAttribute("contentEditable",!0),O.addEventListener("input",D),O.addEventListener("blur",H),O.innerHTML=r.getDate(),A.setAttribute("contentEditable",!0),A.addEventListener("input",L),A.addEventListener("blur",H),A.innerHTML=r.getFullYear();var W=_(function(){return j(-1)}),K=_(function(){return I(-1)}),U=_(function(){return N(-1)}),Z=w(a,[c.classes.button,c.classes.elementHalf,c.classes.backgroundSuccess],function(){h(P.id,b),C(),u?u(r):t&&t(r)}),q=w(l,[c.classes.button,c.classes.elementHalf,c.classes.backgroundError],function(){h(P.id,b),C(),d?d(r):n&&n(r)});Y.appendChild(B),Y.appendChild(J),Y.appendChild(R),Y.appendChild(M),Y.appendChild(O),Y.appendChild(A),Y.appendChild(W),Y.appendChild(K),Y.appendChild(U),F.appendChild(Y),P.appendChild(F),P.appendChild(Z),P.appendChild(q),P.listener=function(e){m(e)?Z.click():y(e)&&q.click()},g(P,b),k(P,b)};t.default={alert:O,force:A,confirm:E,input:D,select:L,date:H,setOptions:l,hideAlerts:S}}])})}).call(t,n(0)(e))}])}); \ No newline at end of file diff --git a/src/notie.js b/src/notie.js index 03d1d27..641eacc 100644 --- a/src/notie.js +++ b/src/notie.js @@ -101,6 +101,14 @@ const getTransition = () => ( const enterClicked = event => event.keyCode === 13 const escapeClicked = event => event.keyCode === 27 +const makeElement = (elemType, classes) => { + const element = document.createElement(elemType) + if (classes) { + classes.forEach(c => element.classList.add(c)) + } + return element +} + const addToDocument = (element, position) => { element.classList.add(options.classes.container) element.style[position] = '-10000px' @@ -128,10 +136,11 @@ const removeFromDocument = (id, position) => { } const addOverlayToDocument = (owner, position) => { - const element = document.createElement('div') + const element = makeElement('div', [ + options.classes.overlay, + options.classes.backgroundOverlay + ]) element.id = options.ids.overlay - element.classList.add(options.classes.overlay) - element.classList.add(options.classes.backgroundOverlay) element.style.opacity = 0 if (owner && options.overlayClickDismiss) { element.onclick = () => { @@ -167,6 +176,29 @@ export const hideAlerts = callback => { } } +// ==================== +// shared elements +// ==================== + +const div = classes => { + const element = makeElement('div', classes) + element.id = generateRandomId() + return element +} + +const button = (innerHTML, classes, onclick) => { + const element = makeElement('div', classes) + element.innerHTML = innerHTML + element.onclick = onclick + return element +} + +const textbox = (text, classes) => { + const element = div(classes) + element.innerHTML = `
${text}
` + return element +} + // ==================== // exports // ==================== @@ -181,15 +213,13 @@ export const alert = ({ blur() hideAlerts() - const element = document.createElement('div') - const id = generateRandomId() - element.id = id + const element = textbox(text, [ + options.classes.textbox, + typeToClassLookup[type], + options.classes.alert + ]) element.position = position - element.classList.add(options.classes.textbox) - element.classList.add(typeToClassLookup[type]) - element.classList.add(options.classes.alert) - element.innerHTML = `
${text}
` - element.onclick = () => removeFromDocument(id, position) + element.onclick = () => removeFromDocument(element.id, position) element.listener = event => { if (enterClicked(event) || escapeClicked(event)) hideAlerts() @@ -198,7 +228,7 @@ export const alert = ({ addToDocument(element, position) if (time && time < 1) time = 1 - if (!stay && time) wait(time).then(() => removeFromDocument(id, position)) + if (!stay && time) wait(time).then(() => removeFromDocument(element.id, position)) } export const force = ({ @@ -211,25 +241,22 @@ export const force = ({ blur() hideAlerts() - const element = document.createElement('div') - const id = generateRandomId() - element.id = id - - const elementText = document.createElement('div') - elementText.classList.add(options.classes.textbox) - elementText.classList.add(options.classes.backgroundInfo) - elementText.innerHTML = `
${text}
` - - const elementButton = document.createElement('div') - elementButton.classList.add(options.classes.button) - elementButton.classList.add(typeToClassLookup[type]) - elementButton.innerHTML = buttonText - elementButton.onclick = () => { - removeFromDocument(id, position) + const element = div() + + const elementText = textbox(text, [ + options.classes.textbox, + options.classes.backgroundInfo + ]) + + const elementButton = button(buttonText, [ + options.classes.button, + typeToClassLookup[type] + ], () => { + removeFromDocument(element.id, position) removeOverlayFromDocument() if (callback) callback() else if (callbackArg) callbackArg() - } + }) element.appendChild(elementText) element.appendChild(elementButton) @@ -254,38 +281,34 @@ export const confirm = ({ blur() hideAlerts() - const element = document.createElement('div') - const id = generateRandomId() - element.id = id - - const elementText = document.createElement('div') - elementText.classList.add(options.classes.textbox) - elementText.classList.add(options.classes.backgroundInfo) - elementText.innerHTML = `
${text}
` - - const elementButtonLeft = document.createElement('div') - elementButtonLeft.classList.add(options.classes.button) - elementButtonLeft.classList.add(options.classes.elementHalf) - elementButtonLeft.classList.add(options.classes.backgroundSuccess) - elementButtonLeft.innerHTML = submitText - elementButtonLeft.onclick = () => { - removeFromDocument(id, position) + const element = div() + + const elementText = textbox(text, [ + options.classes.textbox, + options.classes.backgroundInfo + ]) + + const elementButtonLeft = button(submitText, [ + options.classes.button, + options.classes.elementHalf, + options.classes.backgroundSuccess + ], () => { + removeFromDocument(element.id, position) removeOverlayFromDocument() if (submitCallback) submitCallback() else if (submitCallbackArg) submitCallbackArg() - } + }) - const elementButtonRight = document.createElement('div') - elementButtonRight.classList.add(options.classes.button) - elementButtonRight.classList.add(options.classes.elementHalf) - elementButtonRight.classList.add(options.classes.backgroundError) - elementButtonRight.innerHTML = cancelText - elementButtonRight.onclick = () => { - removeFromDocument(id, position) + const elementButtonRight = button(cancelText, [ + options.classes.button, + options.classes.elementHalf, + options.classes.backgroundError + ], () => { + removeFromDocument(element.id, position) removeOverlayFromDocument() if (cancelCallback) cancelCallback() else if (cancelCallbackArg) cancelCallbackArg() - } + }) element.appendChild(elementText) element.appendChild(elementButtonLeft) @@ -313,17 +336,16 @@ export const input = ({ blur() hideAlerts() - const element = document.createElement('div') - const id = generateRandomId() - element.id = id + const element = div() - const elementText = document.createElement('div') - elementText.classList.add(options.classes.textbox) - elementText.classList.add(options.classes.backgroundInfo) - elementText.innerHTML = `
${text}
` + const elementText = textbox(text, [ + options.classes.textbox, + options.classes.backgroundInfo + ]) - const elementInput = document.createElement('input') - elementInput.classList.add(options.classes.inputField) + const elementInput = makeElement('input', [ + options.classes.inputField + ]) elementInput.setAttribute('autocapitalize', settings.autocapitalize || 'none') elementInput.setAttribute('autocomplete', settings.autocomplete || 'off') @@ -362,29 +384,27 @@ export const input = ({ } } - const elementButtonLeft = document.createElement('div') - elementButtonLeft.classList.add(options.classes.button) - elementButtonLeft.classList.add(options.classes.elementHalf) - elementButtonLeft.classList.add(options.classes.backgroundSuccess) - elementButtonLeft.innerHTML = submitText - elementButtonLeft.onclick = () => { - removeFromDocument(id, position) + const elementButtonLeft = button(submitText, [ + options.classes.button, + options.classes.elementHalf, + options.classes.backgroundSuccess + ], () => { + removeFromDocument(element.id, position) removeOverlayFromDocument() if (submitCallback) submitCallback(elementInput.value) else if (submitCallbackArg) submitCallbackArg(elementInput.value) - } + }) - const elementButtonRight = document.createElement('div') - elementButtonRight.classList.add(options.classes.button) - elementButtonRight.classList.add(options.classes.elementHalf) - elementButtonRight.classList.add(options.classes.backgroundError) - elementButtonRight.innerHTML = cancelText - elementButtonRight.onclick = () => { - removeFromDocument(id, position) + const elementButtonRight = button(cancelText, [ + options.classes.button, + options.classes.elementHalf, + options.classes.backgroundError + ], () => { + removeFromDocument(element.id, position) removeOverlayFromDocument() if (cancelCallback) cancelCallback(elementInput.value) else if (cancelCallbackArg) cancelCallbackArg(elementInput.value) - } + }) element.appendChild(elementText) element.appendChild(elementInput) @@ -413,22 +433,21 @@ export const select = ({ blur() hideAlerts() - const element = document.createElement('div') - const id = generateRandomId() - element.id = id + const element = div() - const elementText = document.createElement('div') - elementText.classList.add(options.classes.textbox) - elementText.classList.add(options.classes.backgroundInfo) - elementText.innerHTML = `
${text}
` + const elementText = textbox(text, [ + options.classes.textbox, + options.classes.backgroundInfo + ]) element.appendChild(elementText) choices.forEach(({ type = 1, text, handler }, index) => { - const elementChoice = document.createElement('div') - elementChoice.classList.add(typeToClassLookup[type]) - elementChoice.classList.add(options.classes.button) - elementChoice.classList.add(options.classes.selectChoice) + const elementChoice = div([ + typeToClassLookup[type], + options.classes.button, + options.classes.selectChoice + ]) const nextChoice = choices[index + 1] if (nextChoice && !nextChoice.type) nextChoice.type = 1 @@ -438,7 +457,7 @@ export const select = ({ elementChoice.innerHTML = text elementChoice.onclick = () => { - removeFromDocument(id, position) + removeFromDocument(element.id, position) removeOverlayFromDocument() handler() } @@ -446,16 +465,15 @@ export const select = ({ element.appendChild(elementChoice) }) - const elementCancel = document.createElement('div') - elementCancel.classList.add(options.classes.backgroundNeutral) - elementCancel.classList.add(options.classes.button) - elementCancel.innerHTML = cancelText - elementCancel.onclick = () => { - removeFromDocument(id, position) + const elementCancel = button(cancelText, [ + options.classes.backgroundNeutral, + options.classes.button + ], () => { + removeFromDocument(element.id, position) removeOverlayFromDocument() if (cancelCallback) cancelCallback() else if (cancelCallbackArg) cancelCallbackArg() - } + }) element.appendChild(elementCancel) @@ -481,9 +499,14 @@ export const date = ({ const arrow = '▾' - const elementDateMonth = document.createElement('div') - const elementDateDay = document.createElement('div') - const elementDateYear = document.createElement('div') + const elementDateThird = () => div([ + options.classes.element, + options.classes.elementThird + ]) + + const elementDateMonth = elementDateThird() + const elementDateDay = elementDateThird() + const elementDateYear = elementDateThird() const setValueHTML = date => { elementDateMonth.innerHTML = options.dateMonths[date.getMonth()] @@ -543,97 +566,62 @@ export const date = ({ setValueHTML(value) } - const element = document.createElement('div') - const id = generateRandomId() - element.id = id - - const elementDateSelector = document.createElement('div') - elementDateSelector.classList.add(options.classes.backgroundInfo) - - const elementDateSelectorInner = document.createElement('div') - elementDateSelectorInner.classList.add(options.classes.dateSelectorInner) + const element = div() + const elementDateSelector = div([options.classes.backgroundInfo]) + const elementDateSelectorInner = div([options.classes.dateSelectorInner]) - const elementDateUpMonth = document.createElement('div') - elementDateUpMonth.classList.add(options.classes.button) - elementDateUpMonth.classList.add(options.classes.elementThird) - elementDateUpMonth.classList.add(options.classes.dateSelectorUp) - elementDateUpMonth.innerHTML = arrow + const downButton = onclick => button(arrow, [ + options.classes.button, + options.classes.elementThird + ], onclick) - const elementDateUpDay = document.createElement('div') - elementDateUpDay.classList.add(options.classes.button) - elementDateUpDay.classList.add(options.classes.elementThird) - elementDateUpDay.classList.add(options.classes.dateSelectorUp) - elementDateUpDay.innerHTML = arrow + const upButton = onclick => { + const element = downButton(onclick) + element.classList.add(options.classes.dateSelectorUp) + return element + } - const elementDateUpYear = document.createElement('div') - elementDateUpYear.classList.add(options.classes.button) - elementDateUpYear.classList.add(options.classes.elementThird) - elementDateUpYear.classList.add(options.classes.dateSelectorUp) - elementDateUpYear.innerHTML = arrow + const elementDateUpMonth = upButton(() => updateMonth(1)) + const elementDateUpDay = upButton(() => updateDay(1)) + const elementDateUpYear = upButton(() => updateYear(1)) - elementDateMonth.classList.add(options.classes.element) - elementDateMonth.classList.add(options.classes.elementThird) elementDateMonth.innerHTML = options.dateMonths[value.getMonth()] - elementDateDay.classList.add(options.classes.element) - elementDateDay.classList.add(options.classes.elementThird) elementDateDay.setAttribute('contentEditable', true) elementDateDay.addEventListener('input', handleDayInput) elementDateDay.addEventListener('blur', handleBlur) elementDateDay.innerHTML = value.getDate() - elementDateYear.classList.add(options.classes.element) - elementDateYear.classList.add(options.classes.elementThird) elementDateYear.setAttribute('contentEditable', true) elementDateYear.addEventListener('input', handleYearInput) elementDateYear.addEventListener('blur', handleBlur) elementDateYear.innerHTML = value.getFullYear() - const elementDateDownMonth = document.createElement('div') - elementDateDownMonth.classList.add(options.classes.button) - elementDateDownMonth.classList.add(options.classes.elementThird) - elementDateDownMonth.innerHTML = arrow - - const elementDateDownDay = document.createElement('div') - elementDateDownDay.classList.add(options.classes.button) - elementDateDownDay.classList.add(options.classes.elementThird) - elementDateDownDay.innerHTML = arrow - - const elementDateDownYear = document.createElement('div') - elementDateDownYear.classList.add(options.classes.button) - elementDateDownYear.classList.add(options.classes.elementThird) - elementDateDownYear.innerHTML = arrow - - elementDateUpMonth.onclick = () => updateMonth(1) - elementDateUpDay.onclick = () => updateDay(1) - elementDateUpYear.onclick = () => updateYear(1) - elementDateDownMonth.onclick = () => updateMonth(-1) - elementDateDownDay.onclick = () => updateDay(-1) - elementDateDownYear.onclick = () => updateYear(-1) - - const elementButtonLeft = document.createElement('div') - elementButtonLeft.classList.add(options.classes.button) - elementButtonLeft.classList.add(options.classes.elementHalf) - elementButtonLeft.classList.add(options.classes.backgroundSuccess) - elementButtonLeft.innerHTML = submitText - elementButtonLeft.onclick = () => { - removeFromDocument(id, position) + const elementDateDownMonth = downButton(() => updateMonth(-1)) + const elementDateDownDay = downButton(() => updateDay(-1)) + const elementDateDownYear = downButton(() => updateYear(-1)) + + const elementButtonLeft = button(submitText, [ + options.classes.button, + options.classes.elementHalf, + options.classes.backgroundSuccess + ], () => { + removeFromDocument(element.id, position) removeOverlayFromDocument() if (submitCallback) submitCallback(value) else if (submitCallbackArg) submitCallbackArg(value) - } + }) - const elementButtonRight = document.createElement('div') - elementButtonRight.classList.add(options.classes.button) - elementButtonRight.classList.add(options.classes.elementHalf) - elementButtonRight.classList.add(options.classes.backgroundError) - elementButtonRight.innerHTML = cancelText - elementButtonRight.onclick = () => { - removeFromDocument(id, position) + const elementButtonRight = button(cancelText, [ + options.classes.button, + options.classes.elementHalf, + options.classes.backgroundError + ], () => { + removeFromDocument(element.id, position) removeOverlayFromDocument() if (cancelCallback) cancelCallback(value) else if (cancelCallbackArg) cancelCallbackArg(value) - } + }) elementDateSelectorInner.appendChild(elementDateUpMonth) elementDateSelectorInner.appendChild(elementDateUpDay)