4chan-x/src/lib/notification.class
2013-04-16 19:45:39 -07:00

31 lines
808 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Notification
constructor: (type, content, @timeout) ->
@add = add.bind @
@close = close.bind @
@el = $.el 'div',
innerHTML: '<a href=javascript:; class=close title=Close>×</a><div class=message></div>'
@el.style.opacity = 0
@setType type
$.on @el.firstElementChild, 'click', @close
if typeof content is 'string'
content = $.tn content
$.add @el.lastElementChild, content
$.ready @add
setType: (type) ->
@el.className = "notification #{type}"
add = ->
if d.hidden
$.on d, 'visibilitychange', @add
return
$.off d, 'visibilitychange', @add
$.add $.id('notifications'), @el
@el.clientHeight # force reflow
@el.style.opacity = 1
setTimeout @close, @timeout * $.SECOND if @timeout
close = ->
$.rm @el