You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/views/misc/notif.js

87 lines
2.2 KiB

// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS002: Fix invalid constructor
* DS206: Consider reworking classes to avoid initClass
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
const Cls = (app.views.Notif = class Notif extends app.View {
static initClass() {
1 year ago
this.className = "_notif";
this.activeClass = "_in";
this.attributes = { role: "alert" };
this.defautOptions = { autoHide: 15000 };
this.events = { click: "onClick" };
}
11 years ago
constructor(type, options) {
this.onClick = this.onClick.bind(this);
this.type = type;
1 year ago
if (options == null) {
options = {};
}
this.options = options;
this.options = $.extend({}, this.constructor.defautOptions, this.options);
super(...arguments);
}
11 years ago
init() {
this.show();
}
11 years ago
show() {
if (this.timeout) {
clearTimeout(this.timeout);
this.timeout = this.delay(this.hide, this.options.autoHide);
} else {
this.render();
this.position();
this.activate();
this.appendTo(document.body);
this.el.offsetWidth; // force reflow
this.addClass(this.constructor.activeClass);
1 year ago
if (this.options.autoHide) {
this.timeout = this.delay(this.hide, this.options.autoHide);
}
}
}
11 years ago
hide() {
clearTimeout(this.timeout);
this.timeout = null;
this.detach();
}
11 years ago
render() {
this.html(this.tmpl(`notif${this.type}`));
}
11 years ago
position() {
const notifications = $$(`.${app.views.Notif.className}`);
if (notifications.length) {
const lastNotif = notifications[notifications.length - 1];
1 year ago
this.el.style.top =
lastNotif.offsetTop + lastNotif.offsetHeight + 16 + "px";
}
}
11 years ago
onClick(event) {
1 year ago
if (event.which !== 1) {
return;
}
const target = $.eventTarget(event);
1 year ago
if (target.hasAttribute("data-behavior")) {
return;
}
if (target.tagName !== "A" || target.classList.contains("_notif-close")) {
$.stopEvent(event);
this.hide();
}
}
});
Cls.initClass();