aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/settings/secondary-search-dictionary-controller.js
diff options
context:
space:
mode:
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});
}
}