diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-12-16 19:55:02 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-17 00:55:02 +0000 |
commit | 95ad1ae1ef4a53802c12eab4c9b1545af0333aa1 (patch) | |
tree | c08016ccb3265a5931baf413cd9d78fcbf600ae9 /ext/js/pages/settings/permissions-origin-controller.js | |
parent | 77d27113d347b4724302f1c72de1f238e04aeead (diff) |
Safer query selector (#364)
* Add querySelectorNotNull helper function
* Use querySelectorNotNull
* Updates
* Update settings
* Remove unused
* Update
* Update function calls
* More updates
* Update types
* Remove obsolete code
Diffstat (limited to 'ext/js/pages/settings/permissions-origin-controller.js')
-rw-r--r-- | ext/js/pages/settings/permissions-origin-controller.js | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/ext/js/pages/settings/permissions-origin-controller.js b/ext/js/pages/settings/permissions-origin-controller.js index a4271f92..6dacced8 100644 --- a/ext/js/pages/settings/permissions-origin-controller.js +++ b/ext/js/pages/settings/permissions-origin-controller.js @@ -17,6 +17,7 @@ */ import {EventListenerCollection} from '../../core.js'; +import {querySelectorNotNull} from '../../dom/query-selector.js'; export class PermissionsOriginController { /** @@ -25,16 +26,16 @@ export class PermissionsOriginController { constructor(settingsController) { /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; - /** @type {?HTMLElement} */ - this._originContainer = null; - /** @type {?HTMLElement} */ - this._originEmpty = null; + /** @type {HTMLElement} */ + this._originContainer = querySelectorNotNull(document, '#permissions-origin-list'); + /** @type {HTMLElement} */ + this._originEmpty = querySelectorNotNull(document, '#permissions-origin-list-empty'); /** @type {?NodeListOf<HTMLInputElement>} */ this._originToggleNodes = null; - /** @type {?HTMLInputElement} */ - this._addOriginInput = null; - /** @type {?HTMLElement} */ - this._errorContainer = null; + /** @type {HTMLInputElement} */ + this._addOriginInput = querySelectorNotNull(document, '#permissions-origin-new-input'); + /** @type {HTMLElement} */ + this._errorContainer = querySelectorNotNull(document, '#permissions-origin-list-error'); /** @type {ChildNode[]} */ this._originContainerChildren = []; /** @type {EventListenerCollection} */ @@ -43,12 +44,9 @@ export class PermissionsOriginController { /** */ async prepare() { - this._originContainer = /** @type {HTMLElement} */ (document.querySelector('#permissions-origin-list')); - this._originEmpty = /** @type {HTMLElement} */ (document.querySelector('#permissions-origin-list-empty')); this._originToggleNodes = /** @type {NodeListOf<HTMLInputElement>} */ (document.querySelectorAll('.permissions-origin-toggle')); - this._addOriginInput = /** @type {HTMLInputElement} */ (document.querySelector('#permissions-origin-new-input')); - this._errorContainer = /** @type {HTMLElement} */ (document.querySelector('#permissions-origin-list-error')); - const addButton = /** @type {HTMLButtonElement} */ (document.querySelector('#permissions-origin-add')); + /** @type {HTMLButtonElement} */ + const addButton = querySelectorNotNull(document, '#permissions-origin-add'); for (const node of this._originToggleNodes) { node.addEventListener('change', this._onOriginToggleChange.bind(this), false); @@ -87,8 +85,10 @@ export class PermissionsOriginController { for (const origin of originsSet) { if (excludeOrigins.has(origin)) { continue; } const node = this._settingsController.instantiateTemplateFragment('permissions-origin'); - const input = /** @type {HTMLInputElement} */ (node.querySelector('.permissions-origin-input')); - const menuButton = /** @type {HTMLElement} */ (node.querySelector('.permissions-origin-button')); + /** @type {HTMLInputElement} */ + const input = querySelectorNotNull(node, '.permissions-origin-input'); + /** @type {HTMLElement} */ + const menuButton = querySelectorNotNull(node, '.permissions-origin-button'); input.value = origin; this._eventListeners.addEventListener(menuButton, 'menuClose', this._onOriginMenuClose.bind(this, origin), false); this._originContainerChildren.push(...node.childNodes); |