diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-11-27 12:48:14 -0500 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-11-27 12:48:14 -0500 |
commit | 4da4827bcbcdd1ef163f635d9b29416ff272b0bb (patch) | |
tree | a8a0f1a8befdb78a554e1be91f2c6059ca3ad5f9 /ext/js/display/search-persistent-state-controller.js | |
parent | fd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff) |
Add JSDoc type annotations to project (rebased)
Diffstat (limited to 'ext/js/display/search-persistent-state-controller.js')
-rw-r--r-- | ext/js/display/search-persistent-state-controller.js | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/ext/js/display/search-persistent-state-controller.js b/ext/js/display/search-persistent-state-controller.js index 60155143..d92ddf68 100644 --- a/ext/js/display/search-persistent-state-controller.js +++ b/ext/js/display/search-persistent-state-controller.js @@ -18,12 +18,17 @@ import {EventDispatcher} from '../core.js'; +/** + * @augments EventDispatcher<import('display').SearchPersistentStateControllerEventType> + */ export class SearchPersistentStateController extends EventDispatcher { constructor() { super(); + /** @type {import('display').SearchMode} */ this._mode = null; } + /** @type {import('display').SearchMode} */ get mode() { return this._mode; } @@ -32,12 +37,14 @@ export class SearchPersistentStateController extends EventDispatcher { this._setMode(value, true); } + /** */ prepare() { this._updateMode(); } // Private + /** */ _updateMode() { let mode = null; try { @@ -45,9 +52,13 @@ export class SearchPersistentStateController extends EventDispatcher { } catch (e) { // Browsers can throw a SecurityError when cookie blocking is enabled. } - this._setMode(mode, false); + this._setMode(this._normalizeMode(mode), false); } + /** + * @param {import('display').SearchMode} mode + * @param {boolean} save + */ _setMode(mode, save) { if (mode === this._mode) { return; } if (save) { @@ -65,4 +76,18 @@ export class SearchPersistentStateController extends EventDispatcher { document.documentElement.dataset.searchMode = (mode !== null ? mode : ''); this.trigger('modeChange', {mode}); } + + /** + * @param {?string} mode + * @returns {import('display').SearchMode} + */ + _normalizeMode(mode) { + switch (mode) { + case 'popup': + case 'action-popup': + return mode; + default: + return null; + } + } } |