4chan-x/src/classes/Notice.js
ccd0 98dcd7cd34 Rename files from .coffee to .js.
for f in src/*/*.coffee; do git mv -- "$f" "${f/.coffee/.js}"; done
2023-03-13 13:07:48 -07:00

49 lines
1.4 KiB
JavaScript

/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
class Notice {
constructor(type, content, timeout, onclose) {
this.add = this.add.bind(this);
this.close = this.close.bind(this);
this.timeout = timeout;
this.onclose = onclose;
this.el = $.el('div',
{innerHTML: "<a href=\"javascript:;\" class=\"close fa fa-times\" title=\"Close\"></a><div class=\"message\"></div>"});
this.el.style.opacity = 0;
this.setType(type);
$.on(this.el.firstElementChild, 'click', this.close);
if (typeof content === 'string') {
content = $.tn(content);
}
$.add(this.el.lastElementChild, content);
$.ready(this.add);
}
setType(type) {
return this.el.className = `notification ${type}`;
}
add() {
if (this.closed) { return; }
if (d.hidden) {
$.on(d, 'visibilitychange', this.add);
return;
}
$.off(d, 'visibilitychange', this.add);
$.add(Header.noticesRoot, this.el);
this.el.clientHeight; // force reflow
this.el.style.opacity = 1;
if (this.timeout) { return setTimeout(this.close, this.timeout * $.SECOND); }
}
close() {
this.closed = true;
$.off(d, 'visibilitychange', this.add);
$.rm(this.el);
return this.onclose?.();
}
}