-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutterup.min.js
2 lines (2 loc) · 4.98 KB
/
butterup.min.js
1
2
/* butterup version 2.0.0 by Nathan Langer * https://github.com/dgtlss/butterup | https://butterup.nlanger.dev * Thankyou for using butterup! Please consider starring the project on GitHub. */
var butterup={options:{maxToasts:5,toastLife:5e3,currentToasts:0},toast:function({title:t,message:e,type:n,location:s,icon:o,theme:a,customIcon:l,dismissable:c,onClick:i,onRender:u,onTimeout:d,customHTML:r,primaryButton:m,secondaryButton:p}){if(null==document.getElementById("toaster")){const t=document.createElement("div");if(t.id="toaster",t.className=null==s?"toaster top-right":"toaster "+s,document.body.appendChild(t),null==document.getElementById("butterupRack")){const e=document.createElement("ol");e.id="butterupRack",e.className="rack",t.appendChild(e)}}else{const t=document.getElementById("toaster");t.classList.forEach((function(e){(e.includes("top-right")||e.includes("top-center")||e.includes("top-left")||e.includes("bottom-right")||e.includes("bottom-center")||e.includes("bottom-left"))&&t.classList.remove(e)})),t.className=null==s?"toaster top-right":"toaster "+s,document.getElementById("butterupRack")}if(butterup.options.currentToasts>=butterup.options.maxToasts){var v=document.getElementById("butterupRack").firstChild;document.getElementById("butterupRack").removeChild(v),butterup.options.currentToasts--}const f=document.createElement("li");if(butterup.options.currentToasts++,f.className="butteruptoast",(toaster.className.includes("top-right")||toaster.className.includes("top-center")||toaster.className.includes("top-left"))&&(f.className+=" toastDown"),(toaster.className.includes("bottom-right")||toaster.className.includes("bottom-center")||toaster.className.includes("bottom-left"))&&(f.className+=" toastUp"),f.id="butterupToast-"+butterup.options.currentToasts,null!=n&&(f.className+=" "+n),null!=a&&(f.className+=" "+a),document.getElementById("butterupRack").appendChild(f),null!=o&&1==o){const t=document.createElement("div");t.className="icon",f.appendChild(t),l&&(t.innerHTML=l),null!=n&&null==l&&(f.className+=" "+n,"success"==n&&(t.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd" /></svg>'),"error"==n&&(t.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z" clip-rule="evenodd" /></svg>'),"warning"==n&&(t.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd" /></svg>'),"info"==n&&(t.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z" clip-rule="evenodd" /></svg>'))}const g=document.createElement("div");g.className="notif",f.appendChild(g);const h=document.createElement("div");if(h.className="desc",g.appendChild(h),null!=t){const e=document.createElement("div");e.className="title",e.innerHTML=t,h.appendChild(e)}if(null!=r){const t=document.createElement("div");t.className="message",t.innerHTML=r,h.appendChild(t)}if(null!=e){const t=document.createElement("div");t.className="message",t.innerHTML=e,h.appendChild(t)}if(m||p){const t=document.createElement("div");if(t.className="toast-buttons",g.appendChild(t),m){const e=document.createElement("button");e.className="toast-button primary",e.textContent=m.text,e.onclick=function(t){t.stopPropagation(),m.onClick(t)},t.appendChild(e)}if(p){const e=document.createElement("button");e.className="toast-button secondary",e.textContent=p.text,e.onclick=function(t){t.stopPropagation(),p.onClick(t)},t.appendChild(e)}}i&&"function"==typeof i&&f.addEventListener("click",(function(t){t.stopPropagation(),i(t)})),u&&"function"==typeof u&&u(f),null!=c&&1==c&&(f.className+=" dismissable",f.addEventListener("click",(function(){butterup.despawnToast(f.id)}))),setTimeout((function(){f.className=f.className.replace(" toastDown",""),f.className=f.className.replace(" toastUp","")}),500),setTimeout((function(){d&&"function"==typeof d&&d(f),butterup.despawnToast(f.id)}),butterup.options.toastLife)},despawnToast(t,e){var n=document.getElementById(t);null!=n&&(n.className+=" fadeOutToast",setTimeout((function(){try{n.style.opacity="0",n.parentNode.removeChild(n),butterup.options.currentToasts--,e&&"function"==typeof e&&e(n)}catch(t){}if(0==butterup.options.currentToasts){var t=document.getElementById("toaster");t.parentNode.removeChild(t)}}),500))}};