Begin notification timeout spawned in non-visible page for when it becomes visible again. #932
This commit is contained in:
parent
d7ab5b15fc
commit
7a6dcb5f73
@ -1118,35 +1118,41 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
Notification = (function() {
|
Notification = (function() {
|
||||||
|
var add, close;
|
||||||
|
|
||||||
function Notification(type, content, timeout) {
|
function Notification(type, content, timeout) {
|
||||||
var el;
|
this.timeout = timeout;
|
||||||
this.type = type;
|
this.add = add.bind(this);
|
||||||
|
this.close = close.bind(this);
|
||||||
this.el = $.el('div', {
|
this.el = $.el('div', {
|
||||||
className: "notification " + type,
|
|
||||||
innerHTML: '<a href=javascript:; class=close title=Close>×</a><div class=message></div>'
|
innerHTML: '<a href=javascript:; class=close title=Close>×</a><div class=message></div>'
|
||||||
});
|
});
|
||||||
$.on(this.el.firstElementChild, 'click', this.close.bind(this));
|
this.setType(type);
|
||||||
|
$.on(this.el.firstElementChild, 'click', this.close);
|
||||||
if (typeof content === 'string') {
|
if (typeof content === 'string') {
|
||||||
content = $.tn(content);
|
content = $.tn(content);
|
||||||
}
|
}
|
||||||
$.add(this.el.lastElementChild, content);
|
$.add(this.el.lastElementChild, content);
|
||||||
if (timeout) {
|
$.ready(this.add);
|
||||||
setTimeout(this.close.bind(this), timeout * $.SECOND);
|
|
||||||
}
|
|
||||||
el = this.el;
|
|
||||||
$.ready(function() {
|
|
||||||
return $.add($.id('notifications'), el);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification.prototype.setType = function(type) {
|
Notification.prototype.setType = function(type) {
|
||||||
$.rmClass(this.el, this.type);
|
return this.el.className = "notification " + type;
|
||||||
$.addClass(this.el, type);
|
|
||||||
return this.type = type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Notification.prototype.close = function() {
|
add = function() {
|
||||||
|
if (d.hidden) {
|
||||||
|
$.on(d, 'visibilitychange', this.add);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$.off(d, 'visibilitychange', this.add);
|
||||||
|
$.add($.id('notifications'), this.el);
|
||||||
|
if (this.timeout) {
|
||||||
|
return setTimeout(this.close, this.timeout * $.SECOND);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
close = function() {
|
||||||
if (this.el.parentNode) {
|
if (this.el.parentNode) {
|
||||||
return $.rm(this.el);
|
return $.rm(this.el);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,28 +90,32 @@ Header =
|
|||||||
Header.menu.toggle e, @, g
|
Header.menu.toggle e, @, g
|
||||||
|
|
||||||
class Notification
|
class Notification
|
||||||
constructor: (@type, content, timeout) ->
|
constructor: (type, content, @timeout) ->
|
||||||
|
@add = add.bind @
|
||||||
|
@close = close.bind @
|
||||||
|
|
||||||
@el = $.el 'div',
|
@el = $.el 'div',
|
||||||
className: "notification #{type}"
|
|
||||||
innerHTML: '<a href=javascript:; class=close title=Close>×</a><div class=message></div>'
|
innerHTML: '<a href=javascript:; class=close title=Close>×</a><div class=message></div>'
|
||||||
$.on @el.firstElementChild, 'click', @close.bind @
|
@setType type
|
||||||
|
$.on @el.firstElementChild, 'click', @close
|
||||||
if typeof content is 'string'
|
if typeof content is 'string'
|
||||||
content = $.tn content
|
content = $.tn content
|
||||||
$.add @el.lastElementChild, content
|
$.add @el.lastElementChild, content
|
||||||
|
|
||||||
if timeout
|
$.ready @add
|
||||||
setTimeout @close.bind(@), timeout * $.SECOND
|
|
||||||
|
|
||||||
el = @el
|
|
||||||
$.ready ->
|
|
||||||
$.add $.id('notifications'), el
|
|
||||||
|
|
||||||
setType: (type) ->
|
setType: (type) ->
|
||||||
$.rmClass @el, @type
|
@el.className = "notification #{type}"
|
||||||
$.addClass @el, type
|
|
||||||
@type = type
|
|
||||||
|
|
||||||
close: ->
|
add = ->
|
||||||
|
if d.hidden
|
||||||
|
$.on d, 'visibilitychange', @add
|
||||||
|
return
|
||||||
|
$.off d, 'visibilitychange', @add
|
||||||
|
$.add $.id('notifications'), @el
|
||||||
|
setTimeout @close, @timeout * $.SECOND if @timeout
|
||||||
|
|
||||||
|
close = ->
|
||||||
$.rm @el if @el.parentNode
|
$.rm @el if @el.parentNode
|
||||||
|
|
||||||
Settings =
|
Settings =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user