-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotificationJS.min.js
1 lines (1 loc) · 2.54 KB
/
notificationJS.min.js
1
if(!window.jQuery){var jQuery=document.createElement('script');jQuery.src='https://code.jquery.com/jquery-latest.min.js',document.head.appendChild(jQuery)}checkErrors=function(a){return a.debug||(a.debug=!0),a.title||(a.title='TITLE UNDEFINED',a.debug&&console.warn('NotificationJS: You need to set a title.')),a.link&&!a.link.href&&a.debug&&console.error('NotificationJS: You need to set a link with href property'),a},notficationJS_getDefaultsStyle=function(){return{maxWidth:'375px',backgroundColor:'#F1F5F6',color:'#242424',border:'none',padding:'10px 15px',borderRadius:'5px',boxShadow:'rgba(36, 36, 36, 0.23) 0px 1px 9px 4px',marginTop:'15px',width:'calc(100vw - 80px)'}},notficationJS_getDefaults=function(){return{status:'info',time:5,hide:!0,animation_duration:.2,showCloseIcon:!0,newestOnTop:!0,debug:!0}},newNotification=function(a){if(!a)return console.error('NotificationJS: You need to set a map with at least a title property like this: '),console.error('NotificationJS: newNotification({"title":"Your title goes here."})'),0;checkErrors(a);let b=$.extend({},notficationJS_getDefaultsStyle(),a.style),c=$.extend({},notficationJS_getDefaults(),a);console.log(b);let d=$(`<div class="notification-panel__item notification__${c.status}"></div>`);d.css({maxWidth:b.maxWidth,width:b.width,backgroundColor:b.backgroundColor,color:b.color,border:b.border,padding:b.padding,borderRadius:b.borderRadius,boxShadow:b.boxShadow,marginTop:b.marginTop});let e=$('<div class="notification-left"></div>'),f=$(`<div class="notification__title">${c.title}</div>`);f.appendTo(e);let g=null;if(c.link&&c.link.href&&(g=$(`<a class="notification__link" href="${c.link.href}"></a>`),void 0==c.link.text?g.text(c.link.href):g.text(c.link.text)),c.description){let a;null==g?a=$(`<div class="notification__description">${c.description}</div>`):(a=$(`<div class="notification__description">${c.description} </div>`),g.appendTo(a)),a.appendTo(e)}else null!=g&&g.appendTo(e);if(d.append(e),c.showCloseIcon){let a=$('<div class="notification-right"></div>'),b=$('<img class="notification_icon" src="examples/close.svg" alt="Close"/>');b.click(function(){d.fadeOut(h),setTimeout(function(){d.remove()},h+100)}),b.appendTo(a),d.append(a)}if(!$('.notification-panel').length){let a=$('<div class="notification-panel"></div>');$('body').append(a)}let h=1e3*c.animation_duration;if(c.newestOnTop?$('.notification-panel').prepend(d).fadeOut(0).fadeIn(h):$('.notification-panel').append(d).fadeOut(0).fadeIn(h),c.hide){let a=1e3*c.time;setTimeout(function(){d.fadeOut(h)},a),setTimeout(function(){d.remove()},a+h+100)}};