bulma-toast
Advanced tools
Comparing version 1.3.0 to 1.4.0
/*! | ||
* bulma-toast 1.3.0 | ||
* bulma-toast 1.4.0 | ||
* (c) 2018-present @rfoel <rafaelfr@outlook.com> | ||
* Released under the MIT License. | ||
*/ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});const defaults={message:'Your message here',duration:2e3,position:'top-right',closeOnClick:!0,opacity:1};let initialized=!1,containers={},positions={};function init(){containers={noticesTopLeft:document.createElement('div'),noticesTopRight:document.createElement('div'),noticesBottomLeft:document.createElement('div'),noticesBottomRight:document.createElement('div'),noticesTopCenter:document.createElement('div'),noticesBottomCenter:document.createElement('div'),noticesCenter:document.createElement('div')};containers.noticesTopLeft.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}left:0;top:0;text-align:left;align-items:flex-start;`),containers.noticesTopRight.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}right:0;top:0;text-align:right;align-items:flex-end;`),containers.noticesBottomLeft.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}left:0;bottom:0;text-align:left;align-items:flex-start;`),containers.noticesBottomRight.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}right:0;bottom:0;text-align:right;align-items:flex-end;`),containers.noticesTopCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}top:0;left:0;right:0;text-align:center;align-items:center;`),containers.noticesBottomCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}bottom:0;left:0;right:0;text-align:center;align-items:center;`),containers.noticesCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}top:0;left:0;right:0;bottom:0;flex-flow:column;justify-content:center;align-items:center;`),Object.keys(containers).forEach(a=>document.body.appendChild(containers[a])),positions={"top-left":containers.noticesTopLeft,"top-right":containers.noticesTopRight,"top-center":containers.noticesTopCenter,"bottom-left":containers.noticesBottomLeft,"bottom-right":containers.noticesBottomRight,"bottom-center":containers.noticesBottomCenter,center:containers.noticesCenter},initialized=!0}function toast(a){initialized||init();let b=Object.assign({},defaults,a);const c=new Toast(b),d=positions[b.position]||positions[defaults.position];d.appendChild(c.element)}class Toast{constructor(a){this.element=document.createElement('div'),this.opacity=a.opacity,this.type=a.type,this.animate=a.animate,this.dismissible=a.dismissible,this.closeOnClick=a.closeOnClick,this.message=a.message,this.duration=a.duration,this.pauseOnHover=a.pauseOnHover;let b=`width:auto;pointer-events:auto;display:inline-flex;opacity:${this.opacity};`,c=['notification'];if(this.type&&c.push(this.type),this.animate&&this.animate.in&&(c.push(`animated ${this.animate.in}`),this.onAnimationEnd(()=>this.element.classList.remove(this.animate.in))),this.element.classList=c.join(' '),this.dismissible){let a=document.createElement('button');a.className='delete',a.addEventListener('click',()=>{this.destroy()}),this.element.insertAdjacentElement('afterbegin',a)}else b+='padding: 1.25rem 1.5rem';this.closeOnClick&&this.element.addEventListener('click',()=>{this.destroy()}),this.element.setAttribute('style',b),this.element.insertAdjacentText('beforeend',this.message);const d=new Timer(()=>{this.destroy()},this.duration);this.pauseOnHover&&(this.element.addEventListener('mouseover',()=>{d.pause()}),this.element.addEventListener('mouseout',()=>{d.resume()}))}destroy(){this.animate&&this.animate.out?(this.element.classList.add(this.animate.out),this.onAnimationEnd(()=>this.element.remove())):this.element.remove()}onAnimationEnd(a=()=>{}){const b={animation:'animationend',OAnimation:'oAnimationEnd',MozAnimation:'mozAnimationEnd',WebkitAnimation:'webkitAnimationEnd'};for(const c in b)if(this.element.style[c]!==void 0){this.element.addEventListener(b[c],()=>a());break}}}class Timer{constructor(a,b){this.timer,this.start,this.remaining=b,this.callback=a,this.resume()}pause(){window.clearTimeout(this.timer),this.remaining-=new Date-this.start}resume(){this.start=new Date,window.clearTimeout(this.timer),this.timer=window.setTimeout(this.callback,this.remaining)}}exports.toast=toast; | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});const defaults={message:'Your message here',duration:2e3,position:'top-right',closeOnClick:!0,opacity:1};let initialized=!1,containers={},positions={};function init(){containers={noticesTopLeft:document.createElement('div'),noticesTopRight:document.createElement('div'),noticesBottomLeft:document.createElement('div'),noticesBottomRight:document.createElement('div'),noticesTopCenter:document.createElement('div'),noticesBottomCenter:document.createElement('div'),noticesCenter:document.createElement('div')};containers.noticesTopLeft.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}left:0;top:0;text-align:left;align-items:flex-start;`),containers.noticesTopRight.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}right:0;top:0;text-align:right;align-items:flex-end;`),containers.noticesBottomLeft.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}left:0;bottom:0;text-align:left;align-items:flex-start;`),containers.noticesBottomRight.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}right:0;bottom:0;text-align:right;align-items:flex-end;`),containers.noticesTopCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}top:0;left:0;right:0;text-align:center;align-items:center;`),containers.noticesBottomCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}bottom:0;left:0;right:0;text-align:center;align-items:center;`),containers.noticesCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}top:0;left:0;right:0;bottom:0;flex-flow:column;justify-content:center;align-items:center;`),Object.keys(containers).forEach(a=>document.body.appendChild(containers[a])),positions={"top-left":containers.noticesTopLeft,"top-right":containers.noticesTopRight,"top-center":containers.noticesTopCenter,"bottom-left":containers.noticesBottomLeft,"bottom-right":containers.noticesBottomRight,"bottom-center":containers.noticesBottomCenter,center:containers.noticesCenter},initialized=!0}function toast(a){initialized||init();let b=Object.assign({},defaults,a);const c=new Toast(b),d=positions[b.position]||positions[defaults.position];d.appendChild(c.element)}class Toast{constructor(a){this.element=document.createElement('div'),this.opacity=a.opacity,this.type=a.type,this.animate=a.animate,this.dismissible=a.dismissible,this.closeOnClick=a.closeOnClick,this.message=a.message,this.duration=a.duration,this.pauseOnHover=a.pauseOnHover;let b=`width:auto;pointer-events:auto;display:inline-flex;opacity:${this.opacity};`,c=['notification'];if(this.type&&c.push(this.type),this.animate&&this.animate.in&&(c.push(`animated ${this.animate.in}`),this.onAnimationEnd(()=>this.element.classList.remove(this.animate.in))),this.element.classList=c.join(' '),this.dismissible){let a=document.createElement('button');a.className='delete',a.addEventListener('click',()=>{this.destroy()}),this.element.insertAdjacentElement('afterbegin',a)}else b+='padding: 1.25rem 1.5rem';this.closeOnClick&&this.element.addEventListener('click',()=>{this.destroy()}),this.element.setAttribute('style',b),'string'==typeof this.message?this.element.insertAdjacentHTML('beforeend',this.message):this.element.appendChild(this.message);const d=new Timer(()=>{this.destroy()},this.duration);this.pauseOnHover&&(this.element.addEventListener('mouseover',()=>{d.pause()}),this.element.addEventListener('mouseout',()=>{d.resume()}))}destroy(){this.animate&&this.animate.out?(this.element.classList.add(this.animate.out),this.onAnimationEnd(()=>this.element.remove())):this.element.remove()}onAnimationEnd(a=()=>{}){const b={animation:'animationend',OAnimation:'oAnimationEnd',MozAnimation:'mozAnimationEnd',WebkitAnimation:'webkitAnimationEnd'};for(const c in b)if(this.element.style[c]!==void 0){this.element.addEventListener(b[c],()=>a());break}}}class Timer{constructor(a,b){this.timer,this.start,this.remaining=b,this.callback=a,this.resume()}pause(){window.clearTimeout(this.timer),this.remaining-=new Date-this.start}resume(){this.start=new Date,window.clearTimeout(this.timer),this.timer=window.setTimeout(this.callback,this.remaining)}}exports.toast=toast; |
/*! | ||
* bulma-toast 1.3.0 | ||
* bulma-toast 1.4.0 | ||
* (c) 2018-present @rfoel <rafaelfr@outlook.com> | ||
* Released under the MIT License. | ||
*/ | ||
const defaults={message:"Your message here",duration:2e3,position:"top-right",closeOnClick:!0,opacity:1};let initialized=!1,containers={},positions={};function init(){containers={noticesTopLeft:document.createElement("div"),noticesTopRight:document.createElement("div"),noticesBottomLeft:document.createElement("div"),noticesBottomRight:document.createElement("div"),noticesTopCenter:document.createElement("div"),noticesBottomCenter:document.createElement("div"),noticesCenter:document.createElement("div")};containers.noticesTopLeft.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}left:0;top:0;text-align:left;align-items:flex-start;`),containers.noticesTopRight.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}right:0;top:0;text-align:right;align-items:flex-end;`),containers.noticesBottomLeft.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}left:0;bottom:0;text-align:left;align-items:flex-start;`),containers.noticesBottomRight.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}right:0;bottom:0;text-align:right;align-items:flex-end;`),containers.noticesTopCenter.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}top:0;left:0;right:0;text-align:center;align-items:center;`),containers.noticesBottomCenter.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}bottom:0;left:0;right:0;text-align:center;align-items:center;`),containers.noticesCenter.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}top:0;left:0;right:0;bottom:0;flex-flow:column;justify-content:center;align-items:center;`),Object.keys(containers).forEach(a=>document.body.appendChild(containers[a])),positions={"top-left":containers.noticesTopLeft,"top-right":containers.noticesTopRight,"top-center":containers.noticesTopCenter,"bottom-left":containers.noticesBottomLeft,"bottom-right":containers.noticesBottomRight,"bottom-center":containers.noticesBottomCenter,center:containers.noticesCenter},initialized=!0}function toast(a){initialized||init();let b=Object.assign({},defaults,a);const c=new Toast(b),d=positions[b.position]||positions[defaults.position];d.appendChild(c.element)}class Toast{constructor(a){this.element=document.createElement("div"),this.opacity=a.opacity,this.type=a.type,this.animate=a.animate,this.dismissible=a.dismissible,this.closeOnClick=a.closeOnClick,this.message=a.message,this.duration=a.duration,this.pauseOnHover=a.pauseOnHover;let b=`width:auto;pointer-events:auto;display:inline-flex;opacity:${this.opacity};`,c=["notification"];if(this.type&&c.push(this.type),this.animate&&this.animate.in&&(c.push(`animated ${this.animate.in}`),this.onAnimationEnd(()=>this.element.classList.remove(this.animate.in))),this.element.classList=c.join(" "),this.dismissible){let a=document.createElement("button");a.className="delete",a.addEventListener("click",()=>{this.destroy()}),this.element.insertAdjacentElement("afterbegin",a)}else b+="padding: 1.25rem 1.5rem";this.closeOnClick&&this.element.addEventListener("click",()=>{this.destroy()}),this.element.setAttribute("style",b),this.element.insertAdjacentText("beforeend",this.message);const d=new Timer(()=>{this.destroy()},this.duration);this.pauseOnHover&&(this.element.addEventListener("mouseover",()=>{d.pause()}),this.element.addEventListener("mouseout",()=>{d.resume()}))}destroy(){this.animate&&this.animate.out?(this.element.classList.add(this.animate.out),this.onAnimationEnd(()=>this.element.remove())):this.element.remove()}onAnimationEnd(a=()=>{}){const b={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"mozAnimationEnd",WebkitAnimation:"webkitAnimationEnd"};for(const c in b)if(this.element.style[c]!==void 0){this.element.addEventListener(b[c],()=>a());break}}}class Timer{constructor(a,b){this.timer,this.start,this.remaining=b,this.callback=a,this.resume()}pause(){window.clearTimeout(this.timer),this.remaining-=new Date-this.start}resume(){this.start=new Date,window.clearTimeout(this.timer),this.timer=window.setTimeout(this.callback,this.remaining)}}export{toast}; | ||
const defaults={message:"Your message here",duration:2e3,position:"top-right",closeOnClick:!0,opacity:1};let initialized=!1,containers={},positions={};function init(){containers={noticesTopLeft:document.createElement("div"),noticesTopRight:document.createElement("div"),noticesBottomLeft:document.createElement("div"),noticesBottomRight:document.createElement("div"),noticesTopCenter:document.createElement("div"),noticesBottomCenter:document.createElement("div"),noticesCenter:document.createElement("div")};containers.noticesTopLeft.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}left:0;top:0;text-align:left;align-items:flex-start;`),containers.noticesTopRight.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}right:0;top:0;text-align:right;align-items:flex-end;`),containers.noticesBottomLeft.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}left:0;bottom:0;text-align:left;align-items:flex-start;`),containers.noticesBottomRight.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}right:0;bottom:0;text-align:right;align-items:flex-end;`),containers.noticesTopCenter.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}top:0;left:0;right:0;text-align:center;align-items:center;`),containers.noticesBottomCenter.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}bottom:0;left:0;right:0;text-align:center;align-items:center;`),containers.noticesCenter.setAttribute("style",`${"width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;"}top:0;left:0;right:0;bottom:0;flex-flow:column;justify-content:center;align-items:center;`),Object.keys(containers).forEach(a=>document.body.appendChild(containers[a])),positions={"top-left":containers.noticesTopLeft,"top-right":containers.noticesTopRight,"top-center":containers.noticesTopCenter,"bottom-left":containers.noticesBottomLeft,"bottom-right":containers.noticesBottomRight,"bottom-center":containers.noticesBottomCenter,center:containers.noticesCenter},initialized=!0}function toast(a){initialized||init();let b=Object.assign({},defaults,a);const c=new Toast(b),d=positions[b.position]||positions[defaults.position];d.appendChild(c.element)}class Toast{constructor(a){this.element=document.createElement("div"),this.opacity=a.opacity,this.type=a.type,this.animate=a.animate,this.dismissible=a.dismissible,this.closeOnClick=a.closeOnClick,this.message=a.message,this.duration=a.duration,this.pauseOnHover=a.pauseOnHover;let b=`width:auto;pointer-events:auto;display:inline-flex;opacity:${this.opacity};`,c=["notification"];if(this.type&&c.push(this.type),this.animate&&this.animate.in&&(c.push(`animated ${this.animate.in}`),this.onAnimationEnd(()=>this.element.classList.remove(this.animate.in))),this.element.classList=c.join(" "),this.dismissible){let a=document.createElement("button");a.className="delete",a.addEventListener("click",()=>{this.destroy()}),this.element.insertAdjacentElement("afterbegin",a)}else b+="padding: 1.25rem 1.5rem";this.closeOnClick&&this.element.addEventListener("click",()=>{this.destroy()}),this.element.setAttribute("style",b),"string"==typeof this.message?this.element.insertAdjacentHTML("beforeend",this.message):this.element.appendChild(this.message);const d=new Timer(()=>{this.destroy()},this.duration);this.pauseOnHover&&(this.element.addEventListener("mouseover",()=>{d.pause()}),this.element.addEventListener("mouseout",()=>{d.resume()}))}destroy(){this.animate&&this.animate.out?(this.element.classList.add(this.animate.out),this.onAnimationEnd(()=>this.element.remove())):this.element.remove()}onAnimationEnd(a=()=>{}){const b={animation:"animationend",OAnimation:"oAnimationEnd",MozAnimation:"mozAnimationEnd",WebkitAnimation:"webkitAnimationEnd"};for(const c in b)if(this.element.style[c]!==void 0){this.element.addEventListener(b[c],()=>a());break}}}class Timer{constructor(a,b){this.timer,this.start,this.remaining=b,this.callback=a,this.resume()}pause(){window.clearTimeout(this.timer),this.remaining-=new Date-this.start}resume(){this.start=new Date,window.clearTimeout(this.timer),this.timer=window.setTimeout(this.callback,this.remaining)}}export{toast}; |
/*! | ||
* bulma-toast 1.3.0 | ||
* bulma-toast 1.4.0 | ||
* (c) 2018-present @rfoel <rafaelfr@outlook.com> | ||
* Released under the MIT License. | ||
*/ | ||
(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports):'function'==typeof define&&define.amd?define(['exports'],b):b(a.bulmaToast={})})(this,function(a){'use strict';function b(){f={noticesTopLeft:document.createElement('div'),noticesTopRight:document.createElement('div'),noticesBottomLeft:document.createElement('div'),noticesBottomRight:document.createElement('div'),noticesTopCenter:document.createElement('div'),noticesBottomCenter:document.createElement('div'),noticesCenter:document.createElement('div')};f.noticesTopLeft.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}left:0;top:0;text-align:left;align-items:flex-start;`),f.noticesTopRight.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}right:0;top:0;text-align:right;align-items:flex-end;`),f.noticesBottomLeft.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}left:0;bottom:0;text-align:left;align-items:flex-start;`),f.noticesBottomRight.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}right:0;bottom:0;text-align:right;align-items:flex-end;`),f.noticesTopCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}top:0;left:0;right:0;text-align:center;align-items:center;`),f.noticesBottomCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}bottom:0;left:0;right:0;text-align:center;align-items:center;`),f.noticesCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}top:0;left:0;right:0;bottom:0;flex-flow:column;justify-content:center;align-items:center;`),Object.keys(f).forEach(a=>document.body.appendChild(f[a])),g={"top-left":f.noticesTopLeft,"top-right":f.noticesTopRight,"top-center":f.noticesTopCenter,"bottom-left":f.noticesBottomLeft,"bottom-right":f.noticesBottomRight,"bottom-center":f.noticesBottomCenter,center:f.noticesCenter},e=!0}function c(a){e||b();let c=Object.assign({},d,a);const f=new h(c),i=g[c.position]||g[d.position];i.appendChild(f.element)}const d={message:'Your message here',duration:2e3,position:'top-right',closeOnClick:!0,opacity:1};let e=!1,f={},g={};class h{constructor(a){this.element=document.createElement('div'),this.opacity=a.opacity,this.type=a.type,this.animate=a.animate,this.dismissible=a.dismissible,this.closeOnClick=a.closeOnClick,this.message=a.message,this.duration=a.duration,this.pauseOnHover=a.pauseOnHover;let b=`width:auto;pointer-events:auto;display:inline-flex;opacity:${this.opacity};`,c=['notification'];if(this.type&&c.push(this.type),this.animate&&this.animate.in&&(c.push(`animated ${this.animate.in}`),this.onAnimationEnd(()=>this.element.classList.remove(this.animate.in))),this.element.classList=c.join(' '),this.dismissible){let a=document.createElement('button');a.className='delete',a.addEventListener('click',()=>{this.destroy()}),this.element.insertAdjacentElement('afterbegin',a)}else b+='padding: 1.25rem 1.5rem';this.closeOnClick&&this.element.addEventListener('click',()=>{this.destroy()}),this.element.setAttribute('style',b),this.element.insertAdjacentText('beforeend',this.message);const d=new i(()=>{this.destroy()},this.duration);this.pauseOnHover&&(this.element.addEventListener('mouseover',()=>{d.pause()}),this.element.addEventListener('mouseout',()=>{d.resume()}))}destroy(){this.animate&&this.animate.out?(this.element.classList.add(this.animate.out),this.onAnimationEnd(()=>this.element.remove())):this.element.remove()}onAnimationEnd(a=()=>{}){const b={animation:'animationend',OAnimation:'oAnimationEnd',MozAnimation:'mozAnimationEnd',WebkitAnimation:'webkitAnimationEnd'};for(const c in b)if(this.element.style[c]!==void 0){this.element.addEventListener(b[c],()=>a());break}}}class i{constructor(a,b){this.timer,this.start,this.remaining=b,this.callback=a,this.resume()}pause(){window.clearTimeout(this.timer),this.remaining-=new Date-this.start}resume(){this.start=new Date,window.clearTimeout(this.timer),this.timer=window.setTimeout(this.callback,this.remaining)}}a.toast=c,Object.defineProperty(a,'__esModule',{value:!0})}); | ||
(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?b(exports):'function'==typeof define&&define.amd?define(['exports'],b):b(a.bulmaToast={})})(this,function(a){'use strict';function b(){f={noticesTopLeft:document.createElement('div'),noticesTopRight:document.createElement('div'),noticesBottomLeft:document.createElement('div'),noticesBottomRight:document.createElement('div'),noticesTopCenter:document.createElement('div'),noticesBottomCenter:document.createElement('div'),noticesCenter:document.createElement('div')};f.noticesTopLeft.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}left:0;top:0;text-align:left;align-items:flex-start;`),f.noticesTopRight.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}right:0;top:0;text-align:right;align-items:flex-end;`),f.noticesBottomLeft.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}left:0;bottom:0;text-align:left;align-items:flex-start;`),f.noticesBottomRight.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}right:0;bottom:0;text-align:right;align-items:flex-end;`),f.noticesTopCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}top:0;left:0;right:0;text-align:center;align-items:center;`),f.noticesBottomCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}bottom:0;left:0;right:0;text-align:center;align-items:center;`),f.noticesCenter.setAttribute('style',`${'width:100%;z-index:99999;position:fixed;pointer-events:none;display:flex;flex-direction:column;padding:15px;'}top:0;left:0;right:0;bottom:0;flex-flow:column;justify-content:center;align-items:center;`),Object.keys(f).forEach(a=>document.body.appendChild(f[a])),g={"top-left":f.noticesTopLeft,"top-right":f.noticesTopRight,"top-center":f.noticesTopCenter,"bottom-left":f.noticesBottomLeft,"bottom-right":f.noticesBottomRight,"bottom-center":f.noticesBottomCenter,center:f.noticesCenter},e=!0}function c(a){e||b();let c=Object.assign({},d,a);const f=new h(c),i=g[c.position]||g[d.position];i.appendChild(f.element)}const d={message:'Your message here',duration:2e3,position:'top-right',closeOnClick:!0,opacity:1};let e=!1,f={},g={};class h{constructor(a){this.element=document.createElement('div'),this.opacity=a.opacity,this.type=a.type,this.animate=a.animate,this.dismissible=a.dismissible,this.closeOnClick=a.closeOnClick,this.message=a.message,this.duration=a.duration,this.pauseOnHover=a.pauseOnHover;let b=`width:auto;pointer-events:auto;display:inline-flex;opacity:${this.opacity};`,c=['notification'];if(this.type&&c.push(this.type),this.animate&&this.animate.in&&(c.push(`animated ${this.animate.in}`),this.onAnimationEnd(()=>this.element.classList.remove(this.animate.in))),this.element.classList=c.join(' '),this.dismissible){let a=document.createElement('button');a.className='delete',a.addEventListener('click',()=>{this.destroy()}),this.element.insertAdjacentElement('afterbegin',a)}else b+='padding: 1.25rem 1.5rem';this.closeOnClick&&this.element.addEventListener('click',()=>{this.destroy()}),this.element.setAttribute('style',b),'string'==typeof this.message?this.element.insertAdjacentHTML('beforeend',this.message):this.element.appendChild(this.message);const d=new i(()=>{this.destroy()},this.duration);this.pauseOnHover&&(this.element.addEventListener('mouseover',()=>{d.pause()}),this.element.addEventListener('mouseout',()=>{d.resume()}))}destroy(){this.animate&&this.animate.out?(this.element.classList.add(this.animate.out),this.onAnimationEnd(()=>this.element.remove())):this.element.remove()}onAnimationEnd(a=()=>{}){const b={animation:'animationend',OAnimation:'oAnimationEnd',MozAnimation:'mozAnimationEnd',WebkitAnimation:'webkitAnimationEnd'};for(const c in b)if(this.element.style[c]!==void 0){this.element.addEventListener(b[c],()=>a());break}}}class i{constructor(a,b){this.timer,this.start,this.remaining=b,this.callback=a,this.resume()}pause(){window.clearTimeout(this.timer),this.remaining-=new Date-this.start}resume(){this.start=new Date,window.clearTimeout(this.timer),this.timer=window.setTimeout(this.callback,this.remaining)}}a.toast=c,Object.defineProperty(a,'__esModule',{value:!0})}); |
{ | ||
"name": "bulma-toast", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Bulma's pure JavaScript extension to display toasts", | ||
@@ -5,0 +5,0 @@ "main": "dist/bulma-toast.cjs.js", |
@@ -10,3 +10,3 @@ # bulma-toast | ||
![Bulma Toast](https://raw.githubusercontent.com/rfoel/bulma-toast/master/bulma-toast.gif) | ||
![Bulma Toast](https://raw.githubusercontent.com/rfoel/bulma-toast/master/bulma-toast.png) | ||
@@ -17,3 +17,3 @@ ## Options | ||
- `message`: The actual message to be displayed. | ||
- `message`: The actual message to be displayed. It can be a string, a template string, or a DOM node. [See examples](#examples). | ||
- `type`: Essentially a Bulma's css class. It can be `is-primary`, `is-link`, `is-info`, `is-success`, `is-warning`, `is-danger`, or any other custom class. Default is a whitesmoke background with dark text as shown [here](https://bulma.io/documentation/elements/notification). | ||
@@ -26,3 +26,3 @@ - `duration`: Duration of the notification in milliseconds. Default is `2000` milliseconds. | ||
- `opacity`: The notification's container opacity. Default is `1`. | ||
- `animate`: [See here](#Animate.css). Default is no animations. | ||
- `animate`: [See here](#animate). Default is no animations. | ||
@@ -46,5 +46,6 @@ ## Install | ||
2. Use bulma-toast to display a toast | ||
```js | ||
bulmaToast.toast({ message: "Hello There" }); | ||
bulmaToast.toast({ message: "General Kenobi", type: "is-danger" }); | ||
bulmaToast.toast({ message: "Hello There" }); | ||
bulmaToast.toast({ message: "General Kenobi", type: "is-danger" }); | ||
``` | ||
@@ -55,14 +56,14 @@ | ||
```js | ||
// Import the toast function | ||
import { toast } from "bulma-toast"; | ||
// Or use | ||
// import { toast as superToast } from 'bulma-toast' | ||
// to rename your import | ||
// Import the toast function | ||
import { toast } from "bulma-toast"; | ||
// Or use | ||
// import { toast as superToast } from 'bulma-toast' | ||
// to rename your import | ||
toast({ | ||
message: "Hello There", | ||
type: "is-success", | ||
dismissible: true, | ||
animate: { in: "fadeIn", out: "fadeOut" } | ||
}); | ||
toast({ | ||
message: "Hello There", | ||
type: "is-success", | ||
dismissible: true, | ||
animate: { in: "fadeIn", out: "fadeOut" } | ||
}); | ||
``` | ||
@@ -84,5 +85,5 @@ | ||
## Animate.css | ||
## Animate | ||
You MUST include [animate.css](https://daneden.github.io/animate.css/) on your document's `<head>` | ||
Bulma Toast supports [animate.css](https://daneden.github.io/animate.css/) (and maybe others?). You MUST include [animate.css](https://daneden.github.io/animate.css/) on your document's `<head>` | ||
@@ -99,3 +100,3 @@ ```html | ||
Bulma Toast supports [animate.css](https://daneden.github.io/animate.css/) (and maybe others?). Accepts a object with `in` and `out` with css classes to add animations. Using Animate.css you would pass a object like this: | ||
Accepts a object with `in` and `out` with css classes to add animations. Using Animate.css you would pass a object like this: | ||
@@ -107,3 +108,2 @@ ```js | ||
position: "top-right", | ||
opacity: 1, | ||
animate: { in: 'fadeIn', out: 'fadeOut' } | ||
@@ -113,2 +113,49 @@ } | ||
_Warning_: Don't use `opacity` when using animations. Some of them use the opacity property like fade in and fade out. | ||
## Examples | ||
```js | ||
import { toast } from "bulma-toast"; | ||
toast({ | ||
message: "Hello There", | ||
type: "is-success", | ||
dismissible: true, | ||
pauseOnHover: true | ||
}); | ||
toast({ | ||
message: "<h1>LOOK HERE</h1>", | ||
type: "is-danger", | ||
dismissible: true, | ||
pauseOnHover: true, | ||
animate: { in: "fadeIn", out: "fadeOut" } | ||
}); | ||
const myMessage = `It's ${new Date().toDateString()}`; | ||
toast({ | ||
message: myMessage, | ||
type: "is-primary", | ||
position: "center", | ||
closeOnClick: true, | ||
pauseOnHover: true, | ||
opacity: 0.8 | ||
}); | ||
const elm = document.createElement("a"); | ||
elm.text = "Visit my website!"; | ||
elm.href = "https://rfoel.com"; | ||
toast({ | ||
message: elm, | ||
type: "is-warning", | ||
position: "center", | ||
closeOnClick: true, | ||
pauseOnHover: true, | ||
animate: { in: "fadeIn", out: "fadeOut" } | ||
}); | ||
``` | ||
## Contributing | ||
@@ -119,5 +166,5 @@ | ||
1. Fork it ( https://github.com/rfoel/bulma-toast/fork ) | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
2. Create your feature branch (`git checkout -b my_new_feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
4. Push to the branch (`git push origin my_new_feature`) | ||
5. Create a new Pull Request |
@@ -121,4 +121,9 @@ const defaults = { | ||
this.element.setAttribute("style", style); | ||
this.element.insertAdjacentText("beforeend", this.message); | ||
if (typeof this.message === "string") { | ||
this.element.insertAdjacentHTML("beforeend", this.message); | ||
} else { | ||
this.element.appendChild(this.message); | ||
} | ||
const timer = new Timer(() => { | ||
@@ -125,0 +130,0 @@ this.destroy(); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
26372
236
161
0