summaryrefslogtreecommitdiff
path: root/ext/js/display/display-notification.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/display/display-notification.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/display/display-notification.js')
-rw-r--r--ext/js/display/display-notification.js32
1 files changed, 30 insertions, 2 deletions
diff --git a/ext/js/display/display-notification.js b/ext/js/display/display-notification.js
index 0c26c613..d1cfa537 100644
--- a/ext/js/display/display-notification.js
+++ b/ext/js/display/display-notification.js
@@ -19,23 +19,36 @@
import {EventListenerCollection} from '../core.js';
export class DisplayNotification {
+ /**
+ * @param {HTMLElement} container
+ * @param {HTMLElement} node
+ */
constructor(container, node) {
+ /** @type {HTMLElement} */
this._container = container;
+ /** @type {HTMLElement} */
this._node = node;
- this._body = node.querySelector('.footer-notification-body');
- this._closeButton = node.querySelector('.footer-notification-close-button');
+ /** @type {HTMLElement} */
+ this._body = /** @type {HTMLElement} */ (node.querySelector('.footer-notification-body'));
+ /** @type {HTMLElement} */
+ this._closeButton = /** @type {HTMLElement} */ (node.querySelector('.footer-notification-close-button'));
+ /** @type {EventListenerCollection} */
this._eventListeners = new EventListenerCollection();
+ /** @type {?import('core').Timeout} */
this._closeTimer = null;
}
+ /** @type {HTMLElement} */
get container() {
return this._container;
}
+ /** @type {HTMLElement} */
get node() {
return this._node;
}
+ /** */
open() {
if (!this.isClosed()) { return; }
@@ -50,6 +63,9 @@ export class DisplayNotification {
this._eventListeners.addEventListener(this._closeButton, 'click', this._onCloseButtonClick.bind(this), false);
}
+ /**
+ * @param {boolean} [animate]
+ */
close(animate=false) {
if (this.isClosed()) { return; }
@@ -69,6 +85,9 @@ export class DisplayNotification {
}
}
+ /**
+ * @param {string|Node} value
+ */
setContent(value) {
if (typeof value === 'string') {
this._body.textContent = value;
@@ -78,25 +97,34 @@ export class DisplayNotification {
}
}
+ /**
+ * @returns {boolean}
+ */
isClosing() {
return this._closeTimer !== null;
}
+ /**
+ * @returns {boolean}
+ */
isClosed() {
return this._node.parentNode === null;
}
// Private
+ /** */
_onCloseButtonClick() {
this.close(true);
}
+ /** */
_onDelayClose() {
this._closeTimer = null;
this.close(false);
}
+ /** */
_clearTimer() {
if (this._closeTimer !== null) {
clearTimeout(this._closeTimer);