From 21e0603d8bdf110dc0a7a47a6554ed811e3f1c03 Mon Sep 17 00:00:00 2001 From: remeh Date: Fri, 28 Jun 2013 22:26:25 +0200 Subject: [PATCH] Let embed html in the content of the notification --- dist/notify.js | 4 ++-- dist/notify.min.js | 2 +- src/notify.coffee | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/notify.js b/dist/notify.js index 05649f9..3139b84 100644 --- a/dist/notify.js +++ b/dist/notify.js @@ -202,7 +202,7 @@ realign = function(alignment, inner, outer) { encode = function(text) { encode.e = encode.e || createElem("div"); - return encode.e.text(text).html(); + return text; }; Notification = (function() { @@ -506,4 +506,4 @@ $(function() { }); }); -}(window,document,jQuery)); \ No newline at end of file +}(window,document,jQuery)); diff --git a/dist/notify.min.js b/dist/notify.min.js index 22e61d5..f8478c6 100644 --- a/dist/notify.min.js +++ b/dist/notify.min.js @@ -2,4 +2,4 @@ * http://notifyjs.com/ * Copyright (c) 2013 Jaime Pillora - MIT */ -(function(t,i,e,n){"use strict";var o,r,s,a,h,l,c,p,u,d,f,m,w,y,g,b,v,x,S,C,H,P,T,N,k=[].indexOf||function(t){for(var i=0,e=this.length;e>i;i++)if(i in this&&this[i]===t)return i;return-1};x="notify",v=x+"js",C={t:"top",m:"middle",b:"bottom",l:"left",c:"center",r:"right"},d=["l","c","r"],N=["t","m","b"],y=["t","b","l","r"],g={t:"b",m:null,b:"t",l:"r",c:null,r:"l"},b=function(t){var i;return i=[],e.each(t.split(/\W+/),function(t,e){var o;return o=e.toLowerCase().charAt(0),C[o]?i.push(o):n}),i},T={},s={name:"core",html:'
\n
\n
\n
',css:"."+v+"-corner {\n position: fixed;\n margin: 5px;\n z-index: 1050;\n}\n\n."+v+"-corner ."+v+"-wrapper,\n."+v+"-corner ."+v+"-container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n margin: 3px;\n}\n\n."+v+"-wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n."+v+"-container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+v+"-text {\n position: relative;\n}\n\n."+v+"-arrow {\n position: absolute;\n z-index: 2;\n width: 0;\n height: 0;\n}"},P={"border-radius":["-webkit-","-moz-"]},p=function(t){return T[t]},r=function(i,o){var r,s;if(!i)throw"Missing Style name";if(!o)throw"Missing Style definition";return(null!=(s=T[i])?s.cssElem:void 0)&&(t.console&&console.warn(""+x+": overwriting style '"+i+"'"),T[i].cssElem.remove()),o.name=i,T[i]=o,r="",o.classes&&e.each(o.classes,function(t,i){return r+="."+v+"-"+o.name+"-"+t+" {\n",e.each(i,function(t,i){return P[t]&&e.each(P[t],function(e,n){return r+=" "+n+t+": "+i+";\n"}),r+=" "+t+": "+i+";\n"}),r+="}\n"}),o.css&&(r+="/* styles for "+o.name+" */\n"+o.css),r?(o.cssElem=w(r),o.cssElem.attr("id","notify-"+o.name)):n},w=function(t){var i;i=a("style"),i.attr("type","text/css"),e("head").append(i);try{i.html(t)}catch(n){i[0].styleSheet.cssText=t}return i},S={clickToHide:!0,autoHide:!0,autoHideDelay:5e3,arrowShow:!0,arrowSize:5,breakNewLines:!0,elementPosition:"bottom",globalPosition:"top right",style:"bootstrap",className:"error",showAnimation:"slideDown",showDuration:400,hideAnimation:"slideUp",hideDuration:200,gap:5},m=function(t,i){var n;return n=function(){},n.prototype=t,e.extend(!0,new n,i)},h=function(t){return e.extend(S,t)},a=function(t){return e("<"+t+">")},u={},c=function(t){var i;return t.is("[type=radio]")&&(i=t.parents("form:first").find("[type=radio]").filter(function(i,n){return e(n).attr("name")===t.attr("name")}),t=i.first()),t},f=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=C[g[i.charAt(0)]],r=i,t[o]!==n&&(i=C[o.charAt(0)],e=-e),t[i]===n?t[i]=e:t[i]+=e,null},H=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"},l=function(t){return l.e=l.e||a("div"),l.e.text(t).html()},o=function(){function t(t,i,n){"string"==typeof n&&(n={className:n}),this.options=m(S,e.isPlainObject(n)?n:{}),this.loadHTML(),this.wrapper=e(s.html),this.wrapper.data(v,this),this.arrow=this.wrapper.find("."+v+"-arrow"),this.container=this.wrapper.find("."+v+"-container"),this.container.append(this.userContainer),t&&t.length&&(this.elementType=t.attr("type"),this.originalElement=t,this.elem=c(t),this.elem.data(v,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=e(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(""+v+"-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,o,r,s,h,l;return l=this.getPosition(),h=l[0],s=l[1],r=C[h],t=C[s],o=h+"|"+s,i=u[o],i||(i=u[o]=a("div"),n={},n[r]=0,"middle"===t?n.top="45%":"center"===t?n.left="45%":n[t]=0,i.css(n).addClass(""+v+"-corner"),e("body").append(i)),i.prepend(this.wrapper)},t.prototype.setElementPosition=function(){var t,i,o,r,s,a,h,l,c,p,u,m,w,b,v,x,S,P,T,A,M,L,z,D,E,j,O,I,W;for(z=this.getPosition(),A=z[0],P=z[1],T=z[2],u=this.elem.position(),l=this.elem.outerHeight(),m=this.elem.outerWidth(),c=this.elem.innerHeight(),p=this.elem.innerWidth(),D=this.wrapper.position(),s=this.container.height(),a=this.container.width(),b=C[A],x=g[A],S=C[x],h={},h[S]="b"===A?l:"r"===A?m:0,f(h,"top",u.top-D.top),f(h,"left",u.left-D.left),W=["top","left"],E=0,O=W.length;O>E;E++)M=W[E],v=parseInt(this.elem.css("margin-"+M),10),v&&f(h,M,v);if(w=Math.max(0,this.options.gap-(this.options.arrowShow?o:0)),f(h,S,w),this.options.arrowShow){for(o=this.options.arrowSize,i=e.extend({},h),t=this.userContainer.css("border-color")||this.userContainer.css("background-color")||"white",j=0,I=y.length;I>j;j++)M=y[j],L=C[M],M!==x&&(r=L===b?t:"transparent",i["border-"+L]=""+o+"px solid "+r);f(h,C[x],o),k.call(y,P)>=0&&f(i,C[P],2*o)}else this.arrow.hide();return k.call(N,A)>=0?(f(h,"left",H(P,a,m)),i&&f(i,"left",H(P,o,p))):k.call(d,A)>=0&&(f(h,"top",H(P,s,l)),i&&f(i,"top",H(P,o,c))),this.container.is(":visible")&&(h.display="block"),this.container.removeAttr("style").css(h),i?this.arrow.removeAttr("style").css(i):n},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=b(i),0===t.length&&(t[0]="b"),e=t[0],0>k.call(y,e))throw"Must be one of ["+y+"]";return(1===t.length||(n=t[0],k.call(N,n)>=0&&(o=t[1],0>k.call(d,o)))||(r=t[0],k.call(d,r)>=0&&(s=t[1],0>k.call(N,s))))&&(t[1]=(a=t[0],k.call(d,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=T[t],!i)throw"Missing style: "+t;return i},t.prototype.updateClasses=function(){var t,i;return t=["base"],e.isArray(this.options.className)?t=t.concat(this.options.className):this.options.className&&t.push(this.options.className),i=this.getStyle(),t=e.map(t,function(t){return""+v+"-"+i.name+"-"+t}).join(" "),this.userContainer.attr("class",t)},t.prototype.run=function(t,i){var o=this;return e.isPlainObject(i)?e.extend(this.options,i):"string"===e.type(i)&&(this.options.color=i),this.container&&!t?(this.show(!1),n):this.container||t?(this.rawHTML||(t=l(t),this.options.breakNewLines&&(t=t.replace(/\n/g,"
"))),this.text.html(t),this.updateClasses(),this.elem?this.setElementPosition():this.setGlobalPosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),this.autohideTimer=setTimeout(function(){return o.show(!1)},this.options.autoHideDelay)):n):n},t.prototype.destroy=function(){return this.wrapper.remove()},t}(),e[x]=function(t,i,n){return t&&t.nodeName||t.jquery?e(t)[x](i,n):(n=i,i=t,new o(null,i,n)),t},e.fn[x]=function(t,i){return e(this).each(function(){var n;return n=c(e(this)).data(v),n?n.run(t,i):new o(e(this),t,i)}),this},e.extend(e[x],{defaults:h,addStyle:r,pluginOptions:S,getStyle:p,insertCSS:w}),e(function(){return w(s.css).attr("id","core-notify"),e(i).on("click notify-hide","."+v+"-wrapper",function(t){var i;return i=e(this).data(v),i&&(i.options.clickToHide||"notify-hide"===t.type)?i.show(!1):n})})})(window,document,jQuery); \ No newline at end of file +(function(t,i,e,n){"use strict";var o,r,s,a,h,l,c,p,u,d,f,m,w,y,g,b,v,x,S,C,H,P,T,N,k=[].indexOf||function(t){for(var i=0,e=this.length;e>i;i++)if(i in this&&this[i]===t)return i;return-1};x="notify",v=x+"js",C={t:"top",m:"middle",b:"bottom",l:"left",c:"center",r:"right"},d=["l","c","r"],N=["t","m","b"],y=["t","b","l","r"],g={t:"b",m:null,b:"t",l:"r",c:null,r:"l"},b=function(t){var i;return i=[],e.each(t.split(/\W+/),function(t,e){var o;return o=e.toLowerCase().charAt(0),C[o]?i.push(o):n}),i},T={},s={name:"core",html:'
\n
\n
\n
',css:"."+v+"-corner {\n position: fixed;\n margin: 5px;\n z-index: 1050;\n}\n\n."+v+"-corner ."+v+"-wrapper,\n."+v+"-corner ."+v+"-container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n margin: 3px;\n}\n\n."+v+"-wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n}\n\n."+v+"-container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+v+"-text {\n position: relative;\n}\n\n."+v+"-arrow {\n position: absolute;\n z-index: 2;\n width: 0;\n height: 0;\n}"},P={"border-radius":["-webkit-","-moz-"]},p=function(t){return T[t]},r=function(i,o){var r,s;if(!i)throw"Missing Style name";if(!o)throw"Missing Style definition";return(null!=(s=T[i])?s.cssElem:void 0)&&(t.console&&console.warn(""+x+": overwriting style '"+i+"'"),T[i].cssElem.remove()),o.name=i,T[i]=o,r="",o.classes&&e.each(o.classes,function(t,i){return r+="."+v+"-"+o.name+"-"+t+" {\n",e.each(i,function(t,i){return P[t]&&e.each(P[t],function(e,n){return r+=" "+n+t+": "+i+";\n"}),r+=" "+t+": "+i+";\n"}),r+="}\n"}),o.css&&(r+="/* styles for "+o.name+" */\n"+o.css),r?(o.cssElem=w(r),o.cssElem.attr("id","notify-"+o.name)):n},w=function(t){var i;i=a("style"),i.attr("type","text/css"),e("head").append(i);try{i.html(t)}catch(n){i[0].styleSheet.cssText=t}return i},S={clickToHide:!0,autoHide:!0,autoHideDelay:5e3,arrowShow:!0,arrowSize:5,breakNewLines:!0,elementPosition:"bottom",globalPosition:"top right",style:"bootstrap",className:"error",showAnimation:"slideDown",showDuration:400,hideAnimation:"slideUp",hideDuration:200,gap:5},m=function(t,i){var n;return n=function(){},n.prototype=t,e.extend(!0,new n,i)},h=function(t){return e.extend(S,t)},a=function(t){return e("<"+t+">")},u={},c=function(t){var i;return t.is("[type=radio]")&&(i=t.parents("form:first").find("[type=radio]").filter(function(i,n){return e(n).attr("name")===t.attr("name")}),t=i.first()),t},f=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=C[g[i.charAt(0)]],r=i,t[o]!==n&&(i=C[o.charAt(0)],e=-e),t[i]===n?t[i]=e:t[i]+=e,null},H=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"},l=function(t){return l.e=l.e||a("div"),t},o=function(){function t(t,i,n){"string"==typeof n&&(n={className:n}),this.options=m(S,e.isPlainObject(n)?n:{}),this.loadHTML(),this.wrapper=e(s.html),this.wrapper.data(v,this),this.arrow=this.wrapper.find("."+v+"-arrow"),this.container=this.wrapper.find("."+v+"-container"),this.container.append(this.userContainer),t&&t.length&&(this.elementType=t.attr("type"),this.originalElement=t,this.elem=c(t),this.elem.data(v,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=e(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(""+v+"-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,o,r,s,h,l;return l=this.getPosition(),h=l[0],s=l[1],r=C[h],t=C[s],o=h+"|"+s,i=u[o],i||(i=u[o]=a("div"),n={},n[r]=0,"middle"===t?n.top="45%":"center"===t?n.left="45%":n[t]=0,i.css(n).addClass(""+v+"-corner"),e("body").append(i)),i.prepend(this.wrapper)},t.prototype.setElementPosition=function(){var t,i,o,r,s,a,h,l,c,p,u,m,w,b,v,x,S,P,T,A,M,L,z,D,E,j,O,I,W;for(z=this.getPosition(),A=z[0],P=z[1],T=z[2],u=this.elem.position(),l=this.elem.outerHeight(),m=this.elem.outerWidth(),c=this.elem.innerHeight(),p=this.elem.innerWidth(),D=this.wrapper.position(),s=this.container.height(),a=this.container.width(),b=C[A],x=g[A],S=C[x],h={},h[S]="b"===A?l:"r"===A?m:0,f(h,"top",u.top-D.top),f(h,"left",u.left-D.left),W=["top","left"],E=0,O=W.length;O>E;E++)M=W[E],v=parseInt(this.elem.css("margin-"+M),10),v&&f(h,M,v);if(w=Math.max(0,this.options.gap-(this.options.arrowShow?o:0)),f(h,S,w),this.options.arrowShow){for(o=this.options.arrowSize,i=e.extend({},h),t=this.userContainer.css("border-color")||this.userContainer.css("background-color")||"white",j=0,I=y.length;I>j;j++)M=y[j],L=C[M],M!==x&&(r=L===b?t:"transparent",i["border-"+L]=""+o+"px solid "+r);f(h,C[x],o),k.call(y,P)>=0&&f(i,C[P],2*o)}else this.arrow.hide();return k.call(N,A)>=0?(f(h,"left",H(P,a,m)),i&&f(i,"left",H(P,o,p))):k.call(d,A)>=0&&(f(h,"top",H(P,s,l)),i&&f(i,"top",H(P,o,c))),this.container.is(":visible")&&(h.display="block"),this.container.removeAttr("style").css(h),i?this.arrow.removeAttr("style").css(i):n},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=b(i),0===t.length&&(t[0]="b"),e=t[0],0>k.call(y,e))throw"Must be one of ["+y+"]";return(1===t.length||(n=t[0],k.call(N,n)>=0&&(o=t[1],0>k.call(d,o)))||(r=t[0],k.call(d,r)>=0&&(s=t[1],0>k.call(N,s))))&&(t[1]=(a=t[0],k.call(d,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=T[t],!i)throw"Missing style: "+t;return i},t.prototype.updateClasses=function(){var t,i;return t=["base"],e.isArray(this.options.className)?t=t.concat(this.options.className):this.options.className&&t.push(this.options.className),i=this.getStyle(),t=e.map(t,function(t){return""+v+"-"+i.name+"-"+t}).join(" "),this.userContainer.attr("class",t)},t.prototype.run=function(t,i){var o=this;return e.isPlainObject(i)?e.extend(this.options,i):"string"===e.type(i)&&(this.options.color=i),this.container&&!t?(this.show(!1),n):this.container||t?(this.rawHTML||(t=l(t),this.options.breakNewLines&&(t=t.replace(/\n/g,"
"))),this.text.html(t),this.updateClasses(),this.elem?this.setElementPosition():this.setGlobalPosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),this.autohideTimer=setTimeout(function(){return o.show(!1)},this.options.autoHideDelay)):n):n},t.prototype.destroy=function(){return this.wrapper.remove()},t}(),e[x]=function(t,i,n){return t&&t.nodeName||t.jquery?e(t)[x](i,n):(n=i,i=t,new o(null,i,n)),t},e.fn[x]=function(t,i){return e(this).each(function(){var n;return n=c(e(this)).data(v),n?n.run(t,i):new o(e(this),t,i)}),this},e.extend(e[x],{defaults:h,addStyle:r,pluginOptions:S,getStyle:p,insertCSS:w}),e(function(){return w(s.css).attr("id","core-notify"),e(i).on("click notify-hide","."+v+"-wrapper",function(t){var i;return i=e(this).data(v),i&&(i.options.clickToHide||"notify-hide"===t.type)?i.show(!1):n})})})(window,document,jQuery); diff --git a/src/notify.coffee b/src/notify.coffee index 1c4a04a..6067e4a 100644 --- a/src/notify.coffee +++ b/src/notify.coffee @@ -239,7 +239,7 @@ realign = (alignment, inner, outer) -> encode = (text) -> encode.e = encode.e or createElem "div" - encode.e.text(text).html() + text # ================================ # NOTIFY CLASS