This commit is contained in:
Jaime Pillora
2013-06-03 09:18:04 +10:00
+27 -33
View File
@@ -6,7 +6,7 @@ pluginName = 'notify'
className = '__'+pluginName className = '__'+pluginName
positions = positions =
t: 'top' t: 'top'
m: 'middle' m: 'middle'
b: 'bottom' b: 'bottom'
@@ -96,34 +96,28 @@ styles =
""" """
user: user:
default: bootstrap:
html: """ html: """
<div class="#{className}Default" <div>
data-notify-style="
color: {{color}};
border-color: {{color}};
">
<span data-notify-text></span> <span data-notify-text></span>
</div> </div>
""" """
css: """ classes:
.#{className}Default { base: """
background: #fff; padding: 8px 35px 8px 14px;
font-size: 11px; margin-bottom: 20px;
box-shadow: 0 0 6px #000; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
-moz-box-shadow: 0 0 6px #000; background-color: #fcf8e3;
-webkit-box-shadow: 0 0 6px #000; border: 1px solid #fbeed5;
padding: 4px 10px 4px 8px; -webkit-border-radius: 4px;
border-radius: 6px; -moz-border-radius: 4px;
border-style: solid; border-radius: 4px;
border-width: 2px; """
-moz-border-radius: 6px; error:
-webkit-border-radius: 6px; info:
white-space: nowrap; warn:
}
"""
bootstrap: bootstrap:
html: """ html: """
<div class="alert alert-error #{className}Bootstrap"> <div class="alert alert-error #{className}Bootstrap">
<strong data-notify-text></strong> <strong data-notify-text></strong>
@@ -199,7 +193,7 @@ incr = (obj, pos, val) ->
return if isNaN val return if isNaN val
opp = positions[opposites[pos.charAt(0)]] opp = positions[opposites[pos.charAt(0)]]
temp = pos temp = pos
#use the opposite if exists #use the opposite if exists
@@ -230,14 +224,14 @@ insertCSS = (style) ->
$("head").append elem $("head").append elem
style.cssElem = elem style.cssElem = elem
try try
elem.html style.css elem.html style.css
catch e #ie fix catch e #ie fix
elem[0].styleSheet.cssText = style.css elem[0].styleSheet.cssText = style.css
#define plugin #define plugin
class Notification class Notification
#setup instance variables #setup instance variables
constructor: (elem, data, options) -> constructor: (elem, data, options) ->
options = {color: options} if typeof options is 'string' options = {color: options} if typeof options is 'string'
@@ -287,7 +281,7 @@ class Notification
show: (show, callback = $.noop) -> show: (show, callback = $.noop) ->
hidden = @container.parent().parents(':hidden').length > 0 hidden = @container.parent().parents(':hidden').length > 0
elems = @container.add @arrow elems = @container.add @arrow
args = [] args = []
@@ -306,7 +300,7 @@ class Notification
args.push callback args.push callback
elems[fn].apply elems, args elems[fn].apply elems, args
updatePosition: -> updatePosition: ->
return unless @elem return unless @elem
@@ -341,7 +335,7 @@ class Notification
# unless navigator.userAgent.match /MSIE/ # unless navigator.userAgent.match /MSIE/
# incr css, 'top', (elemPos.top - wrapPos.top) # incr css, 'top', (elemPos.top - wrapPos.top)
incr css, 'left', elemPos.left - wrapPos.left incr css, 'left', elemPos.left - wrapPos.left
#correct for left margin #correct for left margin
margin = parseInt @elem.css("margin-left"), 10 margin = parseInt @elem.css("margin-left"), 10
incr css, 'left', margin if margin incr css, 'left', margin if margin
@@ -391,7 +385,7 @@ class Notification
pos[0] = 'b' if pos.length is 0 pos[0] = 'b' if pos.length is 0
if pos[0] not in mainPositions if pos[0] not in mainPositions
throw "Must be one of [#{mainPositions}]" throw "Must be one of [#{mainPositions}]"
#validate alignment #validate alignment
if pos.length is 1 or if pos.length is 1 or
(pos[0] in vAligns and pos[1] not in hAligns) or (pos[0] in vAligns and pos[1] not in hAligns) or
@@ -410,7 +404,7 @@ class Notification
styleColors = @getStyle().colors styleColors = @getStyle().colors
return (styleColors and return (styleColors and
styleColors[@options.color]) or styleColors[@options.color]) or
@options.colors[@options.color] or @options.colors[@options.color] or
@options.color @options.color
getStyle: (name) -> getStyle: (name) ->
@@ -432,7 +426,7 @@ class Notification
run: (data, options) -> run: (data, options) ->
#update options #update options
if $.isPlainObject(options) if $.isPlainObject(options)
$.extend @options, options $.extend @options, options
#shortcut special case #shortcut special case
else if $.type(options) is 'string' else if $.type(options) is 'string'
@options.color = options @options.color = options