aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/secondary-search-dictionary-controller.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/pages/settings/secondary-search-dictionary-controller.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
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..b20bd475 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 {import('./settings-controller.js').SettingsController} settingsController
+ */
constructor(settingsController) {
+ /** @type {import('./settings-controller.js').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});
}
}