diff --git a/dist/notify.js b/dist/notify.js
index 5406083..5356664 100644
--- a/dist/notify.js
+++ b/dist/notify.js
@@ -21,7 +21,7 @@ arrowDirs = {
styles = {
core: {
html: "
",
- css: "." + className + "Corner {\n position: fixed;\n top: 0;\n right: 0;\n margin: 5px;\n z-index: 1050;\n}\n\n." + className + "Corner ." + className + "Wrapper,\n." + className + "Corner ." + className + "Container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n}\n\n." + className + "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." + className + "Container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n." + className + "Text {\n position: relative;\n}\n\n." + className + "Arrow {\n margin-top: " + (2 + (document.documentMode === 5 ? size * -4 : 0)) + ";\n position: absolute;\n z-index: 2;\n margin-left: 10px;\n width: 0;\n height: 0;\n}\n"
+ css: "." + className + "Corner {\n position: fixed;\n top: 0;\n right: 0;\n margin: 5px;\n z-index: 1050;\n}\n\n." + className + "Corner ." + className + "Wrapper,\n." + className + "Corner ." + className + "Container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n}\n\n." + className + "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." + className + "Container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n." + className + "Text {\n position: relative;\n}\n\n." + className + "Arrow {\n margin-top: " + (2 + (document.documentMode === 5 ? size * -4 : 0)) + "px;\n position: absolute;\n z-index: 2;\n margin-left: 10px;\n width: 0;\n height: 0;\n}\n"
},
user: {
"default": {
@@ -117,7 +117,7 @@ Notification = (function() {
this.loadCSS();
this.loadHTML();
this.wrapper = $(styles.core.html);
- this.wrapper.data(pluginName, this);
+ this.wrapper.data(className, this);
this.arrow = this.wrapper.find("." + className + "Arrow");
this.container = this.wrapper.find("." + className + "Container");
this.container.append(this.userContainer);
@@ -125,7 +125,7 @@ Notification = (function() {
this.elementType = elem.attr('type');
this.originalElement = elem;
this.elem = getAnchorElement(elem);
- this.elem.data(pluginName, this);
+ this.elem.data(className, this);
this.elem.before(this.wrapper);
} else {
this.options.arrowShow = false;
@@ -155,73 +155,78 @@ Notification = (function() {
};
Notification.prototype.show = function(show) {
- var hidden;
+ var elems, hidden;
hidden = this.container.parent().parents(':hidden').length > 0;
+ elems = this.container.add(this.arrow);
if (hidden && show) {
- this.container.show();
+ elems.show();
}
if (hidden && !show) {
- this.container.hide();
+ elems.hide();
}
if (!hidden && show) {
- this.container[this.options.showAnimation](this.options.showDuration);
+ elems[this.options.showAnimation](this.options.showDuration);
}
if (!hidden && !show) {
- return this.container[this.options.hideAnimation](this.options.hideDuration);
+ return elems[this.options.hideAnimation](this.options.hideDuration);
}
};
Notification.prototype.updatePosition = function() {
- var arrowPosition, elementPosition, height, left, mainPosition, position;
+ var elementPosition, mainPosition, p, position;
if (!this.elem) {
return;
}
elementPosition = this.elem.position();
mainPosition = this.wrapper.position();
position = this.getPosition();
- arrowPosition = this.updateArrow(position);
- left = 0;
- height = 0;
+ p = {
+ top: 0,
+ left: 0
+ };
switch (position) {
case 'bottom':
- height = this.elem.outerHeight();
+ p.top += this.elem.outerHeight();
break;
case 'right':
- left = this.elem.width();
+ p.left += this.elem.width();
break;
default:
throw "Unknown position: " + position;
}
- left += elementPosition.left - mainPosition.left;
if (!navigator.userAgent.match(/MSIE/)) {
- height += elementPosition.top - mainPosition.top;
+ p.top += elementPosition.top - mainPosition.top;
}
- return this.container.css({
- top: height + this.options.offsetY + arrowPosition.top,
- left: left + this.options.offsetX + arrowPosition.left
- });
+ p.left += elementPosition.left - mainPosition.left;
+ p.top += this.options.offsetY;
+ p.left += this.options.offsetX;
+ this.updateArrow(p, position);
+ return this.container.css(p);
};
- Notification.prototype.updateArrow = function(position) {
- var d, dir, offsets, size;
- offsets = {
- top: 0,
- left: 0
- };
+ Notification.prototype.updateArrow = function(p, position) {
+ var d, dir, size;
if (!(this.options.arrowShow && this.elementType !== 'radio')) {
this.arrow.hide();
- return offsets;
+ return;
}
dir = arrowDirs[position];
size = this.options.arrowSize;
this.arrow.css('border-' + position, size + 'px solid ' + this.getColor());
+ this.arrow.css(p);
for (d in arrowDirs) {
if (d !== dir && d !== position) {
this.arrow.css('border-' + d, size + 'px solid transparent');
}
}
- this.arrow.show();
- return offsets;
+ switch (position) {
+ case 'bottom':
+ p.top += size;
+ break;
+ case 'right':
+ p.left += size;
+ }
+ return this.arrow.show();
};
Notification.prototype.getPosition = function() {
@@ -303,7 +308,7 @@ $(function() {
$("link").each(function() {
var src;
src = $(this).attr('href');
- if (src.match(/bootstrap[^\/]*\.css/)) {
+ if (src.match(/bootstrap/)) {
bootstrapDetected = true;
return false;
}
@@ -311,7 +316,7 @@ $(function() {
insertCSS(styles.core);
return $(document).on('click', "." + className + "Wrapper", function() {
var inst;
- inst = $(this).data(pluginName);
+ inst = $(this).data(className);
if (inst) {
return inst.show(false);
}
@@ -332,14 +337,14 @@ $[pluginName].options = function(options) {
return $.extend(pluginOptions, options);
};
-$[pluginName].addStyle = function(s) {
+$[pluginName].styles = function(s) {
return $.extend(true, styles.user, s);
};
$.fn[pluginName] = function(data, options) {
return $(this).each(function() {
var inst;
- inst = getAnchorElement($(this)).data(pluginName);
+ inst = getAnchorElement($(this)).data(className);
if (inst) {
return inst.run(data, options);
} else {
diff --git a/dist/notify.min.js b/dist/notify.min.js
index bb59c8d..7ba1a02 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:'',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))+";\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:!0,arrowSize:5,position:null,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(l,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(l,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;return n=this.container.parent().parents(":hidden").length>0,n&&t&&this.container.show(),n&&!t&&this.container.hide(),!n&&t&&this.container[this.options.showAnimation](this.options.showDuration),n||t?undefined:this.container[this.options.hideAnimation](this.options.hideDuration)},n.prototype.updatePosition=function(){var t,n,i,o,e,r;if(this.elem){switch(n=this.elem.position(),e=this.wrapper.position(),r=this.getPosition(),t=this.updateArrow(r),o=0,i=0,r){case"bottom":i=this.elem.outerHeight();break;case"right":o=this.elem.width();break;default:throw"Unknown position: "+r}return o+=n.left-e.left,navigator.userAgent.match(/MSIE/)||(i+=n.top-e.top),this.container.css({top:i+this.options.offsetY+t.top,left:o+this.options.offsetX+t.left})}},n.prototype.updateArrow=function(t){var n,i,e,r;if(e={top:0,left:0},!this.options.arrowShow||"radio"===this.elementType)return this.arrow.hide(),e;i=o[t],r=this.options.arrowSize,this.arrow.css("border-"+t,r+"px solid "+this.getColor());for(n in o)n!==i&&n!==t&&this.arrow.css("border-"+n,r+"px solid transparent");return this.arrow.show(),e},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[^\/]*\.css/)?(e=!0,!1):undefined}),d(c.core),$(n).on("click","."+r+"Wrapper",function(){var t;return t=$(this).data(l),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].addStyle=function(t){return $.extend(!0,c.user,t)},$.fn[l]=function(t,n){return $(this).each(function(){var o;return o=p($(this)).data(l),o?o.run(t,n):new i($(this),t,n)})}})(window,document);
\ No newline at end of file
+ */(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:'',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:!0,arrowSize:5,position:null,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
diff --git a/src/notify.coffee b/src/notify.coffee
index fba37d8..aea5faf 100644
--- a/src/notify.coffee
+++ b/src/notify.coffee
@@ -57,7 +57,7 @@ styles =
}
.#{className}Arrow {
- margin-top: #{2 + (if document.documentMode is 5 then (size*-4) else 0)};
+ margin-top: #{2 + (if document.documentMode is 5 then (size*-4) else 0)}px;
position: absolute;
z-index: 2;
margin-left: 10px;
@@ -190,7 +190,7 @@ class Notification
@loadHTML()
@wrapper = $(styles.core.html)
- @wrapper.data pluginName, @
+ @wrapper.data className, @
@arrow = @wrapper.find ".#{className}Arrow"
@container = @wrapper.find ".#{className}Container"
@container.append @userContainer
@@ -199,7 +199,7 @@ class Notification
@elementType = elem.attr('type')
@originalElement = elem
@elem = getAnchorElement(elem)
- @elem.data pluginName, @
+ @elem.data className, @
# add into dom above elem
@elem.before @wrapper
else
@@ -226,11 +226,16 @@ class Notification
@text.addClass "#{className}Text"
show: (show) ->
+
+
+
hidden = @container.parent().parents(':hidden').length > 0
- @container.show() if hidden and show
- @container.hide() if hidden and not show
- @container[@options.showAnimation] @options.showDuration if not hidden and show
- @container[@options.hideAnimation] @options.hideDuration if not hidden and not show
+
+ 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
updatePosition: ->
return unless @elem
@@ -240,47 +245,57 @@ class Notification
#
position = @getPosition()
- arrowPosition = @updateArrow(position)
#start calculations
- left = 0
- height = 0
+ p =
+ top: 0
+ left: 0
switch position
when 'bottom'
- height = @elem.outerHeight()
+ p.top += @elem.outerHeight()
when 'right'
- left = @elem.width()
+ p.left += @elem.width()
else
throw "Unknown position: #{position}"
#elem vs wrapper corrections
- left += elementPosition.left - mainPosition.left
- height += (elementPosition.top - mainPosition.top) unless navigator.userAgent.match /MSIE/
+ p.top += (elementPosition.top - mainPosition.top) unless navigator.userAgent.match /MSIE/
+ p.left += elementPosition.left - mainPosition.left
- #set with user offset, with arrow offet
- @container.css
- top: height + @options.offsetY + arrowPosition.top
- left: left + @options.offsetX + arrowPosition.left
+ #set user offset
+ p.top += @options.offsetY
+ p.left += @options.offsetX
- updateArrow: (position) ->
-
- offsets = {top: 0, left: 0}
+ @updateArrow p, position
+
+ # if @setCSS
+ # @container.stop().animate(p)
+ # else
+ @container.css p
+ # @setCSS = true
+
+ updateArrow: (p, position) ->
unless @options.arrowShow and @elementType isnt 'radio'
@arrow.hide()
- return offsets
+ return
dir = arrowDirs[position]
size = @options.arrowSize
@arrow.css 'border-' + position, size + 'px solid ' + @getColor()
+ @arrow.css p
for d of arrowDirs
if d isnt dir and d isnt position
@arrow.css 'border-' + d, size + 'px solid transparent'
- @arrow.show()
- offsets
+ switch position
+ when 'bottom'
+ p.top += size
+ when 'right'
+ p.left += size
+ @arrow.show()
getPosition: ->
return @options.position if @options.position
@@ -343,22 +358,24 @@ class Notification
@show false
, @options.autoHideDelay
-#when ready, bind permanent hide listener
+#when ready
$ ->
+ #corner notification container
$("body").append cornerElem
#auto-detect bootstrap
$("link").each ->
src = $(@).attr 'href'
- if src.match /bootstrap[^\/]*\.css/
+ if src.match /bootstrap/
bootstrapDetected = true
return false
+
#add core styles
insertCSS styles.core
#watch all notifications clicks
$(document).on 'click', ".#{className}Wrapper", ->
- inst = $(@).data pluginName
+ inst = $(@).data className
inst.show false if inst
# publicise jquery plugin
@@ -373,19 +390,17 @@ $[pluginName] = (elem, data, options) ->
data = elem
new Notification null, data, options
-# publicise options method
+# publicise methods
$[pluginName].options = (options) ->
$.extend pluginOptions, options
-$[pluginName].addStyle = (s) ->
+$[pluginName].styles = (s) ->
$.extend true, styles.user, s
# $( ... ).pluginName( { .. } ) creates a cached instance on each
-# selected item with custom options for just that instance
-# return alert "$.fn#{pluginName} already defined" if $.fn[pluginName]?
$.fn[pluginName] = (data, options) ->
$(@).each ->
- inst = getAnchorElement($(@)).data pluginName
+ inst = getAnchorElement($(@)).data className
if inst
inst.run data, options
else