This commit is contained in:
Jaime Pillora committed 2013-05-30 16:35:16 +10:00
1 parent 04ad20dda3
commit aa7d387776
4 files changed
+169 -72

No files matched your search

+74 -38
View File
@@ -1,23 +1,29 @@
/** Notify.js - v0.0.1 - 2013/05/29
/** Notify.js - v0.0.1 - 2013/05/30
* http://notifyjs.com/
* Copyright (c) 2013 Jaime Pillora - MIT
*/
(function(window,document,undefined) {
'use strict';
var Notification, className, cornerElem, createElem, getAnchorElement, hPositions, inherit, insertCSS, parsePosition, pluginName, pluginOptions, styles, vPositions;
var Notification, className, cornerElem, createElem, getAnchorElement, incr, inherit, insertCSS, opposites, parsePosition, pluginName, pluginOptions, positions, styles;
pluginName = 'notify';
className = '__' + pluginName;
vPositions = {
t: 'b',
m: null,
b: 't'
positions = {
t: 'top',
m: 'middle',
b: 'bottom',
l: 'left',
c: 'center',
r: 'right'
};
hPositions = {
opposites = {
t: 'b',
m: null,
b: 't',
l: 'r',
c: null,
r: 'l'
@@ -28,11 +34,8 @@ parsePosition = function(str) {
pos = [];
$.each(str.split(/\W+/), function(i, word) {
var w;
w = word.toLowerCase()[0];
if (vPositions[w]) {
pos.push(w);
}
if (hPositions[w]) {
w = word.toLowerCase().charAt(0);
if (positions[w]) {
return pos.push(w);
}
});
@@ -42,11 +45,11 @@ parsePosition = function(str) {
styles = {
core: {
html: "<div class=\"" + className + "Wrapper\">\n <div class=\"" + className + "Arrow\"></div>\n <div class=\"" + className + "Container\"></div>\n</div>",
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: 2px;\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 border: thin solid red;\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: 2px;\n position: absolute;\n z-index: 2;\n margin-left: 10px;\n width: 0;\n height: 0;\n}\n"
},
user: {
"default": {
html: "<div class=\"" + className + "Default\" \n data-notify-style=\"\n color: {{color}}; \n border-color: {{color}};\n \">\n <span data-notify=\"text\"></span>\n </div>",
html: "<div class=\"" + className + "Default\" \n data-notify-style=\"\n color: {{color}}; \n border-color: {{color}};\n \">\n <span data-notify-text></span>\n </div>",
css: "." + className + "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: {
@@ -65,7 +68,7 @@ pluginOptions = {
arrowShow: false,
arrowSize: 5,
position: 'bottom',
style: null,
style: 'default',
color: 'red',
colors: {
red: '#b94a48',
@@ -105,17 +108,49 @@ getAnchorElement = function(element) {
return element;
};
incr = function(obj, pos, val, useOpposite) {
var opp, temp;
if (useOpposite == null) {
useOpposite = true;
}
if (typeof val === 'string') {
val = parseInt(val, 10);
} else if (typeof val !== 'number') {
return;
}
if (isNaN(val)) {
return;
}
opp = positions[opposites[pos.charAt(0)]];
temp = pos;
if (obj[opp] !== undefined) {
if (!useOpposite) {
return;
}
pos = positions[opp.charAt(0)];
val *= -1;
}
if (obj[pos] === undefined) {
obj[pos] = val;
} else {
obj[pos] += val;
}
console.log("incr (" + opp + ">>" + temp + ") " + pos + " by " + val);
return null;
};
insertCSS = function(style) {
var elem;
if (!(style && style.css)) {
return;
}
elem = style.cssElem;
if (!elem) {
if (elem) {
return;
}
elem = createElem("style");
$("head").append(elem);
style.cssElem = elem;
}
try {
return elem.html(style.css);
} catch (e) {
@@ -166,9 +201,9 @@ Notification = (function() {
var style;
style = this.getStyle();
this.userContainer = $(style.html);
this.text = this.userContainer.find('[data-notify=text]');
this.text = this.userContainer.find('[data-notify-text]');
if (this.text.length === 0) {
throw "style: " + name + " HTML is missing the: data-notify='text' attribute";
throw "style: " + name + " HTML is missing the: 'data-notify-text' attribute";
}
return this.text.addClass("" + className + "Text");
};
@@ -197,34 +232,36 @@ Notification = (function() {
};
Notification.prototype.updatePosition = function() {
var elementPosition, mainPosition, p, position;
var elementPosition, p, position, wrapperPosition;
if (!this.elem) {
return;
}
elementPosition = this.elem.position();
mainPosition = this.wrapper.position();
wrapperPosition = this.wrapper.position();
position = this.getPosition();
p = {
top: 0,
left: 0
};
switch (position) {
case 'bottom':
p.top += this.elem.outerHeight();
console.log(this.elem[0]);
console.log("update position", position, " elem ", elementPosition, " main ", wrapperPosition);
p = {};
switch (position[0]) {
case 'b':
incr(p, 'top', this.elem.outerHeight());
break;
case 'right':
p.left += this.elem.width();
case 't':
incr(p, 'bottom', 0);
break;
case 'l':
incr(p, 'right', 0);
break;
case 'r':
incr(p, 'left', this.elem.outerWidth());
break;
default:
throw "Unknown position: " + position;
}
if (!navigator.userAgent.match(/MSIE/)) {
p.top += elementPosition.top - mainPosition.top;
incr(p, 'top', elementPosition.top - wrapperPosition.top);
}
p.left += elementPosition.left - mainPosition.left;
p.top += this.options.offsetY;
p.left += this.options.offsetX;
this.updateArrow(p, position);
incr(p, 'left', elementPosition.left - wrapperPosition.left);
return this.container.css(p);
};
@@ -283,9 +320,6 @@ Notification = (function() {
if (!name) {
name = this.options.style;
}
if (bootstrapDetected && !name) {
name = 'bootstrap';
}
if (!name) {
name = 'default';
}
@@ -387,6 +421,8 @@ $[pluginName].styles = function(s) {
return $.extend(true, styles.user, s);
};
$[pluginName].insertCSS = insertCSS;
$.fn[pluginName] = function(data, options) {
$(this).each(function() {
var inst;
+2 -2
View File
@@ -1,4 +1,4 @@
/** Notify.js - v0.0.1 - 2013/05/29
/** Notify.js - v0.0.1 - 2013/05/30
* http://notifyjs.com/
* Copyright (c) 2013 Jaime Pillora - MIT
*/(function(t,n){"use strict";var o,e,i,r,s,a,p,h,l,d,u,c,f;d="notify",e="__"+d,f={t:"b",m:null,b:"t"},a={l:"r",c:null,r:"l"},l=function(t){var n;return n=[],$.each(t.split(/\W+/),function(t,o){var e;return e=o.toLowerCase()[0],f[e]&&n.push(e),a[e]?n.push(e):undefined}),n},c={core:{html:'<div class="'+e+'Wrapper">\n <div class="'+e+'Arrow"></div>\n <div class="'+e+'Container"></div>\n</div>',css:"."+e+"Corner {\n position: fixed;\n top: 0;\n right: 0;\n margin: 5px;\n z-index: 1050;\n}\n\n."+e+"Corner ."+e+"Wrapper,\n."+e+"Corner ."+e+"Container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n}\n\n."+e+"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."+e+"Container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+e+"Text {\n position: relative;\n}\n\n."+e+"Arrow {\n margin-top: 2px;\n position: absolute;\n z-index: 2;\n margin-left: 10px;\n width: 0;\n height: 0;\n}\n"},user:{"default":{html:'<div class="'+e+'Default" \n data-notify-style="\n color: {{color}}; \n border-color: {{color}};\n ">\n <span data-notify="text"></span>\n </div>',css:"."+e+"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:'<div class="alert alert-error '+e+'Bootstrap">\n <strong data-notify-text></strong>\n</div>',css:"."+e+"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"}}}},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},r=function(t){return $("<"+t+"></"+t+">")},p=function(t,n){var o;return o=function(){},o.prototype=t,$.extend(!0,new o,n)},i=r("div").addClass(""+e+"Corner"),s=function(t){var n;return t.is("[type=radio]")&&(n=t.parents("form:first").find("[type=radio]").filter(function(n,o){return $(o).attr("name")===t.attr("name")}),t=n.first()),t},h=function(t){var n;if(t&&t.css){n=t.cssElem,n||(n=r("style"),$("head").append(n),t.cssElem=n);try{return n.html(t.css)}catch(o){return n[0].styleSheet.cssText=t.css}}},o=function(){function t(t,n,o){"string"==typeof o&&(o={color:o}),this.options=p(u,$.isPlainObject(o)?o:{}),this.loadCSS(),this.loadHTML(),this.wrapper=$(c.core.html),this.wrapper.data(e,this),this.arrow=this.wrapper.find("."+e+"Arrow"),this.container=this.wrapper.find("."+e+"Container"),this.container.append(this.userContainer),t&&t.length?(this.elementType=t.attr("type"),this.originalElement=t,this.elem=s(t),this.elem.data(e,this),this.elem.before(this.wrapper)):(this.options.arrowShow=!1,i.prepend(this.wrapper)),this.container.hide(),this.run(n)}return t.prototype.loadCSS=function(t){var n;return t||(n=this.options.style,t=this.getStyle(n)),h(t)},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)throw"style: "+name+" HTML is missing the: data-notify='text' attribute";return this.text.addClass(""+e+"Text")},t.prototype.show=function(t,n){var o,e,i,r;return null==n&&(n=$.noop),r=this.container.parent().parents(":hidden").length>0,e=this.container.add(this.arrow),o=[],r&&t?i="show":r&&!t?i="hide":!r&&t?(i=this.options.showAnimation,o.push(this.optLine truncated
*/(function(t,n,o){"use strict";var e,i,r,s,a,p,h,l,u,d,c,f,w,y;c="notify",i="__"+c,w={t:"top",m:"middle",b:"bottom",l:"left",c:"center",r:"right"},u={t:"b",m:null,b:"t",l:"r",c:null,r:"l"},d=function(t){var n;return n=[],$.each(t.split(/\W+/),function(t,e){var i;return i=e.toLowerCase().charAt(0),w[i]?n.push(i):o}),n},y={core:{html:'<div class="'+i+'Wrapper">\n <div class="'+i+'Arrow"></div>\n <div class="'+i+'Container"></div>\n</div>',css:"."+i+"Corner {\n position: fixed;\n top: 0;\n right: 0;\n margin: 5px;\n z-index: 1050;\n}\n\n."+i+"Corner ."+i+"Wrapper,\n."+i+"Corner ."+i+"Container {\n position: relative;\n display: block;\n height: inherit;\n width: inherit;\n}\n\n."+i+"Wrapper {\n z-index: 1;\n position: absolute;\n display: inline-block;\n height: 0;\n width: 0;\n border: thin solid red;\n}\n\n."+i+"Container {\n display: none;\n z-index: 1;\n position: absolute;\n cursor: pointer;\n}\n\n."+i+"Text {\n position: relative;\n}\n\n."+i+"Arrow {\n margin-top: 2px;\n position: absolute;\n z-index: 2;\n margin-left: 10px;\n width: 0;\n height: 0;\n}\n"},user:{"default":{html:'<div class="'+i+'Default" \n data-notify-style="\n color: {{color}}; \n border-color: {{color}};\n ">\n <span data-notify-text></span>\n </div>',css:"."+i+"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:'<div class="alert alert-error '+i+'Bootstrap">\n <strong data-notify-text></strong>\n</div>',css:"."+i+"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"}}}},f={autoHide:!1,autoHideDelay:2e3,arrowShow:!1,arrowSize:5,position:"bottom",style:"default",color:"red",colors:{red:"#b94a48",green:"#33be40",black:"#393939",blue:"#00f"},showAnimation:"slideDown",showDuration:400,hideAnimation:"slideUp",hideDuration:200,offsetY:2,offsetX:0},s=function(t){return $("<"+t+"></"+t+">")},h=function(t,n){var o;return o=function(){},o.prototype=t,$.extend(!0,new o,n)},r=s("div").addClass(""+i+"Corner"),a=function(t){var n;return t.is("[type=radio]")&&(n=t.parents("form:first").find("[type=radio]").filter(function(n,o){return $(o).attr("name")===t.attr("name")}),t=n.first()),t},p=function(t,n,e,i){var r,s;if(null==i&&(i=!0),"string"==typeof e)e=parseInt(e,10);else if("number"!=typeof e)return;if(!isNaN(e)){if(r=w[u[n.charAt(0)]],s=n,t[r]!==o){if(!i)return;n=w[r.charAt(0)],e*=-1}return t[n]===o?t[n]=e:t[n]+=e,console.log("incr ("+r+">>"+s+") "+n+" by "+e),null}},l=function(t){var n;if(t&&t.css&&(n=t.cssElem,!n)){n=s("style"),$("head").append(n),t.cssElem=n;try{return n.html(t.css)}catch(o){return n[0].styleSheet.cssText=t.css}}},e=function(){function t(t,n,o){"string"==typeof o&&(o={color:o}),this.options=h(f,$.isPlainObject(o)?o:{}),this.loadCSS(),this.loadHTML(),this.wrapper=$(y.core.html),this.wrapper.data(i,this),this.arrow=this.wrapper.find("."+i+"Arrow"),this.container=this.wrapper.find("."+i+"Container"),this.container.append(this.userContainer),t&&t.length?(this.elementType=t.attr("type"),this.originalElement=t,this.elem=a(t),this.elem.data(i,this),this.elem.before(this.wrapper)):(this.options.arrowShow=!1,r.prepend(this.wrapper)),this.container.hide(),this.run(n)}return t.prototype.loadCSS=function(t){var n;return t||(n=this.options.style,t=this.getStyle(n)),l(t)},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)throw"Line truncated
+17 -3
View File
@@ -6,7 +6,18 @@
<style type="text/css">
.box { padding: 30px; }
.boxes {
margin: 150px;
}
.box {
padding: 10px;
margin: 10px;
border: thin solid blue;
width: 100px;
}
.wrapper {
margin-top: 50px
}
</style>
<div class="boxes"></div>
@@ -19,8 +30,11 @@
$.each(positions, function(i, p) {
var box = $("<div class=\"box\">"+p+"</div>");
boxes.append(box);
box.notify(p, {pos: p});
boxes.append($("<div class=\"wrapper\"/>").append(box));
setTimeout(function() {
box.notify(p, {position: p});
}, 500)
});
</script>
+76 -29
View File
@@ -5,12 +5,19 @@
pluginName = 'notify'
className = '__'+pluginName
positions =
t: 'top'
m: 'middle'
b: 'bottom'
l: 'left'
c: 'center'
r: 'right'
#positions mapped to opposites
vPositions =
opposites =
t: 'b'
m: null
b: 't'
hPositions =
l: 'r'
c: null
r: 'l'
@@ -18,9 +25,8 @@ hPositions =
parsePosition = (str) ->
pos = []
$.each str.split(/\W+/), (i,word) ->
w = word.toLowerCase()[0]
pos.push w if vPositions[w]
pos.push w if hPositions[w]
w = word.toLowerCase().charAt(0)
pos.push w if positions[w]
pos
#built-in styles
@@ -55,7 +61,7 @@ styles =
display: inline-block;
height: 0;
width: 0;
opacity: 0.85;
border: thin solid red;
}
.#{className}Container {
@@ -87,7 +93,7 @@ styles =
color: {{color}};
border-color: {{color}};
">
<span data-notify="text"></span>
<span data-notify-text></span>
</div>
"""
css: """
@@ -134,7 +140,7 @@ pluginOptions =
arrowSize: 5
position: 'bottom'
# Default style
style: null
style: 'default'
# Default color
color: 'red'
# Color mappings
@@ -154,7 +160,8 @@ pluginOptions =
#parents: { '.ui-dialog': 5001 }
# plugin helpers
createElem = (tag) -> $ "<#{tag}></#{tag}>"
createElem = (tag) ->
$ "<#{tag}></#{tag}>"
inherit = (a, b) ->
F = () ->
F.prototype = a
@@ -173,10 +180,38 @@ getAnchorElement = (element) ->
#custom-styled inputs - find thier real element
element
incr = (obj, pos, val, useOpposite = true) ->
# console.log "incr ---- #{pos} #{val} (#{typeof val})"
if typeof val is 'string'
val = parseInt val, 10
else if typeof val isnt 'number'
return
return if isNaN val
opp = positions[opposites[pos.charAt(0)]]
temp = pos
#use the opposite if exists
if obj[opp] isnt `undefined`
return unless useOpposite
pos = positions[opp.charAt(0)]
val *= -1
if obj[pos] is `undefined`
obj[pos] = val
else
obj[pos] += val
console.log "incr (#{opp}>>#{temp}) #{pos} by #{val}"
null
insertCSS = (style) ->
return unless style and style.css
elem = style.cssElem
unless elem
return if elem
elem = createElem("style")
$("head").append elem
style.cssElem = elem
@@ -230,9 +265,9 @@ class Notification
loadHTML: ->
style = @getStyle()
@userContainer = $(style.html)
@text = @userContainer.find '[data-notify=text]'
@text = @userContainer.find '[data-notify-text]'
if @text.length is 0
throw "style: #{name} HTML is missing the: data-notify='text' attribute"
throw "style: #{name} HTML is missing the: 'data-notify-text' attribute"
@text.addClass "#{className}Text"
show: (show, callback = $.noop) ->
@@ -261,32 +296,43 @@ class Notification
return unless @elem
#
elementPosition = @elem.position()
mainPosition = @wrapper.position()
wrapperPosition = @wrapper.position()
#
position = @getPosition()
console.log @elem[0]
console.log "update position", position, " elem ", elementPosition, " main ", wrapperPosition
#start calculations
p =
top: 0
left: 0
switch position
when 'bottom'
p.top += @elem.outerHeight()
when 'right'
p.left += @elem.width()
p = {}
switch position[0]
when 'b'
incr p, 'top', @elem.outerHeight()
when 't'
incr p, 'bottom', 0
when 'l'
incr p, 'right', 0
when 'r'
incr p, 'left', @elem.outerWidth()
else
throw "Unknown position: #{position}"
#elem vs wrapper corrections
p.top += (elementPosition.top - mainPosition.top) unless navigator.userAgent.match /MSIE/
p.left += elementPosition.left - mainPosition.left
unless navigator.userAgent.match /MSIE/
incr p, 'top', (elementPosition.top - wrapperPosition.top)
incr p, 'left', elementPosition.left - wrapperPosition.left
# console.log "corrent margin"
# for pos in ['top','right','bottom','left']
# incr p, pos, @elem.css("margin-#{pos}"), false
#set user offset
p.top += @options.offsetY
p.left += @options.offsetX
# p.top += @options.offsetY
# p.left += @options.offsetX
@updateArrow p, position
# @updateArrow p, position
# if @setCSS
# @container.stop().animate(p)
@@ -344,7 +390,6 @@ class Notification
getStyle: (name) ->
name = @options.style unless name
name = 'bootstrap' if bootstrapDetected and not name
name = 'default' unless name
style = styles.user[name]
throw "Missing style: #{name}" unless style
@@ -379,7 +424,6 @@ class Notification
else
@text.empty().append(data)
@updatePosition()
@show true
@@ -438,13 +482,16 @@ $[pluginName].options = (options) ->
$[pluginName].styles = (s) ->
$.extend true, styles.user, s
$[pluginName].insertCSS = insertCSS
# $( ... ).pluginName( { .. } ) creates a cached instance on each
$.fn[pluginName] = (data, options) ->
$(@).each ->
inst = getAnchorElement($(@)).data className
inst = getAnchorElement($(@)).data(className)
if inst
inst.run data, options
else
new Notification $(@), data, options
@