awesome-notifications
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -7,2 +7,7 @@ # Changelog | ||
## [3.0.3] - 06.25.2019 | ||
### Added | ||
* `confirm` now has option to hide 'Cancel' button. Read docs to learn more. | ||
## [3.0.2] - 05.08.2019 | ||
@@ -9,0 +14,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AWN=e():t.AWN=e()}(window,function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}n.r(e);var r={maxNotifications:10,animationDuration:300,position:"bottom-right",labels:{tip:"Tip",info:"Info",success:"Success",warning:"Attention",alert:"Error",async:"Loading",confirm:"Confirmation required",confirmOk:"OK",confirmCancel:"Cancel"},icons:{tip:"question-circle",info:"info-circle",success:"check-circle",warning:"exclamation-circle",alert:"exclamation-triangle",async:"cog fa-spin",confirm:"exclamation-triangle",prefix:"<i class='fa fas fa-fw fa-",suffix:"'></i>",enabled:!0},replacements:{tip:null,info:null,success:null,warning:null,alert:null,async:null,"async-block":null,modal:null,confirm:null,general:{"<script>":"","<\/script>":""}},messages:{tip:"",info:"",success:"Action has been succeeded",warning:"",alert:"Action has been failed",confirm:"This action can't be undone. Continue?",async:"Please, wait...","async-block":"Loading"},formatError:function(t){if(t.response){if(!t.response.data)return"500 API Server Error";if(t.response.data.errors)return t.response.data.errors.map(function(t){return t.detail}).join("<br>");if(t.response.statusText)return"".concat(t.response.status," ").concat(t.response.statusText,": ").concat(t.response.data)}return t.message?t.message:t},durations:{global:5e3,success:null,info:null,tip:null,warning:null,alert:null},minDurations:{async:1e3,"async-block":1e3}},a=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Object.assign(this,this.defaultsDeep(n,e))}var e,n,a;return e=t,(n=[{key:"icon",value:function(t){return this.icons.enabled?"".concat(this.icons.prefix).concat(this.icons[t]).concat(this.icons.suffix):""}},{key:"label",value:function(t){return this.labels[t]}},{key:"duration",value:function(t){var e=this.durations[t];return null===e?this.durations.global:e}},{key:"toSecs",value:function(t){return"".concat(t/1e3,"s")}},{key:"applyReplacements",value:function(t,e){if(!t)return this.messages[e]||"";for(var n=0,o=["general",e];n<o.length;n++){var i=o[n];if(this.replacements[i])for(var r in this.replacements[i])t=t.replace(r,this.replacements[i][r])}return t}},{key:"override",value:function(e){return e?new t(e,this):this}},{key:"defaultsDeep",value:function(t,e){var n={};for(var i in t)e.hasOwnProperty(i)?n[i]="object"===o(t[i])&&null!==t[i]?this.defaultsDeep(t[i],e[i]):e[i]:n[i]=t[i];return n}}])&&i(e.prototype,n),a&&i(e,a),t}(),s={popup:"".concat("awn","-popup"),toast:"".concat("awn","-toast"),btn:"".concat("awn","-btn"),confirm:"".concat("awn","-confirm")},c={prefix:s.toast,klass:{label:"".concat(s.toast,"-label"),content:"".concat(s.toast,"-content"),icon:"".concat(s.toast,"-icon"),progressBar:"".concat(s.toast,"-progress-bar"),progressBarPause:"".concat(s.toast,"-progress-bar-paused")},ids:{container:"".concat(s.toast,"-container")}},u={prefix:s.popup,klass:{buttons:"".concat("awn","-buttons"),button:s.btn,successBtn:"".concat(s.btn,"-success"),cancelBtn:"".concat(s.btn,"-cancel"),title:"".concat(s.popup,"-title"),body:"".concat(s.popup,"-body"),content:"".concat(s.popup,"-content"),dotAnimation:"".concat(s.popup,"-loading-dots")},ids:{wrapper:"".concat(s.popup,"-wrapper"),confirmOk:"".concat(s.confirm,"-ok"),confirmCancel:"".concat(s.confirm,"-cancel")}},l={klass:{hiding:"".concat("awn","-hiding")},lib:"awn"};function f(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var p=function(){function t(e,n,o,i,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.newNode=document.createElement("div"),n&&(this.newNode.id=n),o&&(this.newNode.className=o),i&&(this.newNode.style.cssText=i),this.parent=e,this.options=r}var e,n,o;return e=t,(n=[{key:"beforeInsert",value:function(){}},{key:"afterInsert",value:function(){}},{key:"insert",value:function(){return this.beforeInsert(),this.el=this.parent.appendChild(this.newNode),this.afterInsert(),this}},{key:"replace",value:function(t){var e=this;if(this.getElement())return this.beforeDelete().then(function(){return e.updateType(t.type),e.parent.replaceChild(t.newNode,e.el),e.el=e.getElement(t.newNode),e.afterInsert(),e})}},{key:"beforeDelete",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el,n=0;return this.start&&(n=this.options.minDurations[this.type]+this.start-Date.now())<0&&(n=0),new Promise(function(o){setTimeout(function(){e.classList.add(l.klass.hiding),setTimeout(o,t.options.animationDuration)},n)})}},{key:"delete",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el;return this.getElement(e)?this.beforeDelete(e).then(function(){e.remove(),t.afterDelete()}):null}},{key:"afterDelete",value:function(){}},{key:"getElement",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el;return document.getElementById(t.id)}},{key:"addEvent",value:function(t,e){this.el.addEventListener(t,e)}},{key:"toggleClass",value:function(t){this.el.classList.toggle(t)}},{key:"updateType",value:function(t){this.type=t,this.duration=this.options.duration(this.type)}}])&&f(e.prototype,n),o&&f(e,o),t}();function d(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var y=function(){function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.callback=e,this.remaining=n,this.resume()}var e,n,o;return e=t,(n=[{key:"pause",value:function(){this.paused=!0,window.clearTimeout(this.timerId),this.remaining-=new Date-this.start}},{key:"resume",value:function(){var t=this;this.paused=!1,this.start=new Date,window.clearTimeout(this.timerId),this.timerId=window.setTimeout(function(){window.clearTimeout(t.timerId),t.callback()},this.remaining)}},{key:"toggle",value:function(){this.paused?this.resume():this.pause()}}])&&d(e.prototype,n),o&&d(e,o),t}();function h(t){return(h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function m(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function b(t,e){return!e||"object"!==h(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function v(t){return(v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function k(t,e){return(k=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var g=function(t){function e(t,n,o,i){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(r=b(this,v(e).call(this,i,"".concat(c.prefix,"-").concat(Math.floor(Date.now()-100*Math.random())),"".concat(c.prefix," ").concat(c.prefix,"-").concat(n),"animation-duration: ".concat(o.toSecs(o.animationDuration),";"),o))).updateType(n),r.setInnerHtml(t),r}var n,o,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&k(t,e)}(e,p),n=e,(o=[{key:"setInnerHtml",value:function(t){"alert"===this.type&&t&&(t=this.options.formatError(t)),t=this.options.applyReplacements(t,this.type),this.newNode.innerHTML='<div class="awn-toast-wrapper">'.concat(this.progressBar).concat(this.label,'<div class="').concat(c.klass.content,'">').concat(t,'</div><span class="').concat(c.klass.icon,'">').concat(this.options.icon(this.type),"</span></div>")}},{key:"beforeInsert",value:function(){var t=this;if(this.parent.childElementCount>=this.options.maxNotifications){var e=Array.from(this.parent.getElementsByClassName(c.prefix));this.delete(e.find(function(e){return!t.isDeleted(e)}))}}},{key:"afterInsert",value:function(){var t=this;if("async"==this.type)return this.start=Date.now();if(this.addEvent("click",function(){return t.delete()}),!(this.duration<=0)){this.timer=new y(function(){return t.delete()},this.duration);for(var e=0,n=["mouseenter","mouseleave"];e<n.length;e++){var o=n[e];this.addEvent(o,function(){t.isDeleted()||(t.toggleClass(c.klass.progressBarPause),t.timer.toggle())})}}}},{key:"isDeleted",value:function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el).classList.contains(l.klass.hiding)}},{key:"progressBar",get:function(){return this.duration<=0||"async"===this.type?"":"<div class='".concat(c.klass.progressBar,"' style=\"animation-duration:").concat(this.options.toSecs(this.duration),';"></div>')}},{key:"label",get:function(){return'<b class="'.concat(c.klass.label,'">').concat(this.options.label(this.type),"</b>")}}])&&m(n.prototype,o),i&&m(n,i),e}();function w(t){return(w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function _(t,e){return!e||"object"!==w(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function T(t){return(T=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function E(t,e){return(E=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var S=function(t){function e(t){var n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"modal",i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,a=arguments.length>4?arguments[4]:void 0;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var s="animation-duration: ".concat(i.toSecs(i.animationDuration),";");return(n=_(this,T(e).call(this,document.body,u.ids.wrapper,null,s,i)))[u.ids.confirmOk]=r,n[u.ids.confirmCancel]=a,n.className=o,["confirm","async-block","modal"].includes(o)||(o="modal"),n.updateType(o),n.setInnerHtml(t),n.insert(),n}var n,o,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&E(t,e)}(e,p),n=e,(o=[{key:"setInnerHtml",value:function(t){var e=this.options.applyReplacements(t,this.type);switch(this.type){case"confirm":e="".concat(this.options.icon(this.type),"<div class='").concat(u.klass.title,"'>").concat(this.options.label(this.type),'</div><div class="').concat(u.klass.content,'">').concat(e,"</div><div class='").concat(u.klass.buttons,"'><button class='").concat(u.klass.button," ").concat(u.klass.successBtn,"'id='").concat(u.ids.confirmOk,"'>").concat(this.options.labels.confirmOk,"</button><button class='").concat(u.klass.button," ").concat(u.klass.cancelBtn,"'id='").concat(u.ids.confirmCancel,"'>").concat(this.options.labels.confirmCancel,"</button></div>");break;case"async-block":e="".concat(e,'<div class="').concat(u.klass.dotAnimation,'"></div>')}this.newNode.innerHTML='<div class="'.concat(u.klass.body," ").concat(u.prefix,"-").concat(this.className,'">').concat(e,"</div>")}},{key:"keyupListener",value:function(t){if("async-block"===this.type)return t.preventDefault();switch(t.code){case"Escape":t.preventDefault(),this.delete();case"Tab":if(t.preventDefault(),"confirm"!==this.type)return!0;var e=this.okBtn;t.shiftKey?document.activeElement.id==u.ids.confirmOk&&(e=this.cancelBtn):document.activeElement.id!==u.ids.confirmCancel&&(e=this.cancelBtn),e.focus()}}},{key:"afterInsert",value:function(){var t=this;switch(this.listener=function(e){return t.keyupListener(e)},window.addEventListener("keydown",this.listener),this.type){case"async-block":this.start=Date.now();break;case"confirm":this.okBtn.focus(),this.addEvent("click",function(e){if("BUTTON"!==e.target.nodeName)return!1;t.delete(),t[e.target.id]&&t[e.target.id]()});break;default:document.activeElement.blur(),this.addEvent("click",function(e){e.target.id===t.newNode.id&&t.delete()})}}},{key:"afterDelete",value:function(){window.removeEventListener("keydown",this.listener)}},{key:"okBtn",get:function(){return document.getElementById(u.ids.confirmOk)}},{key:"cancelBtn",get:function(){return document.getElementById(u.ids.confirmCancel)}}])&&O(n.prototype,o),i&&O(n,i),e}();function j(t){return(j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function x(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}n.d(e,"default",function(){return P});var P=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=new a(e)}var e,n,o;return e=t,(n=[{key:"tip",value:function(t,e){return this._addToast(t,"tip",e).el}},{key:"info",value:function(t,e){return this._addToast(t,"info",e).el}},{key:"success",value:function(t,e){return this._addToast(t,"success",e).el}},{key:"warning",value:function(t,e){return this._addToast(t,"warning",e).el}},{key:"alert",value:function(t,e){return this._addToast(t,"alert",e).el}},{key:"async",value:function(t,e,n,o,i){var r=this._addToast(o,"async",i);return this._afterAsync(t,e,n,i,r)}},{key:"confirm",value:function(t,e,n,o){return this._addPopup(t,"confirm",o,e,n)}},{key:"asyncBlock",value:function(t,e,n,o,i){var r=this._addPopup(o,"async-block",i);return this._afterAsync(t,e,n,i,r)}},{key:"modal",value:function(t,e,n){return this._addPopup(t,e,n)}},{key:"_addPopup",value:function(t,e,n,o,i){return new S(t,e,this.options.override(n),o,i)}},{key:"_addToast",value:function(t,e,n,o){n=this.options.override(n);var i=new g(t,e,n,this.container);return o?o instanceof S?o.delete().then(function(){return i.insert()}):o.replace(i):i.insert()}},{key:"_afterAsync",value:function(t,e,n,o,i){return t.then(this._responseHandler(e,"success",o,i),this._responseHandler(n,"alert",o,i))}},{key:"_responseHandler",value:function(t,e,n,o){var i=this;return function(r){switch(j(t)){case"undefined":case"string":var a="alert"===e?t||r:t;i._addToast(a,e,n,o);break;default:o.delete().then(function(){t&&t(r)})}return"alert"===e?Promise.reject(r):r}}},{key:"_createContainer",value:function(){return new p(document.body,c.ids.container,"awn-".concat(this.options.position)).insert().el}},{key:"container",get:function(){return document.getElementById(c.ids.container)||this._createContainer()}}])&&x(e.prototype,n),o&&x(e,o),t}()}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AWN=e():t.AWN=e()}(window,function(){return function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}n.r(e);var r={maxNotifications:10,animationDuration:300,position:"bottom-right",labels:{tip:"Tip",info:"Info",success:"Success",warning:"Attention",alert:"Error",async:"Loading",confirm:"Confirmation required",confirmOk:"OK",confirmCancel:"Cancel"},icons:{tip:"question-circle",info:"info-circle",success:"check-circle",warning:"exclamation-circle",alert:"exclamation-triangle",async:"cog fa-spin",confirm:"exclamation-triangle",prefix:"<i class='fa fas fa-fw fa-",suffix:"'></i>",enabled:!0},replacements:{tip:null,info:null,success:null,warning:null,alert:null,async:null,"async-block":null,modal:null,confirm:null,general:{"<script>":"","<\/script>":""}},messages:{tip:"",info:"",success:"Action has been succeeded",warning:"",alert:"Action has been failed",confirm:"This action can't be undone. Continue?",async:"Please, wait...","async-block":"Loading"},formatError:function(t){if(t.response){if(!t.response.data)return"500 API Server Error";if(t.response.data.errors)return t.response.data.errors.map(function(t){return t.detail}).join("<br>");if(t.response.statusText)return"".concat(t.response.status," ").concat(t.response.statusText,": ").concat(t.response.data)}return t.message?t.message:t},durations:{global:5e3,success:null,info:null,tip:null,warning:null,alert:null},minDurations:{async:1e3,"async-block":1e3}},a=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Object.assign(this,this.defaultsDeep(n,e))}var e,n,a;return e=t,(n=[{key:"icon",value:function(t){return this.icons.enabled?"".concat(this.icons.prefix).concat(this.icons[t]).concat(this.icons.suffix):""}},{key:"label",value:function(t){return this.labels[t]}},{key:"duration",value:function(t){var e=this.durations[t];return null===e?this.durations.global:e}},{key:"toSecs",value:function(t){return"".concat(t/1e3,"s")}},{key:"applyReplacements",value:function(t,e){if(!t)return this.messages[e]||"";for(var n=0,o=["general",e];n<o.length;n++){var i=o[n];if(this.replacements[i])for(var r in this.replacements[i])t=t.replace(r,this.replacements[i][r])}return t}},{key:"override",value:function(e){return e?new t(e,this):this}},{key:"defaultsDeep",value:function(t,e){var n={};for(var i in t)e.hasOwnProperty(i)?n[i]="object"===o(t[i])&&null!==t[i]?this.defaultsDeep(t[i],e[i]):e[i]:n[i]=t[i];return n}}])&&i(e.prototype,n),a&&i(e,a),t}(),c={popup:"".concat("awn","-popup"),toast:"".concat("awn","-toast"),btn:"".concat("awn","-btn"),confirm:"".concat("awn","-confirm")},s={prefix:c.toast,klass:{label:"".concat(c.toast,"-label"),content:"".concat(c.toast,"-content"),icon:"".concat(c.toast,"-icon"),progressBar:"".concat(c.toast,"-progress-bar"),progressBarPause:"".concat(c.toast,"-progress-bar-paused")},ids:{container:"".concat(c.toast,"-container")}},u={prefix:c.popup,klass:{buttons:"".concat("awn","-buttons"),button:c.btn,successBtn:"".concat(c.btn,"-success"),cancelBtn:"".concat(c.btn,"-cancel"),title:"".concat(c.popup,"-title"),body:"".concat(c.popup,"-body"),content:"".concat(c.popup,"-content"),dotAnimation:"".concat(c.popup,"-loading-dots")},ids:{wrapper:"".concat(c.popup,"-wrapper"),confirmOk:"".concat(c.confirm,"-ok"),confirmCancel:"".concat(c.confirm,"-cancel")}},l={klass:{hiding:"".concat("awn","-hiding")},lib:"awn"};function f(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var p=function(){function t(e,n,o,i,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.newNode=document.createElement("div"),n&&(this.newNode.id=n),o&&(this.newNode.className=o),i&&(this.newNode.style.cssText=i),this.parent=e,this.options=r}var e,n,o;return e=t,(n=[{key:"beforeInsert",value:function(){}},{key:"afterInsert",value:function(){}},{key:"insert",value:function(){return this.beforeInsert(),this.el=this.parent.appendChild(this.newNode),this.afterInsert(),this}},{key:"replace",value:function(t){var e=this;if(this.getElement())return this.beforeDelete().then(function(){return e.updateType(t.type),e.parent.replaceChild(t.newNode,e.el),e.el=e.getElement(t.newNode),e.afterInsert(),e})}},{key:"beforeDelete",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el,n=0;return this.start&&(n=this.options.minDurations[this.type]+this.start-Date.now())<0&&(n=0),new Promise(function(o){setTimeout(function(){e.classList.add(l.klass.hiding),setTimeout(o,t.options.animationDuration)},n)})}},{key:"delete",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el;return this.getElement(e)?this.beforeDelete(e).then(function(){e.remove(),t.afterDelete()}):null}},{key:"afterDelete",value:function(){}},{key:"getElement",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el;return document.getElementById(t.id)}},{key:"addEvent",value:function(t,e){this.el.addEventListener(t,e)}},{key:"toggleClass",value:function(t){this.el.classList.toggle(t)}},{key:"updateType",value:function(t){this.type=t,this.duration=this.options.duration(this.type)}}])&&f(e.prototype,n),o&&f(e,o),t}();function d(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var y=function(){function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.callback=e,this.remaining=n,this.resume()}var e,n,o;return e=t,(n=[{key:"pause",value:function(){this.paused=!0,window.clearTimeout(this.timerId),this.remaining-=new Date-this.start}},{key:"resume",value:function(){var t=this;this.paused=!1,this.start=new Date,window.clearTimeout(this.timerId),this.timerId=window.setTimeout(function(){window.clearTimeout(t.timerId),t.callback()},this.remaining)}},{key:"toggle",value:function(){this.paused?this.resume():this.pause()}}])&&d(e.prototype,n),o&&d(e,o),t}();function h(t){return(h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function m(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function b(t,e){return!e||"object"!==h(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function v(t){return(v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function k(t,e){return(k=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var g=function(t){function e(t,n,o,i){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(r=b(this,v(e).call(this,i,"".concat(s.prefix,"-").concat(Math.floor(Date.now()-100*Math.random())),"".concat(s.prefix," ").concat(s.prefix,"-").concat(n),"animation-duration: ".concat(o.toSecs(o.animationDuration),";"),o))).updateType(n),r.setInnerHtml(t),r}var n,o,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&k(t,e)}(e,p),n=e,(o=[{key:"setInnerHtml",value:function(t){"alert"===this.type&&t&&(t=this.options.formatError(t)),t=this.options.applyReplacements(t,this.type),this.newNode.innerHTML='<div class="awn-toast-wrapper">'.concat(this.progressBar).concat(this.label,'<div class="').concat(s.klass.content,'">').concat(t,'</div><span class="').concat(s.klass.icon,'">').concat(this.options.icon(this.type),"</span></div>")}},{key:"beforeInsert",value:function(){var t=this;if(this.parent.childElementCount>=this.options.maxNotifications){var e=Array.from(this.parent.getElementsByClassName(s.prefix));this.delete(e.find(function(e){return!t.isDeleted(e)}))}}},{key:"afterInsert",value:function(){var t=this;if("async"==this.type)return this.start=Date.now();if(this.addEvent("click",function(){return t.delete()}),!(this.duration<=0)){this.timer=new y(function(){return t.delete()},this.duration);for(var e=0,n=["mouseenter","mouseleave"];e<n.length;e++){var o=n[e];this.addEvent(o,function(){t.isDeleted()||(t.toggleClass(s.klass.progressBarPause),t.timer.toggle())})}}}},{key:"isDeleted",value:function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el).classList.contains(l.klass.hiding)}},{key:"progressBar",get:function(){return this.duration<=0||"async"===this.type?"":"<div class='".concat(s.klass.progressBar,"' style=\"animation-duration:").concat(this.options.toSecs(this.duration),';"></div>')}},{key:"label",get:function(){return'<b class="'.concat(s.klass.label,'">').concat(this.options.label(this.type),"</b>")}}])&&m(n.prototype,o),i&&m(n,i),e}();function w(t){return(w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function _(t,e){return!e||"object"!==w(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function T(t){return(T=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function E(t,e){return(E=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var j=function(t){function e(t){var n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"modal",i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,a=arguments.length>4?arguments[4]:void 0;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var c="animation-duration: ".concat(i.toSecs(i.animationDuration),";");return(n=_(this,T(e).call(this,document.body,u.ids.wrapper,null,c,i)))[u.ids.confirmOk]=r,n[u.ids.confirmCancel]=a,n.className="".concat(u.prefix,"-").concat(o),["confirm","async-block","modal"].includes(o)||(o="modal"),n.updateType(o),n.setInnerHtml(t),n.insert(),n}var n,o,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&E(t,e)}(e,p),n=e,(o=[{key:"setInnerHtml",value:function(t){var e=this.options.applyReplacements(t,this.type);switch(this.type){case"confirm":var n=["<button class='".concat(u.klass.button," ").concat(u.klass.successBtn,"'id='").concat(u.ids.confirmOk,"'>").concat(this.options.labels.confirmOk,"</button>")];!1!==this[u.ids.confirmCancel]&&n.push("<button class='".concat(u.klass.button," ").concat(u.klass.cancelBtn,"'id='").concat(u.ids.confirmCancel,"'>").concat(this.options.labels.confirmCancel,"</button>")),e="".concat(this.options.icon(this.type),"<div class='").concat(u.klass.title,"'>").concat(this.options.label(this.type),'</div><div class="').concat(u.klass.content,'">').concat(e,"</div><div class='").concat(u.klass.buttons," ").concat(u.klass.buttons,"-").concat(n.length,"'>").concat(n.join(),"</div>");break;case"async-block":e="".concat(e,'<div class="').concat(u.klass.dotAnimation,'"></div>')}this.newNode.innerHTML='<div class="'.concat(u.klass.body," ").concat(this.className,'">').concat(e,"</div>")}},{key:"keyupListener",value:function(t){if("async-block"===this.type)return t.preventDefault();switch(t.code){case"Escape":t.preventDefault(),this.delete();case"Tab":if(t.preventDefault(),"confirm"!==this.type||!1===this[u.ids.confirmCancel])return!0;var e=this.okBtn;t.shiftKey?document.activeElement.id==u.ids.confirmOk&&(e=this.cancelBtn):document.activeElement.id!==u.ids.confirmCancel&&(e=this.cancelBtn),e.focus()}}},{key:"afterInsert",value:function(){var t=this;switch(this.listener=function(e){return t.keyupListener(e)},window.addEventListener("keydown",this.listener),this.type){case"async-block":this.start=Date.now();break;case"confirm":this.okBtn.focus(),this.addEvent("click",function(e){if("BUTTON"!==e.target.nodeName)return!1;t.delete(),t[e.target.id]&&t[e.target.id]()});break;default:document.activeElement.blur(),this.addEvent("click",function(e){e.target.id===t.newNode.id&&t.delete()})}}},{key:"afterDelete",value:function(){window.removeEventListener("keydown",this.listener)}},{key:"okBtn",get:function(){return document.getElementById(u.ids.confirmOk)}},{key:"cancelBtn",get:function(){return document.getElementById(u.ids.confirmCancel)}}])&&O(n.prototype,o),i&&O(n,i),e}();function S(t){return(S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function x(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}n.d(e,"default",function(){return P});var P=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=new a(e)}var e,n,o;return e=t,(n=[{key:"tip",value:function(t,e){return this._addToast(t,"tip",e).el}},{key:"info",value:function(t,e){return this._addToast(t,"info",e).el}},{key:"success",value:function(t,e){return this._addToast(t,"success",e).el}},{key:"warning",value:function(t,e){return this._addToast(t,"warning",e).el}},{key:"alert",value:function(t,e){return this._addToast(t,"alert",e).el}},{key:"async",value:function(t,e,n,o,i){var r=this._addToast(o,"async",i);return this._afterAsync(t,e,n,i,r)}},{key:"confirm",value:function(t,e,n,o){return this._addPopup(t,"confirm",o,e,n)}},{key:"asyncBlock",value:function(t,e,n,o,i){var r=this._addPopup(o,"async-block",i);return this._afterAsync(t,e,n,i,r)}},{key:"modal",value:function(t,e,n){return this._addPopup(t,e,n)}},{key:"_addPopup",value:function(t,e,n,o,i){return new j(t,e,this.options.override(n),o,i)}},{key:"_addToast",value:function(t,e,n,o){n=this.options.override(n);var i=new g(t,e,n,this.container);return o?o instanceof j?o.delete().then(function(){return i.insert()}):o.replace(i):i.insert()}},{key:"_afterAsync",value:function(t,e,n,o,i){return t.then(this._responseHandler(e,"success",o,i),this._responseHandler(n,"alert",o,i))}},{key:"_responseHandler",value:function(t,e,n,o){var i=this;return function(r){switch(S(t)){case"undefined":case"string":var a="alert"===e?t||r:t;i._addToast(a,e,n,o);break;default:o.delete().then(function(){t&&t(r)})}return"alert"===e?Promise.reject(r):r}}},{key:"_createContainer",value:function(){return new p(document.body,s.ids.container,"awn-".concat(this.options.position)).insert().el}},{key:"container",get:function(){return document.getElementById(s.ids.container)||this._createContainer()}}])&&x(e.prototype,n),o&&x(e,o),t}()}])}); |
@@ -1,1 +0,1 @@ | ||
var AWN=function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){t.exports=n(1).default},function(t,e,n){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}n.r(e);var r={maxNotifications:10,animationDuration:300,position:"bottom-right",labels:{tip:"Tip",info:"Info",success:"Success",warning:"Attention",alert:"Error",async:"Loading",confirm:"Confirmation required",confirmOk:"OK",confirmCancel:"Cancel"},icons:{tip:"question-circle",info:"info-circle",success:"check-circle",warning:"exclamation-circle",alert:"exclamation-triangle",async:"cog fa-spin",confirm:"exclamation-triangle",prefix:"<i class='fa fas fa-fw fa-",suffix:"'></i>",enabled:!0},replacements:{tip:null,info:null,success:null,warning:null,alert:null,async:null,"async-block":null,modal:null,confirm:null,general:{"<script>":"","<\/script>":""}},messages:{tip:"",info:"",success:"Action has been succeeded",warning:"",alert:"Action has been failed",confirm:"This action can't be undone. Continue?",async:"Please, wait...","async-block":"Loading"},formatError:function(t){if(t.response){if(!t.response.data)return"500 API Server Error";if(t.response.data.errors)return t.response.data.errors.map(function(t){return t.detail}).join("<br>");if(t.response.statusText)return"".concat(t.response.status," ").concat(t.response.statusText,": ").concat(t.response.data)}return t.message?t.message:t},durations:{global:5e3,success:null,info:null,tip:null,warning:null,alert:null},minDurations:{async:1e3,"async-block":1e3}},a=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Object.assign(this,this.defaultsDeep(n,e))}var e,n,a;return e=t,(n=[{key:"icon",value:function(t){return this.icons.enabled?"".concat(this.icons.prefix).concat(this.icons[t]).concat(this.icons.suffix):""}},{key:"label",value:function(t){return this.labels[t]}},{key:"duration",value:function(t){var e=this.durations[t];return null===e?this.durations.global:e}},{key:"toSecs",value:function(t){return"".concat(t/1e3,"s")}},{key:"applyReplacements",value:function(t,e){if(!t)return this.messages[e]||"";for(var n=0,o=["general",e];n<o.length;n++){var i=o[n];if(this.replacements[i])for(var r in this.replacements[i])t=t.replace(r,this.replacements[i][r])}return t}},{key:"override",value:function(e){return e?new t(e,this):this}},{key:"defaultsDeep",value:function(t,e){var n={};for(var i in t)e.hasOwnProperty(i)?n[i]="object"===o(t[i])&&null!==t[i]?this.defaultsDeep(t[i],e[i]):e[i]:n[i]=t[i];return n}}])&&i(e.prototype,n),a&&i(e,a),t}(),s={popup:"".concat("awn","-popup"),toast:"".concat("awn","-toast"),btn:"".concat("awn","-btn"),confirm:"".concat("awn","-confirm")},c={prefix:s.toast,klass:{label:"".concat(s.toast,"-label"),content:"".concat(s.toast,"-content"),icon:"".concat(s.toast,"-icon"),progressBar:"".concat(s.toast,"-progress-bar"),progressBarPause:"".concat(s.toast,"-progress-bar-paused")},ids:{container:"".concat(s.toast,"-container")}},u={prefix:s.popup,klass:{buttons:"".concat("awn","-buttons"),button:s.btn,successBtn:"".concat(s.btn,"-success"),cancelBtn:"".concat(s.btn,"-cancel"),title:"".concat(s.popup,"-title"),body:"".concat(s.popup,"-body"),content:"".concat(s.popup,"-content"),dotAnimation:"".concat(s.popup,"-loading-dots")},ids:{wrapper:"".concat(s.popup,"-wrapper"),confirmOk:"".concat(s.confirm,"-ok"),confirmCancel:"".concat(s.confirm,"-cancel")}},l={klass:{hiding:"".concat("awn","-hiding")},lib:"awn"};function f(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var p=function(){function t(e,n,o,i,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.newNode=document.createElement("div"),n&&(this.newNode.id=n),o&&(this.newNode.className=o),i&&(this.newNode.style.cssText=i),this.parent=e,this.options=r}var e,n,o;return e=t,(n=[{key:"beforeInsert",value:function(){}},{key:"afterInsert",value:function(){}},{key:"insert",value:function(){return this.beforeInsert(),this.el=this.parent.appendChild(this.newNode),this.afterInsert(),this}},{key:"replace",value:function(t){var e=this;if(this.getElement())return this.beforeDelete().then(function(){return e.updateType(t.type),e.parent.replaceChild(t.newNode,e.el),e.el=e.getElement(t.newNode),e.afterInsert(),e})}},{key:"beforeDelete",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el,n=0;return this.start&&(n=this.options.minDurations[this.type]+this.start-Date.now())<0&&(n=0),new Promise(function(o){setTimeout(function(){e.classList.add(l.klass.hiding),setTimeout(o,t.options.animationDuration)},n)})}},{key:"delete",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el;return this.getElement(e)?this.beforeDelete(e).then(function(){e.remove(),t.afterDelete()}):null}},{key:"afterDelete",value:function(){}},{key:"getElement",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el;return document.getElementById(t.id)}},{key:"addEvent",value:function(t,e){this.el.addEventListener(t,e)}},{key:"toggleClass",value:function(t){this.el.classList.toggle(t)}},{key:"updateType",value:function(t){this.type=t,this.duration=this.options.duration(this.type)}}])&&f(e.prototype,n),o&&f(e,o),t}();function d(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var y=function(){function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.callback=e,this.remaining=n,this.resume()}var e,n,o;return e=t,(n=[{key:"pause",value:function(){this.paused=!0,window.clearTimeout(this.timerId),this.remaining-=new Date-this.start}},{key:"resume",value:function(){var t=this;this.paused=!1,this.start=new Date,window.clearTimeout(this.timerId),this.timerId=window.setTimeout(function(){window.clearTimeout(t.timerId),t.callback()},this.remaining)}},{key:"toggle",value:function(){this.paused?this.resume():this.pause()}}])&&d(e.prototype,n),o&&d(e,o),t}();function h(t){return(h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function m(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function v(t,e){return!e||"object"!==h(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function b(t){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function k(t,e){return(k=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var g=function(t){function e(t,n,o,i){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(r=v(this,b(e).call(this,i,"".concat(c.prefix,"-").concat(Math.floor(Date.now()-100*Math.random())),"".concat(c.prefix," ").concat(c.prefix,"-").concat(n),"animation-duration: ".concat(o.toSecs(o.animationDuration),";"),o))).updateType(n),r.setInnerHtml(t),r}var n,o,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&k(t,e)}(e,p),n=e,(o=[{key:"setInnerHtml",value:function(t){"alert"===this.type&&t&&(t=this.options.formatError(t)),t=this.options.applyReplacements(t,this.type),this.newNode.innerHTML='<div class="awn-toast-wrapper">'.concat(this.progressBar).concat(this.label,'<div class="').concat(c.klass.content,'">').concat(t,'</div><span class="').concat(c.klass.icon,'">').concat(this.options.icon(this.type),"</span></div>")}},{key:"beforeInsert",value:function(){var t=this;if(this.parent.childElementCount>=this.options.maxNotifications){var e=Array.from(this.parent.getElementsByClassName(c.prefix));this.delete(e.find(function(e){return!t.isDeleted(e)}))}}},{key:"afterInsert",value:function(){var t=this;if("async"==this.type)return this.start=Date.now();if(this.addEvent("click",function(){return t.delete()}),!(this.duration<=0)){this.timer=new y(function(){return t.delete()},this.duration);for(var e=0,n=["mouseenter","mouseleave"];e<n.length;e++){var o=n[e];this.addEvent(o,function(){t.isDeleted()||(t.toggleClass(c.klass.progressBarPause),t.timer.toggle())})}}}},{key:"isDeleted",value:function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el).classList.contains(l.klass.hiding)}},{key:"progressBar",get:function(){return this.duration<=0||"async"===this.type?"":"<div class='".concat(c.klass.progressBar,"' style=\"animation-duration:").concat(this.options.toSecs(this.duration),';"></div>')}},{key:"label",get:function(){return'<b class="'.concat(c.klass.label,'">').concat(this.options.label(this.type),"</b>")}}])&&m(n.prototype,o),i&&m(n,i),e}();function w(t){return(w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function _(t,e){return!e||"object"!==w(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function T(t){return(T=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function E(t,e){return(E=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var S=function(t){function e(t){var n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"modal",i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,a=arguments.length>4?arguments[4]:void 0;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var s="animation-duration: ".concat(i.toSecs(i.animationDuration),";");return(n=_(this,T(e).call(this,document.body,u.ids.wrapper,null,s,i)))[u.ids.confirmOk]=r,n[u.ids.confirmCancel]=a,n.className=o,["confirm","async-block","modal"].includes(o)||(o="modal"),n.updateType(o),n.setInnerHtml(t),n.insert(),n}var n,o,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&E(t,e)}(e,p),n=e,(o=[{key:"setInnerHtml",value:function(t){var e=this.options.applyReplacements(t,this.type);switch(this.type){case"confirm":e="".concat(this.options.icon(this.type),"<div class='").concat(u.klass.title,"'>").concat(this.options.label(this.type),'</div><div class="').concat(u.klass.content,'">').concat(e,"</div><div class='").concat(u.klass.buttons,"'><button class='").concat(u.klass.button," ").concat(u.klass.successBtn,"'id='").concat(u.ids.confirmOk,"'>").concat(this.options.labels.confirmOk,"</button><button class='").concat(u.klass.button," ").concat(u.klass.cancelBtn,"'id='").concat(u.ids.confirmCancel,"'>").concat(this.options.labels.confirmCancel,"</button></div>");break;case"async-block":e="".concat(e,'<div class="').concat(u.klass.dotAnimation,'"></div>')}this.newNode.innerHTML='<div class="'.concat(u.klass.body," ").concat(u.prefix,"-").concat(this.className,'">').concat(e,"</div>")}},{key:"keyupListener",value:function(t){if("async-block"===this.type)return t.preventDefault();switch(t.code){case"Escape":t.preventDefault(),this.delete();case"Tab":if(t.preventDefault(),"confirm"!==this.type)return!0;var e=this.okBtn;t.shiftKey?document.activeElement.id==u.ids.confirmOk&&(e=this.cancelBtn):document.activeElement.id!==u.ids.confirmCancel&&(e=this.cancelBtn),e.focus()}}},{key:"afterInsert",value:function(){var t=this;switch(this.listener=function(e){return t.keyupListener(e)},window.addEventListener("keydown",this.listener),this.type){case"async-block":this.start=Date.now();break;case"confirm":this.okBtn.focus(),this.addEvent("click",function(e){if("BUTTON"!==e.target.nodeName)return!1;t.delete(),t[e.target.id]&&t[e.target.id]()});break;default:document.activeElement.blur(),this.addEvent("click",function(e){e.target.id===t.newNode.id&&t.delete()})}}},{key:"afterDelete",value:function(){window.removeEventListener("keydown",this.listener)}},{key:"okBtn",get:function(){return document.getElementById(u.ids.confirmOk)}},{key:"cancelBtn",get:function(){return document.getElementById(u.ids.confirmCancel)}}])&&O(n.prototype,o),i&&O(n,i),e}();function P(t){return(P="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function j(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}n.d(e,"default",function(){return x});var x=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=new a(e)}var e,n,o;return e=t,(n=[{key:"tip",value:function(t,e){return this._addToast(t,"tip",e).el}},{key:"info",value:function(t,e){return this._addToast(t,"info",e).el}},{key:"success",value:function(t,e){return this._addToast(t,"success",e).el}},{key:"warning",value:function(t,e){return this._addToast(t,"warning",e).el}},{key:"alert",value:function(t,e){return this._addToast(t,"alert",e).el}},{key:"async",value:function(t,e,n,o,i){var r=this._addToast(o,"async",i);return this._afterAsync(t,e,n,i,r)}},{key:"confirm",value:function(t,e,n,o){return this._addPopup(t,"confirm",o,e,n)}},{key:"asyncBlock",value:function(t,e,n,o,i){var r=this._addPopup(o,"async-block",i);return this._afterAsync(t,e,n,i,r)}},{key:"modal",value:function(t,e,n){return this._addPopup(t,e,n)}},{key:"_addPopup",value:function(t,e,n,o,i){return new S(t,e,this.options.override(n),o,i)}},{key:"_addToast",value:function(t,e,n,o){n=this.options.override(n);var i=new g(t,e,n,this.container);return o?o instanceof S?o.delete().then(function(){return i.insert()}):o.replace(i):i.insert()}},{key:"_afterAsync",value:function(t,e,n,o,i){return t.then(this._responseHandler(e,"success",o,i),this._responseHandler(n,"alert",o,i))}},{key:"_responseHandler",value:function(t,e,n,o){var i=this;return function(r){switch(P(t)){case"undefined":case"string":var a="alert"===e?t||r:t;i._addToast(a,e,n,o);break;default:o.delete().then(function(){t&&t(r)})}return"alert"===e?Promise.reject(r):r}}},{key:"_createContainer",value:function(){return new p(document.body,c.ids.container,"awn-".concat(this.options.position)).insert().el}},{key:"container",get:function(){return document.getElementById(c.ids.container)||this._createContainer()}}])&&j(e.prototype,n),o&&j(e,o),t}()}]); | ||
var AWN=function(t){var e={};function n(o){if(e[o])return e[o].exports;var i=e[o]={i:o,l:!1,exports:{}};return t[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(o,i,function(e){return t[e]}.bind(null,i));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){t.exports=n(1).default},function(t,e,n){"use strict";function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}n.r(e);var r={maxNotifications:10,animationDuration:300,position:"bottom-right",labels:{tip:"Tip",info:"Info",success:"Success",warning:"Attention",alert:"Error",async:"Loading",confirm:"Confirmation required",confirmOk:"OK",confirmCancel:"Cancel"},icons:{tip:"question-circle",info:"info-circle",success:"check-circle",warning:"exclamation-circle",alert:"exclamation-triangle",async:"cog fa-spin",confirm:"exclamation-triangle",prefix:"<i class='fa fas fa-fw fa-",suffix:"'></i>",enabled:!0},replacements:{tip:null,info:null,success:null,warning:null,alert:null,async:null,"async-block":null,modal:null,confirm:null,general:{"<script>":"","<\/script>":""}},messages:{tip:"",info:"",success:"Action has been succeeded",warning:"",alert:"Action has been failed",confirm:"This action can't be undone. Continue?",async:"Please, wait...","async-block":"Loading"},formatError:function(t){if(t.response){if(!t.response.data)return"500 API Server Error";if(t.response.data.errors)return t.response.data.errors.map(function(t){return t.detail}).join("<br>");if(t.response.statusText)return"".concat(t.response.status," ").concat(t.response.statusText,": ").concat(t.response.data)}return t.message?t.message:t},durations:{global:5e3,success:null,info:null,tip:null,warning:null,alert:null},minDurations:{async:1e3,"async-block":1e3}},a=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Object.assign(this,this.defaultsDeep(n,e))}var e,n,a;return e=t,(n=[{key:"icon",value:function(t){return this.icons.enabled?"".concat(this.icons.prefix).concat(this.icons[t]).concat(this.icons.suffix):""}},{key:"label",value:function(t){return this.labels[t]}},{key:"duration",value:function(t){var e=this.durations[t];return null===e?this.durations.global:e}},{key:"toSecs",value:function(t){return"".concat(t/1e3,"s")}},{key:"applyReplacements",value:function(t,e){if(!t)return this.messages[e]||"";for(var n=0,o=["general",e];n<o.length;n++){var i=o[n];if(this.replacements[i])for(var r in this.replacements[i])t=t.replace(r,this.replacements[i][r])}return t}},{key:"override",value:function(e){return e?new t(e,this):this}},{key:"defaultsDeep",value:function(t,e){var n={};for(var i in t)e.hasOwnProperty(i)?n[i]="object"===o(t[i])&&null!==t[i]?this.defaultsDeep(t[i],e[i]):e[i]:n[i]=t[i];return n}}])&&i(e.prototype,n),a&&i(e,a),t}(),s={popup:"".concat("awn","-popup"),toast:"".concat("awn","-toast"),btn:"".concat("awn","-btn"),confirm:"".concat("awn","-confirm")},c={prefix:s.toast,klass:{label:"".concat(s.toast,"-label"),content:"".concat(s.toast,"-content"),icon:"".concat(s.toast,"-icon"),progressBar:"".concat(s.toast,"-progress-bar"),progressBarPause:"".concat(s.toast,"-progress-bar-paused")},ids:{container:"".concat(s.toast,"-container")}},u={prefix:s.popup,klass:{buttons:"".concat("awn","-buttons"),button:s.btn,successBtn:"".concat(s.btn,"-success"),cancelBtn:"".concat(s.btn,"-cancel"),title:"".concat(s.popup,"-title"),body:"".concat(s.popup,"-body"),content:"".concat(s.popup,"-content"),dotAnimation:"".concat(s.popup,"-loading-dots")},ids:{wrapper:"".concat(s.popup,"-wrapper"),confirmOk:"".concat(s.confirm,"-ok"),confirmCancel:"".concat(s.confirm,"-cancel")}},l={klass:{hiding:"".concat("awn","-hiding")},lib:"awn"};function f(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var p=function(){function t(e,n,o,i,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.newNode=document.createElement("div"),n&&(this.newNode.id=n),o&&(this.newNode.className=o),i&&(this.newNode.style.cssText=i),this.parent=e,this.options=r}var e,n,o;return e=t,(n=[{key:"beforeInsert",value:function(){}},{key:"afterInsert",value:function(){}},{key:"insert",value:function(){return this.beforeInsert(),this.el=this.parent.appendChild(this.newNode),this.afterInsert(),this}},{key:"replace",value:function(t){var e=this;if(this.getElement())return this.beforeDelete().then(function(){return e.updateType(t.type),e.parent.replaceChild(t.newNode,e.el),e.el=e.getElement(t.newNode),e.afterInsert(),e})}},{key:"beforeDelete",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el,n=0;return this.start&&(n=this.options.minDurations[this.type]+this.start-Date.now())<0&&(n=0),new Promise(function(o){setTimeout(function(){e.classList.add(l.klass.hiding),setTimeout(o,t.options.animationDuration)},n)})}},{key:"delete",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el;return this.getElement(e)?this.beforeDelete(e).then(function(){e.remove(),t.afterDelete()}):null}},{key:"afterDelete",value:function(){}},{key:"getElement",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el;return document.getElementById(t.id)}},{key:"addEvent",value:function(t,e){this.el.addEventListener(t,e)}},{key:"toggleClass",value:function(t){this.el.classList.toggle(t)}},{key:"updateType",value:function(t){this.type=t,this.duration=this.options.duration(this.type)}}])&&f(e.prototype,n),o&&f(e,o),t}();function d(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}var y=function(){function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.callback=e,this.remaining=n,this.resume()}var e,n,o;return e=t,(n=[{key:"pause",value:function(){this.paused=!0,window.clearTimeout(this.timerId),this.remaining-=new Date-this.start}},{key:"resume",value:function(){var t=this;this.paused=!1,this.start=new Date,window.clearTimeout(this.timerId),this.timerId=window.setTimeout(function(){window.clearTimeout(t.timerId),t.callback()},this.remaining)}},{key:"toggle",value:function(){this.paused?this.resume():this.pause()}}])&&d(e.prototype,n),o&&d(e,o),t}();function h(t){return(h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function m(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function v(t,e){return!e||"object"!==h(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function b(t){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function k(t,e){return(k=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var g=function(t){function e(t,n,o,i){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(r=v(this,b(e).call(this,i,"".concat(c.prefix,"-").concat(Math.floor(Date.now()-100*Math.random())),"".concat(c.prefix," ").concat(c.prefix,"-").concat(n),"animation-duration: ".concat(o.toSecs(o.animationDuration),";"),o))).updateType(n),r.setInnerHtml(t),r}var n,o,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&k(t,e)}(e,p),n=e,(o=[{key:"setInnerHtml",value:function(t){"alert"===this.type&&t&&(t=this.options.formatError(t)),t=this.options.applyReplacements(t,this.type),this.newNode.innerHTML='<div class="awn-toast-wrapper">'.concat(this.progressBar).concat(this.label,'<div class="').concat(c.klass.content,'">').concat(t,'</div><span class="').concat(c.klass.icon,'">').concat(this.options.icon(this.type),"</span></div>")}},{key:"beforeInsert",value:function(){var t=this;if(this.parent.childElementCount>=this.options.maxNotifications){var e=Array.from(this.parent.getElementsByClassName(c.prefix));this.delete(e.find(function(e){return!t.isDeleted(e)}))}}},{key:"afterInsert",value:function(){var t=this;if("async"==this.type)return this.start=Date.now();if(this.addEvent("click",function(){return t.delete()}),!(this.duration<=0)){this.timer=new y(function(){return t.delete()},this.duration);for(var e=0,n=["mouseenter","mouseleave"];e<n.length;e++){var o=n[e];this.addEvent(o,function(){t.isDeleted()||(t.toggleClass(c.klass.progressBarPause),t.timer.toggle())})}}}},{key:"isDeleted",value:function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.el).classList.contains(l.klass.hiding)}},{key:"progressBar",get:function(){return this.duration<=0||"async"===this.type?"":"<div class='".concat(c.klass.progressBar,"' style=\"animation-duration:").concat(this.options.toSecs(this.duration),';"></div>')}},{key:"label",get:function(){return'<b class="'.concat(c.klass.label,'">').concat(this.options.label(this.type),"</b>")}}])&&m(n.prototype,o),i&&m(n,i),e}();function w(t){return(w="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function O(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}function _(t,e){return!e||"object"!==w(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function T(t){return(T=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function E(t,e){return(E=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}var S=function(t){function e(t){var n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"modal",i=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,a=arguments.length>4?arguments[4]:void 0;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var s="animation-duration: ".concat(i.toSecs(i.animationDuration),";");return(n=_(this,T(e).call(this,document.body,u.ids.wrapper,null,s,i)))[u.ids.confirmOk]=r,n[u.ids.confirmCancel]=a,n.className="".concat(u.prefix,"-").concat(o),["confirm","async-block","modal"].includes(o)||(o="modal"),n.updateType(o),n.setInnerHtml(t),n.insert(),n}var n,o,i;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&E(t,e)}(e,p),n=e,(o=[{key:"setInnerHtml",value:function(t){var e=this.options.applyReplacements(t,this.type);switch(this.type){case"confirm":var n=["<button class='".concat(u.klass.button," ").concat(u.klass.successBtn,"'id='").concat(u.ids.confirmOk,"'>").concat(this.options.labels.confirmOk,"</button>")];!1!==this[u.ids.confirmCancel]&&n.push("<button class='".concat(u.klass.button," ").concat(u.klass.cancelBtn,"'id='").concat(u.ids.confirmCancel,"'>").concat(this.options.labels.confirmCancel,"</button>")),e="".concat(this.options.icon(this.type),"<div class='").concat(u.klass.title,"'>").concat(this.options.label(this.type),'</div><div class="').concat(u.klass.content,'">').concat(e,"</div><div class='").concat(u.klass.buttons," ").concat(u.klass.buttons,"-").concat(n.length,"'>").concat(n.join(),"</div>");break;case"async-block":e="".concat(e,'<div class="').concat(u.klass.dotAnimation,'"></div>')}this.newNode.innerHTML='<div class="'.concat(u.klass.body," ").concat(this.className,'">').concat(e,"</div>")}},{key:"keyupListener",value:function(t){if("async-block"===this.type)return t.preventDefault();switch(t.code){case"Escape":t.preventDefault(),this.delete();case"Tab":if(t.preventDefault(),"confirm"!==this.type||!1===this[u.ids.confirmCancel])return!0;var e=this.okBtn;t.shiftKey?document.activeElement.id==u.ids.confirmOk&&(e=this.cancelBtn):document.activeElement.id!==u.ids.confirmCancel&&(e=this.cancelBtn),e.focus()}}},{key:"afterInsert",value:function(){var t=this;switch(this.listener=function(e){return t.keyupListener(e)},window.addEventListener("keydown",this.listener),this.type){case"async-block":this.start=Date.now();break;case"confirm":this.okBtn.focus(),this.addEvent("click",function(e){if("BUTTON"!==e.target.nodeName)return!1;t.delete(),t[e.target.id]&&t[e.target.id]()});break;default:document.activeElement.blur(),this.addEvent("click",function(e){e.target.id===t.newNode.id&&t.delete()})}}},{key:"afterDelete",value:function(){window.removeEventListener("keydown",this.listener)}},{key:"okBtn",get:function(){return document.getElementById(u.ids.confirmOk)}},{key:"cancelBtn",get:function(){return document.getElementById(u.ids.confirmCancel)}}])&&O(n.prototype,o),i&&O(n,i),e}();function j(t){return(j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function P(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}n.d(e,"default",function(){return x});var x=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.options=new a(e)}var e,n,o;return e=t,(n=[{key:"tip",value:function(t,e){return this._addToast(t,"tip",e).el}},{key:"info",value:function(t,e){return this._addToast(t,"info",e).el}},{key:"success",value:function(t,e){return this._addToast(t,"success",e).el}},{key:"warning",value:function(t,e){return this._addToast(t,"warning",e).el}},{key:"alert",value:function(t,e){return this._addToast(t,"alert",e).el}},{key:"async",value:function(t,e,n,o,i){var r=this._addToast(o,"async",i);return this._afterAsync(t,e,n,i,r)}},{key:"confirm",value:function(t,e,n,o){return this._addPopup(t,"confirm",o,e,n)}},{key:"asyncBlock",value:function(t,e,n,o,i){var r=this._addPopup(o,"async-block",i);return this._afterAsync(t,e,n,i,r)}},{key:"modal",value:function(t,e,n){return this._addPopup(t,e,n)}},{key:"_addPopup",value:function(t,e,n,o,i){return new S(t,e,this.options.override(n),o,i)}},{key:"_addToast",value:function(t,e,n,o){n=this.options.override(n);var i=new g(t,e,n,this.container);return o?o instanceof S?o.delete().then(function(){return i.insert()}):o.replace(i):i.insert()}},{key:"_afterAsync",value:function(t,e,n,o,i){return t.then(this._responseHandler(e,"success",o,i),this._responseHandler(n,"alert",o,i))}},{key:"_responseHandler",value:function(t,e,n,o){var i=this;return function(r){switch(j(t)){case"undefined":case"string":var a="alert"===e?t||r:t;i._addToast(a,e,n,o);break;default:o.delete().then(function(){t&&t(r)})}return"alert"===e?Promise.reject(r):r}}},{key:"_createContainer",value:function(){return new p(document.body,c.ids.container,"awn-".concat(this.options.position)).insert().el}},{key:"container",get:function(){return document.getElementById(c.ids.container)||this._createContainer()}}])&&P(e.prototype,n),o&&P(e,o),t}()}]); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AWN=e():t.AWN=e()}(window,function(){return function(t){var e={};function n(s){if(e[s])return e[s].exports;var i=e[s]={i:s,l:!1,exports:{}};return t[s].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,s){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(n.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(s,i,function(e){return t[e]}.bind(null,i));return s},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e);const s={maxNotifications:10,animationDuration:300,position:"bottom-right",labels:{tip:"Tip",info:"Info",success:"Success",warning:"Attention",alert:"Error",async:"Loading",confirm:"Confirmation required",confirmOk:"OK",confirmCancel:"Cancel"},icons:{tip:"question-circle",info:"info-circle",success:"check-circle",warning:"exclamation-circle",alert:"exclamation-triangle",async:"cog fa-spin",confirm:"exclamation-triangle",prefix:"<i class='fa fas fa-fw fa-",suffix:"'></i>",enabled:!0},replacements:{tip:null,info:null,success:null,warning:null,alert:null,async:null,"async-block":null,modal:null,confirm:null,general:{"<script>":"","<\/script>":""}},messages:{tip:"",info:"",success:"Action has been succeeded",warning:"",alert:"Action has been failed",confirm:"This action can't be undone. Continue?",async:"Please, wait...","async-block":"Loading"},formatError(t){if(t.response){if(!t.response.data)return"500 API Server Error";if(t.response.data.errors)return t.response.data.errors.map(t=>t.detail).join("<br>");if(t.response.statusText)return"".concat(t.response.status," ").concat(t.response.statusText,": ").concat(t.response.data)}return t.message?t.message:t},durations:{global:5e3,success:null,info:null,tip:null,warning:null,alert:null},minDurations:{async:1e3,"async-block":1e3}};class i{constructor(t={},e=s){Object.assign(this,this.defaultsDeep(e,t))}icon(t){return this.icons.enabled?"".concat(this.icons.prefix).concat(this.icons[t]).concat(this.icons.suffix):""}label(t){return this.labels[t]}duration(t){let e=this.durations[t];return null===e?this.durations.global:e}toSecs(t){return"".concat(t/1e3,"s")}applyReplacements(t,e){if(!t)return this.messages[e]||"";for(const n of["general",e])if(this.replacements[n])for(const e in this.replacements[n])t=t.replace(e,this.replacements[n][e]);return t}override(t){return t?new i(t,this):this}defaultsDeep(t,e){let n={};for(const s in t)e.hasOwnProperty(s)?n[s]="object"==typeof t[s]&&null!==t[s]?this.defaultsDeep(t[s],e[s]):e[s]:n[s]=t[s];return n}}const a={popup:"".concat("awn","-popup"),toast:"".concat("awn","-toast"),btn:"".concat("awn","-btn"),confirm:"".concat("awn","-confirm")},o={prefix:a.toast,klass:{label:"".concat(a.toast,"-label"),content:"".concat(a.toast,"-content"),icon:"".concat(a.toast,"-icon"),progressBar:"".concat(a.toast,"-progress-bar"),progressBarPause:"".concat(a.toast,"-progress-bar-paused")},ids:{container:"".concat(a.toast,"-container")}},r={prefix:a.popup,klass:{buttons:"".concat("awn","-buttons"),button:a.btn,successBtn:"".concat(a.btn,"-success"),cancelBtn:"".concat(a.btn,"-cancel"),title:"".concat(a.popup,"-title"),body:"".concat(a.popup,"-body"),content:"".concat(a.popup,"-content"),dotAnimation:"".concat(a.popup,"-loading-dots")},ids:{wrapper:"".concat(a.popup,"-wrapper"),confirmOk:"".concat(a.confirm,"-ok"),confirmCancel:"".concat(a.confirm,"-cancel")}},c={klass:{hiding:"".concat("awn","-hiding")},lib:"awn"};var l=class{constructor(t,e,n,s,i){this.newNode=document.createElement("div"),e&&(this.newNode.id=e),n&&(this.newNode.className=n),s&&(this.newNode.style.cssText=s),this.parent=t,this.options=i}beforeInsert(){}afterInsert(){}insert(){return this.beforeInsert(),this.el=this.parent.appendChild(this.newNode),this.afterInsert(),this}replace(t){if(this.getElement())return this.beforeDelete().then(()=>(this.updateType(t.type),this.parent.replaceChild(t.newNode,this.el),this.el=this.getElement(t.newNode),this.afterInsert(),this))}beforeDelete(t=this.el){let e=0;return this.start&&(e=this.options.minDurations[this.type]+this.start-Date.now())<0&&(e=0),new Promise(n=>{setTimeout(()=>{t.classList.add(c.klass.hiding),setTimeout(n,this.options.animationDuration)},e)})}delete(t=this.el){return this.getElement(t)?this.beforeDelete(t).then(()=>{t.remove(),this.afterDelete()}):null}afterDelete(){}getElement(t=this.el){return document.getElementById(t.id)}addEvent(t,e){this.el.addEventListener(t,e)}toggleClass(t){this.el.classList.toggle(t)}updateType(t){this.type=t,this.duration=this.options.duration(this.type)}},d=class extends l{constructor(t,e,n,s){super(s,"".concat(o.prefix,"-").concat(Math.floor(Date.now()-100*Math.random())),"".concat(o.prefix," ").concat(o.prefix,"-").concat(e),"animation-duration: ".concat(n.toSecs(n.animationDuration),";"),n),this.updateType(e),this.setInnerHtml(t)}setInnerHtml(t){"alert"===this.type&&t&&(t=this.options.formatError(t)),t=this.options.applyReplacements(t,this.type),this.newNode.innerHTML='<div class="awn-toast-wrapper">'.concat(this.progressBar).concat(this.label,'<div class="').concat(o.klass.content,'">').concat(t,'</div><span class="').concat(o.klass.icon,'">').concat(this.options.icon(this.type),"</span></div>")}beforeInsert(){if(this.parent.childElementCount>=this.options.maxNotifications){let t=Array.from(this.parent.getElementsByClassName(o.prefix));this.delete(t.find(t=>!this.isDeleted(t)))}}afterInsert(){if("async"==this.type)return this.start=Date.now();if(this.addEvent("click",()=>this.delete()),!(this.duration<=0)){this.timer=new class{constructor(t,e){this.callback=t,this.remaining=e,this.resume()}pause(){this.paused=!0,window.clearTimeout(this.timerId),this.remaining-=new Date-this.start}resume(){this.paused=!1,this.start=new Date,window.clearTimeout(this.timerId),this.timerId=window.setTimeout(()=>{window.clearTimeout(this.timerId),this.callback()},this.remaining)}toggle(){this.paused?this.resume():this.pause()}}(()=>this.delete(),this.duration);for(const t of["mouseenter","mouseleave"])this.addEvent(t,()=>{this.isDeleted()||(this.toggleClass(o.klass.progressBarPause),this.timer.toggle())})}}isDeleted(t=this.el){return t.classList.contains(c.klass.hiding)}get progressBar(){return this.duration<=0||"async"===this.type?"":"<div class='".concat(o.klass.progressBar,"' style=\"animation-duration:").concat(this.options.toSecs(this.duration),';"></div>')}get label(){return'<b class="'.concat(o.klass.label,'">').concat(this.options.label(this.type),"</b>")}},u=class extends l{constructor(t,e="modal",n,s,i){let a="animation-duration: ".concat(n.toSecs(n.animationDuration),";");super(document.body,r.ids.wrapper,null,a,n),this[r.ids.confirmOk]=s,this[r.ids.confirmCancel]=i,this.className=e,["confirm","async-block","modal"].includes(e)||(e="modal"),this.updateType(e),this.setInnerHtml(t),this.insert()}setInnerHtml(t){let e=this.options.applyReplacements(t,this.type);switch(this.type){case"confirm":e="".concat(this.options.icon(this.type),"<div class='").concat(r.klass.title,"'>").concat(this.options.label(this.type),'</div><div class="').concat(r.klass.content,'">').concat(e,"</div><div class='").concat(r.klass.buttons,"'><button class='").concat(r.klass.button," ").concat(r.klass.successBtn,"'id='").concat(r.ids.confirmOk,"'>").concat(this.options.labels.confirmOk,"</button><button class='").concat(r.klass.button," ").concat(r.klass.cancelBtn,"'id='").concat(r.ids.confirmCancel,"'>").concat(this.options.labels.confirmCancel,"</button></div>");break;case"async-block":e="".concat(e,'<div class="').concat(r.klass.dotAnimation,'"></div>')}this.newNode.innerHTML='<div class="'.concat(r.klass.body," ").concat(r.prefix,"-").concat(this.className,'">').concat(e,"</div>")}keyupListener(t){if("async-block"===this.type)return t.preventDefault();switch(t.code){case"Escape":t.preventDefault(),this.delete();case"Tab":if(t.preventDefault(),"confirm"!==this.type)return!0;let e=this.okBtn;t.shiftKey?document.activeElement.id==r.ids.confirmOk&&(e=this.cancelBtn):document.activeElement.id!==r.ids.confirmCancel&&(e=this.cancelBtn),e.focus()}}afterInsert(){switch(this.listener=(t=>this.keyupListener(t)),window.addEventListener("keydown",this.listener),this.type){case"async-block":this.start=Date.now();break;case"confirm":this.okBtn.focus(),this.addEvent("click",t=>{if("BUTTON"!==t.target.nodeName)return!1;this.delete(),this[t.target.id]&&this[t.target.id]()});break;default:document.activeElement.blur(),this.addEvent("click",t=>{t.target.id===this.newNode.id&&this.delete()})}}afterDelete(){window.removeEventListener("keydown",this.listener)}get okBtn(){return document.getElementById(r.ids.confirmOk)}get cancelBtn(){return document.getElementById(r.ids.confirmCancel)}};n.d(e,"default",function(){return p});class p{constructor(t={}){this.options=new i(t)}tip(t,e){return this._addToast(t,"tip",e).el}info(t,e){return this._addToast(t,"info",e).el}success(t,e){return this._addToast(t,"success",e).el}warning(t,e){return this._addToast(t,"warning",e).el}alert(t,e){return this._addToast(t,"alert",e).el}async(t,e,n,s,i){let a=this._addToast(s,"async",i);return this._afterAsync(t,e,n,i,a)}confirm(t,e,n,s){return this._addPopup(t,"confirm",s,e,n)}asyncBlock(t,e,n,s,i){let a=this._addPopup(s,"async-block",i);return this._afterAsync(t,e,n,i,a)}modal(t,e,n){return this._addPopup(t,e,n)}_addPopup(t,e,n,s,i){return new u(t,e,this.options.override(n),s,i)}_addToast(t,e,n,s){n=this.options.override(n);let i=new d(t,e,n,this.container);if(s){if(s instanceof u)return s.delete().then(()=>i.insert());return s.replace(i)}return i.insert()}_afterAsync(t,e,n,s,i){return t.then(this._responseHandler(e,"success",s,i),this._responseHandler(n,"alert",s,i))}_responseHandler(t,e,n,s){return i=>{switch(typeof t){case"undefined":case"string":let a="alert"===e?t||i:t;this._addToast(a,e,n,s);break;default:s.delete().then(()=>{t&&t(i)})}return"alert"===e?Promise.reject(i):i}}_createContainer(){return new l(document.body,o.ids.container,"awn-".concat(this.options.position)).insert().el}get container(){return document.getElementById(o.ids.container)||this._createContainer()}}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.AWN=e():t.AWN=e()}(window,function(){return function(t){var e={};function n(s){if(e[s])return e[s].exports;var i=e[s]={i:s,l:!1,exports:{}};return t[s].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,s){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(n.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(s,i,function(e){return t[e]}.bind(null,i));return s},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";n.r(e);const s={maxNotifications:10,animationDuration:300,position:"bottom-right",labels:{tip:"Tip",info:"Info",success:"Success",warning:"Attention",alert:"Error",async:"Loading",confirm:"Confirmation required",confirmOk:"OK",confirmCancel:"Cancel"},icons:{tip:"question-circle",info:"info-circle",success:"check-circle",warning:"exclamation-circle",alert:"exclamation-triangle",async:"cog fa-spin",confirm:"exclamation-triangle",prefix:"<i class='fa fas fa-fw fa-",suffix:"'></i>",enabled:!0},replacements:{tip:null,info:null,success:null,warning:null,alert:null,async:null,"async-block":null,modal:null,confirm:null,general:{"<script>":"","<\/script>":""}},messages:{tip:"",info:"",success:"Action has been succeeded",warning:"",alert:"Action has been failed",confirm:"This action can't be undone. Continue?",async:"Please, wait...","async-block":"Loading"},formatError(t){if(t.response){if(!t.response.data)return"500 API Server Error";if(t.response.data.errors)return t.response.data.errors.map(t=>t.detail).join("<br>");if(t.response.statusText)return"".concat(t.response.status," ").concat(t.response.statusText,": ").concat(t.response.data)}return t.message?t.message:t},durations:{global:5e3,success:null,info:null,tip:null,warning:null,alert:null},minDurations:{async:1e3,"async-block":1e3}};class i{constructor(t={},e=s){Object.assign(this,this.defaultsDeep(e,t))}icon(t){return this.icons.enabled?"".concat(this.icons.prefix).concat(this.icons[t]).concat(this.icons.suffix):""}label(t){return this.labels[t]}duration(t){let e=this.durations[t];return null===e?this.durations.global:e}toSecs(t){return"".concat(t/1e3,"s")}applyReplacements(t,e){if(!t)return this.messages[e]||"";for(const n of["general",e])if(this.replacements[n])for(const e in this.replacements[n])t=t.replace(e,this.replacements[n][e]);return t}override(t){return t?new i(t,this):this}defaultsDeep(t,e){let n={};for(const s in t)e.hasOwnProperty(s)?n[s]="object"==typeof t[s]&&null!==t[s]?this.defaultsDeep(t[s],e[s]):e[s]:n[s]=t[s];return n}}const o={popup:"".concat("awn","-popup"),toast:"".concat("awn","-toast"),btn:"".concat("awn","-btn"),confirm:"".concat("awn","-confirm")},a={prefix:o.toast,klass:{label:"".concat(o.toast,"-label"),content:"".concat(o.toast,"-content"),icon:"".concat(o.toast,"-icon"),progressBar:"".concat(o.toast,"-progress-bar"),progressBarPause:"".concat(o.toast,"-progress-bar-paused")},ids:{container:"".concat(o.toast,"-container")}},r={prefix:o.popup,klass:{buttons:"".concat("awn","-buttons"),button:o.btn,successBtn:"".concat(o.btn,"-success"),cancelBtn:"".concat(o.btn,"-cancel"),title:"".concat(o.popup,"-title"),body:"".concat(o.popup,"-body"),content:"".concat(o.popup,"-content"),dotAnimation:"".concat(o.popup,"-loading-dots")},ids:{wrapper:"".concat(o.popup,"-wrapper"),confirmOk:"".concat(o.confirm,"-ok"),confirmCancel:"".concat(o.confirm,"-cancel")}},c={klass:{hiding:"".concat("awn","-hiding")},lib:"awn"};var l=class{constructor(t,e,n,s,i){this.newNode=document.createElement("div"),e&&(this.newNode.id=e),n&&(this.newNode.className=n),s&&(this.newNode.style.cssText=s),this.parent=t,this.options=i}beforeInsert(){}afterInsert(){}insert(){return this.beforeInsert(),this.el=this.parent.appendChild(this.newNode),this.afterInsert(),this}replace(t){if(this.getElement())return this.beforeDelete().then(()=>(this.updateType(t.type),this.parent.replaceChild(t.newNode,this.el),this.el=this.getElement(t.newNode),this.afterInsert(),this))}beforeDelete(t=this.el){let e=0;return this.start&&(e=this.options.minDurations[this.type]+this.start-Date.now())<0&&(e=0),new Promise(n=>{setTimeout(()=>{t.classList.add(c.klass.hiding),setTimeout(n,this.options.animationDuration)},e)})}delete(t=this.el){return this.getElement(t)?this.beforeDelete(t).then(()=>{t.remove(),this.afterDelete()}):null}afterDelete(){}getElement(t=this.el){return document.getElementById(t.id)}addEvent(t,e){this.el.addEventListener(t,e)}toggleClass(t){this.el.classList.toggle(t)}updateType(t){this.type=t,this.duration=this.options.duration(this.type)}},d=class extends l{constructor(t,e,n,s){super(s,"".concat(a.prefix,"-").concat(Math.floor(Date.now()-100*Math.random())),"".concat(a.prefix," ").concat(a.prefix,"-").concat(e),"animation-duration: ".concat(n.toSecs(n.animationDuration),";"),n),this.updateType(e),this.setInnerHtml(t)}setInnerHtml(t){"alert"===this.type&&t&&(t=this.options.formatError(t)),t=this.options.applyReplacements(t,this.type),this.newNode.innerHTML='<div class="awn-toast-wrapper">'.concat(this.progressBar).concat(this.label,'<div class="').concat(a.klass.content,'">').concat(t,'</div><span class="').concat(a.klass.icon,'">').concat(this.options.icon(this.type),"</span></div>")}beforeInsert(){if(this.parent.childElementCount>=this.options.maxNotifications){let t=Array.from(this.parent.getElementsByClassName(a.prefix));this.delete(t.find(t=>!this.isDeleted(t)))}}afterInsert(){if("async"==this.type)return this.start=Date.now();if(this.addEvent("click",()=>this.delete()),!(this.duration<=0)){this.timer=new class{constructor(t,e){this.callback=t,this.remaining=e,this.resume()}pause(){this.paused=!0,window.clearTimeout(this.timerId),this.remaining-=new Date-this.start}resume(){this.paused=!1,this.start=new Date,window.clearTimeout(this.timerId),this.timerId=window.setTimeout(()=>{window.clearTimeout(this.timerId),this.callback()},this.remaining)}toggle(){this.paused?this.resume():this.pause()}}(()=>this.delete(),this.duration);for(const t of["mouseenter","mouseleave"])this.addEvent(t,()=>{this.isDeleted()||(this.toggleClass(a.klass.progressBarPause),this.timer.toggle())})}}isDeleted(t=this.el){return t.classList.contains(c.klass.hiding)}get progressBar(){return this.duration<=0||"async"===this.type?"":"<div class='".concat(a.klass.progressBar,"' style=\"animation-duration:").concat(this.options.toSecs(this.duration),';"></div>')}get label(){return'<b class="'.concat(a.klass.label,'">').concat(this.options.label(this.type),"</b>")}},u=class extends l{constructor(t,e="modal",n,s,i){let o="animation-duration: ".concat(n.toSecs(n.animationDuration),";");super(document.body,r.ids.wrapper,null,o,n),this[r.ids.confirmOk]=s,this[r.ids.confirmCancel]=i,this.className="".concat(r.prefix,"-").concat(e),["confirm","async-block","modal"].includes(e)||(e="modal"),this.updateType(e),this.setInnerHtml(t),this.insert()}setInnerHtml(t){let e=this.options.applyReplacements(t,this.type);switch(this.type){case"confirm":let t=["<button class='".concat(r.klass.button," ").concat(r.klass.successBtn,"'id='").concat(r.ids.confirmOk,"'>").concat(this.options.labels.confirmOk,"</button>")];!1!==this[r.ids.confirmCancel]&&t.push("<button class='".concat(r.klass.button," ").concat(r.klass.cancelBtn,"'id='").concat(r.ids.confirmCancel,"'>").concat(this.options.labels.confirmCancel,"</button>")),e="".concat(this.options.icon(this.type),"<div class='").concat(r.klass.title,"'>").concat(this.options.label(this.type),'</div><div class="').concat(r.klass.content,'">').concat(e,"</div><div class='").concat(r.klass.buttons," ").concat(r.klass.buttons,"-").concat(t.length,"'>").concat(t.join(),"</div>");break;case"async-block":e="".concat(e,'<div class="').concat(r.klass.dotAnimation,'"></div>')}this.newNode.innerHTML='<div class="'.concat(r.klass.body," ").concat(this.className,'">').concat(e,"</div>")}keyupListener(t){if("async-block"===this.type)return t.preventDefault();switch(t.code){case"Escape":t.preventDefault(),this.delete();case"Tab":if(t.preventDefault(),"confirm"!==this.type||!1===this[r.ids.confirmCancel])return!0;let e=this.okBtn;t.shiftKey?document.activeElement.id==r.ids.confirmOk&&(e=this.cancelBtn):document.activeElement.id!==r.ids.confirmCancel&&(e=this.cancelBtn),e.focus()}}afterInsert(){switch(this.listener=(t=>this.keyupListener(t)),window.addEventListener("keydown",this.listener),this.type){case"async-block":this.start=Date.now();break;case"confirm":this.okBtn.focus(),this.addEvent("click",t=>{if("BUTTON"!==t.target.nodeName)return!1;this.delete(),this[t.target.id]&&this[t.target.id]()});break;default:document.activeElement.blur(),this.addEvent("click",t=>{t.target.id===this.newNode.id&&this.delete()})}}afterDelete(){window.removeEventListener("keydown",this.listener)}get okBtn(){return document.getElementById(r.ids.confirmOk)}get cancelBtn(){return document.getElementById(r.ids.confirmCancel)}};n.d(e,"default",function(){return p});class p{constructor(t={}){this.options=new i(t)}tip(t,e){return this._addToast(t,"tip",e).el}info(t,e){return this._addToast(t,"info",e).el}success(t,e){return this._addToast(t,"success",e).el}warning(t,e){return this._addToast(t,"warning",e).el}alert(t,e){return this._addToast(t,"alert",e).el}async(t,e,n,s,i){let o=this._addToast(s,"async",i);return this._afterAsync(t,e,n,i,o)}confirm(t,e,n,s){return this._addPopup(t,"confirm",s,e,n)}asyncBlock(t,e,n,s,i){let o=this._addPopup(s,"async-block",i);return this._afterAsync(t,e,n,i,o)}modal(t,e,n){return this._addPopup(t,e,n)}_addPopup(t,e,n,s,i){return new u(t,e,this.options.override(n),s,i)}_addToast(t,e,n,s){n=this.options.override(n);let i=new d(t,e,n,this.container);if(s){if(s instanceof u)return s.delete().then(()=>i.insert());return s.replace(i)}return i.insert()}_afterAsync(t,e,n,s,i){return t.then(this._responseHandler(e,"success",s,i),this._responseHandler(n,"alert",s,i))}_responseHandler(t,e,n,s){return i=>{switch(typeof t){case"undefined":case"string":let o="alert"===e?t||i:t;this._addToast(o,e,n,s);break;default:s.delete().then(()=>{t&&t(i)})}return"alert"===e?Promise.reject(i):i}}_createContainer(){return new l(document.body,a.ids.container,"awn-".concat(this.options.position)).insert().el}get container(){return document.getElementById(a.ids.container)||this._createContainer()}}}])}); |
@@ -1,1 +0,1 @@ | ||
var AWN=function(t){var e={};function n(s){if(e[s])return e[s].exports;var i=e[s]={i:s,l:!1,exports:{}};return t[s].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,s){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(n.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(s,i,function(e){return t[e]}.bind(null,i));return s},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){t.exports=n(1).default},function(t,e,n){"use strict";n.r(e);const s={maxNotifications:10,animationDuration:300,position:"bottom-right",labels:{tip:"Tip",info:"Info",success:"Success",warning:"Attention",alert:"Error",async:"Loading",confirm:"Confirmation required",confirmOk:"OK",confirmCancel:"Cancel"},icons:{tip:"question-circle",info:"info-circle",success:"check-circle",warning:"exclamation-circle",alert:"exclamation-triangle",async:"cog fa-spin",confirm:"exclamation-triangle",prefix:"<i class='fa fas fa-fw fa-",suffix:"'></i>",enabled:!0},replacements:{tip:null,info:null,success:null,warning:null,alert:null,async:null,"async-block":null,modal:null,confirm:null,general:{"<script>":"","<\/script>":""}},messages:{tip:"",info:"",success:"Action has been succeeded",warning:"",alert:"Action has been failed",confirm:"This action can't be undone. Continue?",async:"Please, wait...","async-block":"Loading"},formatError(t){if(t.response){if(!t.response.data)return"500 API Server Error";if(t.response.data.errors)return t.response.data.errors.map(t=>t.detail).join("<br>");if(t.response.statusText)return"".concat(t.response.status," ").concat(t.response.statusText,": ").concat(t.response.data)}return t.message?t.message:t},durations:{global:5e3,success:null,info:null,tip:null,warning:null,alert:null},minDurations:{async:1e3,"async-block":1e3}};class i{constructor(t={},e=s){Object.assign(this,this.defaultsDeep(e,t))}icon(t){return this.icons.enabled?"".concat(this.icons.prefix).concat(this.icons[t]).concat(this.icons.suffix):""}label(t){return this.labels[t]}duration(t){let e=this.durations[t];return null===e?this.durations.global:e}toSecs(t){return"".concat(t/1e3,"s")}applyReplacements(t,e){if(!t)return this.messages[e]||"";for(const n of["general",e])if(this.replacements[n])for(const e in this.replacements[n])t=t.replace(e,this.replacements[n][e]);return t}override(t){return t?new i(t,this):this}defaultsDeep(t,e){let n={};for(const s in t)e.hasOwnProperty(s)?n[s]="object"==typeof t[s]&&null!==t[s]?this.defaultsDeep(t[s],e[s]):e[s]:n[s]=t[s];return n}}const a={popup:"".concat("awn","-popup"),toast:"".concat("awn","-toast"),btn:"".concat("awn","-btn"),confirm:"".concat("awn","-confirm")},o={prefix:a.toast,klass:{label:"".concat(a.toast,"-label"),content:"".concat(a.toast,"-content"),icon:"".concat(a.toast,"-icon"),progressBar:"".concat(a.toast,"-progress-bar"),progressBarPause:"".concat(a.toast,"-progress-bar-paused")},ids:{container:"".concat(a.toast,"-container")}},r={prefix:a.popup,klass:{buttons:"".concat("awn","-buttons"),button:a.btn,successBtn:"".concat(a.btn,"-success"),cancelBtn:"".concat(a.btn,"-cancel"),title:"".concat(a.popup,"-title"),body:"".concat(a.popup,"-body"),content:"".concat(a.popup,"-content"),dotAnimation:"".concat(a.popup,"-loading-dots")},ids:{wrapper:"".concat(a.popup,"-wrapper"),confirmOk:"".concat(a.confirm,"-ok"),confirmCancel:"".concat(a.confirm,"-cancel")}},c={klass:{hiding:"".concat("awn","-hiding")},lib:"awn"};var l=class{constructor(t,e,n,s,i){this.newNode=document.createElement("div"),e&&(this.newNode.id=e),n&&(this.newNode.className=n),s&&(this.newNode.style.cssText=s),this.parent=t,this.options=i}beforeInsert(){}afterInsert(){}insert(){return this.beforeInsert(),this.el=this.parent.appendChild(this.newNode),this.afterInsert(),this}replace(t){if(this.getElement())return this.beforeDelete().then(()=>(this.updateType(t.type),this.parent.replaceChild(t.newNode,this.el),this.el=this.getElement(t.newNode),this.afterInsert(),this))}beforeDelete(t=this.el){let e=0;return this.start&&(e=this.options.minDurations[this.type]+this.start-Date.now())<0&&(e=0),new Promise(n=>{setTimeout(()=>{t.classList.add(c.klass.hiding),setTimeout(n,this.options.animationDuration)},e)})}delete(t=this.el){return this.getElement(t)?this.beforeDelete(t).then(()=>{t.remove(),this.afterDelete()}):null}afterDelete(){}getElement(t=this.el){return document.getElementById(t.id)}addEvent(t,e){this.el.addEventListener(t,e)}toggleClass(t){this.el.classList.toggle(t)}updateType(t){this.type=t,this.duration=this.options.duration(this.type)}},d=class extends l{constructor(t,e,n,s){super(s,"".concat(o.prefix,"-").concat(Math.floor(Date.now()-100*Math.random())),"".concat(o.prefix," ").concat(o.prefix,"-").concat(e),"animation-duration: ".concat(n.toSecs(n.animationDuration),";"),n),this.updateType(e),this.setInnerHtml(t)}setInnerHtml(t){"alert"===this.type&&t&&(t=this.options.formatError(t)),t=this.options.applyReplacements(t,this.type),this.newNode.innerHTML='<div class="awn-toast-wrapper">'.concat(this.progressBar).concat(this.label,'<div class="').concat(o.klass.content,'">').concat(t,'</div><span class="').concat(o.klass.icon,'">').concat(this.options.icon(this.type),"</span></div>")}beforeInsert(){if(this.parent.childElementCount>=this.options.maxNotifications){let t=Array.from(this.parent.getElementsByClassName(o.prefix));this.delete(t.find(t=>!this.isDeleted(t)))}}afterInsert(){if("async"==this.type)return this.start=Date.now();if(this.addEvent("click",()=>this.delete()),!(this.duration<=0)){this.timer=new class{constructor(t,e){this.callback=t,this.remaining=e,this.resume()}pause(){this.paused=!0,window.clearTimeout(this.timerId),this.remaining-=new Date-this.start}resume(){this.paused=!1,this.start=new Date,window.clearTimeout(this.timerId),this.timerId=window.setTimeout(()=>{window.clearTimeout(this.timerId),this.callback()},this.remaining)}toggle(){this.paused?this.resume():this.pause()}}(()=>this.delete(),this.duration);for(const t of["mouseenter","mouseleave"])this.addEvent(t,()=>{this.isDeleted()||(this.toggleClass(o.klass.progressBarPause),this.timer.toggle())})}}isDeleted(t=this.el){return t.classList.contains(c.klass.hiding)}get progressBar(){return this.duration<=0||"async"===this.type?"":"<div class='".concat(o.klass.progressBar,"' style=\"animation-duration:").concat(this.options.toSecs(this.duration),';"></div>')}get label(){return'<b class="'.concat(o.klass.label,'">').concat(this.options.label(this.type),"</b>")}},u=class extends l{constructor(t,e="modal",n,s,i){let a="animation-duration: ".concat(n.toSecs(n.animationDuration),";");super(document.body,r.ids.wrapper,null,a,n),this[r.ids.confirmOk]=s,this[r.ids.confirmCancel]=i,this.className=e,["confirm","async-block","modal"].includes(e)||(e="modal"),this.updateType(e),this.setInnerHtml(t),this.insert()}setInnerHtml(t){let e=this.options.applyReplacements(t,this.type);switch(this.type){case"confirm":e="".concat(this.options.icon(this.type),"<div class='").concat(r.klass.title,"'>").concat(this.options.label(this.type),'</div><div class="').concat(r.klass.content,'">').concat(e,"</div><div class='").concat(r.klass.buttons,"'><button class='").concat(r.klass.button," ").concat(r.klass.successBtn,"'id='").concat(r.ids.confirmOk,"'>").concat(this.options.labels.confirmOk,"</button><button class='").concat(r.klass.button," ").concat(r.klass.cancelBtn,"'id='").concat(r.ids.confirmCancel,"'>").concat(this.options.labels.confirmCancel,"</button></div>");break;case"async-block":e="".concat(e,'<div class="').concat(r.klass.dotAnimation,'"></div>')}this.newNode.innerHTML='<div class="'.concat(r.klass.body," ").concat(r.prefix,"-").concat(this.className,'">').concat(e,"</div>")}keyupListener(t){if("async-block"===this.type)return t.preventDefault();switch(t.code){case"Escape":t.preventDefault(),this.delete();case"Tab":if(t.preventDefault(),"confirm"!==this.type)return!0;let e=this.okBtn;t.shiftKey?document.activeElement.id==r.ids.confirmOk&&(e=this.cancelBtn):document.activeElement.id!==r.ids.confirmCancel&&(e=this.cancelBtn),e.focus()}}afterInsert(){switch(this.listener=(t=>this.keyupListener(t)),window.addEventListener("keydown",this.listener),this.type){case"async-block":this.start=Date.now();break;case"confirm":this.okBtn.focus(),this.addEvent("click",t=>{if("BUTTON"!==t.target.nodeName)return!1;this.delete(),this[t.target.id]&&this[t.target.id]()});break;default:document.activeElement.blur(),this.addEvent("click",t=>{t.target.id===this.newNode.id&&this.delete()})}}afterDelete(){window.removeEventListener("keydown",this.listener)}get okBtn(){return document.getElementById(r.ids.confirmOk)}get cancelBtn(){return document.getElementById(r.ids.confirmCancel)}};n.d(e,"default",function(){return h});class h{constructor(t={}){this.options=new i(t)}tip(t,e){return this._addToast(t,"tip",e).el}info(t,e){return this._addToast(t,"info",e).el}success(t,e){return this._addToast(t,"success",e).el}warning(t,e){return this._addToast(t,"warning",e).el}alert(t,e){return this._addToast(t,"alert",e).el}async(t,e,n,s,i){let a=this._addToast(s,"async",i);return this._afterAsync(t,e,n,i,a)}confirm(t,e,n,s){return this._addPopup(t,"confirm",s,e,n)}asyncBlock(t,e,n,s,i){let a=this._addPopup(s,"async-block",i);return this._afterAsync(t,e,n,i,a)}modal(t,e,n){return this._addPopup(t,e,n)}_addPopup(t,e,n,s,i){return new u(t,e,this.options.override(n),s,i)}_addToast(t,e,n,s){n=this.options.override(n);let i=new d(t,e,n,this.container);if(s){if(s instanceof u)return s.delete().then(()=>i.insert());return s.replace(i)}return i.insert()}_afterAsync(t,e,n,s,i){return t.then(this._responseHandler(e,"success",s,i),this._responseHandler(n,"alert",s,i))}_responseHandler(t,e,n,s){return i=>{switch(typeof t){case"undefined":case"string":let a="alert"===e?t||i:t;this._addToast(a,e,n,s);break;default:s.delete().then(()=>{t&&t(i)})}return"alert"===e?Promise.reject(i):i}}_createContainer(){return new l(document.body,o.ids.container,"awn-".concat(this.options.position)).insert().el}get container(){return document.getElementById(o.ids.container)||this._createContainer()}}}]); | ||
var AWN=function(t){var e={};function n(s){if(e[s])return e[s].exports;var i=e[s]={i:s,l:!1,exports:{}};return t[s].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,s){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:s})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var s=Object.create(null);if(n.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(s,i,function(e){return t[e]}.bind(null,i));return s},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){t.exports=n(1).default},function(t,e,n){"use strict";n.r(e);const s={maxNotifications:10,animationDuration:300,position:"bottom-right",labels:{tip:"Tip",info:"Info",success:"Success",warning:"Attention",alert:"Error",async:"Loading",confirm:"Confirmation required",confirmOk:"OK",confirmCancel:"Cancel"},icons:{tip:"question-circle",info:"info-circle",success:"check-circle",warning:"exclamation-circle",alert:"exclamation-triangle",async:"cog fa-spin",confirm:"exclamation-triangle",prefix:"<i class='fa fas fa-fw fa-",suffix:"'></i>",enabled:!0},replacements:{tip:null,info:null,success:null,warning:null,alert:null,async:null,"async-block":null,modal:null,confirm:null,general:{"<script>":"","<\/script>":""}},messages:{tip:"",info:"",success:"Action has been succeeded",warning:"",alert:"Action has been failed",confirm:"This action can't be undone. Continue?",async:"Please, wait...","async-block":"Loading"},formatError(t){if(t.response){if(!t.response.data)return"500 API Server Error";if(t.response.data.errors)return t.response.data.errors.map(t=>t.detail).join("<br>");if(t.response.statusText)return"".concat(t.response.status," ").concat(t.response.statusText,": ").concat(t.response.data)}return t.message?t.message:t},durations:{global:5e3,success:null,info:null,tip:null,warning:null,alert:null},minDurations:{async:1e3,"async-block":1e3}};class i{constructor(t={},e=s){Object.assign(this,this.defaultsDeep(e,t))}icon(t){return this.icons.enabled?"".concat(this.icons.prefix).concat(this.icons[t]).concat(this.icons.suffix):""}label(t){return this.labels[t]}duration(t){let e=this.durations[t];return null===e?this.durations.global:e}toSecs(t){return"".concat(t/1e3,"s")}applyReplacements(t,e){if(!t)return this.messages[e]||"";for(const n of["general",e])if(this.replacements[n])for(const e in this.replacements[n])t=t.replace(e,this.replacements[n][e]);return t}override(t){return t?new i(t,this):this}defaultsDeep(t,e){let n={};for(const s in t)e.hasOwnProperty(s)?n[s]="object"==typeof t[s]&&null!==t[s]?this.defaultsDeep(t[s],e[s]):e[s]:n[s]=t[s];return n}}const a={popup:"".concat("awn","-popup"),toast:"".concat("awn","-toast"),btn:"".concat("awn","-btn"),confirm:"".concat("awn","-confirm")},o={prefix:a.toast,klass:{label:"".concat(a.toast,"-label"),content:"".concat(a.toast,"-content"),icon:"".concat(a.toast,"-icon"),progressBar:"".concat(a.toast,"-progress-bar"),progressBarPause:"".concat(a.toast,"-progress-bar-paused")},ids:{container:"".concat(a.toast,"-container")}},r={prefix:a.popup,klass:{buttons:"".concat("awn","-buttons"),button:a.btn,successBtn:"".concat(a.btn,"-success"),cancelBtn:"".concat(a.btn,"-cancel"),title:"".concat(a.popup,"-title"),body:"".concat(a.popup,"-body"),content:"".concat(a.popup,"-content"),dotAnimation:"".concat(a.popup,"-loading-dots")},ids:{wrapper:"".concat(a.popup,"-wrapper"),confirmOk:"".concat(a.confirm,"-ok"),confirmCancel:"".concat(a.confirm,"-cancel")}},c={klass:{hiding:"".concat("awn","-hiding")},lib:"awn"};var l=class{constructor(t,e,n,s,i){this.newNode=document.createElement("div"),e&&(this.newNode.id=e),n&&(this.newNode.className=n),s&&(this.newNode.style.cssText=s),this.parent=t,this.options=i}beforeInsert(){}afterInsert(){}insert(){return this.beforeInsert(),this.el=this.parent.appendChild(this.newNode),this.afterInsert(),this}replace(t){if(this.getElement())return this.beforeDelete().then(()=>(this.updateType(t.type),this.parent.replaceChild(t.newNode,this.el),this.el=this.getElement(t.newNode),this.afterInsert(),this))}beforeDelete(t=this.el){let e=0;return this.start&&(e=this.options.minDurations[this.type]+this.start-Date.now())<0&&(e=0),new Promise(n=>{setTimeout(()=>{t.classList.add(c.klass.hiding),setTimeout(n,this.options.animationDuration)},e)})}delete(t=this.el){return this.getElement(t)?this.beforeDelete(t).then(()=>{t.remove(),this.afterDelete()}):null}afterDelete(){}getElement(t=this.el){return document.getElementById(t.id)}addEvent(t,e){this.el.addEventListener(t,e)}toggleClass(t){this.el.classList.toggle(t)}updateType(t){this.type=t,this.duration=this.options.duration(this.type)}},d=class extends l{constructor(t,e,n,s){super(s,"".concat(o.prefix,"-").concat(Math.floor(Date.now()-100*Math.random())),"".concat(o.prefix," ").concat(o.prefix,"-").concat(e),"animation-duration: ".concat(n.toSecs(n.animationDuration),";"),n),this.updateType(e),this.setInnerHtml(t)}setInnerHtml(t){"alert"===this.type&&t&&(t=this.options.formatError(t)),t=this.options.applyReplacements(t,this.type),this.newNode.innerHTML='<div class="awn-toast-wrapper">'.concat(this.progressBar).concat(this.label,'<div class="').concat(o.klass.content,'">').concat(t,'</div><span class="').concat(o.klass.icon,'">').concat(this.options.icon(this.type),"</span></div>")}beforeInsert(){if(this.parent.childElementCount>=this.options.maxNotifications){let t=Array.from(this.parent.getElementsByClassName(o.prefix));this.delete(t.find(t=>!this.isDeleted(t)))}}afterInsert(){if("async"==this.type)return this.start=Date.now();if(this.addEvent("click",()=>this.delete()),!(this.duration<=0)){this.timer=new class{constructor(t,e){this.callback=t,this.remaining=e,this.resume()}pause(){this.paused=!0,window.clearTimeout(this.timerId),this.remaining-=new Date-this.start}resume(){this.paused=!1,this.start=new Date,window.clearTimeout(this.timerId),this.timerId=window.setTimeout(()=>{window.clearTimeout(this.timerId),this.callback()},this.remaining)}toggle(){this.paused?this.resume():this.pause()}}(()=>this.delete(),this.duration);for(const t of["mouseenter","mouseleave"])this.addEvent(t,()=>{this.isDeleted()||(this.toggleClass(o.klass.progressBarPause),this.timer.toggle())})}}isDeleted(t=this.el){return t.classList.contains(c.klass.hiding)}get progressBar(){return this.duration<=0||"async"===this.type?"":"<div class='".concat(o.klass.progressBar,"' style=\"animation-duration:").concat(this.options.toSecs(this.duration),';"></div>')}get label(){return'<b class="'.concat(o.klass.label,'">').concat(this.options.label(this.type),"</b>")}},u=class extends l{constructor(t,e="modal",n,s,i){let a="animation-duration: ".concat(n.toSecs(n.animationDuration),";");super(document.body,r.ids.wrapper,null,a,n),this[r.ids.confirmOk]=s,this[r.ids.confirmCancel]=i,this.className="".concat(r.prefix,"-").concat(e),["confirm","async-block","modal"].includes(e)||(e="modal"),this.updateType(e),this.setInnerHtml(t),this.insert()}setInnerHtml(t){let e=this.options.applyReplacements(t,this.type);switch(this.type){case"confirm":let t=["<button class='".concat(r.klass.button," ").concat(r.klass.successBtn,"'id='").concat(r.ids.confirmOk,"'>").concat(this.options.labels.confirmOk,"</button>")];!1!==this[r.ids.confirmCancel]&&t.push("<button class='".concat(r.klass.button," ").concat(r.klass.cancelBtn,"'id='").concat(r.ids.confirmCancel,"'>").concat(this.options.labels.confirmCancel,"</button>")),e="".concat(this.options.icon(this.type),"<div class='").concat(r.klass.title,"'>").concat(this.options.label(this.type),'</div><div class="').concat(r.klass.content,'">').concat(e,"</div><div class='").concat(r.klass.buttons," ").concat(r.klass.buttons,"-").concat(t.length,"'>").concat(t.join(),"</div>");break;case"async-block":e="".concat(e,'<div class="').concat(r.klass.dotAnimation,'"></div>')}this.newNode.innerHTML='<div class="'.concat(r.klass.body," ").concat(this.className,'">').concat(e,"</div>")}keyupListener(t){if("async-block"===this.type)return t.preventDefault();switch(t.code){case"Escape":t.preventDefault(),this.delete();case"Tab":if(t.preventDefault(),"confirm"!==this.type||!1===this[r.ids.confirmCancel])return!0;let e=this.okBtn;t.shiftKey?document.activeElement.id==r.ids.confirmOk&&(e=this.cancelBtn):document.activeElement.id!==r.ids.confirmCancel&&(e=this.cancelBtn),e.focus()}}afterInsert(){switch(this.listener=(t=>this.keyupListener(t)),window.addEventListener("keydown",this.listener),this.type){case"async-block":this.start=Date.now();break;case"confirm":this.okBtn.focus(),this.addEvent("click",t=>{if("BUTTON"!==t.target.nodeName)return!1;this.delete(),this[t.target.id]&&this[t.target.id]()});break;default:document.activeElement.blur(),this.addEvent("click",t=>{t.target.id===this.newNode.id&&this.delete()})}}afterDelete(){window.removeEventListener("keydown",this.listener)}get okBtn(){return document.getElementById(r.ids.confirmOk)}get cancelBtn(){return document.getElementById(r.ids.confirmCancel)}};n.d(e,"default",function(){return h});class h{constructor(t={}){this.options=new i(t)}tip(t,e){return this._addToast(t,"tip",e).el}info(t,e){return this._addToast(t,"info",e).el}success(t,e){return this._addToast(t,"success",e).el}warning(t,e){return this._addToast(t,"warning",e).el}alert(t,e){return this._addToast(t,"alert",e).el}async(t,e,n,s,i){let a=this._addToast(s,"async",i);return this._afterAsync(t,e,n,i,a)}confirm(t,e,n,s){return this._addPopup(t,"confirm",s,e,n)}asyncBlock(t,e,n,s,i){let a=this._addPopup(s,"async-block",i);return this._afterAsync(t,e,n,i,a)}modal(t,e,n){return this._addPopup(t,e,n)}_addPopup(t,e,n,s,i){return new u(t,e,this.options.override(n),s,i)}_addToast(t,e,n,s){n=this.options.override(n);let i=new d(t,e,n,this.container);if(s){if(s instanceof u)return s.delete().then(()=>i.insert());return s.replace(i)}return i.insert()}_afterAsync(t,e,n,s,i){return t.then(this._responseHandler(e,"success",s,i),this._responseHandler(n,"alert",s,i))}_responseHandler(t,e,n,s){return i=>{switch(typeof t){case"undefined":case"string":let a="alert"===e?t||i:t;this._addToast(a,e,n,s);break;default:s.delete().then(()=>{t&&t(i)})}return"alert"===e?Promise.reject(i):i}}_createContainer(){return new l(document.body,o.ids.container,"awn-".concat(this.options.position)).insert().el}get container(){return document.getElementById(o.ids.container)||this._createContainer()}}}]); |
{ | ||
"name": "awesome-notifications", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Lightweight library for beautifull and smooth notifications", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -12,3 +12,3 @@ import Elem from "./elem" | ||
this[mConsts.ids.confirmCancel] = onCancel | ||
this.className = type | ||
this.className = `${mConsts.prefix}-${type}` | ||
if (!['confirm', 'async-block', 'modal'].includes(type)) type = 'modal' | ||
@@ -24,3 +24,7 @@ this.updateType(type) | ||
case "confirm": | ||
innerHTML = `${this.options.icon(this.type)}<div class='${mConsts.klass.title}'>${this.options.label(this.type)}</div><div class="${mConsts.klass.content}">${innerHTML}</div><div class='${mConsts.klass.buttons}'><button class='${mConsts.klass.button} ${mConsts.klass.successBtn}'id='${mConsts.ids.confirmOk}'>${this.options.labels.confirmOk}</button><button class='${mConsts.klass.button} ${mConsts.klass.cancelBtn}'id='${mConsts.ids.confirmCancel}'>${this.options.labels.confirmCancel}</button></div>` | ||
let buttons = [`<button class='${mConsts.klass.button} ${mConsts.klass.successBtn}'id='${mConsts.ids.confirmOk}'>${this.options.labels.confirmOk}</button>`] | ||
if (this[mConsts.ids.confirmCancel] !== false) { | ||
buttons.push(`<button class='${mConsts.klass.button} ${mConsts.klass.cancelBtn}'id='${mConsts.ids.confirmCancel}'>${this.options.labels.confirmCancel}</button>`) | ||
} | ||
innerHTML = `${this.options.icon(this.type)}<div class='${mConsts.klass.title}'>${this.options.label(this.type)}</div><div class="${mConsts.klass.content}">${innerHTML}</div><div class='${mConsts.klass.buttons} ${mConsts.klass.buttons}-${buttons.length}'>${buttons.join()}</div>` | ||
break | ||
@@ -30,3 +34,3 @@ case "async-block": | ||
} | ||
this.newNode.innerHTML = `<div class="${mConsts.klass.body} ${mConsts.prefix}-${this.className}">${innerHTML}</div>` | ||
this.newNode.innerHTML = `<div class="${mConsts.klass.body} ${this.className}">${innerHTML}</div>` | ||
} | ||
@@ -42,3 +46,3 @@ | ||
e.preventDefault() | ||
if (this.type !== 'confirm') return true | ||
if (this.type !== 'confirm' || this[mConsts.ids.confirmCancel] === false) return true | ||
let next = this.okBtn | ||
@@ -45,0 +49,0 @@ if (e.shiftKey) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
111854
542