6 lines
40 KiB
JavaScript
6 lines
40 KiB
JavaScript
/** Notify.js - v0.0.1 - 2013/06/05
|
|||
|
|
* http://notifyjs.com/
|
||
|
|
* Copyright (c) 2013 Jaime Pillora - MIT
|
||
|
|
*/
|
||
|
|
(function(t,i,e){"use strict";var n,o,r,s,a,h,l,p,c,u,d,f,A,m,w,g,y,b,v,x,C,H,S=[].indexOf||function(t){for(var i=0,e=this.length;e>i;i++)if(i in this&&this[i]===t)return i;return-1};g="notify",w=g+"js",b={t:"top",m:"middle",b:"bottom",l:"left",c:"center",r:"right"},p=["l","c","r"],H=["t","m","b"],f=["t","b","l","r"],A={t:"b",m:null,b:"t",l:"r",c:null,r:"l"},m=function(t){var i;return i=[],$.each(t.split(/\W+/),function(t,n){var o;return o=n.toLowerCase().charAt(0),b[o]?i.push(o):e}),i},C={},r={name:"core",html:'<div class="'+w+'-wrapper">\n <div class="'+w+'-arrow"></div>\n <div class="'+w+'-container"></div>\n</div>',css:"."+w+"-corner {\n position: fixed;\n top: 0;\n right: 0;\n margin: 5px;\n z-index: 1050;\n}\n\n."+w+"-corner ."+w+"-wrapper,\n."+w+"-corner ."+w+"-container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n}\n\n."+w+"-wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n."+w+"-container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+w+"-text {\n position: relative;\n}\n\n."+w+"-arrow {\n position: absolute;\n z-index: 2;\n width: 0;\n height: 0;\n}"},x={"border-radius":["-webkit-","-moz-"]},o=function(i,n){var o;return C[i]&&(t.console&&console.warn(""+g+": overwriting style '"+i+"'"),$("#notify-"+i).remove()),n.name=i,C[i]=n,!n.cssElem&&(o="",n.classes&&$.each(n.classes,function(t,i){return o+="."+w+"-"+n.name+"-"+t+" {\n",$.each(i,function(t,i){return x[t]&&$.each(x[t],function(e,n){return o+=" "+n+t+": "+i+";\n"}),o+=" "+t+": "+i+";\n"}),o+="}\n"}),n.css&&(o+="/* styles for "+n.name+" */\n"+n.css),o)?(n.cssElem=d(o),n.cssElem.attr("id","notify-"+n.name)):e},d=function(t){var i;i=a("style"),$("head").append(i);try{i.html(t)}catch(e){i[0].styleSheet.cssText=t}return i},y={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 e;return e=function(){},e.prototype=t,$.extend(!0,new e,i)},h=function(t){return $.extend(y,t)},a=function(t){return $("<"+t+"></"+t+">")},s=a("div").addClass(""+w+"-corner"),l=function(t){var i;return t.is("[type=radio]")&&(i=t.parents("form:first").find("[type=radio]").filter(function(i,e){return $(e).attr("name")===t.attr("name")}),t=i.first()),t},c=function(t,i,n){var o,r;if("string"==typeof n)n=parseInt(n,10);else if("number"!=typeof n)return;if(!isNaN(n))return o=b[A[i.charAt(0)]],r=i,t[o]!==e&&(i=b[o.charAt(0)],n*=-1),t[i]===e?t[i]=n:t[i]+=n,null},v=function(t,i,e){if("l"===t||"t"===t)return 0;if("c"===t||"m"===t)return e/2-i/2;if("r"===t||"b"===t)return e-i;throw"Invalid alignment"},n=function(){function t(t,i,e){"string"==typeof e&&(e={className:e}),this.options=u(y,$.isPlainObject(e)?e:{}),this.loadHTML(),this.wrapper=$(r.html),this.wrapper.data(w,this),this.arrow=this.wrapper.find("."+w+"-arrow"),this.container=this.wrapper.find("."+w+"-container"),this.container.append(this.userContainer),t&&t.length?(this.elementType=t.attr("type"),this.originalElement=t,this.elem=l(t),this.elem.data(w,this),this.elem.before(this.wrapper)):(this.options.arrowShow=!1,s.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(""+w+"-text")},t.prototype.show=function(t,i){var e,n,o,r;if(null==i&&(i=$.noop),r=this.container.parent().parents(":hidden").length>0,n=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 i();o=this.options.hideAni
|
||
|
|
}return e.push(i),n[o].apply(n,e)},t.prototype.updatePosition=function(){var t,i,n,o,r,s,a,h,l,u,d,m,w,g,y,x,C,E,D,M,T,k,z,F,R,X,B;if(this.elem){if(d=this.elem.position(),h=this.elem.outerHeight(),m=this.elem.outerWidth(),l=this.elem.innerHeight(),u=this.elem.innerWidth(),R=this.wrapper.position(),r=this.container.height(),s=this.container.width(),z=this.getPosition(),D=z[0],C=z[1],E=z[2]||C,w=b[D],y=A[D],x=b[y],a={},a[x]="b"===D?h:"r"===D?m:0,c(a,"left",d.left-R.left),g=parseInt(this.elem.css("margin-left"),10),g&&c(a,"left",g),/^inline/.test(this.elem.css("display"))&&(M=parseInt(this.elem.css("padding-top"),10),M&&c(a,"top",-M)),c(a,"top",this.options.offsetY),c(a,"left",this.options.offsetX),F=this.getStyle(),this.options.arrowShow){for(n=this.options.arrowSize,i=$.extend({},a),t=this.userContainer.css("border-color")||this.userContainer.css("background-color")||"white",X=0,B=f.length;B>X;X++)T=f[X],k=b[T],T!==y&&(o=k===w?t:"transparent",i["border-"+k]=""+n+"px solid "+o);c(a,b[y],n),S.call(f,C)>=0&&c(i,b[C],2*n)}else this.arrow.hide();return S.call(H,D)>=0?(c(a,"left",v(C,s,m)),i&&c(i,"left",v(C,n,u))):S.call(p,D)>=0&&(c(a,"top",v(C,r,h)),i&&c(i,"top",v(C,n,l))),this.container.is(":visible")&&(a.display="block"),this.container.removeAttr("style").css(a),i?this.arrow.removeAttr("style").css(i):e}},t.prototype.getPosition=function(){var t,i,e,n,o,r,s,a;if(i=this.options.position||(this.elem?this.options.elementPosition:this.options.globalPosition),t=m(i),0===t.length&&(t[0]="b"),e=t[0],0>S.call(f,e))throw"Must be one of ["+f+"]";if((1===t.length||(n=t[0],S.call(H,n)>=0&&(o=t[1],0>S.call(p,o)))||(r=t[0],S.call(p,r)>=0&&(s=t[1],0>S.call(H,s))))&&(t[1]=(a=t[0],S.call(p,a)>=0?"m":"l")),!this.options.autoReposition)return t;throw"Not implemented"},t.prototype.getStyle=function(t){var i;if(t||(t=this.options.style),t||(t="default"),i=C[t],!i)throw"Missing style: "+t;return i},t.prototype.updateClasses=function(){var t,i;return t=["base"],$.isArray(this.options.className)?t=t.concat(this.options.className):this.options.className&&t.push(this.options.className),i=this.getStyle(),t=$.map(t,function(t){return""+w+"-"+i.name+"-"+t}).join(" "),this.userContainer.attr("class",t)},t.prototype.run=function(t,i){var n=this;return $.isPlainObject(i)?$.extend(this.options,i):"string"===$.type(i)&&(this.options.color=i),this.container&&!t?(this.show(!1),e):this.container||t?("string"===$.type(t)?this.text[this.rawHTML?"html":"text"](t):this.text.empty().append(t),this.updateClasses(),this.updatePosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),this.autohideTimer=setTimeout(function(){return n.show(!1)},this.options.autoHideDelay)):e):e},t.prototype.destroy=function(){var t=this;return this.show(!1,function(){return t.wrapper.remove()})},t}(),$[g]=function(t,i,e){return t&&t.nodeName||t.jquery?$(t)[g](i,e):(e=i,i=t,new n(null,i,e)),t},$.fn[g]=function(t,i){return $(this).each(function(){var e;return e=l($(this)).data(w),e?e.run(t,i):new n($(this),t,i)}),this},$.extend($[g],{defaults:h,addStyle:o}),$(function(){return $("body").append(s),$("link").each(function(){var t,i;return i=$(this).attr("href"),i.match(/bootstrap/)?(t=!0,!1):e}),d(r.css).attr("data-notify-style","core"),$(i).on("click","."+w+"-wrapper",function(){var t;return(t=$(this).data(w))?t.elem?t.show(!1):t.destroy():e})})}(window,document),$.notify.addStyle("bootstrap",{html:"<div>\n<span data-notify-text></span>\n</div>",classes:{base:{"font-weight":"bold",padding:"8px 15px 8px 14px","text-shadow":"0 1px 0 rgba(255, 255, 255, 0.5)","background-color":"#fcf8e3",border:"1px solid #fbeed5","border-radius":"4px","white-space":"nowrap","padding-left":"25px","background-repeat":"no-repeat","background-position":"3px 7px"},error:{color:"#B94A48","background-color":"#F2DEDE","border-color":"#EED3D7","background-image":"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAtRJREFUeNqkVc1u00AQHq+dOD+0poIQfkIjalW0SEGqRMuRnHos3DjwAH0ArlyQeANOOSMeAA5VjyBxKBQhgSpVUKKQNGloFdw4cWw2jtfMOna6J
|