mini-toastr-o8
Version:
Non-blocking toaster notifications
1 lines • 4.05 kB
JavaScript
;var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a};function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}var miniToastr=function(){var h,i;function a(o,p){var q=this;o.style.opacity&&0.05<o.style.opacity?o.style.opacity-=0.05:o.style.opacity&&0.1>=o.style.opacity?o.parentNode&&(o.parentNode.removeChild(o),p&&p()):o.style.opacity=0.9,setTimeout(function(){return a.apply(q,[o,p])},1e3/30)}function b(o,p,q){for(var r in p=p||{},q=q||'',o)if(o.hasOwnProperty(r)){var s=o[r];s&&'object'===('undefined'==typeof s?'undefined':_typeof(s))&&!(s instanceof Date||s instanceof RegExp)?b(s,p,q+r+' '):p[q]&&'object'===_typeof(p[q])?p[q][r]=s:(p[q]={},p[q][r]=s)}return p}function c(o){var p=b(o),q=JSON.stringify(p,null,2);return q=q.replace(/"([^"]*)": \{/g,'$1 {').replace(/"([^"]*)"/g,'$1').replace(/(\w*-?\w*): ([\w\d .#]*),?/g,'$1: $2;').replace(/},/g,'}\n').replace(/ &([.:])/g,'$1'),q=q.substr(1,q.lastIndexOf('}')-1),q}function d(o){var p=document.head||document.getElementsByTagName('head')[0],q=e('style');q.id='mini-toastr-styles',q.type='text/css',q.styleSheet?q.styleSheet.cssText=o:q.appendChild(document.createTextNode(o)),p.appendChild(q)}function e(){var o=0<arguments.length&&arguments[0]!==void 0?arguments[0]:'div';return document.createElement(o)}function f(o,p,q){var r=e(q.icons[p].nodeType),s=q.icons[p].attrs;for(var t in s)s.hasOwnProperty(t)&&r.setAttribute(t,s[t]);o.appendChild(r)}function g(o,p,q){var r=e();r.className=q,r.appendChild(document.createTextNode(p)),o.appendChild(r)}if('undefined'==typeof window)return{init:function init(){}};var j={error:'error',warn:'warn',success:'success',info:'info'},l={container:'mini-toastr',notification:'mini-toastr__notification',title:'mini-toastr-notification__title',icon:'mini-toastr-notification__icon',message:'mini-toastr-notification__message',error:'-'+j.error,warn:'-'+j.warn,success:'-'+j.success,info:'-'+j.info},m={types:j,animation:a,timeout:3e3,icons:{},appendTarget:document.body,node:e(),style:(i={},_defineProperty(i,'.'+l.container,{position:'fixed','z-index':99999,right:'12px',top:'12px'}),_defineProperty(i,'.'+l.notification,(h={cursor:'pointer',padding:'12px 18px',margin:'0 0 6px 0','background-color':'#000',opacity:0.8,color:'#fff','border-radius':'3px','box-shadow':'#3c3b3b 0 0 12px',width:'300px'},_defineProperty(h,'&.'+l.error,{'background-color':'#D5122B'}),_defineProperty(h,'&.'+l.warn,{'background-color':'#F5AA1E'}),_defineProperty(h,'&.'+l.success,{'background-color':'#7AC13E'}),_defineProperty(h,'&.'+l.info,{'background-color':'#4196E1'}),_defineProperty(h,'&:hover',{opacity:1,'box-shadow':'#000 0 0 12px'}),h)),_defineProperty(i,'.'+l.title,{'font-weight':'500'}),_defineProperty(i,'.'+l.message,{display:'inline-block','vertical-align':'middle',width:'240px',padding:'0 12px'}),i)},n={config:m,showMessage:function showMessage(o,p,q,r,s,t){var u={};Object.assign(u,this.config),Object.assign(u,t);var w=e();return w.className=l.notification+' '+l[q],w.onclick=function(){u.animation(w,null)},p&&g(w,p,l.title),u.icons[q]&&f(w,q,u),o&&g(w,o,l.message),u.node.insertBefore(w,u.node.firstChild),setTimeout(function(){return u.animation(w,s)},r||u.timeout),s&&s(),this},init:function init(o){var p=this,q={};Object.assign(q,m),Object.assign(q,o),this.config=q;var r=c(q.style);return d(r),q.node.id=''+l.container,q.node.className=''+l.container,q.appendTarget.appendChild(q.node),Object.keys(q.types).forEach(function(s){n[q.types[s]]=function(t,u,w,x,y){return this.showMessage(t,u,q.types[s],w,x,y),this}.bind(p)}),this},setIcon:function setIcon(o){var p=1<arguments.length&&arguments[1]!==void 0?arguments[1]:'i',q=2<arguments.length&&arguments[2]!==void 0?arguments[2]:[];q['class']=q['class']?q['class']+' '+l.icon:l.icon,this.config.icons[o]={nodeType:p,attrs:q}}};return n}();