/
jquery.classynotty.min.js
executable file
·10 lines (10 loc) · 2.52 KB
/
jquery.classynotty.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* jQuery ClassyNotty
* www.class.pm
*
* Written by Marius Stanciu - Sergiu <marius@class.pm>
* Licensed under the MIT license www.class.pm/LICENSE-MIT
* Version 1.2.0
*
*/
(function(a){a.ClassyNotty=function(b){function m(a){var b=[[2,"One second","1 second from now"],[60,"seconds",1],[120,"One minute","1 minute from now"],[3600,"minutes",60],[7200,"One hour","1 hour from now"],[86400,"hours",3600],[172800,"One day","tomorrow"],[604800,"days",86400],[1209600,"One week","next week"],[2419200,"weeks",604800],[4838400,"One month","next month"],[29030400,"months",2419200],[58060800,"One year","next year"],[290304E4,"years",29030400],[580608E4,"One century","next century"], [580608E5,"centuries",290304E4]],c=(new Date-a)/1E3,e=1;0>c&&(c=Math.abs(c),e=1);for(var f=0,d;d=b[f++];)if(c<d[0])return"string"===typeof d[2]?d[e]:Math.floor(c/d[2])+" "+d[1];return a}var g,c,f,d,h,k,e;b=a.extend({title:void 0,content:void 0,timeout:0,img:void 0,showTime:!0,click:void 0},b);g=a("#nottys");g.length||(g=a("<div>",{id:"nottys"}).appendTo(document.body));c=a("<div>");c.addClass("notty npop");f=a("<div>",{click:function(){a(this).parent().removeClass("npop").addClass("nremove").delay(300).queue(function(){a(this).clearQueue(); a(this).remove()})},touchstart:function(){a(this).parent().removeClass("npop").addClass("nremove").delay(300).queue(function(){a(this).clearQueue();a(this).remove()})}});f.addClass("nhide");f.html("Hide notification");if(void 0!==b.img){d=a("<div>",{style:"background: url("+b.img+")"});d.addClass("nimg");k=a('<div class="nleft">');h=a('<div class="nright">');e=void 0!==b.title?"<h2>"+b.title+"</h2>":"";var l=void 0!==b.content?b.content:"";e=a("<div>",{html:e+l});e.addClass("ninner");e.appendTo(h); d.appendTo(k);k.appendTo(c);h.appendTo(c)}else e=void 0!==b.title?"<h2>"+b.title+"</h2>":"",l=void 0!==b.content?b.content:"",c.html(e+l);f.appendTo(c);!1!==b.showTime&&(d=Number(new Date),timeHTML=a("<div>",{html:"<strong>"+m(d)+"</strong> ago"}),timeHTML.addClass("ntime").attr("title",d),void 0!==b.img?timeHTML.appendTo(h):timeHTML.appendTo(c),setInterval(function(){a(".ntime").each(function(){var b=a(this).attr("title");a(this).html("<strong>"+m(b)+"</strong> ago")})},4E3));c.hover(function(){f.show()}, function(){f.hide()});c.prependTo(g);c.show();b.timeout&&setTimeout(function(){c.removeClass("npop").addClass("nremove").delay(300).queue(function(){a(this).clearQueue();a(this).remove()})},b.timeout);void 0!==b.click&&(c.addClass("nclick"),c.click(function(c){a(c.target).is(".nhide")||b.click.call(this)}));return this}})(jQuery);