-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjquery.notifications.min.js
2 lines (2 loc) · 2.47 KB
/
jquery.notifications.min.js
1
2
/* jQuery.notifications Plugin * @author Stéphan Zych <[email protected]> * @copyriht 2010-2011 Stéphan Zych <[email protected]> * @license New BSD License <http://creativecommons.org/licenses/BSD/> */
(function(e){"use strict";var t=function(e,t){for(var n in t)e=e.replace(new RegExp("{"+n+"}","g"),t[n]);return e},n=function(){var n={className:"notification",alive:4e3,fadeIn:600,fadeOut:800,sticky:!1,tpl:'<div class="{className}"><div class="{className}-img"><img src="{image}" alt="" /></div><div class="{className}-content"><div class="{className}-title">{title}</div>{content}</div></div>',onShow:function(){},onHide:function(){}},r=function(r){e("#notifications-wrapper").length||e("body").append('<div id="notifications-wrapper"></div>');var i=e("#notifications-wrapper"),s=i.data("count")+1||1;n=e.extend({},n,r);i.data("count",s);e(t(n.tpl,n)).attr("data-id",s).appendTo(i).css({opacity:0}).animate({opacity:1},n.fadeIn,function(){var t=this,r=e(t),i=parseInt(t.getAttribute("data-id"),10);r.on("click",function(){e.notifications("remove",i)}).find("a").on("click",function(e){e.stopImmediatePropagation()});if(!n.sticky){r.data("timer",setTimeout(function(){e.notifications("remove",i)},n.alive));r.on("mouseenter",function(){clearTimeout(r.data("timer"))}).on("mouseleave",function(){r.data("timer",setTimeout(function(){e.notifications("remove",i)},n.alive))})}n.onShow(n)})},i=function(){var t=e("."+n.className+":not(.removing)").last().data("id"),r,i;if(arguments.length)if(typeof arguments[0]=="function")i=arguments[0];else if(typeof arguments[1]=="function"){t=arguments[0];i=arguments[1]}else t=arguments[0];r=e('[data-id="'+t+'"]');i&&(n=e.extend({},n,{onHide:i}));r.addClass("removing").animate({opacity:0},n.fadeOut,function(){r.animate({height:0},150,function(){clearTimeout(r.data("timer"));r.remove();n.onHide(n)})})},s=function(t){typeof t=="function"&&(n=e.extend({},n,{onHide:t}));e("."+n.className).each(function(){e.notifications("remove",this.getAttribute("data-id"),{onHide:null})});e("#notifications-wrapper").data("count",0);n.onHide(n)};return{add:r,remove:i,removeAll:s}}();e.notifications=function(t){if(n[t])return n[t].apply(this,Array.prototype.slice.call(arguments,1));if(typeof t=="object"||!t)return n.add.apply(this,arguments);e.error('Method "'+arguments[0]+'" does not exist in $.notifications plugin!')};e(document).on("click.notification.data-api",'[data-toggle="notification"]',function(t){var n=e(this),r=n.data();t.preventDefault();e.notifications("add",r)})})(jQuery);