This commit is contained in:
Jaime Pillora
2013-04-16 15:57:38 +10:00
parent 54d3e7822c
commit ec89df8d00
3 changed files with 30 additions and 31 deletions
+16 -17
View File
@@ -1,11 +1,11 @@
/** Notify.js - v0.0.1 - 2013/04/11
/** Notify.js - v0.0.1 - 2013/04/16
* http://notifyjs.com/
* Copyright (c) 2013 Jaime Pillora - MIT
*/
(function(window,document,undefined) {
'use strict';
var Notification, arrowDirs, bootstrapDetected, className, cornerElem, create, getAnchorElement, inherit, insertCSS, pluginName, pluginOptions, styles;
var Notification, arrowDirs, bootstrapDetected, className, cornerElem, createElem, getAnchorElement, inherit, insertCSS, pluginName, pluginOptions, styles;
pluginName = 'notify';
@@ -62,8 +62,8 @@ pluginOptions = {
offsetX: 0
};
create = function(tag) {
return $(document.createElement(tag));
createElem = function(tag) {
return $("<" + tag + "></" + tag + ">");
};
inherit = function(a, b) {
@@ -73,20 +73,16 @@ inherit = function(a, b) {
return $.extend(true, new F(), b);
};
cornerElem = create("div").addClass("" + className + "Corner");
cornerElem = createElem("div").addClass("" + className + "Corner");
getAnchorElement = function(element) {
var fBefore, radios;
var radios;
if (element.is('[type=radio]')) {
radios = element.parents('form:first').find('[type=radio]').filter(function(i, e) {
return $(e).attr('name') === element.attr('name');
});
element = radios.first();
}
fBefore = element.prev();
if (fBefore.is('span.styled,span.OBS_checkbox')) {
element = fBefore;
}
return element;
};
@@ -96,12 +92,15 @@ insertCSS = function(style) {
return;
}
elem = style.cssElem;
if (elem) {
return elem.html(style.css);
} else {
elem = create("style").attr('type', 'text/css').html(style.css);
if (!elem) {
elem = createElem("style");
$("head").append(elem);
return style.cssElem = elem;
style.cssElem = elem;
}
try {
return elem.html(style.css);
} catch (e) {
return elem[0].styleSheet.cssText = style.css;
}
};
@@ -175,7 +174,7 @@ Notification = (function() {
args.push(this.options.hideDuration);
}
args.push(callback);
return elems[fn].apply(elems, callback);
return elems[fn].apply(elems, args);
};
Notification.prototype.updatePosition = function() {
@@ -342,7 +341,7 @@ $(function() {
});
$[pluginName] = function(elem, data, options) {
if (elem instanceof HTMLElement || elem.jquery) {
if ((elem && elem.nodeName) || elem.jquery) {
return $(elem)[pluginName](data, options);
} else {
options = data;
+2 -2
View File
File diff suppressed because one or more lines are too long
+12 -12
View File
@@ -143,8 +143,8 @@ pluginOptions =
#parents: { '.ui-dialog': 5001 }
# plugin helpers
create = (tag) ->
$ document.createElement(tag)
createElem = (tag) ->
$ "<#{tag}></#{tag}>"
inherit = (a, b) ->
F = () ->
@@ -152,7 +152,7 @@ inherit = (a, b) ->
$.extend true, new F(), b
# container for element-less notifications
cornerElem = create("div").addClass("#{className}Corner")
cornerElem = createElem("div").addClass("#{className}Corner")
#gets first on n radios, and gets the fancy stylised input for hidden inputs
getAnchorElement = (element) ->
@@ -162,20 +162,21 @@ getAnchorElement = (element) ->
$(e).attr('name') is element.attr('name')
element = radios.first()
#custom-styled inputs - find thier real element
fBefore = element.prev()
element = fBefore if fBefore.is('span.styled,span.OBS_checkbox')
element
insertCSS = (style) ->
return unless style and style.css
elem = style.cssElem
if elem
elem.html style.css
else
elem = create("style").attr('type','text/css').html style.css
unless elem
elem = createElem("style")
$("head").append elem
style.cssElem = elem
try
elem.html style.css
catch e #ie fix
elem[0].styleSheet.cssText = style.css
#define plugin
class Notification
@@ -245,7 +246,7 @@ class Notification
args.push callback
elems[fn].apply elems, callback
elems[fn].apply elems, args
updatePosition: ->
return unless @elem
@@ -400,8 +401,7 @@ $ ->
# return alert "$.#{pluginName} already defined" if $[pluginName]?
# $.pluginName( { ... } ) changes options for all instances
$[pluginName] = (elem, data, options) ->
if elem instanceof HTMLElement or
elem.jquery
if (elem and elem.nodeName) or elem.jquery
$(elem)[pluginName](data, options)
else
options = data