2015-01-12 02:03:45 +01:00
|
|
|
class Notifications
|
|
|
|
constructor: (@elem) ->
|
|
|
|
@
|
|
|
|
|
|
|
|
test: ->
|
|
|
|
setTimeout (=>
|
|
|
|
@add("connection", "error", "Connection lost to <b>UiServer</b> on <b>localhost</b>!")
|
|
|
|
@add("message-Anyone", "info", "New from <b>Anyone</b>.")
|
|
|
|
), 1000
|
|
|
|
setTimeout (=>
|
|
|
|
@add("connection", "done", "<b>UiServer</b> connection recovered.", 5000)
|
|
|
|
), 3000
|
|
|
|
|
|
|
|
|
|
|
|
add: (id, type, body, timeout=0) ->
|
|
|
|
@log id, type, body, timeout
|
|
|
|
# Close notifications with same id
|
|
|
|
for elem in $(".notification-#{id}")
|
|
|
|
@close $(elem)
|
|
|
|
|
|
|
|
# Create element
|
|
|
|
elem = $(".notification.template", @elem).clone().removeClass("template")
|
|
|
|
elem.addClass("notification-#{type}").addClass("notification-#{id}")
|
|
|
|
|
|
|
|
# Update text
|
|
|
|
if type == "error"
|
|
|
|
$(".notification-icon", elem).html("!")
|
|
|
|
else if type == "done"
|
|
|
|
$(".notification-icon", elem).html("<div class='icon-success'></div>")
|
2015-01-21 12:58:26 +01:00
|
|
|
else if type == "ask"
|
|
|
|
$(".notification-icon", elem).html("?")
|
2015-01-12 02:03:45 +01:00
|
|
|
else
|
|
|
|
$(".notification-icon", elem).html("i")
|
|
|
|
|
2015-01-21 12:58:26 +01:00
|
|
|
if typeof(body) == "string"
|
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
|
|
|
$(".body", elem).html("<span class='message'>"+body+"</span>")
|
2015-01-21 12:58:26 +01:00
|
|
|
else
|
|
|
|
$(".body", elem).html("").append(body)
|
2015-01-12 02:03:45 +01:00
|
|
|
|
|
|
|
elem.appendTo(@elem)
|
|
|
|
|
|
|
|
# Timeout
|
|
|
|
if timeout
|
|
|
|
$(".close", elem).remove() # No need of close button
|
|
|
|
setTimeout (=>
|
|
|
|
@close elem
|
|
|
|
), timeout
|
|
|
|
|
|
|
|
# Animate
|
|
|
|
width = elem.outerWidth()
|
|
|
|
if not timeout then width += 20 # Add space for close button
|
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
|
|
|
if elem.outerHeight() > 55 then elem.addClass("long")
|
2015-01-12 02:03:45 +01:00
|
|
|
elem.css({"width": "50px", "transform": "scale(0.01)"})
|
|
|
|
elem.animate({"scale": 1}, 800, "easeOutElastic")
|
|
|
|
elem.animate({"width": width}, 700, "easeInOutCubic")
|
version 0.2.7, plugin system, multiuser plugin for zeroproxies, reworked imports, cookie parse, stats moved to plugin, usermanager class, dont generate site auth on listing, multiline notifications, allow server side prompt from user, update script keep plugins disabled status
2015-03-24 01:33:09 +01:00
|
|
|
$(".body", elem).cssLater("box-shadow", "0px 0px 5px rgba(0,0,0,0.1)", 1000)
|
2015-01-12 02:03:45 +01:00
|
|
|
|
|
|
|
# Close button
|
|
|
|
$(".close", elem).on "click", =>
|
|
|
|
@close elem
|
|
|
|
return false
|
|
|
|
|
2015-01-21 12:58:26 +01:00
|
|
|
# Close on button click within body (confirm dialog)
|
|
|
|
$(".button", elem).on "click", =>
|
|
|
|
@close elem
|
|
|
|
return false
|
2015-01-12 02:03:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
close: (elem) ->
|
|
|
|
elem.stop().animate {"width": 0, "opacity": 0}, 700, "easeInOutCubic"
|
|
|
|
elem.slideUp 300, (-> elem.remove())
|
|
|
|
|
|
|
|
|
|
|
|
log: (args...) ->
|
|
|
|
console.log "[Notifications]", args...
|
|
|
|
|
|
|
|
|
|
|
|
window.Notifications = Notifications
|