-
Notifications
You must be signed in to change notification settings - Fork 0
/
fvuar.min.js
9 lines (9 loc) · 3.78 KB
/
fvuar.min.js
1
2
3
4
5
6
7
8
9
/**
* @name fvuarjs
* @version 0.0.5
* @author ahmetcanisik
* @long_name Fast Visual User Alerts Resource
* @description Notification message library with a modern look for your project!
* @licence MIT
*/
class Defines{static CONFIG={MAXCOUNT:4,MAXTIME:4,DEFAULTTIME:4,DEFAULTTHEME:"default",DEFAULTPOSITION:"top-right",CPALERT:!1,ALERTOFFSET:70,CLOSEMETHOD:"click",HOVERTOTOP:!1,CLICKTOCLOSE:"click",MULTIPLY:!1};static SUCCESS="success";static ERROR="error";static DEFAULT="default";static WARNING="warning";static INFO="info";static ORANGE="orange";static PREFIX="fvuar-alert";static POS={"top-left":10,"top-center":10,"top-right":10,"center-left":10,center:10,"center-right":10,"bottom-left":10,"bottom-center":10,"bottom-right":10}}class FvUtils{static tota(e,t=void 0){return 1===e?`${Defines.PREFIX}-${Defines.ERROR}`:`${Defines.PREFIX}-${t}`}static reposAlert(e,t,s,a=!1,i=Defines.CONFIG.MULTIPLY){if(a)i&&(Defines.POS[t]-=Defines.CONFIG.ALERTOFFSET);else{switch(s){case"top":e.style.top=`${Defines.POS[t]}px`;break;case"bottom":e.style.bottom=`${Defines.POS[t]}px`;break;case"center":e.style.top=`calc(50% + ${Defines.POS[t]}px)`,"center-left"===t?(e.style.left="10px",e.style.right="auto",e.style.transform="translateY(-50%)"):"center-right"===t?(e.style.right="10px",e.style.left="auto",e.style.transform="translateY(-50%)"):(e.style.left="50%",e.style.right="auto",e.style.transform="translate(-50%, -50%)")}e.classList.add(`bubble-${s}`),i&&(Defines.POS[t]+=e.offsetHeight+Defines.CONFIG.ALERTOFFSET)}}}class Fvuar{static LEN=0;static fvAlert=document.createElement("fv-alert");static configure(e=Defines.CONFIG){Defines.CONFIG={...Defines.CONFIG,...e},console.log(Defines.CONFIG)}static alert({theme:e,position:t,text:s,time:a,css:i,clickToClose:r}){try{Fvuar.fvAlert.parentNode||document.body.appendChild(Fvuar.fvAlert);let n=1e3*a,l=document.createElement("fv-container"),o=document.createElement("fv-text");const c=(e,s=!1)=>{"none"===e?(l.remove(),s&&(Fvuar.LEN-=1,FvUtils.reposAlert(l,t,t.split("-")[0],!0,Defines.CONFIG.MULTIPLY))):"flex"===e?(Fvuar.LEN+=1,l.style.display="flex"):console.error("sav() fonksiyonu iki parametre alır: ['flex','none'], Counter(boolean)")};switch(e){case Defines.ERROR:l.className=FvUtils.tota(1);break;case Defines.DEFAULT:l.className=FvUtils.tota(0,Defines.DEFAULT);break;case Defines.WARNING:l.className=FvUtils.tota(0,Defines.WARNING);break;case Defines.SUCCESS:l.className=FvUtils.tota(0,Defines.SUCCESS);break;case Defines.INFO:l.className=FvUtils.tota(0,Defines.INFO);break;case Defines.ORANGE:l.className=FvUtils.tota(0,Defines.ORANGE);break;default:console.error("Please write success, warning or error. usage should be createAlert({ e: 'success', a: 'Your message' })")}i&&Object.assign(l.style,i),Object.keys(Defines.POS).forEach((e=>l.classList.remove(`${e}`))),l.classList.add(`${t}`),FvUtils.reposAlert(l,t,t.split("-")[0],!1,Defines.CONFIG.MULTIPLY),l.classList.add("fvc"),o.classList.add("fvt"),Defines.CONFIG.MULTIPLY||(Fvuar.fvAlert.innerHTML=""),Fvuar.fvAlert.appendChild(l),o.innerHTML=s,l.appendChild(o),c("flex");let f=setTimeout((()=>{c("none",!0)}),n);r&&l.addEventListener("click",(()=>{clearTimeout(f),c("none",!0)}))}catch(e){console.error("Ups! An error occurred while creating the alert!",e)}}static new({theme:e=Defines.CONFIG.DEFAULTTHEME,position:t=Defines.CONFIG.DEFAULTPOSITION,text:s,time:a=Defines.CONFIG.DEFAULTTIME,css:i=null,clickToClose:r=Defines.CONFIG.CLICKTOCLOSE}){Defines.CONFIG.MULTIPLY&&Fvuar.LEN>=Defines.CONFIG.MAXCOUNT?console.warn(`You have reached the maximum number of alerts. Defines.CONFIG.MAXCOUNT: ${Defines.CONFIG.MAXCOUNT}`):Fvuar.alert({theme:e,position:t,text:s,time:a,css:i,clickToClose:r})}}"undefined"!=typeof module&&void 0!==module.exports?module.exports=Fvuar:window.Fvuar=Fvuar;