From 9275312b034df601040762e30f4ef4bf583079a8 Mon Sep 17 00:00:00 2001 From: Jaime Pillora Date: Wed, 12 Jun 2013 13:28:47 +1000 Subject: [PATCH] minor fixes, doc updates --- README.md | 25 +++++++++++++++++++++++-- dist/notify-combined.js | 18 ++++++++---------- dist/notify-combined.min.js | 4 ++-- dist/notify.js | 18 ++++++++---------- dist/notify.min.js | 4 ++-- src/notify.coffee | 13 ++++++------- 6 files changed, 49 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 012eb9b..a9bc7c0 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,29 @@ Notify.js > A simple, versatile notification library - - See demos and full documentation at: ## http://notifyjs.com/ + +#### MIT License + +Copyright © 2013 Jaime Pillora <dev@jpillora.com> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/dist/notify-combined.js b/dist/notify-combined.js index ece2b53..30454fd 100644 --- a/dist/notify-combined.js +++ b/dist/notify-combined.js @@ -1,4 +1,4 @@ -/** Notify.js - v0.0.1 - 2013/06/11 +/** Notify.js - v0.0.1 - 2013/06/12 * http://notifyjs.com/ * Copyright (c) 2013 Jaime Pillora - MIT */ @@ -109,6 +109,7 @@ addStyle = function(name, def) { insertCSS = function(cssText) { var elem; elem = createElem("style"); + elem.attr('type', 'text/css'); $("head").append(elem); try { elem.html(cssText); @@ -119,6 +120,7 @@ insertCSS = function(cssText) { }; pluginOptions = { + clickToHide: true, autoHide: true, autoHideDelay: 5000, arrowShow: true, @@ -477,21 +479,17 @@ $.extend($[pluginName], { defaults: defaults, addStyle: addStyle, pluginOptions: pluginOptions, - getStyle: getStyle + getStyle: getStyle, + insertCSS: insertCSS }); $(function() { - insertCSS(coreStyle.css).attr('data-notify-style', 'core'); - return $(document).on('click', "." + pluginClassName + "-wrapper", function() { + insertCSS(coreStyle.css).attr('id', 'core-notify'); + return $(document).on('click notify-hide', "." + pluginClassName + "-wrapper", function(e) { var inst; inst = $(this).data(pluginClassName); - if (!inst) { - return; - } - if (inst.elem) { + if (inst && (inst.options.clickToHide || e.type === 'notify-hide')) { return inst.show(false); - } else { - return inst.destroy(); } }); }); diff --git a/dist/notify-combined.min.js b/dist/notify-combined.min.js index 1ca4bdc..ae3bc88 100644 --- a/dist/notify-combined.min.js +++ b/dist/notify-combined.min.js @@ -1,5 +1,5 @@ -/** Notify.js - v0.0.1 - 2013/06/11 +/** Notify.js - v0.0.1 - 2013/06/12 * http://notifyjs.com/ * Copyright (c) 2013 Jaime Pillora - MIT */ -(function(t,n,i){"use strict";var e,o,r,s,a,l,h,c,p,u,d,A,f,m,w,g,y,b,v,x,C,E,S,M=[].indexOf||function(t){for(var n=0,i=this.length;i>n;n++)if(n in this&&this[n]===t)return n;return-1};y="notify",g=y+"js",v={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 n;return n=[],$.each(t.split(/\W+/),function(t,e){var o;return o=e.toLowerCase().charAt(0),v[o]?n.push(o):i}),n},E={},r={name:"core",html:'
\n
\n
\n
',css:"."+g+"-corner {\n position: fixed;\n margin: 5px;\n z-index: 1050;\n}\n\n."+g+"-corner ."+g+"-wrapper,\n."+g+"-corner ."+g+"-container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n margin: 3px;\n}\n\n."+g+"-wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n."+g+"-container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+g+"-text {\n position: relative;\n}\n\n."+g+"-arrow {\n position: absolute;\n z-index: 2;\n width: 0;\n height: 0;\n}"},C={"border-radius":["-webkit-","-moz-"]},h=function(t){return E[t]},o=function(n,e){var o,r;if(!n)throw"Missing Style name";if(!e)throw"Missing Style definition";return(null!=(r=E[n])?r.cssElem:void 0)&&(t.console&&console.warn(""+y+": overwriting style '"+n+"'"),E[n].cssElem.remove()),e.name=n,E[n]=e,o="",e.classes&&$.each(e.classes,function(t,n){return o+="."+g+"-"+e.name+"-"+t+" {\n",$.each(n,function(t,n){return C[t]&&$.each(C[t],function(i,e){return o+=" "+e+t+": "+n+";\n"}),o+=" "+t+": "+n+";\n"}),o+="}\n"}),e.css&&(o+="/* styles for "+e.name+" */\n"+e.css),o?(e.cssElem=A(o),e.cssElem.attr("id","notify-"+e.name)):i},A=function(t){var n;n=s("style"),$("head").append(n);try{n.html(t)}catch(i){n[0].styleSheet.cssText=t}return n},b={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,gap:5},d=function(t,n){var i;return i=function(){},i.prototype=t,$.extend(!0,new i,n)},a=function(t){return $.extend(b,t)},s=function(t){return $("<"+t+">")},c={},l=function(t){var n;return t.is("[type=radio]")&&(n=t.parents("form:first").find("[type=radio]").filter(function(n,i){return $(i).attr("name")===t.attr("name")}),t=n.first()),t},u=function(t,n,e){var o,r;if("string"==typeof e)e=parseInt(e,10);else if("number"!=typeof e)return;if(!isNaN(e))return o=v[m[n.charAt(0)]],r=n,t[o]!==i&&(n=v[o.charAt(0)],e=-e),t[n]===i?t[n]=e:t[n]+=e,null},x=function(t,n,i){if("l"===t||"t"===t)return 0;if("c"===t||"m"===t)return i/2-n/2;if("r"===t||"b"===t)return i-n;throw"Invalid alignment"},e=function(){function t(t,n,i){"string"==typeof i&&(i={className:i}),this.options=d(b,$.isPlainObject(i)?i:{}),this.loadHTML(),this.wrapper=$(r.html),this.wrapper.data(g,this),this.arrow=this.wrapper.find("."+g+"-arrow"),this.container=this.wrapper.find("."+g+"-container"),this.container.append(this.userContainer),t&&t.length&&(this.elementType=t.attr("type"),this.originalElement=t,this.elem=l(t),this.elem.data(g,this),this.elem.before(this.wrapper)),this.container.hide(),this.run(n)}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(""+g+"-text")},t.prototype.show=function(t,n){var e,o,r,s,a,l=this;if(o=function(){return t||l.elem||l.destroy(),n?n():i},a=this.container.parent().parents(":hidden").length>0,r=this.container.add(this.arrow),e=[],a&&t)s="show";else if(a&&!t)s="hide";else if(!a&&t)s=this.options.showAnimation,e.push(this.options.showDuration);else{if(a||t)return o();s=this.options.hideAnimation,e.push(this.options.hideDuration)}return e.push(o),r[s].apply(r,e)},t.prototype.setGlobalPosition=function(){var t,n,i,e,o,r,a,l;return l=this.getPosition(),a=l[0],r=l[1],o=v[a],t=v[r],e=a+"|"+r,n=c[e],n||(n=c[e]=s("div"),i={},i[o]=0,"middle"===t?i.top="45%":"center"===t?i.left="45%":i[t]=0,n.css(i).addClass(""+g+"-corner"),$("body").append(n)),n.prepend(this.wrapper)},t.prototype.setElementPosition=function(){var t,n,e,o,r,s,a,l,h,c,d,A,w,g,y,b,C,E,H,D,T,F,z,k,B,Q,R,U,P;for(z=this.getPosition(),D=z[0],E=z[1],H=z[2],d=this.elem.position(),l=this.elem.outerHeight(),A=this.elem.outerWidth(),h=this.elem.innerHeight(),c=this.elem.innerWidth(),k=this.wrapper.position(),r=this.container.height(),s=this.container.width(),g=v[D],b=m[D],C=v[b],a={},a[C]="b"===D?l:"r"===D?A:0,u(a,"top",d.top-k.top),u(a,"left",d.left-k.left),P=["top","left"],B=0,R=P.length;R>B;B++)T=P[B],y=parseInt(this.elem.css("margin-"+T),10),y&&u(a,T,y);if(w=Math.max(0,this.options.gap-(this.options.arrowShow?e:0)),u(a,C,w),this.options.arrowShow){for(e=this.options.arrowSize,n=$.extend({},a),t=this.userContainer.css("border-color")||this.userContainer.css("background-color")||"white",Q=0,U=f.length;U>Q;Q++)T=f[Q],F=v[T],T!==b&&(o=F===g?t:"transparent",n["border-"+F]=""+e+"px solid "+o);u(a,v[b],e),M.call(f,E)>=0&&u(n,v[E],2*e)}else this.arrow.hide();return M.call(S,D)>=0?(u(a,"left",x(E,s,A)),n&&u(n,"left",x(E,e,c))):M.call(p,D)>=0&&(u(a,"top",x(E,r,l)),n&&u(n,"top",x(E,e,h))),this.container.is(":visible")&&(a.display="block"),this.container.removeAttr("style").css(a),n?this.arrow.removeAttr("style").css(n):i},t.prototype.getPosition=function(){var t,n,i,e,o,r,s,a;if(n=this.options.position||(this.elem?this.options.elementPosition:this.options.globalPosition),t=w(n),0===t.length&&(t[0]="b"),i=t[0],0>M.call(f,i))throw"Must be one of ["+f+"]";return(1===t.length||(e=t[0],M.call(S,e)>=0&&(o=t[1],0>M.call(p,o)))||(r=t[0],M.call(p,r)>=0&&(s=t[1],0>M.call(S,s))))&&(t[1]=(a=t[0],M.call(p,a)>=0?"m":"l")),2===t.length&&(t[2]=t[1]),t},t.prototype.getStyle=function(t){var n;if(t||(t=this.options.style),t||(t="default"),n=E[t],!n)throw"Missing style: "+t;return n},t.prototype.updateClasses=function(){var t,n;return t=["base"],$.isArray(this.options.className)?t=t.concat(this.options.className):this.options.className&&t.push(this.options.className),n=this.getStyle(),t=$.map(t,function(t){return""+g+"-"+n.name+"-"+t}).join(" "),this.userContainer.attr("class",t)},t.prototype.run=function(t,n){var e=this;return $.isPlainObject(n)?$.extend(this.options,n):"string"===$.type(n)&&(this.options.color=n),this.container&&!t?(this.show(!1),i):this.container||t?(this.text[this.rawHTML?"html":"text"](t),this.updateClasses(),this.elem?this.setElementPosition():this.setGlobalPosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),this.autohideTimer=setTimeout(function(){return e.show(!1)},this.options.autoHideDelay)):i):i},t.prototype.destroy=function(){return this.wrapper.remove()},t}(),$[y]=function(t,n,i){return t&&t.nodeName||t.jquery?$(t)[y](n,i):(i=n,n=t,new e(null,n,i)),t},$.fn[y]=function(t,n){return $(this).each(function(){var i;return i=l($(this)).data(g),i?i.run(t,n):new e($(this),t,n)}),this},$.extend($[y],{defaults:a,addStyle:o,pluginOptions:b,getStyle:h}),$(function(){return A(r.css).attr("data-notify-style","core"),$(n).on("click","."+g+"-wrapper",function(){var t;return(t=$(this).data(g))?t.elem?t.show(!1):t.destroy():i})})})(window,document),$.notify.addStyle("bootstrap",{html:"
\n\n
",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+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=)"},success:{color:"#468847","background-color":"#DFF0D8","border-color":"#D6E9C6","background-image":"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAutJREFUeNq0lctPE0Ecx38zu/RFS1EryqtgJFA08YCiMZIAQQ4eRG8eDGdPJiYeTIwHTfwPiAcvXIwXLwoXPaDxkWgQ6islKlJLSQWLUraPLTv7Gme32zoF9KSTfLO7v53vZ3d/M7/fIth+IO6INt2jjoA7bjHCJoAlzCRw59YwHYjBnfMPqAKWQYKjGkfCJqAF0xwZjipQtA3MxeSG87VhOOYegVrUCy7UZM9S6TLIdAamySTclZdYhFhRHloGYg7mgZv1Zzztvgud7V1tbQ2twYA34LJmF4p5dXF1KTufnE+SxeJtuCZNsLDCQU0+RyKTF27Unw101l8e6hns3u0PBalORVVVkcaEKBJDgV3+cGM4tKKmI+ohlIGnygKX00rSBfszz/n2uXv81wd6+rt1orsZCHRdr1Imk2F2Kob3hutSxW8thsd8AXNaln9D7CTfA6O+0UgkMuwVvEFFUbbAcrkcTA8+AtOk8E6KiQiDmMFSDqZItAzEVQviRkdDdaFgPp8HSZKAEAL5Qh7Sq2lIJBJwv2scUqkUnKoZgNhcDKhKg5aH+1IkcouCAdFGAQsuWZYhOjwFHQ96oagWgRoUov1T9kRBEODAwxM2QtEUl+Wp+Ln9VRo6BcMw4ErHRYjH4/B26AlQoQQTRdHWwcd9AH57+UAXddvDD37DmrBBV34WfqiXPl61g+vr6xA9zsGeM9gOdsNXkgpEtTwVvwOklXLKm6+/p5ezwk4B+j6droBs2CsGa/gNs6RIxazl4Tc25mpTgw/apPR1LYlNRFAzgsOxkyXYLIM1V8NMwyAkJSctD1eGVKiq5wWjSPdjmeTkiKvVW4f2YPHWl3GAVq6ymcyCTgovM3FzyRiDe2TaKcEKsLpJvNHjZgPNqEtyi6mZIm4SRFyLMUsONSSdkPeFtY1n0mczoY3BHTLhwPRy9/lzcziCw9ACI+yql0VLzcGAZbYSM5CCSZg1/9oc/nn7+i8N9p/8An4JMADxhH+xHfuiKwAAAABJRU5ErkJggg==)"},info:{color:"#3A87AD","background-color":"#D9EDF7","border-color":"#BCE8F1","background-image":"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QYFAhkSsdes/QAAA8dJREFUOMvVlGtMW2UYx//POaWHXg6lLaW0ypAtw1UCgbniNOLcVOLmAjHZolOYlxmTGXVZdAnRfXQm+7SoU4mXaOaiZsEpC9FkiQs6Z6bdCnNYruM6KNBw6YWewzl9z+sHImEWv+vz7XmT95f/+3/+7wP814v+efDOV3/SoX3lHAA+6ODeUFfMfjOWMADgdk+eEKz0pF7aQdMAcOKLLjrcVMVX3xdWN29/GhYP7SvnP0cWfS8caSkfHZsPE9Fgnt02JNutQ0QYHB2dDz9/pKX8QjjuO9xUxd/66HdxTeCHZ3rojQObGQBcuNjfplkD3b19Y/6MrimSaKgSMmpGU5WevmE/swa6Oy73tQHA0Rdr2Mmv/6A1n9w9suQ7097Z9lM4FlTgTDrzZTu4StXVfpiI48rVcUDM5cmEksrFnHxfpTtU/3BFQzCQF/2bYVoNbH7zmItbSoMj40JSzmMyX5qDvriA7QdrIIpA+3cdsMpu0nXI8cV0MtKXCPZev+gCEM1S2NHPvWfP/hL+7FSr3+0p5RBEyhEN5JCKYr8XnASMT0xBNyzQGQeI8fjsGD39RMPk7se2bd5ZtTyoFYXftF6y37gx7NeUtJJOTFlAHDZLDuILU3j3+H5oOrD3yWbIztugaAzgnBKJuBLpGfQrS8wO4FZgV+c1IxaLgWVU0tMLEETCos4xMzEIv9cJXQcyagIwigDGwJgOAtHAwAhisQUjy0ORGERiELgG4iakkzo4MYAxcM5hAMi1WWG1yYCJIcMUaBkVRLdGeSU2995TLWzcUAzONJ7J6FBVBYIggMzmFbvdBV44Corg8vjhzC+EJEl8U1kJtgYrhCzgc/vvTwXKSib1paRFVRVORDAJAsw5FuTaJEhWM2SHB3mOAlhkNxwuLzeJsGwqWzf5TFNdKgtY5qHp6ZFf67Y/sAVadCaVY5YACDDb3Oi4NIjLnWMw2QthCBIsVhsUTU9tvXsjeq9+X1d75/KEs4LNOfcdf/+HthMnvwxOD0wmHaXr7ZItn2wuH2SnBzbZAbPJwpPx+VQuzcm7dgRCB57a1uBzUDRL4bfnI0RE0eaXd9W89mpjqHZnUI5Hh2l2dkZZUhOqpi2qSmpOmZ64Tuu9qlz/SEXo6MEHa3wOip46F1n7633eekV8ds8Wxjn37Wl63VVa+ej5oeEZ/82ZBETJjpJ1Rbij2D3Z/1trXUvLsblCK0XfOx0SX2kMsn9dX+d+7Kf6h8o4AIykuffjT8L20LU+w4AZd5VvEPY+XpWqLV327HR7DzXuDnD8r+ovkBehJ8i+y8YAAAAASUVORK5CYII=)"},warn:{color:"#C09853","background-color":"#FCF8E3","border-color":"#FBEED5","background-image":"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAMAAAC6V+0/AAABJlBMVEXr6eb/2oD/wi7/xjr/0mP/ykf/tQD/vBj/3o7/uQ//vyL/twebhgD/4pzX1K3z8e349vK6tHCilCWbiQymn0jGworr6dXQza3HxcKkn1vWvV/5uRfk4dXZ1bD18+/52YebiAmyr5S9mhCzrWq5t6ufjRH54aLs0oS+qD751XqPhAybhwXsujG3sm+Zk0PTwG6Shg+PhhObhwOPgQL4zV2nlyrf27uLfgCPhRHu7OmLgAafkyiWkD3l49ibiAfTs0C+lgCniwD4sgDJxqOilzDWowWFfAH08uebig6qpFHBvH/aw26FfQTQzsvy8OyEfz20r3jAvaKbhgG9q0nc2LbZxXanoUu/u5WSggCtp1anpJKdmFz/zlX/1nGJiYmuq5Dx7+sAAADoPUZSAAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfdBgUBGhh4aah5AAAAlklEQVQY02NgoBIIE8EUcwn1FkIXM1Tj5dDUQhPU502Mi7XXQxGz5uVIjGOJUUUW81HnYEyMi2HVcUOICQZzMMYmxrEyMylJwgUt5BljWRLjmJm4pI1hYp5SQLGYxDgmLnZOVxuooClIDKgXKMbN5ggV1ACLJcaBxNgcoiGCBiZwdWxOETBDrTyEFey0jYJ4eHjMGWgEAIpRFRCUt08qAAAAAElFTkSuQmCC)"}}}); \ No newline at end of file +(function(t,i,n){"use strict";var e,o,r,s,a,l,h,c,p,u,d,A,f,m,w,g,y,b,v,x,C,E,S,H=[].indexOf||function(t){for(var i=0,n=this.length;n>i;i++)if(i in this&&this[i]===t)return i;return-1};y="notify",g=y+"js",v={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),v[o]?i.push(o):n}),i},E={},r={name:"core",html:'
\n
\n
\n
',css:"."+g+"-corner {\n position: fixed;\n margin: 5px;\n z-index: 1050;\n}\n\n."+g+"-corner ."+g+"-wrapper,\n."+g+"-corner ."+g+"-container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n margin: 3px;\n}\n\n."+g+"-wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n."+g+"-container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+g+"-text {\n position: relative;\n}\n\n."+g+"-arrow {\n position: absolute;\n z-index: 2;\n width: 0;\n height: 0;\n}"},C={"border-radius":["-webkit-","-moz-"]},h=function(t){return E[t]},o=function(i,e){var o,r;if(!i)throw"Missing Style name";if(!e)throw"Missing Style definition";return(null!=(r=E[i])?r.cssElem:void 0)&&(t.console&&console.warn(""+y+": overwriting style '"+i+"'"),E[i].cssElem.remove()),e.name=i,E[i]=e,o="",e.classes&&$.each(e.classes,function(t,i){return o+="."+g+"-"+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=A(o),e.cssElem.attr("id","notify-"+e.name)):n},A=function(t){var i;i=s("style"),i.attr("type","text/css"),$("head").append(i);try{i.html(t)}catch(n){i[0].styleSheet.cssText=t}return i},b={clickToHide:!0,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,gap:5},d=function(t,i){var n;return n=function(){},n.prototype=t,$.extend(!0,new n,i)},a=function(t){return $.extend(b,t)},s=function(t){return $("<"+t+">")},c={},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},u=function(t,i,e){var o,r;if("string"==typeof e)e=parseInt(e,10);else if("number"!=typeof e)return;if(!isNaN(e))return o=v[m[i.charAt(0)]],r=i,t[o]!==n&&(i=v[o.charAt(0)],e=-e),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=d(b,$.isPlainObject(n)?n:{}),this.loadHTML(),this.wrapper=$(r.html),this.wrapper.data(g,this),this.arrow=this.wrapper.find("."+g+"-arrow"),this.container=this.wrapper.find("."+g+"-container"),this.container.append(this.userContainer),t&&t.length&&(this.elementType=t.attr("type"),this.originalElement=t,this.elem=l(t),this.elem.data(g,this),this.elem.before(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(""+g+"-text")},t.prototype.show=function(t,i){var e,o,r,s,a,l=this;if(o=function(){return t||l.elem||l.destroy(),i?i():n},a=this.container.parent().parents(":hidden").length>0,r=this.container.add(this.arrow),e=[],a&&t)s="show";else if(a&&!t)s="hide";else if(!a&&t)s=this.options.showAnimation,e.push(this.options.showDuration);else{if(a||t)return o();s=this.options.hideAnimation,e.push(this.options.hideDuration)}return e.push(o),r[s].apply(r,e)},t.prototype.setGlobalPosition=function(){var t,i,n,e,o,r,a,l;return l=this.getPosition(),a=l[0],r=l[1],o=v[a],t=v[r],e=a+"|"+r,i=c[e],i||(i=c[e]=s("div"),n={},n[o]=0,"middle"===t?n.top="45%":"center"===t?n.left="45%":n[t]=0,i.css(n).addClass(""+g+"-corner"),$("body").append(i)),i.prepend(this.wrapper)},t.prototype.setElementPosition=function(){var t,i,e,o,r,s,a,l,h,c,d,A,w,g,y,b,C,E,M,D,T,k,F,z,B,Q,R,U,P;for(F=this.getPosition(),D=F[0],E=F[1],M=F[2],d=this.elem.position(),l=this.elem.outerHeight(),A=this.elem.outerWidth(),h=this.elem.innerHeight(),c=this.elem.innerWidth(),z=this.wrapper.position(),r=this.container.height(),s=this.container.width(),g=v[D],b=m[D],C=v[b],a={},a[C]="b"===D?l:"r"===D?A:0,u(a,"top",d.top-z.top),u(a,"left",d.left-z.left),P=["top","left"],B=0,R=P.length;R>B;B++)T=P[B],y=parseInt(this.elem.css("margin-"+T),10),y&&u(a,T,y);if(w=Math.max(0,this.options.gap-(this.options.arrowShow?e:0)),u(a,C,w),this.options.arrowShow){for(e=this.options.arrowSize,i=$.extend({},a),t=this.userContainer.css("border-color")||this.userContainer.css("background-color")||"white",Q=0,U=f.length;U>Q;Q++)T=f[Q],k=v[T],T!==b&&(o=k===g?t:"transparent",i["border-"+k]=""+e+"px solid "+o);u(a,v[b],e),H.call(f,E)>=0&&u(i,v[E],2*e)}else this.arrow.hide();return H.call(S,D)>=0?(u(a,"left",x(E,s,A)),i&&u(i,"left",x(E,e,c))):H.call(p,D)>=0&&(u(a,"top",x(E,r,l)),i&&u(i,"top",x(E,e,h))),this.container.is(":visible")&&(a.display="block"),this.container.removeAttr("style").css(a),i?this.arrow.removeAttr("style").css(i):n},t.prototype.getPosition=function(){var t,i,n,e,o,r,s,a;if(i=this.options.position||(this.elem?this.options.elementPosition:this.options.globalPosition),t=w(i),0===t.length&&(t[0]="b"),n=t[0],0>H.call(f,n))throw"Must be one of ["+f+"]";return(1===t.length||(e=t[0],H.call(S,e)>=0&&(o=t[1],0>H.call(p,o)))||(r=t[0],H.call(p,r)>=0&&(s=t[1],0>H.call(S,s))))&&(t[1]=(a=t[0],H.call(p,a)>=0?"m":"l")),2===t.length&&(t[2]=t[1]),t},t.prototype.getStyle=function(t){var i;if(t||(t=this.options.style),t||(t="default"),i=E[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""+g+"-"+i.name+"-"+t}).join(" "),this.userContainer.attr("class",t)},t.prototype.run=function(t,i){var e=this;return $.isPlainObject(i)?$.extend(this.options,i):"string"===$.type(i)&&(this.options.color=i),this.container&&!t?(this.show(!1),n):this.container||t?(this.text[this.rawHTML?"html":"text"](t),this.updateClasses(),this.elem?this.setElementPosition():this.setGlobalPosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),this.autohideTimer=setTimeout(function(){return e.show(!1)},this.options.autoHideDelay)):n):n},t.prototype.destroy=function(){return this.wrapper.remove()},t}(),$[y]=function(t,i,n){return t&&t.nodeName||t.jquery?$(t)[y](i,n):(n=i,i=t,new e(null,i,n)),t},$.fn[y]=function(t,i){return $(this).each(function(){var n;return n=l($(this)).data(g),n?n.run(t,i):new e($(this),t,i)}),this},$.extend($[y],{defaults:a,addStyle:o,pluginOptions:b,getStyle:h,insertCSS:A}),$(function(){return A(r.css).attr("id","core-notify"),$(i).on("click notify-hide","."+g+"-wrapper",function(t){var i;return i=$(this).data(g),i&&(i.options.clickToHide||"notify-hide"===t.type)?i.show(!1):n})})})(window,document),$.notify.addStyle("bootstrap",{html:"
\n\n
",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+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=)"},success:{color:"#468847","background-color":"#DFF0D8","border-color":"#D6E9C6","background-image":"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAutJREFUeNq0lctPE0Ecx38zu/RFS1EryqtgJFA08YCiMZIAQQ4eRG8eDGdPJiYeTIwHTfwPiAcvXIwXLwoXPaDxkWgQ6islKlJLSQWLUraPLTv7Gme32zoF9KSTfLO7v53vZ3d/M7/fIth+IO6INt2jjoA7bjHCJoAlzCRw59YwHYjBnfMPqAKWQYKjGkfCJqAF0xwZjipQtA3MxeSG87VhOOYegVrUCy7UZM9S6TLIdAamySTclZdYhFhRHloGYg7mgZv1Zzztvgud7V1tbQ2twYA34LJmF4p5dXF1KTufnE+SxeJtuCZNsLDCQU0+RyKTF27Unw101l8e6hns3u0PBalORVVVkcaEKBJDgV3+cGM4tKKmI+ohlIGnygKX00rSBfszz/n2uXv81wd6+rt1orsZCHRdr1Imk2F2Kob3hutSxW8thsd8AXNaln9D7CTfA6O+0UgkMuwVvEFFUbbAcrkcTA8+AtOk8E6KiQiDmMFSDqZItAzEVQviRkdDdaFgPp8HSZKAEAL5Qh7Sq2lIJBJwv2scUqkUnKoZgNhcDKhKg5aH+1IkcouCAdFGAQsuWZYhOjwFHQ96oagWgRoUov1T9kRBEODAwxM2QtEUl+Wp+Ln9VRo6BcMw4ErHRYjH4/B26AlQoQQTRdHWwcd9AH57+UAXddvDD37DmrBBV34WfqiXPl61g+vr6xA9zsGeM9gOdsNXkgpEtTwVvwOklXLKm6+/p5ezwk4B+j6droBs2CsGa/gNs6RIxazl4Tc25mpTgw/apPR1LYlNRFAzgsOxkyXYLIM1V8NMwyAkJSctD1eGVKiq5wWjSPdjmeTkiKvVW4f2YPHWl3GAVq6ymcyCTgovM3FzyRiDe2TaKcEKsLpJvNHjZgPNqEtyi6mZIm4SRFyLMUsONSSdkPeFtY1n0mczoY3BHTLhwPRy9/lzcziCw9ACI+yql0VLzcGAZbYSM5CCSZg1/9oc/nn7+i8N9p/8An4JMADxhH+xHfuiKwAAAABJRU5ErkJggg==)"},info:{color:"#3A87AD","background-color":"#D9EDF7","border-color":"#BCE8F1","background-image":"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QYFAhkSsdes/QAAA8dJREFUOMvVlGtMW2UYx//POaWHXg6lLaW0ypAtw1UCgbniNOLcVOLmAjHZolOYlxmTGXVZdAnRfXQm+7SoU4mXaOaiZsEpC9FkiQs6Z6bdCnNYruM6KNBw6YWewzl9z+sHImEWv+vz7XmT95f/+3/+7wP814v+efDOV3/SoX3lHAA+6ODeUFfMfjOWMADgdk+eEKz0pF7aQdMAcOKLLjrcVMVX3xdWN29/GhYP7SvnP0cWfS8caSkfHZsPE9Fgnt02JNutQ0QYHB2dDz9/pKX8QjjuO9xUxd/66HdxTeCHZ3rojQObGQBcuNjfplkD3b19Y/6MrimSaKgSMmpGU5WevmE/swa6Oy73tQHA0Rdr2Mmv/6A1n9w9suQ7097Z9lM4FlTgTDrzZTu4StXVfpiI48rVcUDM5cmEksrFnHxfpTtU/3BFQzCQF/2bYVoNbH7zmItbSoMj40JSzmMyX5qDvriA7QdrIIpA+3cdsMpu0nXI8cV0MtKXCPZev+gCEM1S2NHPvWfP/hL+7FSr3+0p5RBEyhEN5JCKYr8XnASMT0xBNyzQGQeI8fjsGD39RMPk7se2bd5ZtTyoFYXftF6y37gx7NeUtJJOTFlAHDZLDuILU3j3+H5oOrD3yWbIztugaAzgnBKJuBLpGfQrS8wO4FZgV+c1IxaLgWVU0tMLEETCos4xMzEIv9cJXQcyagIwigDGwJgOAtHAwAhisQUjy0ORGERiELgG4iakkzo4MYAxcM5hAMi1WWG1yYCJIcMUaBkVRLdGeSU2995TLWzcUAzONJ7J6FBVBYIggMzmFbvdBV44Corg8vjhzC+EJEl8U1kJtgYrhCzgc/vvTwXKSib1paRFVRVORDAJAsw5FuTaJEhWM2SHB3mOAlhkNxwuLzeJsGwqWzf5TFNdKgtY5qHp6ZFf67Y/sAVadCaVY5YACDDb3Oi4NIjLnWMw2QthCBIsVhsUTU9tvXsjeq9+X1d75/KEs4LNOfcdf/+HthMnvwxOD0wmHaXr7ZItn2wuH2SnBzbZAbPJwpPx+VQuzcm7dgRCB57a1uBzUDRL4bfnI0RE0eaXd9W89mpjqHZnUI5Hh2l2dkZZUhOqpi2qSmpOmZ64Tuu9qlz/SEXo6MEHa3wOip46F1n7633eekV8ds8Wxjn37Wl63VVa+ej5oeEZ/82ZBETJjpJ1Rbij2D3Z/1trXUvLsblCK0XfOx0SX2kMsn9dX+d+7Kf6h8o4AIykuffjT8L20LU+w4AZd5VvEPY+XpWqLV327HR7DzXuDnD8r+ovkBehJ8i+y8YAAAAASUVORK5CYII=)"},warn:{color:"#C09853","background-color":"#FCF8E3","border-color":"#FBEED5","background-image":"url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAMAAAC6V+0/AAABJlBMVEXr6eb/2oD/wi7/xjr/0mP/ykf/tQD/vBj/3o7/uQ//vyL/twebhgD/4pzX1K3z8e349vK6tHCilCWbiQymn0jGworr6dXQza3HxcKkn1vWvV/5uRfk4dXZ1bD18+/52YebiAmyr5S9mhCzrWq5t6ufjRH54aLs0oS+qD751XqPhAybhwXsujG3sm+Zk0PTwG6Shg+PhhObhwOPgQL4zV2nlyrf27uLfgCPhRHu7OmLgAafkyiWkD3l49ibiAfTs0C+lgCniwD4sgDJxqOilzDWowWFfAH08uebig6qpFHBvH/aw26FfQTQzsvy8OyEfz20r3jAvaKbhgG9q0nc2LbZxXanoUu/u5WSggCtp1anpJKdmFz/zlX/1nGJiYmuq5Dx7+sAAADoPUZSAAAAAXRSTlMAQObYZgAAAAFiS0dEAIgFHUgAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfdBgUBGhh4aah5AAAAlklEQVQY02NgoBIIE8EUcwn1FkIXM1Tj5dDUQhPU502Mi7XXQxGz5uVIjGOJUUUW81HnYEyMi2HVcUOICQZzMMYmxrEyMylJwgUt5BljWRLjmJm4pI1hYp5SQLGYxDgmLnZOVxuooClIDKgXKMbN5ggV1ACLJcaBxNgcoiGCBiZwdWxOETBDrTyEFey0jYJ4eHjMGWgEAIpRFRCUt08qAAAAAElFTkSuQmCC)"}}}); \ No newline at end of file diff --git a/dist/notify.js b/dist/notify.js index 45965ae..f75369f 100644 --- a/dist/notify.js +++ b/dist/notify.js @@ -1,4 +1,4 @@ -/** Notify.js - v0.0.1 - 2013/06/11 +/** Notify.js - v0.0.1 - 2013/06/12 * http://notifyjs.com/ * Copyright (c) 2013 Jaime Pillora - MIT */ @@ -109,6 +109,7 @@ addStyle = function(name, def) { insertCSS = function(cssText) { var elem; elem = createElem("style"); + elem.attr('type', 'text/css'); $("head").append(elem); try { elem.html(cssText); @@ -119,6 +120,7 @@ insertCSS = function(cssText) { }; pluginOptions = { + clickToHide: true, autoHide: true, autoHideDelay: 5000, arrowShow: true, @@ -477,21 +479,17 @@ $.extend($[pluginName], { defaults: defaults, addStyle: addStyle, pluginOptions: pluginOptions, - getStyle: getStyle + getStyle: getStyle, + insertCSS: insertCSS }); $(function() { - insertCSS(coreStyle.css).attr('data-notify-style', 'core'); - return $(document).on('click', "." + pluginClassName + "-wrapper", function() { + insertCSS(coreStyle.css).attr('id', 'core-notify'); + return $(document).on('click notify-hide', "." + pluginClassName + "-wrapper", function(e) { var inst; inst = $(this).data(pluginClassName); - if (!inst) { - return; - } - if (inst.elem) { + if (inst && (inst.options.clickToHide || e.type === 'notify-hide')) { return inst.show(false); - } else { - return inst.destroy(); } }); }); diff --git a/dist/notify.min.js b/dist/notify.min.js index 1cb3b35..88493ac 100644 --- a/dist/notify.min.js +++ b/dist/notify.min.js @@ -1,5 +1,5 @@ -/** Notify.js - v0.0.1 - 2013/06/11 +/** Notify.js - v0.0.1 - 2013/06/12 * http://notifyjs.com/ * Copyright (c) 2013 Jaime Pillora - MIT */ -(function(t,n,i){"use strict";var e,o,r,s,a,h,l,p,c,u,d,f,m,w,y,g,v,b,x,P,S,C,H,T=[].indexOf||function(t){for(var n=0,i=this.length;i>n;n++)if(n in this&&this[n]===t)return n;return-1};v="notify",g=v+"js",x={t:"top",m:"middle",b:"bottom",l:"left",c:"center",r:"right"},c=["l","c","r"],H=["t","m","b"],m=["t","b","l","r"],w={t:"b",m:null,b:"t",l:"r",c:null,r:"l"},y=function(t){var n;return n=[],$.each(t.split(/\W+/),function(t,e){var o;return o=e.toLowerCase().charAt(0),x[o]?n.push(o):i}),n},C={},r={name:"core",html:'
\n
\n
\n
',css:"."+g+"-corner {\n position: fixed;\n margin: 5px;\n z-index: 1050;\n}\n\n."+g+"-corner ."+g+"-wrapper,\n."+g+"-corner ."+g+"-container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n margin: 3px;\n}\n\n."+g+"-wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n."+g+"-container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+g+"-text {\n position: relative;\n}\n\n."+g+"-arrow {\n position: absolute;\n z-index: 2;\n width: 0;\n height: 0;\n}"},S={"border-radius":["-webkit-","-moz-"]},l=function(t){return C[t]},o=function(n,e){var o,r;if(!n)throw"Missing Style name";if(!e)throw"Missing Style definition";return(null!=(r=C[n])?r.cssElem:void 0)&&(t.console&&console.warn(""+v+": overwriting style '"+n+"'"),C[n].cssElem.remove()),e.name=n,C[n]=e,o="",e.classes&&$.each(e.classes,function(t,n){return o+="."+g+"-"+e.name+"-"+t+" {\n",$.each(n,function(t,n){return S[t]&&$.each(S[t],function(i,e){return o+=" "+e+t+": "+n+";\n"}),o+=" "+t+": "+n+";\n"}),o+="}\n"}),e.css&&(o+="/* styles for "+e.name+" */\n"+e.css),o?(e.cssElem=f(o),e.cssElem.attr("id","notify-"+e.name)):i},f=function(t){var n;n=s("style"),$("head").append(n);try{n.html(t)}catch(i){n[0].styleSheet.cssText=t}return n},b={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,gap:5},d=function(t,n){var i;return i=function(){},i.prototype=t,$.extend(!0,new i,n)},a=function(t){return $.extend(b,t)},s=function(t){return $("<"+t+">")},p={},h=function(t){var n;return t.is("[type=radio]")&&(n=t.parents("form:first").find("[type=radio]").filter(function(n,i){return $(i).attr("name")===t.attr("name")}),t=n.first()),t},u=function(t,n,e){var o,r;if("string"==typeof e)e=parseInt(e,10);else if("number"!=typeof e)return;if(!isNaN(e))return o=x[w[n.charAt(0)]],r=n,t[o]!==i&&(n=x[o.charAt(0)],e=-e),t[n]===i?t[n]=e:t[n]+=e,null},P=function(t,n,i){if("l"===t||"t"===t)return 0;if("c"===t||"m"===t)return i/2-n/2;if("r"===t||"b"===t)return i-n;throw"Invalid alignment"},e=function(){function t(t,n,i){"string"==typeof i&&(i={className:i}),this.options=d(b,$.isPlainObject(i)?i:{}),this.loadHTML(),this.wrapper=$(r.html),this.wrapper.data(g,this),this.arrow=this.wrapper.find("."+g+"-arrow"),this.container=this.wrapper.find("."+g+"-container"),this.container.append(this.userContainer),t&&t.length&&(this.elementType=t.attr("type"),this.originalElement=t,this.elem=h(t),this.elem.data(g,this),this.elem.before(this.wrapper)),this.container.hide(),this.run(n)}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(""+g+"-text")},t.prototype.show=function(t,n){var e,o,r,s,a,h=this;if(o=function(){return t||h.elem||h.destroy(),n?n():i},a=this.container.parent().parents(":hidden").length>0,r=this.container.add(this.arrow),e=[],a&&t)s="show";else if(a&&!t)s="hide";else if(!a&&t)s=this.options.showAnimation,e.push(this.options.showDuration);else{if(a||t)return o();s=this.options.hideAnimation,e.push(this.options.hideDuration)}return e.push(o),r[s].apply(r,e)},t.prototype.setGlobalPosition=function(){var t,n,i,e,o,r,a,h;return h=this.getPosition(),a=h[0],r=h[1],o=x[a],t=x[r],e=a+"|"+r,n=p[e],n||(n=p[e]=s("div"),i={},i[o]=0,"middle"===t?i.top="45%":"center"===t?i.left="45%":i[t]=0,n.css(i).addClass(""+g+"-corner"),$("body").append(n)),n.prepend(this.wrapper)},t.prototype.setElementPosition=function(){var t,n,e,o,r,s,a,h,l,p,d,f,y,g,v,b,S,C,A,M,N,z,D,E,k,L,j,O,I;for(D=this.getPosition(),M=D[0],C=D[1],A=D[2],d=this.elem.position(),h=this.elem.outerHeight(),f=this.elem.outerWidth(),l=this.elem.innerHeight(),p=this.elem.innerWidth(),E=this.wrapper.position(),r=this.container.height(),s=this.container.width(),g=x[M],b=w[M],S=x[b],a={},a[S]="b"===M?h:"r"===M?f:0,u(a,"top",d.top-E.top),u(a,"left",d.left-E.left),I=["top","left"],k=0,j=I.length;j>k;k++)N=I[k],v=parseInt(this.elem.css("margin-"+N),10),v&&u(a,N,v);if(y=Math.max(0,this.options.gap-(this.options.arrowShow?e:0)),u(a,S,y),this.options.arrowShow){for(e=this.options.arrowSize,n=$.extend({},a),t=this.userContainer.css("border-color")||this.userContainer.css("background-color")||"white",L=0,O=m.length;O>L;L++)N=m[L],z=x[N],N!==b&&(o=z===g?t:"transparent",n["border-"+z]=""+e+"px solid "+o);u(a,x[b],e),T.call(m,C)>=0&&u(n,x[C],2*e)}else this.arrow.hide();return T.call(H,M)>=0?(u(a,"left",P(C,s,f)),n&&u(n,"left",P(C,e,p))):T.call(c,M)>=0&&(u(a,"top",P(C,r,h)),n&&u(n,"top",P(C,e,l))),this.container.is(":visible")&&(a.display="block"),this.container.removeAttr("style").css(a),n?this.arrow.removeAttr("style").css(n):i},t.prototype.getPosition=function(){var t,n,i,e,o,r,s,a;if(n=this.options.position||(this.elem?this.options.elementPosition:this.options.globalPosition),t=y(n),0===t.length&&(t[0]="b"),i=t[0],0>T.call(m,i))throw"Must be one of ["+m+"]";return(1===t.length||(e=t[0],T.call(H,e)>=0&&(o=t[1],0>T.call(c,o)))||(r=t[0],T.call(c,r)>=0&&(s=t[1],0>T.call(H,s))))&&(t[1]=(a=t[0],T.call(c,a)>=0?"m":"l")),2===t.length&&(t[2]=t[1]),t},t.prototype.getStyle=function(t){var n;if(t||(t=this.options.style),t||(t="default"),n=C[t],!n)throw"Missing style: "+t;return n},t.prototype.updateClasses=function(){var t,n;return t=["base"],$.isArray(this.options.className)?t=t.concat(this.options.className):this.options.className&&t.push(this.options.className),n=this.getStyle(),t=$.map(t,function(t){return""+g+"-"+n.name+"-"+t}).join(" "),this.userContainer.attr("class",t)},t.prototype.run=function(t,n){var e=this;return $.isPlainObject(n)?$.extend(this.options,n):"string"===$.type(n)&&(this.options.color=n),this.container&&!t?(this.show(!1),i):this.container||t?(this.text[this.rawHTML?"html":"text"](t),this.updateClasses(),this.elem?this.setElementPosition():this.setGlobalPosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),this.autohideTimer=setTimeout(function(){return e.show(!1)},this.options.autoHideDelay)):i):i},t.prototype.destroy=function(){return this.wrapper.remove()},t}(),$[v]=function(t,n,i){return t&&t.nodeName||t.jquery?$(t)[v](n,i):(i=n,n=t,new e(null,n,i)),t},$.fn[v]=function(t,n){return $(this).each(function(){var i;return i=h($(this)).data(g),i?i.run(t,n):new e($(this),t,n)}),this},$.extend($[v],{defaults:a,addStyle:o,pluginOptions:b,getStyle:l}),$(function(){return f(r.css).attr("data-notify-style","core"),$(n).on("click","."+g+"-wrapper",function(){var t;return(t=$(this).data(g))?t.elem?t.show(!1):t.destroy():i})})})(window,document); \ No newline at end of file +(function(t,i,n){"use strict";var e,o,r,s,a,h,l,c,p,u,d,f,m,w,y,g,v,b,x,S,C,H,P,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};v="notify",g=v+"js",x={t:"top",m:"middle",b:"bottom",l:"left",c:"center",r:"right"},p=["l","c","r"],P=["t","m","b"],m=["t","b","l","r"],w={t:"b",m:null,b:"t",l:"r",c:null,r:"l"},y=function(t){var i;return i=[],$.each(t.split(/\W+/),function(t,e){var o;return o=e.toLowerCase().charAt(0),x[o]?i.push(o):n}),i},H={},r={name:"core",html:'
\n
\n
\n
',css:"."+g+"-corner {\n position: fixed;\n margin: 5px;\n z-index: 1050;\n}\n\n."+g+"-corner ."+g+"-wrapper,\n."+g+"-corner ."+g+"-container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n margin: 3px;\n}\n\n."+g+"-wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n."+g+"-container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+g+"-text {\n position: relative;\n}\n\n."+g+"-arrow {\n position: absolute;\n z-index: 2;\n width: 0;\n height: 0;\n}"},C={"border-radius":["-webkit-","-moz-"]},l=function(t){return H[t]},o=function(i,e){var o,r;if(!i)throw"Missing Style name";if(!e)throw"Missing Style definition";return(null!=(r=H[i])?r.cssElem:void 0)&&(t.console&&console.warn(""+v+": overwriting style '"+i+"'"),H[i].cssElem.remove()),e.name=i,H[i]=e,o="",e.classes&&$.each(e.classes,function(t,i){return o+="."+g+"-"+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=f(o),e.cssElem.attr("id","notify-"+e.name)):n},f=function(t){var i;i=s("style"),i.attr("type","text/css"),$("head").append(i);try{i.html(t)}catch(n){i[0].styleSheet.cssText=t}return i},b={clickToHide:!0,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,gap:5},d=function(t,i){var n;return n=function(){},n.prototype=t,$.extend(!0,new n,i)},a=function(t){return $.extend(b,t)},s=function(t){return $("<"+t+">")},c={},h=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},u=function(t,i,e){var o,r;if("string"==typeof e)e=parseInt(e,10);else if("number"!=typeof e)return;if(!isNaN(e))return o=x[w[i.charAt(0)]],r=i,t[o]!==n&&(i=x[o.charAt(0)],e=-e),t[i]===n?t[i]=e:t[i]+=e,null},S=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=d(b,$.isPlainObject(n)?n:{}),this.loadHTML(),this.wrapper=$(r.html),this.wrapper.data(g,this),this.arrow=this.wrapper.find("."+g+"-arrow"),this.container=this.wrapper.find("."+g+"-container"),this.container.append(this.userContainer),t&&t.length&&(this.elementType=t.attr("type"),this.originalElement=t,this.elem=h(t),this.elem.data(g,this),this.elem.before(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(""+g+"-text")},t.prototype.show=function(t,i){var e,o,r,s,a,h=this;if(o=function(){return t||h.elem||h.destroy(),i?i():n},a=this.container.parent().parents(":hidden").length>0,r=this.container.add(this.arrow),e=[],a&&t)s="show";else if(a&&!t)s="hide";else if(!a&&t)s=this.options.showAnimation,e.push(this.options.showDuration);else{if(a||t)return o();s=this.options.hideAnimation,e.push(this.options.hideDuration)}return e.push(o),r[s].apply(r,e)},t.prototype.setGlobalPosition=function(){var t,i,n,e,o,r,a,h;return h=this.getPosition(),a=h[0],r=h[1],o=x[a],t=x[r],e=a+"|"+r,i=c[e],i||(i=c[e]=s("div"),n={},n[o]=0,"middle"===t?n.top="45%":"center"===t?n.left="45%":n[t]=0,i.css(n).addClass(""+g+"-corner"),$("body").append(i)),i.prepend(this.wrapper)},t.prototype.setElementPosition=function(){var t,i,e,o,r,s,a,h,l,c,d,f,y,g,v,b,C,H,A,M,N,k,z,D,E,L,j,O,I;for(z=this.getPosition(),M=z[0],H=z[1],A=z[2],d=this.elem.position(),h=this.elem.outerHeight(),f=this.elem.outerWidth(),l=this.elem.innerHeight(),c=this.elem.innerWidth(),D=this.wrapper.position(),r=this.container.height(),s=this.container.width(),g=x[M],b=w[M],C=x[b],a={},a[C]="b"===M?h:"r"===M?f:0,u(a,"top",d.top-D.top),u(a,"left",d.left-D.left),I=["top","left"],E=0,j=I.length;j>E;E++)N=I[E],v=parseInt(this.elem.css("margin-"+N),10),v&&u(a,N,v);if(y=Math.max(0,this.options.gap-(this.options.arrowShow?e:0)),u(a,C,y),this.options.arrowShow){for(e=this.options.arrowSize,i=$.extend({},a),t=this.userContainer.css("border-color")||this.userContainer.css("background-color")||"white",L=0,O=m.length;O>L;L++)N=m[L],k=x[N],N!==b&&(o=k===g?t:"transparent",i["border-"+k]=""+e+"px solid "+o);u(a,x[b],e),T.call(m,H)>=0&&u(i,x[H],2*e)}else this.arrow.hide();return T.call(P,M)>=0?(u(a,"left",S(H,s,f)),i&&u(i,"left",S(H,e,c))):T.call(p,M)>=0&&(u(a,"top",S(H,r,h)),i&&u(i,"top",S(H,e,l))),this.container.is(":visible")&&(a.display="block"),this.container.removeAttr("style").css(a),i?this.arrow.removeAttr("style").css(i):n},t.prototype.getPosition=function(){var t,i,n,e,o,r,s,a;if(i=this.options.position||(this.elem?this.options.elementPosition:this.options.globalPosition),t=y(i),0===t.length&&(t[0]="b"),n=t[0],0>T.call(m,n))throw"Must be one of ["+m+"]";return(1===t.length||(e=t[0],T.call(P,e)>=0&&(o=t[1],0>T.call(p,o)))||(r=t[0],T.call(p,r)>=0&&(s=t[1],0>T.call(P,s))))&&(t[1]=(a=t[0],T.call(p,a)>=0?"m":"l")),2===t.length&&(t[2]=t[1]),t},t.prototype.getStyle=function(t){var i;if(t||(t=this.options.style),t||(t="default"),i=H[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""+g+"-"+i.name+"-"+t}).join(" "),this.userContainer.attr("class",t)},t.prototype.run=function(t,i){var e=this;return $.isPlainObject(i)?$.extend(this.options,i):"string"===$.type(i)&&(this.options.color=i),this.container&&!t?(this.show(!1),n):this.container||t?(this.text[this.rawHTML?"html":"text"](t),this.updateClasses(),this.elem?this.setElementPosition():this.setGlobalPosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),this.autohideTimer=setTimeout(function(){return e.show(!1)},this.options.autoHideDelay)):n):n},t.prototype.destroy=function(){return this.wrapper.remove()},t}(),$[v]=function(t,i,n){return t&&t.nodeName||t.jquery?$(t)[v](i,n):(n=i,i=t,new e(null,i,n)),t},$.fn[v]=function(t,i){return $(this).each(function(){var n;return n=h($(this)).data(g),n?n.run(t,i):new e($(this),t,i)}),this},$.extend($[v],{defaults:a,addStyle:o,pluginOptions:b,getStyle:l,insertCSS:f}),$(function(){return f(r.css).attr("id","core-notify"),$(i).on("click notify-hide","."+g+"-wrapper",function(t){var i;return i=$(this).data(g),i&&(i.options.clickToHide||"notify-hide"===t.type)?i.show(!1):n})})})(window,document); \ No newline at end of file diff --git a/src/notify.coffee b/src/notify.coffee index cd01181..5ed6acd 100644 --- a/src/notify.coffee +++ b/src/notify.coffee @@ -144,6 +144,7 @@ addStyle = (name, def) -> insertCSS = (cssText) -> elem = createElem("style") + elem.attr 'type', 'text/css' $("head").append elem try elem.html cssText @@ -158,6 +159,7 @@ insertCSS = (cssText) -> #overridable options pluginOptions = + clickToHide: true autoHide: true autoHideDelay: 5000 arrowShow: true @@ -519,19 +521,16 @@ $.fn[pluginName] = (data, options) -> @ #extra methods -$.extend $[pluginName], { defaults, addStyle, pluginOptions, getStyle } +$.extend $[pluginName], { defaults, addStyle, pluginOptions, getStyle, insertCSS } #when ready $ -> #insert default style - insertCSS(coreStyle.css).attr('data-notify-style', 'core') + insertCSS(coreStyle.css).attr('id', 'core-notify') #watch all notifications clicks - $(document).on 'click', ".#{pluginClassName}-wrapper", -> + $(document).on 'click notify-hide', ".#{pluginClassName}-wrapper", (e) -> inst = $(@).data pluginClassName - return unless inst - if inst.elem + if inst and (inst.options.clickToHide or e.type is 'notify-hide') inst.show false - else - inst.destroy()