Files
jquery-notify/dist/notify.min.js
T
2013-06-03 09:15:58 +10:00

4 lines
8.8 KiB
JavaScript

/** Notify.js - v0.0.1 - 2013/06/03
* http://notifyjs.com/
* Copyright (c) 2013 Jaime Pillora - MIT
*/(function(t,n,e){"use strict";var i,o,r,s,a,l,h,p,u,d,c,f,w,y,m,A,g,b,x=[].indexOf||function(t){for(var n=0,e=this.length;e>n;n++)if(n in this&&this[n]===t)return n;return-1};w="notify",o="__"+w,m={t:"top",m:"middle",b:"bottom",l:"left",c:"center",r:"right"},l=["l","c","r"],b=["t","m","b"],d=["t","b","l","r"],c={t:"b",m:null,b:"t",l:"r",c:null,r:"l"},f=function(t){var n;return n=[],$.each(t.split(/\W+/),function(t,i){var o;return o=i.toLowerCase().charAt(0),m[o]?n.push(o):e}),n},g={core:{html:'<div class="'+o+'Wrapper">\n <div class="'+o+'Arrow"></div>\n <div class="'+o+'Container"></div>\n</div>',css:"."+o+"Corner {\n position: fixed;\n top: 0;\n right: 0;\n margin: 5px;\n z-index: 1050;\n}\n\n."+o+"Corner ."+o+"Wrapper,\n."+o+"Corner ."+o+"Container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n}\n\n."+o+"Wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n."+o+"Container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+o+"Text {\n position: relative;\n}\n\n."+o+"Arrow {\n position: absolute;\n z-index: 2;\n width: 0;\n height: 0;\n}\n"},user:{"default":{html:'<div class="'+o+'Default" \n data-notify-style="\n color: {{color}}; \n border-color: {{color}};\n ">\n <span data-notify-text></span>\n </div>',css:"."+o+"Default {\n background: #fff;\n font-size: 11px;\n box-shadow: 0 0 6px #000;\n -moz-box-shadow: 0 0 6px #000;\n -webkit-box-shadow: 0 0 6px #000;\n padding: 4px 10px 4px 8px;\n border-radius: 6px;\n border-style: solid;\n border-width: 2px;\n -moz-border-radius: 6px;\n -webkit-border-radius: 6px;\n white-space: nowrap;\n}"},bootstrap:{html:'<div class="alert alert-error '+o+'Bootstrap">\n <strong data-notify-text></strong>\n</div>',css:"."+o+"Bootstrap {\n white-space: nowrap;\n margin: 5px !important;\n padding-left: 25px !important;\n background-repeat: no-repeat;\n background-position: 3px 7px;\n background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAtRJREFUeNqkVc1u00AQHq+dOD+0poIQfkIjalW0SEGqRMuRnHos3DjwAH0ArlyQeANOOSMeAA5VjyBxKBQhgSpVUKKQNGloFdw4cWw2jtfMOna6JOUArDTazXi/b3dm55socPqQhFka++aHBsI8GsopRJERNFlY88FCEk9Yiwf8RhgRyaHFQpPHCDmZG5oX2ui2yilkcTT1AcDsbYC1NMAyOi7zTX2Agx7A9luAl88BauiiQ/cJaZQfIpAlngDcvZZMrl8vFPK5+XktrWlx3/ehZ5r9+t6e+WVnp1pxnNIjgBe4/6dAysQc8dsmHwPcW9C0h3fW1hans1ltwJhy0GxK7XZbUlMp5Ww2eyan6+ft/f2FAqXGK4CvQk5HueFz7D6GOZtIrK+srupdx1GRBBqNBtzc2AiMr7nPplRdKhb1q6q6zjFhrklEFOUutoQ50xcX86ZlqaZpQrfbBdu2R6/G19zX6XSgh6RX5ubyHCM8nqSID6ICrGiZjGYYxojEsiw4PDwMSL5VKsC8Yf4VRYFzMzMaxwjlJSlCyAQ9l0CW44PBADzXhe7xMdi9HtTrdYjFYkDQL0cn4Xdq2/EAE+InCnvADTf2eah4Sx9vExQjkqXT6aAERICMewd/UAp/IeYANM2joxt+q5VI+ieq2i0Wg3l6DNzHwTERPgo1ko7XBXj3vdlsT2F+UuhIhYkp7u7CarkcrFOCtR3H5JiwbAIeImjT/YQKKBtGjRFCU5IUgFRe7fF4cCNVIPMYo3VKqxwjyNAXNepuopyqnld602qVsfRpEkkz+GFL1wPj6ySXBpJtWVa5xlhpcyhBNwpZHmtX8AGgfIExo0ZpzkWVTBGiXCSEaHh62/PoR0p/vHaczxXGnj4bSo+G78lELU80h1uogBwWLf5YlsPmgDEd4M236xjm+8nm4IuE/9u+/PH2JXZfbwz4zw1WbO+SQPpXfwG/BBgAhCNZiSb/pOQAAAAASUVORK5CYII=);\n}",colors:{red:"#eed3d7"}}}},y={autoHide:!1,autoHideDelay:2e3,arrowShow:!0,arrowSize:5,position:"bottom",style:"default",color:"black",colors:{red:"#b94a48",green:"#33be40",black:"#393939",blue:"#00f"},showAnimation:"slideDown",showDuration:400,hideAnimation:"slideUp",hideDuration:200,offsetY:0,offsetX:0},s=function(t){return $("<"+t+"></"+t+">")},p=function(t,n){var e;return e=function(){},e.prototype=t,$.extend(!0,new e,n)},r=s("div").addClass(""+o+"Corner"),a=function(t){var n;return t.is("[type=radio]")&&(n=t.parents("form:first").find("[type=radio]").filter(function(n,e){return $(e).attr("name")===t.attr("name")}),t=n.first()),t},h=function(t,n,i){var o,r;if("string"==typeof i)i=parseInt(i,10);else if("number"!=typeof i)return;if(!isNaN(i))return o=m[c[n.charAt(0)]],r=n,t[o]!==e&&(n=m[o.charAt(0)],i*=-1),t[n]===e?t[n]=i:t[n]+=i,null},A=function(t,n,e){if("l"===t||"t"===t)return 0;if("c"===t||"m"===t)return e/2-n/2;if("r"===t||"b"===t)return e-n;throw"Invalid alignment"},u=function(t){var n;if(t&&t.css&&(n=t.cssElem,!n)){n=s("style"),$("head").append(n),t.cssElem=n;try{return n.html(t.css)}catch(e){return n[0].styleSheet.cssText=t.css}}},i=function(){function t(t,n,e){"string"==typeof e&&(e={color:e}),this.options=p(y,$.isPlainObject(e)?e:{}),this.loadCSS(),this.loadHTML(),this.wrapper=$(g.core.html),this.wrapper.data(o,this),this.arrow=this.wrapper.find("."+o+"Arrow"),this.container=this.wrapper.find("."+o+"Container"),this.container.append(this.userContainer),t&&t.length?(this.elementType=t.attr("type"),this.originalElement=t,this.elem=a(t),this.elem.data(o,this),this.elem.before(this.wrapper)):(this.options.arrowShow=!1,r.prepend(this.wrapper)),this.container.hide(),this.run(n)}return t.prototype.loadCSS=function(t){var n;return t||(n=this.options.style,t=this.getStyle(n)),u(t)},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)throw"style: "+name+" HTML is missing the: 'data-notify-text' attribute";return this.text.addClass(""+o+"Text")},t.prototype.show=function(t,n){var e,i,o,r;if(null==n&&(n=$.noop),r=this.container.parent().parents(":hidden").length>0,i=this.container.add(this.arrow),e=[],r&&t)o="show";else if(r&&!t)o="hide";else if(!r&&t)o=this.options.showAnimation,e.push(this.options.showDuration);else{if(r||t)return n();o=this.options.hideAnimation,e.push(this.options.hideDuration)}return e.push(n),i[o].apply(i,e)},t.prototype.updatePosition=function(){var t,n,i,o,r,s,a,p,u,f,w,y,g,v,C,S,k,R,H,B,I,X,z,D,T;if(this.elem){if(f=this.elem.position(),a=this.elem.outerHeight(),w=this.elem.outerWidth(),p=this.elem.innerHeight(),u=this.elem.innerWidth(),z=this.wrapper.position(),o=this.container.height(),r=this.container.width(),X=this.getPosition(),R=X[0],S=X[1],k=X[2]||S,y=m[R],v=c[R],C=m[v],s={},s[C]="b"===R?a:"r"===R?w:0,h(s,"left",f.left-z.left),g=parseInt(this.elem.css("margin-left"),10),g&&h(s,"left",g),/^inline/.test(this.elem.css("display"))&&(H=parseInt(this.elem.css("padding-top"),10),H&&h(s,"top",-H)),h(s,"top",this.options.offsetY),h(s,"left",this.options.offsetX),this.options.arrowShow){for(n=this.options.arrowSize,t=$.extend({},s),D=0,T=d.length;T>D;D++)B=d[D],I=m[B],B!==v&&(i=I===y?this.getColor():"transparent",t["border-"+I]=""+n+"px solid "+i);h(s,m[v],n),x.call(d,S)>=0&&h(t,m[S],2*n)}else this.arrow.hide();return x.call(b,R)>=0?(h(s,"left",A(S,r,w)),t&&h(t,"left",A(S,n,u))):x.call(l,R)>=0&&(h(s,"top",A(S,o,a)),t&&h(t,"top",A(S,n,p))),this.container.is(":visible")&&(s.display="block"),this.container.removeAttr("style").css(s),t?this.arrow.removeAttr("style").css(t):e}},t.prototype.getPosition=function(){var t,n,e,i,o,r,s,a;if(n=this.options.position,t=f(n),0===t.length&&(t[0]="b"),e=t[0],0>x.call(d,e))throw"Must be one of ["+d+"]";if((1===t.length||(i=t[0],x.call(b,i)>=0&&(o=t[1],0>x.call(l,o)))||(r=t[0],x.call(l,r)>=0&&(s=t[1],0>x.call(b,s))))&&(t[1]=(a=t[0],x.call(l,a)>=0?"m":"l")),!this.options.autoReposition)return t;throw"Not implemented"},t.prototype.getColor=function(){var t;return t=this.getStyle().colors,t&&t[this.options.color]||this.options.colors[this.options.color]||this.options.color},t.prototype.getStyle=function(t){var n;if(t||(t=this.options.style),t||(t="default"),n=g.user[t],!n)throw"Missing style: "+t;return n},t.prototype.updateStyle=function(){var t=this;return this.wrapper.find("[data-notify-style]").each(function(n,e){return $(e).attr("style",$(e).attr("data-notify-style").replace(/\{\{\s*color\s*\}\}/gi,t.getColor()))})},t.prototype.run=function(t,n){var i=this;return $.isPlainObject(n)?$.extend(this.options,n):"string"===$.type(n)&&(this.options.color=n),this.container&&!t?(this.show(!1),e):this.container||t?("string"===$.type(t)?this.text.html(t.replace("\n","<br/>")):this.text.empty().append(t),this.updatePosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),this.autohideTimer=setTimeout(function(){return i.show(!1)},this.options.autoHideDelay)):e):e},t.prototype.destroy=function(){var t=this;return this.show(!1,function(){return t.wrapper.remove()})},t}(),$(function(){return $("body").append(r),$("link").each(function(){var t,n;return n=$(this).attr("href"),n.match(/bootstrap/)?(t=!0,!1):e}),u(g.core),$(n).on("click","."+o+"Wrapper",function(){var t;return(t=$(this).data(o))?t.elem?t.show(!1):t.destroy():e})}),$[w]=function(t,n,e){return t&&t.nodeName||t.jquery?$(t)[w](n,e):(e=n,n=t,new i(null,n,e)),t},$[w].options=function(t){return $.extend(y,t)},$[w].styles=function(t){return $.extend(!0,g.user,t)},$[w].insertCSS=u,$.fn[w]=function(t,n){return $(this).each(function(){var e;return e=a($(this)).data(o),e?e.run(t,n):new i($(this),t,n)}),this}})(window,document);