Files
jquery-notify/dist/notify.min.js
T

5 lines
7.4 KiB
JavaScript
Raw Normal View History

2013-06-05 13:17:20 +10:00
/** Notify.js - v0.0.1 - 2013/06/05
2013-04-04 13:13:08 +11:00
* http://notifyjs.com/
* Copyright (c) 2013 Jaime Pillora - MIT
2013-06-05 13:17:20 +10:00
*/
(function(t,i,n){"use strict";var e,o,s,r,a,h,l,p,c,u,d,f,m,w,y,g,v,b,x,C,H,S,T=[].indexOf||function(t){for(var i=0,n=this.length;n>i;i++)if(i in this&&this[i]===t)return i;return-1};g="notify",y=g+"js",b={t:"top",m:"middle",b:"bottom",l:"left",c:"center",r:"right"},p=["l","c","r"],S=["t","m","b"],f=["t","b","l","r"],m={t:"b",m:null,b:"t",l:"r",c:null,r:"l"},w=function(t){var i;return i=[],$.each(t.split(/\W+/),function(t,e){var o;return o=e.toLowerCase().charAt(0),b[o]?i.push(o):n}),i},H={},s={name:"core",html:'<div class="'+y+'-wrapper">\n <div class="'+y+'-arrow"></div>\n <div class="'+y+'-container"></div>\n</div>',css:"."+y+"-corner {\n position: fixed;\n top: 0;\n right: 0;\n margin: 5px;\n z-index: 1050;\n}\n\n."+y+"-corner ."+y+"-wrapper,\n."+y+"-corner ."+y+"-container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n}\n\n."+y+"-wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n."+y+"-container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+y+"-text {\n position: relative;\n}\n\n."+y+"-arrow {\n position: absolute;\n z-index: 2;\n width: 0;\n height: 0;\n}"},C={"border-radius":["-webkit-","-moz-"]},o=function(i,e){var o;return H[i]&&(t.console&&console.warn(""+g+": overwriting style '"+i+"'"),$("#notify-"+i).remove()),e.name=i,H[i]=e,!e.cssElem&&(o="",e.classes&&$.each(e.classes,function(t,i){return o+="."+y+"-"+e.name+"-"+t+" {\n",$.each(i,function(t,i){return C[t]&&$.each(C[t],function(n,e){return o+=" "+e+t+": "+i+";\n"}),o+=" "+t+": "+i+";\n"}),o+="}\n"}),e.css&&(o+="/* styles for "+e.name+" */\n"+e.css),o)?(e.cssElem=d(o),e.cssElem.attr("id","notify-"+e.name)):n},d=function(t){var i;i=a("style"),$("head").append(i);try{i.html(t)}catch(n){i[0].styleSheet.cssText=t}return i},v={autoHide:!0,autoHideDelay:5e3,arrowShow:!0,arrowSize:5,elementPosition:"bottom",globalPosition:"top right",style:"bootstrap",className:"error",showAnimation:"slideDown",showDuration:400,hideAnimation:"slideUp",hideDuration:200,offsetY:0,offsetX:0},u=function(t,i){var n;return n=function(){},n.prototype=t,$.extend(!0,new n,i)},h=function(t){return $.extend(v,t)},a=function(t){return $("<"+t+"></"+t+">")},r=a("div").addClass(""+y+"-corner"),l=function(t){var i;return t.is("[type=radio]")&&(i=t.parents("form:first").find("[type=radio]").filter(function(i,n){return $(n).attr("name")===t.attr("name")}),t=i.first()),t},c=function(t,i,e){var o,s;if("string"==typeof e)e=parseInt(e,10);else if("number"!=typeof e)return;if(!isNaN(e))return o=b[m[i.charAt(0)]],s=i,t[o]!==n&&(i=b[o.charAt(0)],e*=-1),t[i]===n?t[i]=e:t[i]+=e,null},x=function(t,i,n){if("l"===t||"t"===t)return 0;if("c"===t||"m"===t)return n/2-i/2;if("r"===t||"b"===t)return n-i;throw"Invalid alignment"},e=function(){function t(t,i,n){"string"==typeof n&&(n={className:n}),this.options=u(v,$.isPlainObject(n)?n:{}),this.loadHTML(),this.wrapper=$(s.html),this.wrapper.data(y,this),this.arrow=this.wrapper.find("."+y+"-arrow"),this.container=this.wrapper.find("."+y+"-container"),this.container.append(this.userContainer),t&&t.length?(this.elementType=t.attr("type"),this.originalElement=t,this.elem=l(t),this.elem.data(y,this),this.elem.before(this.wrapper)):(this.options.arrowShow=!1,r.prepend(this.wrapper)),this.container.hide(),this.run(i)}return t.prototype.loadHTML=function(){var t;if(t=this.getStyle(),this.userContainer=$(t.html),this.text=this.userContainer.find("[data-notify-text]"),0===this.text.length&&(this.text=this.userContainer.find("[data-notify-html]"),this.rawHTML=!0),0===this.text.length)throw"style: '"+name+"' HTML is missing a: 'data-notify-text' or 'data-notify-html' attribute";return this.text.addClass(""+y+"-text")},t.prototype.show=function(t,i){var n,e,o,s;if(null==i&&(i=$.noop),s=this.container.parent().parents(":hidden").length>0,e=this.container.add(this.arrow),n=[],s&&t)o="show";else if(s&&!t)o="hide";else if(!s&&t)o=this.options.showAnimation,n.push(this.options.showDuration);else{if(s||t)return i();o=this.options.hideAni