aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display/search-persistent-state-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/display/search-persistent-state-controller.js')
-rw-r--r--ext/js/display/search-persistent-state-controller.js27
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;
+ }
+ }
}