refactoring of cmaps, widgets, etc.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/** Manage a status element and optional automatic clearing of its message. */
|
||||
export class StatusField {
|
||||
constructor(element, visibleClass = "") {
|
||||
this.element = element;
|
||||
this.visibleClass = visibleClass;
|
||||
this.timer = null;
|
||||
}
|
||||
|
||||
set(message) {
|
||||
window.clearTimeout(this.timer);
|
||||
this.timer = null;
|
||||
this.element.textContent = message || "";
|
||||
if (this.visibleClass) {
|
||||
this.element.classList.toggle(this.visibleClass, Boolean(message));
|
||||
}
|
||||
}
|
||||
|
||||
showTemporarily(message, duration = 1800) {
|
||||
this.set(message);
|
||||
if (!message) return;
|
||||
this.timer = window.setTimeout(() => this.clear(), duration);
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.set("");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user