From d0f6a851434e58116ef305fb85d7b12ab8edb07e Mon Sep 17 00:00:00 2001 From: Jaime Pillora Date: Fri, 5 Apr 2013 15:34:55 +1100 Subject: [PATCH] updated show function --- dist/notify.js | 45 +++++++++++++++++++++++++++++++-------------- dist/notify.min.js | 2 +- src/notify.coffee | 36 +++++++++++++++++++++++++++--------- 3 files changed, 59 insertions(+), 24 deletions(-) diff --git a/dist/notify.js b/dist/notify.js index 4fbc6ee..a68ca9b 100644 --- a/dist/notify.js +++ b/dist/notify.js @@ -30,7 +30,7 @@ styles = { }, bootstrap: { html: "
\n \n
", - css: "." + className + "Bootstrap {\n white-space: nowrap;\n margin-bottom: 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}", + css: "." + className + "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' } @@ -154,22 +154,27 @@ Notification = (function() { return this.text.addClass("" + className + "Text"); }; - Notification.prototype.show = function(show) { - var elems, hidden; + Notification.prototype.show = function(show, callback) { + var args, elems, fn, hidden; + if (callback == null) { + callback = $.noop; + } hidden = this.container.parent().parents(':hidden').length > 0; elems = this.container.add(this.arrow); + args = []; if (hidden && show) { - elems.show(); - } - if (hidden && !show) { - elems.hide(); - } - if (!hidden && show) { - elems[this.options.showAnimation](this.options.showDuration); - } - if (!hidden && !show) { - return elems[this.options.hideAnimation](this.options.hideDuration); + fn = 'show'; + } else if (hidden && !show) { + fn = 'hide'; + } else if (!hidden && show) { + fn = this.options.showAnimation; + args.push(this.options.showDuration); + } else if (!hidden && !show) { + fn = this.options.hideAnimation; + args.push(this.options.hideDuration); } + args.push(callback); + return elems[fn].apply(elems, callback); }; Notification.prototype.updatePosition = function() { @@ -299,6 +304,13 @@ Notification = (function() { } }; + Notification.prototype.destroy = function() { + var _this = this; + return this.show(false, function() { + return _this.wrapper.remove(); + }); + }; + return Notification; })(); @@ -317,8 +329,13 @@ $(function() { return $(document).on('click', "." + className + "Wrapper", function() { var inst; inst = $(this).data(className); - if (inst) { + if (!inst) { + return; + } + if (inst.elem) { return inst.show(false); + } else { + return inst.destroy(); } }); }); diff --git a/dist/notify.min.js b/dist/notify.min.js index 5e7cb1b..0eb610d 100644 --- a/dist/notify.min.js +++ b/dist/notify.min.js @@ -1,4 +1,4 @@ /** Notify.js - v0.0.1 - 2013/04/05 * http://notifyjs.com/ * Copyright (c) 2013 Jaime Pillora - MIT - */(function(t,n){"use strict";var i,o,e,r,s,a,p,h,d,l,u,c;l="notify",r="__"+l,o={top:"bottom",bottom:"top",left:"right",right:"left"},c={core:{html:'
\n
\n
\n
',css:"."+r+"Corner {\n position: fixed;\n top: 0;\n right: 0;\n margin: 5px;\n z-index: 1050;\n}\n\n."+r+"Corner ."+r+"Wrapper,\n."+r+"Corner ."+r+"Container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n}\n\n."+r+"Wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n opacity: 0.85;\n}\n\n."+r+"Container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+r+"Text {\n position: relative;\n}\n\n."+r+"Arrow {\n margin-top: "+(2+(5===n.documentMode?-4*size:0))+"px;\n position: absolute;\n z-index: 2;\n margin-left: 10px;\n width: 0;\n height: 0;\n}\n"},user:{"default":{html:'
\n \n
',css:"."+r+"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:'
\n \n
',css:"."+r+"Bootstrap {\n white-space: nowrap;\n margin-bottom: 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"}}}},e=!1,u={autoHide:!1,autoHideDelay:2e3,arrowShow:!1,arrowSize:5,position:"bottom",style:null,color:"red",colors:{red:"#b94a48",green:"#33be40",black:"#393939",blue:"#00f"},showAnimation:"slideDown",showDuration:400,hideAnimation:"slideUp",hideDuration:200,offsetY:2,offsetX:0},a=function(t){return $(n.createElement(t))},h=function(t,n){var i;return i=function(){},i.prototype=t,$.extend(!0,new i,n)},s=a("div").addClass(""+r+"Corner"),p=function(t){var n,i;return t.is("[type=radio]")&&(i=t.parents("form:first").find("[type=radio]").filter(function(n,i){return $(i).attr("name")===t.attr("name")}),t=i.first()),n=t.prev(),n.is("span.styled,span.OBS_checkbox")&&(t=n),t},d=function(t){var n;if(t&&t.css)return n=t.cssElem,n?n.html(t.css):(n=a("style").attr("type","text/css").html(t.css),$("head").append(n),t.cssElem=n)},i=function(){function n(t,n,i){"string"==typeof i&&(i={color:i}),this.options=h(u,$.isPlainObject(i)?i:{}),this.loadCSS(),this.loadHTML(),this.wrapper=$(c.core.html),this.wrapper.data(r,this),this.arrow=this.wrapper.find("."+r+"Arrow"),this.container=this.wrapper.find("."+r+"Container"),this.container.append(this.userContainer),t&&t.length?(this.elementType=t.attr("type"),this.originalElement=t,this.elem=p(t),this.elem.data(r,this),this.elem.before(this.wrapper)):(this.options.arrowShow=!1,s.prepend(this.wrapper)),this.container.hide(),this.run(n)}return n.prototype.loadCSS=function(t){var n;return t||(n=this.options.style,t=this.getStyle(n)),d(t)},n.prototype.loadHTML=function(t){if(t=this.getStyle(name),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(""+r+"Text")},n.prototype.show=function(t){var n,i;return i=this.container.parent().parents(":hidden").length>0,n=this.container.add(this.arrow),i&&t&&n.show(),i&&!t&&n.hide(),!i&&t&&n[this.options.showAnimation](this.options.showDuration),i||t?undefined:n[this.options.hideAnimation](this.options.hideDuration)},n.prototype.updatePosition=function(){var t,n,i,o;if(this.elem){switch(t=this.elem.position(),n=this.wrapper.position(),o=this.getPosition(),i={top:0,left:0},o){case"bottom":i.top+=this.elem.outerHeight();break;case"right":i.left+=this.elem.width();break;default:throw"Unknown position: "+o}return navigator.userAgent.match(/MSIE/)||(i.top+=t.top-n.top),i.left+=t.left-n.left,i.top+=this.options.offsetY,i.left+=this.options.offsetX,this.updateArrow(i,o),this.container.css(i)}},n.prototype.updateArrow=function(t,n){var i,e,r;if(!this.options.arrowShow||"radio"===this.elementType)return this.arrow.hide(),undefined;e=o[n],r=this.options.arrowSize,this.arrow.css("border-"+n,r+"px solid "+this.getColor()),this.arrow.css(t);for(i in o)i!==e&&i!==n&&this.arrow.css("border-"+i,r+"px solid transparent");switch(n){case"bottom":t.top+=r;break;case"right":t.left+=r}return this.arrow.show()},n.prototype.getPosition=function(){return this.options.position?this.options.position:this.elem.position().left+this.elem.width()+this.wrapper.width()<$(t).width()?"right":"bottom"},n.prototype.getColor=function(){var t;return t=this.getStyle().colors,t&&t[this.options.color]||this.options.colors[this.options.color]||this.options.color},n.prototype.getStyle=function(t){var n;if(t||(t=this.options.style),e&&!t&&(t="bootstrap"),t||(t="default"),n=c.user[t],!n)throw"Missing style: "+t;return n},n.prototype.updateStyle=function(){var t=this;return this.wrapper.find("[data-notify-style]").each(function(n,i){return $(i).attr("style",$(i).attr("data-notify-style").replace(/\{\{\s*color\s*\}\}/gi,t.getColor()).replace(/\{\{\s*position\s*\}\}/gi,t.getPosition()))})},n.prototype.run=function(t,n){var i,o=this;return $.isPlainObject(n)?$.extend(this.options,n):"string"===$.type(n)&&(this.options.color=n),this.container&&!t?(this.show(!1),undefined):this.container||t?("string"===$.type(t)?this.text.html(t.replace("\n","
")):this.text.empty().append(t),this.updatePosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),i=setTimeout(function(){return o.show(!1)},this.options.autoHideDelay)):undefined):undefined},n}(),$(function(){return $("body").append(s),$("link").each(function(){var t;return t=$(this).attr("href"),t.match(/bootstrap/)?(e=!0,!1):undefined}),d(c.core),$(n).on("click","."+r+"Wrapper",function(){var t;return t=$(this).data(r),t?t.show(!1):undefined})}),$[l]=function(t,n,o){return t instanceof HTMLElement||t.jquery?$(t)[l](n,o):(o=n,n=t,new i(null,n,o))},$[l].options=function(t){return $.extend(u,t)},$[l].styles=function(t){return $.extend(!0,c.user,t)},$.fn[l]=function(t,n){return $(this).each(function(){var o;return o=p($(this)).data(r),o?o.run(t,n):new i($(this),t,n)})}})(window,document); \ No newline at end of file + */(function(t,n){"use strict";var o,i,e,r,s,a,p,h,l,d,u,c;d="notify",r="__"+d,i={top:"bottom",bottom:"top",left:"right",right:"left"},c={core:{html:'
\n
\n
\n
',css:"."+r+"Corner {\n position: fixed;\n top: 0;\n right: 0;\n margin: 5px;\n z-index: 1050;\n}\n\n."+r+"Corner ."+r+"Wrapper,\n."+r+"Corner ."+r+"Container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n}\n\n."+r+"Wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n opacity: 0.85;\n}\n\n."+r+"Container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+r+"Text {\n position: relative;\n}\n\n."+r+"Arrow {\n margin-top: "+(2+(5===n.documentMode?-4*size:0))+"px;\n position: absolute;\n z-index: 2;\n margin-left: 10px;\n width: 0;\n height: 0;\n}\n"},user:{"default":{html:'
\n \n
',css:"."+r+"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:'
\n \n
',css:"."+r+"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"}}}},e=!1,u={autoHide:!1,autoHideDelay:2e3,arrowShow:!1,arrowSize:5,position:"bottom",style:null,color:"red",colors:{red:"#b94a48",green:"#33be40",black:"#393939",blue:"#00f"},showAnimation:"slideDown",showDuration:400,hideAnimation:"slideUp",hideDuration:200,offsetY:2,offsetX:0},a=function(t){return $(n.createElement(t))},h=function(t,n){var o;return o=function(){},o.prototype=t,$.extend(!0,new o,n)},s=a("div").addClass(""+r+"Corner"),p=function(t){var n,o;return t.is("[type=radio]")&&(o=t.parents("form:first").find("[type=radio]").filter(function(n,o){return $(o).attr("name")===t.attr("name")}),t=o.first()),n=t.prev(),n.is("span.styled,span.OBS_checkbox")&&(t=n),t},l=function(t){var n;if(t&&t.css)return n=t.cssElem,n?n.html(t.css):(n=a("style").attr("type","text/css").html(t.css),$("head").append(n),t.cssElem=n)},o=function(){function n(t,n,o){"string"==typeof o&&(o={color:o}),this.options=h(u,$.isPlainObject(o)?o:{}),this.loadCSS(),this.loadHTML(),this.wrapper=$(c.core.html),this.wrapper.data(r,this),this.arrow=this.wrapper.find("."+r+"Arrow"),this.container=this.wrapper.find("."+r+"Container"),this.container.append(this.userContainer),t&&t.length?(this.elementType=t.attr("type"),this.originalElement=t,this.elem=p(t),this.elem.data(r,this),this.elem.before(this.wrapper)):(this.options.arrowShow=!1,s.prepend(this.wrapper)),this.container.hide(),this.run(n)}return n.prototype.loadCSS=function(t){var n;return t||(n=this.options.style,t=this.getStyle(n)),l(t)},n.prototype.loadHTML=function(t){if(t=this.getStyle(name),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(""+r+"Text")},n.prototype.show=function(t,n){var o,i,e,r;return null==n&&(n=$.noop),r=this.container.parent().parents(":hidden").length>0,i=this.container.add(this.arrow),o=[],r&&t?e="show":r&&!t?e="hide":!r&&t?(e=this.options.showAnimation,o.push(this.options.showDuration)):r||t||(e=this.options.hideAnimation,o.push(this.options.hideDuration)),o.push(n),i[e].apply(i,n)},n.prototype.updatePosition=function(){var t,n,o,i;if(this.elem){switch(t=this.elem.position(),n=this.wrapper.position(),i=this.getPosition(),o={top:0,left:0},i){case"bottom":o.top+=this.elem.outerHeight();break;case"right":o.left+=this.elem.width();break;default:throw"Unknown position: "+i}return navigator.userAgent.match(/MSIE/)||(o.top+=t.top-n.top),o.left+=t.left-n.left,o.top+=this.options.offsetY,o.left+=this.options.offsetX,this.updateArrow(o,i),this.container.css(o)}},n.prototype.updateArrow=function(t,n){var o,e,r;if(!this.options.arrowShow||"radio"===this.elementType)return this.arrow.hide(),undefined;e=i[n],r=this.options.arrowSize,this.arrow.css("border-"+n,r+"px solid "+this.getColor()),this.arrow.css(t);for(o in i)o!==e&&o!==n&&this.arrow.css("border-"+o,r+"px solid transparent");switch(n){case"bottom":t.top+=r;break;case"right":t.left+=r}return this.arrow.show()},n.prototype.getPosition=function(){return this.options.position?this.options.position:this.elem.position().left+this.elem.width()+this.wrapper.width()<$(t).width()?"right":"bottom"},n.prototype.getColor=function(){var t;return t=this.getStyle().colors,t&&t[this.options.color]||this.options.colors[this.options.color]||this.options.color},n.prototype.getStyle=function(t){var n;if(t||(t=this.options.style),e&&!t&&(t="bootstrap"),t||(t="default"),n=c.user[t],!n)throw"Missing style: "+t;return n},n.prototype.updateStyle=function(){var t=this;return this.wrapper.find("[data-notify-style]").each(function(n,o){return $(o).attr("style",$(o).attr("data-notify-style").replace(/\{\{\s*color\s*\}\}/gi,t.getColor()).replace(/\{\{\s*position\s*\}\}/gi,t.getPosition()))})},n.prototype.run=function(t,n){var o,i=this;return $.isPlainObject(n)?$.extend(this.options,n):"string"===$.type(n)&&(this.options.color=n),this.container&&!t?(this.show(!1),undefined):this.container||t?("string"===$.type(t)?this.text.html(t.replace("\n","
")):this.text.empty().append(t),this.updatePosition(),this.show(!0),this.options.autoHide?(clearTimeout(this.autohideTimer),o=setTimeout(function(){return i.show(!1)},this.options.autoHideDelay)):undefined):undefined},n.prototype.destroy=function(){var t=this;return this.show(!1,function(){return t.wrapper.remove()})},n}(),$(function(){return $("body").append(s),$("link").each(function(){var t;return t=$(this).attr("href"),t.match(/bootstrap/)?(e=!0,!1):undefined}),l(c.core),$(n).on("click","."+r+"Wrapper",function(){var t;return(t=$(this).data(r))?t.elem?t.show(!1):t.destroy():undefined})}),$[d]=function(t,n,i){return t instanceof HTMLElement||t.jquery?$(t)[d](n,i):(i=n,n=t,new o(null,n,i))},$[d].options=function(t){return $.extend(u,t)},$[d].styles=function(t){return $.extend(!0,c.user,t)},$.fn[d]=function(t,n){return $(this).each(function(){var i;return i=p($(this)).data(r),i?i.run(t,n):new o($(this),t,n)})}})(window,document); \ No newline at end of file diff --git a/src/notify.coffee b/src/notify.coffee index 95085d0..41b86ae 100644 --- a/src/notify.coffee +++ b/src/notify.coffee @@ -103,7 +103,7 @@ styles = css: """ .#{className}Bootstrap { white-space: nowrap; - margin-bottom: 5px !important; + margin: 5px !important; padding-left: 25px !important; background-repeat: no-repeat; background-position: 3px 7px; @@ -225,17 +225,27 @@ class Notification throw "style: #{name} HTML is missing the: data-notify='text' attribute" @text.addClass "#{className}Text" - show: (show) -> - - + show: (show, callback = $.noop) -> hidden = @container.parent().parents(':hidden').length > 0 elems = @container.add @arrow - elems.show() if hidden and show - elems.hide() if hidden and not show - elems[@options.showAnimation] @options.showDuration if not hidden and show - elems[@options.hideAnimation] @options.hideDuration if not hidden and not show + args = [] + + if hidden and show + fn = 'show' + else if hidden and not show + fn = 'hide' + else if not hidden and show + fn = @options.showAnimation + args.push @options.showDuration + else if not hidden and not show + fn = @options.hideAnimation + args.push @options.hideDuration + + args.push callback + + elems[fn].apply elems, callback updatePosition: -> return unless @elem @@ -358,6 +368,10 @@ class Notification @show false , @options.autoHideDelay + destroy: -> + @show false, => + @wrapper.remove() + #when ready $ -> #corner notification container @@ -376,7 +390,11 @@ $ -> #watch all notifications clicks $(document).on 'click', ".#{className}Wrapper", -> inst = $(@).data className - inst.show false if inst + return unless inst + if inst.elem + inst.show false + else + inst.destroy() # publicise jquery plugin # return alert "$.#{pluginName} already defined" if $[pluginName]?