diff --git a/dist/index.d.ts b/dist/index.d.ts index 82dae89..d5e6cc4 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -16,6 +16,7 @@ export interface AlertOptions { color?: string; position?: string; backdrop?: boolean; + duration?: number; } export interface ConfirmOptions { template: string; diff --git a/dist/mystical.js b/dist/mystical.js index 3f3175e..9f71bd1 100644 --- a/dist/mystical.js +++ b/dist/mystical.js @@ -1 +1 @@ -!function(t,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.mystical=o():t.mystical=o()}(this,function(){return function(t){function o(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,o),i.l=!0,i.exports}var e={};return o.m=t,o.c=e,o.i=function(t){return t},o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,o){return Object.prototype.hasOwnProperty.call(t,o)},o.p="",o(o.s=0)}([function(t,o,e){"use strict";function n(t,o,e,n){"top"===t.pos?d().then(function(){o.style.top=e,o.style.opacity="1"}):d().then(function(){o.style.bottom=n,o.style.opacity="1"})}function i(){var t=document.createElement("div");return t.style.cssText="position: fixed; height: 100%; width: 100%; top: 0; left: 0; overflow: hidden; background-color: rgba(33,33,33,1.0); opacity: 0.48;",t}function r(t){var o=document.createElement("div");return o.tabIndex=-1,o.style.cssText="background-color: "+t.bg+"; z-index: 99999999; border: none; user-select: none; -webkit-tap-highlight-color: rgba(255, 255, 255, 0); outline: none; cursor: pointer; color: "+t.fg+"; position: fixed; left: 0; padding: 10px; width: 100%; transition: all 0.5s ease; margin: 0 auto; overflow-x: hidden;",o}function c(t,o){var e,n;return"top"===t.pos?(e="0px",n="",o.style.top="-200px"):(e="",n="0%",o.style.bottom="-200px"),{top:e,bottom:n}}function u(t,o,e){"top"===e?t.style.top="-150px":t.style.bottom="-150px",d().then(function(){void 0!==o&&document.body.removeChild(o)}),p(500).then(function(){void 0!==t&&document.body.removeChild(t)})}function d(){return new Promise(function(t){setTimeout(t,0)})}function p(t){return new Promise(function(o){setTimeout(o,t)})}function l(t){return{bg:t.backgroundColor?t.backgroundColor:"#333",fg:t.color?t.color:"#fff",pos:t.position?t.position:"top",backdrop:!t.backdrop||t.backdrop,posText:t.positiveText?t.positiveText:"Yes",negText:t.negativeText?t.negativeText:"No"}}function s(){return"mystical-"+(Math.floor(9e4*Math.random())+1e4)}Object.defineProperty(o,"__esModule",{value:!0});var a=function(){function t(){}return t.alert=function(t){var o,e=l(t),d=r(e);e.backdrop===!0&&(o=i(),document.body.appendChild(o),o.onclick=function(t){t.preventDefault(),u(d,o,e.pos)}),d.onclick=function(){u(d,o,e.pos)},d.onkeydown=function(t){13!==t.keyCode&&27!==t.keyCode||u(d,o,e.pos)},d.innerHTML='\n
\n '+t.template+"\n
\n ";var p=c(e,d);document.body.appendChild(d),d.focus(),n(e,d,p.top,p.bottom)},t.confirm=function(t){return new Promise(function(o,e){var d,p=l(t),a=r(p);p.backdrop===!0&&(d=i(),document.body.appendChild(d),d.onclick=function(t){t.preventDefault(),o(!1),u(a,d,p.pos)}),a.onkeydown=function(t){13!==t.keyCode&&27!==t.keyCode||(t.preventDefault(),u(a,d,p.pos),o(!1))};var f=s(),b=s(),y="color: "+p.fg+"; background-color: "+p.bg+"; cursor: pointer; border: none; background: transparent; padding:4px; font-size: 1em;";a.innerHTML='\n
\n '+t.template+'\n
\n \n \n
\n
\n ";var m=c(p,a);document.body.appendChild(a),document.getElementById(f).onclick=function(t){u(a,d,p.pos),o(!0)};var v=document.getElementById(b);v.onclick=function(t){o(!1),u(a,d,p.pos)},v.focus(),n(p,a,m.top,m.bottom)})},t}();o.Mystical=a}])}); \ No newline at end of file +!function(t,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.mystical=o():t.mystical=o()}(this,function(){return function(t){function o(e){if(n[e])return n[e].exports;var i=n[e]={i:e,l:!1,exports:{}};return t[e].call(i.exports,i,i.exports,o),i.l=!0,i.exports}var n={};return o.m=t,o.c=n,o.i=function(t){return t},o.d=function(t,n,e){o.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:e})},o.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(n,"a",n),n},o.o=function(t,o){return Object.prototype.hasOwnProperty.call(t,o)},o.p="",o(o.s=0)}([function(t,o,n){"use strict";function e(t,o,n,e){"top"===t.pos?d().then(function(){o.style.top=n,o.style.opacity="1"}):d().then(function(){o.style.bottom=e,o.style.opacity="1"})}function i(){var t=document.createElement("div");return t.style.cssText="position: fixed; height: 100%; width: 100%; top: 0; left: 0; overflow: hidden; background-color: rgba(33,33,33,1.0); opacity: 0.48;",t}function r(t){var o=document.createElement("div");return o.tabIndex=-1,o.style.cssText="background-color: "+t.bg+"; z-index: 99999999; border: none; user-select: none; -webkit-tap-highlight-color: rgba(255, 255, 255, 0); outline: none; cursor: pointer; color: "+t.fg+"; position: fixed; left: 0; padding: 10px; width: 100%; transition: all 0.5s ease; margin: 0 auto; overflow-x: hidden;",o}function c(t,o){var n,e;return"top"===t.pos?(n="0px",e="",o.style.top="-200px"):(n="",e="0%",o.style.bottom="-200px"),{top:n,bottom:e}}function u(t,o,n){"top"===n?t.style.top="-150px":t.style.bottom="-150px",d().then(function(){void 0!==o&&document.body.removeChild(o)}),p(500).then(function(){void 0!==t&&document.body.removeChild(t)})}function d(){return new Promise(function(t){setTimeout(t,0)})}function p(t){return new Promise(function(o){setTimeout(o,t)})}function a(t){return{bg:t.backgroundColor?t.backgroundColor:"#333",fg:t.color?t.color:"#fff",pos:t.position?t.position:"top",backdrop:!t.backdrop||t.backdrop,duration:t.duration?t.duration:void 0,posText:t.positiveText?t.positiveText:"Yes",negText:t.negativeText?t.negativeText:"No"}}function l(){return"mystical-"+(Math.floor(9e4*Math.random())+1e4)}Object.defineProperty(o,"__esModule",{value:!0});var s=function(){function t(){}return t.alert=function(t){var o,n=a(t),d=r(n);n.backdrop===!0&&(o=i(),document.body.appendChild(o),o.onclick=function(t){t.preventDefault(),u(d,o,n.pos)}),d.onclick=function(){u(d,o,n.pos)},d.onkeydown=function(t){13!==t.keyCode&&27!==t.keyCode||u(d,o,n.pos)},d.innerHTML='\n
\n '+t.template+"\n
\n ";var l=c(n,d);document.body.appendChild(d),d.focus(),e(n,d,l.top,l.bottom),void 0!==n.duration&&p(n.duration).then(function(){u(d,o,n.pos)})},t.confirm=function(t){return new Promise(function(o,n){var d,p=a(t),s=r(p);p.backdrop===!0&&(d=i(),document.body.appendChild(d),d.onclick=function(t){t.preventDefault(),o(!1),u(s,d,p.pos)}),s.onkeydown=function(t){13!==t.keyCode&&27!==t.keyCode||(t.preventDefault(),u(s,d,p.pos),o(!1))};var f=l(),b=l(),y="color: "+p.fg+"; background-color: "+p.bg+"; cursor: pointer; border: none; background: transparent; padding:4px; font-size: 1em;";s.innerHTML='\n
\n '+t.template+'\n
\n \n \n
\n
\n ";var m=c(p,s);document.body.appendChild(s),document.getElementById(f).onclick=function(t){u(s,d,p.pos),o(!0)};var v=document.getElementById(b);v.onclick=function(t){o(!1),u(s,d,p.pos)},v.focus(),e(p,s,m.top,m.bottom)})},t}();o.Mystical=s}])}); \ No newline at end of file diff --git a/package.json b/package.json index 91a9a13..febbeff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mystical-notification", - "version": "0.4.0", + "version": "0.5.0", "description": "Web alerts I needed.", "main": "dist/mystical", "typings": "dist/index.d.ts", diff --git a/src/index.d.ts b/src/index.d.ts index 82dae89..d5e6cc4 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -16,6 +16,7 @@ export interface AlertOptions { color?: string; position?: string; backdrop?: boolean; + duration?: number; } export interface ConfirmOptions { template: string; diff --git a/src/index.ts b/src/index.ts index 4b14769..917a6fa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,6 +44,12 @@ export class Mystical { // after the note div is on the DOM - to trigger the CSS transition startTransition(defaults, note, iStyles.top, iStyles.bottom) + if (defaults.duration !== undefined) { + wait(defaults.duration).then(() => { + removeNoteFromDom(note, backdrop, defaults.pos) + }) + } + } /** @@ -227,9 +233,10 @@ function initDefaults(opts) { const fg = opts.color ? opts.color : "#fff" const pos = opts.position ? opts.position : "top" const backdrop = opts.backdrop ? opts.backdrop : true + const duration = opts.duration ? opts.duration : undefined const posText = opts.positiveText ? opts.positiveText : "Yes" const negText = opts.negativeText ? opts.negativeText : "No" - return { bg, fg, pos, backdrop, posText, negText } + return { bg, fg, pos, backdrop, duration, posText, negText } } /** @@ -246,6 +253,7 @@ export interface AlertOptions { color?: string position?: string backdrop?: boolean + duration?: number } export interface ConfirmOptions { template: string