diff --git a/dist/notie.js b/dist/notie.js index 372cf12..1147771 100644 --- a/dist/notie.js +++ b/dist/notie.js @@ -585,6 +585,53 @@ 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 setValueHTML = function setValueHTML(date) { + elementDateMonth.innerHTML = options.dateMonths[date.getMonth()]; + elementDateDay.innerHTML = date.getDate(); + elementDateYear.innerHTML = date.getFullYear(); + }; + + var handleDayInput = function handleDayInput(event) { + var daysInMonth = new Date(value.getFullYear(), value.getMonth() + 1, 0).getDate(); + var day = event.target.textContent.replace(/^0+/, '').replace(/[^\d]/g, '').slice(0, 2); + if (Number(day) > daysInMonth) day = daysInMonth.toString(); + event.target.textContent = day; + if (Number(day) < 1) day = '1'; + value.setDate(Number(day)); + }; + + var handleYearInput = function handleYearInput(event) { + var year = event.target.textContent.replace(/^0+/, '').replace(/[^\d]/g, '').slice(0, 4); + event.target.textContent = year; + value.setFullYear(Number(year)); + }; + + var handleBlur = function handleBlur(event) { + setValueHTML(value); + }; + + var updateMonth = function updateMonth(amount) { + var daysInNextMonth = new Date(value.getFullYear(), value.getMonth() + amount + 1, 0).getDate(); + if (value.getDate() > daysInNextMonth) value.setDate(daysInNextMonth); + value.setMonth(value.getMonth() + amount); + setValueHTML(value); + }; + + var updateDay = function updateDay(amount) { + value.setDate(value.getDate() + amount); + setValueHTML(value); + }; + + var updateYear = function updateYear(amount) { + var nextYear = value.getFullYear() + amount; + if (nextYear < 0) value.setFullYear(0);else value.setFullYear(value.getFullYear() + amount); + setValueHTML(value); + }; + var element = document.createElement('div'); var id = generateRandomId(); element.id = id; @@ -613,38 +660,22 @@ var date = exports.date = function date(_ref7, submitCallbackArg, cancelCallback elementDateUpYear.classList.add(options.classes.dateSelectorUp); elementDateUpYear.innerHTML = arrow; - var elementDateMonth = document.createElement('div'); elementDateMonth.classList.add(options.classes.element); elementDateMonth.classList.add(options.classes.elementThird); elementDateMonth.innerHTML = options.dateMonths[value.getMonth()]; - var handleDayInput = function handleDayInput(event) { - var daysInMonth = new Date(value.getFullYear(), value.getMonth() + 1, 0).getDate(); - var day = event.target.textContent.replace(/^0+/, '').replace(/[^\d]/g, '').slice(0, 2); - if (Number(day) > daysInMonth) day = daysInMonth.toString(); - event.target.textContent = day; - if (Number(day) < 1) day = '1'; - value.setDate(Number(day)); - }; - - var elementDateDay = document.createElement('div'); 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(); - var handleYearInput = function handleYearInput(event) { - var year = event.target.textContent.replace(/^0+/, '').replace(/[^\d]/g, '').slice(0, 4); - event.target.textContent = year; - value.setFullYear(Number(year)); - }; - - var elementDateYear = document.createElement('div'); 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'); @@ -662,30 +693,6 @@ var date = exports.date = function date(_ref7, submitCallbackArg, cancelCallback elementDateDownYear.classList.add(options.classes.elementThird); elementDateDownYear.innerHTML = arrow; - var setValueHTML = function setValueHTML(date) { - elementDateMonth.innerHTML = options.dateMonths[date.getMonth()]; - elementDateDay.innerHTML = date.getDate(); - elementDateYear.innerHTML = date.getFullYear(); - }; - - var updateMonth = function updateMonth(amount) { - var daysInNextMonth = new Date(value.getFullYear(), value.getMonth() + amount + 1, 0).getDate(); - if (value.getDate() > daysInNextMonth) value.setDate(daysInNextMonth); - value.setMonth(value.getMonth() + amount); - setValueHTML(value); - }; - - var updateDay = function updateDay(amount) { - value.setDate(value.getDate() + amount); - setValueHTML(value); - }; - - var updateYear = function updateYear(amount) { - var nextYear = value.getFullYear() + amount; - if (nextYear < 0) value.setFullYear(0);else value.setFullYear(value.getFullYear() + amount); - setValueHTML(value); - }; - elementDateUpMonth.onclick = function () { return updateMonth(1); }; diff --git a/dist/notie.min.js b/dist/notie.min.js index df0aa4d..f8ec1f2 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(a){if(n[a])return n[a].exports;var s=n[a]={i:a,l:!1,exports:{}};return e[a].call(s.exports,s,s.exports,t),s.l=!0,s.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,a){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:a})},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,a,s,c="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(i,r){"object"===c(t)&&"object"===c(e)?e.exports=r():(a=[],n=r,s="function"==typeof n?n.apply(t,a):n,!(void 0!==s&&(e.exports=s)))}(void 0,function(){return function(e){function t(a){if(n[a])return n[a].exports;var s=n[a]={i:a,l:!1,exports:{}};return e[a].call(s.exports,s,s.exports,t),s.l=!0,s.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,a){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:a})},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 a(e,t){var n={};for(var a in e)t.indexOf(a)>=0||Object.prototype.hasOwnProperty.call(e,a)&&(n[a]=e[a]);return n}Object.defineProperty(t,"__esModule",{value:!0});var s="function"==typeof Symbol&&"symbol"===c(Symbol.iterator)?function(e){return"undefined"==typeof e?"undefined":c(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":"undefined"==typeof e?"undefined":c(e)},i=Object.assign||function(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:"top";e.classList.add(r.classes.container),e.style[t]="-10000px",document.body.appendChild(e),e.style[t]="-"+e.offsetHeight+"px",e.listener&&window.addEventListener("keydown",e.listener),o().then(function(){e.style.transition=m(),e.style[t]=0})},y=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"top",n=document.getElementById(e);n&&(n.style[t]="-"+n.offsetHeight+"px",n.listener&&window.removeEventListener("keydown",n.listener),d(r.transitionDuration).then(function(){n.parentNode&&n.parentNode.removeChild(n)}))},L=function(e,t){var n=document.createElement("div");n.id=r.ids.overlay,n.classList.add(r.classes.overlay),n.classList.add(r.classes.backgroundOverlay),n.style.opacity=0,e&&r.overlayClickDismiss&&(n.onclick=function(){y(e.id,t),g()}),document.body.appendChild(n),o().then(function(){n.style.transition=m(),n.style.opacity=r.overlayOpacity})},g=function(){var e=document.getElementById(r.ids.overlay);e.style.opacity=0,d(r.transitionDuration).then(function(){e.parentNode&&e.parentNode.removeChild(e)})},h=t.hideAlerts=function(e){var t=document.getElementsByClassName(r.classes.alert);if(t.length){for(var n=0;n'+a+"",o.onclick=function(){return y(m)},o.listener=function(e){(v(e)||b(e))&&h()},x(o),c&&c<1&&(c=1),!l&&c&&d(c).then(function(){return y(m)})},C=t.force=function(e,t){var n=e.type,a=void 0===n?5:n,s=e.text,c=e.buttonText,i=void 0===c?"OK":c,l=e.callback;u(),h();var o=document.createElement("div"),d=f();o.id=d;var m=document.createElement("div");m.classList.add(r.classes.textbox),m.classList.add(r.classes.backgroundInfo),m.innerHTML='
'+s+"
";var b=document.createElement("div");b.classList.add(r.classes.button),b.classList.add(p[a]),b.innerHTML=i,b.onclick=function(){y(d),g(),l?l():t&&t()},o.appendChild(m),o.appendChild(b),o.listener=function(e){v(e)&&b.click()},x(o),L()},E=t.confirm=function(e,t,n){var a=e.text,s=e.submitText,c=void 0===s?"Yes":s,i=e.cancelText,l=void 0===i?"Cancel":i,o=e.submitCallback,d=e.cancelCallback;u(),h();var p=document.createElement("div"),m=f();p.id=m;var k=document.createElement("div");k.classList.add(r.classes.textbox),k.classList.add(r.classes.backgroundInfo),k.innerHTML='
'+a+"
";var C=document.createElement("div");C.classList.add(r.classes.button),C.classList.add(r.classes.elementHalf),C.classList.add(r.classes.backgroundSuccess),C.innerHTML=c,C.onclick=function(){y(m),g(),o?o():t&&t()};var E=document.createElement("div");E.classList.add(r.classes.button),E.classList.add(r.classes.elementHalf),E.classList.add(r.classes.backgroundError),E.innerHTML=l,E.onclick=function(){y(m),g(),d?d():n&&n()},p.appendChild(k),p.appendChild(C),p.appendChild(E),p.listener=function(e){v(e)?C.click():b(e)&&E.click()},x(p),L(p)},T=function(e,t,n){var c=e.text,i=e.submitText,l=void 0===i?"Submit":i,o=e.cancelText,d=void 0===o?"Cancel":o,p=e.submitCallback,m=e.cancelCallback,k=a(e,["text","submitText","cancelText","submitCallback","cancelCallback"]);u(),h();var C=document.createElement("div"),E=f();C.id=E;var T=document.createElement("div");T.classList.add(r.classes.textbox),T.classList.add(r.classes.backgroundInfo),T.innerHTML='
'+c+"
";var M=document.createElement("input");M.classList.add(r.classes.inputField),M.setAttribute("autocapitalize",k.autocapitalize||"none"),M.setAttribute("autocomplete",k.autocomplete||"off"),M.setAttribute("autocorrect",k.autocorrect||"off"),M.setAttribute("autofocus",k.autofocus||"true"),M.setAttribute("inputmode",k.inputmode||"verbatim"),M.setAttribute("max",k.max||""),M.setAttribute("maxlength",k.maxlength||""),M.setAttribute("min",k.min||""),M.setAttribute("minlength",k.minlength||""),M.setAttribute("placeholder",k.placeholder||""),M.setAttribute("spellcheck",k.spellcheck||"default"),M.setAttribute("step",k.step||"any"),M.setAttribute("type",k.type||"text"),M.value=k.value||"",k.allowed&&(M.oninput=function(){var e=void 0;if(Array.isArray(k.allowed)){for(var t="",n=k.allowed,a=0;a'+n+"",o.appendChild(m),i.forEach(function(e,t){var n=e.type,a=void 0===n?1:n,s=e.text,c=e.handler,u=document.createElement("div");u.classList.add(p[a]),u.classList.add(r.classes.button),u.classList.add(r.classes.selectChoice);var f=i[t+1];f&&!f.type&&(f.type=1),f&&f.type===a&&u.classList.add(r.classes.selectChoiceRepeated),u.innerHTML=s,u.onclick=function(){y(d,l),g(),c()},o.appendChild(u)});var v=document.createElement("div");v.classList.add(r.classes.backgroundNeutral),v.classList.add(r.classes.button),v.innerHTML=s,v.onclick=function(){y(d,l),g(),c?c():t&&t()},o.appendChild(v),o.listener=function(e){b(e)&&v.click()},x(o,l),L(o,l)},H=t.date=function(e,t,n){var a=e.value,s=void 0===a?new Date:a,c=e.submitText,i=void 0===c?"OK":c,l=e.cancelText,o=void 0===l?"Cancel":l,d=e.submitCallback,p=e.cancelCallback;u(),h();var m="▾",k=document.createElement("div"),C=f();k.id=C;var E=document.createElement("div");E.classList.add(r.classes.backgroundInfo);var T=document.createElement("div");T.classList.add(r.classes.dateSelectorInner);var M=document.createElement("div");M.classList.add(r.classes.button),M.classList.add(r.classes.elementThird),M.classList.add(r.classes.dateSelectorUp),M.innerHTML=m;var H=document.createElement("div");H.classList.add(r.classes.button),H.classList.add(r.classes.elementThird),H.classList.add(r.classes.dateSelectorUp),H.innerHTML=m;var S=document.createElement("div");S.classList.add(r.classes.button),S.classList.add(r.classes.elementThird),S.classList.add(r.classes.dateSelectorUp),S.innerHTML=m;var w=document.createElement("div");w.classList.add(r.classes.element),w.classList.add(r.classes.elementThird),w.innerHTML=r.dateMonths[s.getMonth()];var O=function(e){var t=new Date(s.getFullYear(),s.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"),s.setDate(Number(n))},A=document.createElement("div");A.classList.add(r.classes.element),A.classList.add(r.classes.elementThird),A.setAttribute("contentEditable",!0),A.addEventListener("input",O),A.innerHTML=s.getDate();var D=function(e){var t=e.target.textContent.replace(/^0+/,"").replace(/[^\d]/g,"").slice(0,4);e.target.textContent=t,s.setFullYear(Number(t))},I=document.createElement("div");I.classList.add(r.classes.element),I.classList.add(r.classes.elementThird),I.setAttribute("contentEditable",!0),I.addEventListener("input",D),I.innerHTML=s.getFullYear();var j=document.createElement("div");j.classList.add(r.classes.button),j.classList.add(r.classes.elementThird),j.innerHTML=m;var N=document.createElement("div");N.classList.add(r.classes.button),N.classList.add(r.classes.elementThird),N.innerHTML=m;var P=document.createElement("div");P.classList.add(r.classes.button),P.classList.add(r.classes.elementThird),P.innerHTML=m;var F=function(e){w.innerHTML=r.dateMonths[e.getMonth()],A.innerHTML=e.getDate(),I.innerHTML=e.getFullYear()},Y=function(e){var t=new Date(s.getFullYear(),s.getMonth()+e+1,0).getDate();s.getDate()>t&&s.setDate(t),s.setMonth(s.getMonth()+e),F(s)},_=function(e){s.setDate(s.getDate()+e),F(s)},z=function(e){var t=s.getFullYear()+e;t<0?s.setFullYear(0):s.setFullYear(s.getFullYear()+e),F(s)};M.onclick=function(){return Y(1)},H.onclick=function(){return _(1)},S.onclick=function(){return z(1)},j.onclick=function(){return Y(-1)},N.onclick=function(){return _(-1)},P.onclick=function(){return z(-1)};var U=document.createElement("div");U.classList.add(r.classes.button),U.classList.add(r.classes.elementHalf),U.classList.add(r.classes.backgroundSuccess),U.innerHTML=i,U.onclick=function(){y(C),g(),d?d(s):t&&t(s)};var B=document.createElement("div");B.classList.add(r.classes.button),B.classList.add(r.classes.elementHalf),B.classList.add(r.classes.backgroundError),B.innerHTML=o,B.onclick=function(){y(C),g(),p?p(s):n&&n(s)},T.appendChild(M),T.appendChild(H),T.appendChild(S),T.appendChild(w),T.appendChild(A),T.appendChild(I),T.appendChild(j),T.appendChild(N),T.appendChild(P),E.appendChild(T),k.appendChild(E),k.appendChild(U),k.appendChild(B),k.listener=function(e){v(e)?U.click():b(e)&&B.click()},x(k),L(k)};t.default={alert:k,force:C,confirm:E,input:T,select:M,date:H,setOptions:l,hideAlerts:h}}])})}).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(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,c="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(i,r){"object"===c(t)&&"object"===c(e)?e.exports=r():(s=[],n=r,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"===c(Symbol.iterator)?function(e){return"undefined"==typeof e?"undefined":c(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":"undefined"==typeof e?"undefined":c(e)},i=Object.assign||function(e){for(var t=1;t1&&void 0!==arguments[1]?arguments[1]:"top";e.classList.add(r.classes.container),e.style[t]="-10000px",document.body.appendChild(e),e.style[t]="-"+e.offsetHeight+"px",e.listener&&window.addEventListener("keydown",e.listener),o().then(function(){e.style.transition=m(),e.style[t]=0})},y=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"top",n=document.getElementById(e);n&&(n.style[t]="-"+n.offsetHeight+"px",n.listener&&window.removeEventListener("keydown",n.listener),d(r.transitionDuration).then(function(){n.parentNode&&n.parentNode.removeChild(n)}))},L=function(e,t){var n=document.createElement("div");n.id=r.ids.overlay,n.classList.add(r.classes.overlay),n.classList.add(r.classes.backgroundOverlay),n.style.opacity=0,e&&r.overlayClickDismiss&&(n.onclick=function(){y(e.id,t),g()}),document.body.appendChild(n),o().then(function(){n.style.transition=m(),n.style.opacity=r.overlayOpacity})},g=function(){var e=document.getElementById(r.ids.overlay);e.style.opacity=0,d(r.transitionDuration).then(function(){e.parentNode&&e.parentNode.removeChild(e)})},h=t.hideAlerts=function(e){var t=document.getElementsByClassName(r.classes.alert);if(t.length){for(var n=0;n'+s+"",o.onclick=function(){return y(m)},o.listener=function(e){(v(e)||b(e))&&h()},x(o),c&&c<1&&(c=1),!l&&c&&d(c).then(function(){return y(m)})},C=t.force=function(e,t){var n=e.type,s=void 0===n?5:n,a=e.text,c=e.buttonText,i=void 0===c?"OK":c,l=e.callback;u(),h();var o=document.createElement("div"),d=f();o.id=d;var m=document.createElement("div");m.classList.add(r.classes.textbox),m.classList.add(r.classes.backgroundInfo),m.innerHTML='
'+a+"
";var b=document.createElement("div");b.classList.add(r.classes.button),b.classList.add(p[s]),b.innerHTML=i,b.onclick=function(){y(d),g(),l?l():t&&t()},o.appendChild(m),o.appendChild(b),o.listener=function(e){v(e)&&b.click()},x(o),L()},E=t.confirm=function(e,t,n){var s=e.text,a=e.submitText,c=void 0===a?"Yes":a,i=e.cancelText,l=void 0===i?"Cancel":i,o=e.submitCallback,d=e.cancelCallback;u(),h();var p=document.createElement("div"),m=f();p.id=m;var k=document.createElement("div");k.classList.add(r.classes.textbox),k.classList.add(r.classes.backgroundInfo),k.innerHTML='
'+s+"
";var C=document.createElement("div");C.classList.add(r.classes.button),C.classList.add(r.classes.elementHalf),C.classList.add(r.classes.backgroundSuccess),C.innerHTML=c,C.onclick=function(){y(m),g(),o?o():t&&t()};var E=document.createElement("div");E.classList.add(r.classes.button),E.classList.add(r.classes.elementHalf),E.classList.add(r.classes.backgroundError),E.innerHTML=l,E.onclick=function(){y(m),g(),d?d():n&&n()},p.appendChild(k),p.appendChild(C),p.appendChild(E),p.listener=function(e){v(e)?C.click():b(e)&&E.click()},x(p),L(p)},T=function(e,t,n){var c=e.text,i=e.submitText,l=void 0===i?"Submit":i,o=e.cancelText,d=void 0===o?"Cancel":o,p=e.submitCallback,m=e.cancelCallback,k=s(e,["text","submitText","cancelText","submitCallback","cancelCallback"]);u(),h();var C=document.createElement("div"),E=f();C.id=E;var T=document.createElement("div");T.classList.add(r.classes.textbox),T.classList.add(r.classes.backgroundInfo),T.innerHTML='
'+c+"
";var M=document.createElement("input");M.classList.add(r.classes.inputField),M.setAttribute("autocapitalize",k.autocapitalize||"none"),M.setAttribute("autocomplete",k.autocomplete||"off"),M.setAttribute("autocorrect",k.autocorrect||"off"),M.setAttribute("autofocus",k.autofocus||"true"),M.setAttribute("inputmode",k.inputmode||"verbatim"),M.setAttribute("max",k.max||""),M.setAttribute("maxlength",k.maxlength||""),M.setAttribute("min",k.min||""),M.setAttribute("minlength",k.minlength||""),M.setAttribute("placeholder",k.placeholder||""),M.setAttribute("spellcheck",k.spellcheck||"default"),M.setAttribute("step",k.step||"any"),M.setAttribute("type",k.type||"text"),M.value=k.value||"",k.allowed&&(M.oninput=function(){var e=void 0;if(Array.isArray(k.allowed)){for(var t="",n=k.allowed,s=0;s'+n+"",o.appendChild(m),i.forEach(function(e,t){var n=e.type,s=void 0===n?1:n,a=e.text,c=e.handler,u=document.createElement("div");u.classList.add(p[s]),u.classList.add(r.classes.button),u.classList.add(r.classes.selectChoice);var f=i[t+1];f&&!f.type&&(f.type=1),f&&f.type===s&&u.classList.add(r.classes.selectChoiceRepeated),u.innerHTML=a,u.onclick=function(){y(d,l),g(),c()},o.appendChild(u)});var v=document.createElement("div");v.classList.add(r.classes.backgroundNeutral),v.classList.add(r.classes.button),v.innerHTML=a,v.onclick=function(){y(d,l),g(),c?c():t&&t()},o.appendChild(v),o.listener=function(e){b(e)&&v.click()},x(o,l),L(o,l)},H=t.date=function(e,t,n){var s=e.value,a=void 0===s?new Date:s,c=e.submitText,i=void 0===c?"OK":c,l=e.cancelText,o=void 0===l?"Cancel":l,d=e.submitCallback,p=e.cancelCallback;u(),h();var m="▾",k=document.createElement("div"),C=document.createElement("div"),E=document.createElement("div"),T=function(e){k.innerHTML=r.dateMonths[e.getMonth()],C.innerHTML=e.getDate(),E.innerHTML=e.getFullYear()},M=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))},H=function(e){var t=e.target.textContent.replace(/^0+/,"").replace(/[^\d]/g,"").slice(0,4);e.target.textContent=t,a.setFullYear(Number(t))},S=function(e){T(a)},w=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),T(a)},O=function(e){a.setDate(a.getDate()+e),T(a)},A=function(e){var t=a.getFullYear()+e;t<0?a.setFullYear(0):a.setFullYear(a.getFullYear()+e),T(a)},D=document.createElement("div"),I=f();D.id=I;var j=document.createElement("div");j.classList.add(r.classes.backgroundInfo);var N=document.createElement("div");N.classList.add(r.classes.dateSelectorInner);var P=document.createElement("div");P.classList.add(r.classes.button),P.classList.add(r.classes.elementThird),P.classList.add(r.classes.dateSelectorUp),P.innerHTML=m;var F=document.createElement("div");F.classList.add(r.classes.button),F.classList.add(r.classes.elementThird),F.classList.add(r.classes.dateSelectorUp),F.innerHTML=m;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=m,k.classList.add(r.classes.element),k.classList.add(r.classes.elementThird),k.innerHTML=r.dateMonths[a.getMonth()],C.classList.add(r.classes.element),C.classList.add(r.classes.elementThird),C.setAttribute("contentEditable",!0),C.addEventListener("input",M),C.addEventListener("blur",S),C.innerHTML=a.getDate(),E.classList.add(r.classes.element),E.classList.add(r.classes.elementThird),E.setAttribute("contentEditable",!0),E.addEventListener("input",H),E.addEventListener("blur",S),E.innerHTML=a.getFullYear();var _=document.createElement("div");_.classList.add(r.classes.button),_.classList.add(r.classes.elementThird),_.innerHTML=m;var z=document.createElement("div");z.classList.add(r.classes.button),z.classList.add(r.classes.elementThird),z.innerHTML=m;var U=document.createElement("div");U.classList.add(r.classes.button),U.classList.add(r.classes.elementThird),U.innerHTML=m,P.onclick=function(){return w(1)},F.onclick=function(){return O(1)},Y.onclick=function(){return A(1)},_.onclick=function(){return w(-1)},z.onclick=function(){return O(-1)},U.onclick=function(){return A(-1)};var B=document.createElement("div");B.classList.add(r.classes.button),B.classList.add(r.classes.elementHalf),B.classList.add(r.classes.backgroundSuccess),B.innerHTML=i,B.onclick=function(){y(I),g(),d?d(a):t&&t(a)};var J=document.createElement("div");J.classList.add(r.classes.button),J.classList.add(r.classes.elementHalf),J.classList.add(r.classes.backgroundError),J.innerHTML=o,J.onclick=function(){y(I),g(),p?p(a):n&&n(a)},N.appendChild(P),N.appendChild(F),N.appendChild(Y),N.appendChild(k),N.appendChild(C),N.appendChild(E),N.appendChild(_),N.appendChild(z),N.appendChild(U),j.appendChild(N),D.appendChild(j),D.appendChild(B),D.appendChild(J),D.listener=function(e){v(e)?B.click():b(e)&&J.click()},x(D),L(D)};t.default={alert:k,force:C,confirm:E,input:T,select:M,date:H,setOptions:l,hideAlerts:h}}])})}).call(t,n(0)(e))}])}); \ No newline at end of file diff --git a/package.json b/package.json index 3fd04a5..82f8d8c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "notie", "description": "notie - a clean and simple notification, input, and selection suite for javascript, with no dependencies", "author": "Jared Reich", - "version": "4.2.0", + "version": "4.2.1", "main": "./dist/notie.min.js", "files": [ "dist/", diff --git a/src/notie.js b/src/notie.js index 8072ff8..6ca66ea 100644 --- a/src/notie.js +++ b/src/notie.js @@ -462,6 +462,68 @@ export const date = ({ const arrow = '▾' + const elementDateMonth = document.createElement('div') + const elementDateDay = document.createElement('div') + const elementDateYear = document.createElement('div') + + const setValueHTML = date => { + elementDateMonth.innerHTML = options.dateMonths[date.getMonth()] + elementDateDay.innerHTML = date.getDate() + elementDateYear.innerHTML = date.getFullYear() + } + + const handleDayInput = event => { + const daysInMonth = new Date( + value.getFullYear(), + value.getMonth() + 1, + 0 + ).getDate() + let day = event.target.textContent + .replace(/^0+/, '') + .replace(/[^\d]/g, '') + .slice(0, 2) + if (Number(day) > daysInMonth) day = daysInMonth.toString() + event.target.textContent = day + if (Number(day) < 1) day = '1' + value.setDate(Number(day)) + } + + const handleYearInput = event => { + const year = event.target.textContent + .replace(/^0+/, '') + .replace(/[^\d]/g, '') + .slice(0, 4) + event.target.textContent = year + value.setFullYear(Number(year)) + } + + const handleBlur = event => { + setValueHTML(value) + } + + const updateMonth = amount => { + const daysInNextMonth = new Date( + value.getFullYear(), + value.getMonth() + amount + 1, + 0 + ).getDate() + if (value.getDate() > daysInNextMonth) value.setDate(daysInNextMonth) + value.setMonth(value.getMonth() + amount) + setValueHTML(value) + } + + const updateDay = amount => { + value.setDate(value.getDate() + amount) + setValueHTML(value) + } + + const updateYear = amount => { + const nextYear = value.getFullYear() + amount + if (nextYear < 0) value.setFullYear(0) + else value.setFullYear(value.getFullYear() + amount) + setValueHTML(value) + } + const element = document.createElement('div') const id = generateRandomId() element.id = id @@ -490,48 +552,22 @@ export const date = ({ elementDateUpYear.classList.add(options.classes.dateSelectorUp) elementDateUpYear.innerHTML = arrow - const elementDateMonth = document.createElement('div') elementDateMonth.classList.add(options.classes.element) elementDateMonth.classList.add(options.classes.elementThird) elementDateMonth.innerHTML = options.dateMonths[value.getMonth()] - const handleDayInput = event => { - const daysInMonth = new Date( - value.getFullYear(), - value.getMonth() + 1, - 0 - ).getDate() - let day = event.target.textContent - .replace(/^0+/, '') - .replace(/[^\d]/g, '') - .slice(0, 2) - if (Number(day) > daysInMonth) day = daysInMonth.toString() - event.target.textContent = day - if (Number(day) < 1) day = '1' - value.setDate(Number(day)) - } - - const elementDateDay = document.createElement('div') 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() - const handleYearInput = event => { - const year = event.target.textContent - .replace(/^0+/, '') - .replace(/[^\d]/g, '') - .slice(0, 4) - event.target.textContent = year - value.setFullYear(Number(year)) - } - - const elementDateYear = document.createElement('div') 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') @@ -549,35 +585,6 @@ export const date = ({ elementDateDownYear.classList.add(options.classes.elementThird) elementDateDownYear.innerHTML = arrow - const setValueHTML = date => { - elementDateMonth.innerHTML = options.dateMonths[date.getMonth()] - elementDateDay.innerHTML = date.getDate() - elementDateYear.innerHTML = date.getFullYear() - } - - const updateMonth = amount => { - const daysInNextMonth = new Date( - value.getFullYear(), - value.getMonth() + amount + 1, - 0 - ).getDate() - if (value.getDate() > daysInNextMonth) value.setDate(daysInNextMonth) - value.setMonth(value.getMonth() + amount) - setValueHTML(value) - } - - const updateDay = amount => { - value.setDate(value.getDate() + amount) - setValueHTML(value) - } - - const updateYear = amount => { - const nextYear = value.getFullYear() + amount - if (nextYear < 0) value.setFullYear(0) - else value.setFullYear(value.getFullYear() + amount) - setValueHTML(value) - } - elementDateUpMonth.onclick = () => updateMonth(1) elementDateUpDay.onclick = () => updateDay(1) elementDateUpYear.onclick = () => updateYear(1)