aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/secondary-search-dictionary-controller.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2023-11-27 12:48:14 -0500
commit4da4827bcbcdd1ef163f635d9b29416ff272b0bb (patch)
treea8a0f1a8befdb78a554e1be91f2c6059ca3ad5f9 /ext/js/pages/settings/secondary-search-dictionary-controller.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
Add JSDoc type annotations to project (rebased)
Diffstat (limited to 'ext/js/pages/settings/secondary-search-dictionary-controller.js')
-rw-r--r--ext/js/pages/settings/secondary-search-dictionary-controller.js40
1 files changed, 30 insertions, 10 deletions
diff --git a/ext/js/pages/settings/secondary-search-dictionary-controller.js b/ext/js/pages/settings/secondary-search-dictionary-controller.js
index cc873901..7c2d3907 100644
--- a/ext/js/pages/settings/secondary-search-dictionary-controller.js
+++ b/ext/js/pages/settings/secondary-search-dictionary-controller.js
@@ -20,16 +20,25 @@ import {EventListenerCollection} from '../../core.js';
import {yomitan} from '../../yomitan.js';
export class SecondarySearchDictionaryController {
+ /**
+ * @param {SettingsController} settingsController
+ */
constructor(settingsController) {
+ /** @type {SettingsController} */
this._settingsController = settingsController;
+ /** @type {?import('core').TokenObject} */
this._getDictionaryInfoToken = null;
+ /** @type {Map<string, import('dictionary-importer').Summary>} */
this._dictionaryInfoMap = new Map();
+ /** @type {EventListenerCollection} */
this._eventListeners = new EventListenerCollection();
+ /** @type {?HTMLElement} */
this._container = null;
}
+ /** */
async prepare() {
- this._container = document.querySelector('#secondary-search-dictionary-list');
+ this._container = /** @type {HTMLElement} */ (document.querySelector('#secondary-search-dictionary-list'));
await this._onDatabaseUpdated();
@@ -40,7 +49,9 @@ export class SecondarySearchDictionaryController {
// Private
+ /** */
async _onDatabaseUpdated() {
+ /** @type {?import('core').TokenObject} */
const token = {};
this._getDictionaryInfoToken = token;
const dictionaries = await this._settingsController.getDictionaryInfo();
@@ -52,10 +63,12 @@ export class SecondarySearchDictionaryController {
this._dictionaryInfoMap.set(entry.title, entry);
}
- const options = await this._settingsController.getOptions();
- this._onOptionsChanged({options});
+ await this._onDictionarySettingsReordered();
}
+ /**
+ * @param {import('settings-controller').OptionsChangedEvent} details
+ */
_onOptionsChanged({options}) {
this._eventListeners.removeAllEventListeners();
@@ -67,31 +80,38 @@ export class SecondarySearchDictionaryController {
const dictionaryInfo = this._dictionaryInfoMap.get(name);
if (typeof dictionaryInfo === 'undefined') { continue; }
- const node = this._settingsController.instantiateTemplate('secondary-search-dictionary');
+ const node = /** @type {HTMLElement} */ (this._settingsController.instantiateTemplate('secondary-search-dictionary'));
fragment.appendChild(node);
- const nameNode = node.querySelector('.dictionary-title');
+ const nameNode = /** @type {HTMLElement} */ (node.querySelector('.dictionary-title'));
nameNode.textContent = name;
- const versionNode = node.querySelector('.dictionary-version');
+ const versionNode = /** @type {HTMLElement} */ (node.querySelector('.dictionary-version'));
versionNode.textContent = `rev.${dictionaryInfo.revision}`;
- const toggle = node.querySelector('.dictionary-allow-secondary-searches');
+ const toggle = /** @type {HTMLElement} */ (node.querySelector('.dictionary-allow-secondary-searches'));
toggle.dataset.setting = `dictionaries[${i}].allowSecondarySearches`;
this._eventListeners.addEventListener(toggle, 'settingChanged', this._onEnabledChanged.bind(this, node), false);
}
- this._container.textContent = '';
- this._container.appendChild(fragment);
+ const container = /** @type {HTMLElement} */ (this._container);
+ container.textContent = '';
+ container.appendChild(fragment);
}
+ /**
+ * @param {HTMLElement} node
+ * @param {import('dom-data-binder').SettingChangedEvent} e
+ */
_onEnabledChanged(node, e) {
const {detail: {value}} = e;
node.dataset.enabled = `${value}`;
}
+ /** */
async _onDictionarySettingsReordered() {
const options = await this._settingsController.getOptions();
- this._onOptionsChanged({options});
+ const optionsContext = this._settingsController.getOptionsContext();
+ this._onOptionsChanged({options, optionsContext});
}
}