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/pages/settings/nested-popups-controller.js | |
parent | fd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff) |
Add JSDoc type annotations to project (rebased)
Diffstat (limited to 'ext/js/pages/settings/nested-popups-controller.js')
-rw-r--r-- | ext/js/pages/settings/nested-popups-controller.js | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/ext/js/pages/settings/nested-popups-controller.js b/ext/js/pages/settings/nested-popups-controller.js index b9621ef0..ac078a0c 100644 --- a/ext/js/pages/settings/nested-popups-controller.js +++ b/ext/js/pages/settings/nested-popups-controller.js @@ -19,50 +19,79 @@ import {DocumentUtil} from '../../dom/document-util.js'; export class NestedPopupsController { + /** + * @param {SettingsController} settingsController + */ constructor(settingsController) { + /** @type {SettingsController} */ this._settingsController = settingsController; + /** @type {number} */ this._popupNestingMaxDepth = 0; + /** @type {?HTMLInputElement} */ + this._nestedPopupsEnabled = null; + /** @type {?HTMLInputElement} */ + this._nestedPopupsCount = null; + /** @type {?HTMLElement} */ + this._nestedPopupsEnabledMoreOptions = null; } + /** */ async prepare() { - this._nestedPopupsEnabled = document.querySelector('#nested-popups-enabled'); - this._nestedPopupsCount = document.querySelector('#nested-popups-count'); - this._nestedPopupsEnabledMoreOptions = document.querySelector('#nested-popups-enabled-more-options'); + this._nestedPopupsEnabled = /** @type {HTMLInputElement} */ (document.querySelector('#nested-popups-enabled')); + this._nestedPopupsCount = /** @type {HTMLInputElement} */ (document.querySelector('#nested-popups-count')); + this._nestedPopupsEnabledMoreOptions = /** @type {HTMLElement} */ (document.querySelector('#nested-popups-enabled-more-options')); const options = await this._settingsController.getOptions(); + const optionsContext = this._settingsController.getOptionsContext(); this._nestedPopupsEnabled.addEventListener('change', this._onNestedPopupsEnabledChange.bind(this), false); this._nestedPopupsCount.addEventListener('change', this._onNestedPopupsCountChange.bind(this), false); this._settingsController.on('optionsChanged', this._onOptionsChanged.bind(this)); - this._onOptionsChanged({options}); + this._onOptionsChanged({options, optionsContext}); } // Private + /** + * @param {import('settings-controller').OptionsChangedEvent} details + */ _onOptionsChanged({options}) { this._updatePopupNestingMaxDepth(options.scanning.popupNestingMaxDepth); } + /** + * @param {Event} e + */ _onNestedPopupsEnabledChange(e) { - const value = e.currentTarget.checked; + const node = /** @type {HTMLInputElement} */ (e.currentTarget); + const value = node.checked; if (value && this._popupNestingMaxDepth > 0) { return; } this._setPopupNestingMaxDepth(value ? 1 : 0); } + /** + * @param {Event} e + */ _onNestedPopupsCountChange(e) { - const node = e.currentTarget; + const node = /** @type {HTMLInputElement} */ (e.currentTarget); const value = Math.max(1, DocumentUtil.convertElementValueToNumber(node.value, node)); this._setPopupNestingMaxDepth(value); } + /** + * @param {number} value + */ _updatePopupNestingMaxDepth(value) { const enabled = (value > 0); this._popupNestingMaxDepth = value; - this._nestedPopupsEnabled.checked = enabled; - this._nestedPopupsCount.value = `${value}`; - this._nestedPopupsEnabledMoreOptions.hidden = !enabled; + /** @type {HTMLInputElement} */ (this._nestedPopupsEnabled).checked = enabled; + /** @type {HTMLInputElement} */ (this._nestedPopupsCount).value = `${value}`; + /** @type {HTMLElement} */ (this._nestedPopupsEnabledMoreOptions).hidden = !enabled; } + /** + * @param {number} value + */ async _setPopupNestingMaxDepth(value) { this._updatePopupNestingMaxDepth(value); await this._settingsController.setProfileSetting('scanning.popupNestingMaxDepth', value); |