diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2024-02-18 08:11:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-18 13:11:47 +0000 |
commit | cfc65c31313731dfa0d36c2eceaca35e9d50992f (patch) | |
tree | ec96ec7ab1c3dae559fe5d7930c186347fb64a25 /ext/js/pages/settings | |
parent | 6cf38229b54efbbc3ae7bc174c3999f9dfa7b1d2 (diff) |
Refactor DocumentUtil (#706)
* Refactor DocumentUtil
* Isolate suppression
Diffstat (limited to 'ext/js/pages/settings')
7 files changed, 17 insertions, 17 deletions
diff --git a/ext/js/pages/settings/generic-setting-controller.js b/ext/js/pages/settings/generic-setting-controller.js index 12db2ab7..7c082a96 100644 --- a/ext/js/pages/settings/generic-setting-controller.js +++ b/ext/js/pages/settings/generic-setting-controller.js @@ -18,7 +18,7 @@ import {ExtensionError} from '../../core/extension-error.js'; import {parseJson} from '../../core/json.js'; -import {DocumentUtil} from '../../dom/document-util.js'; +import {convertElementValueToNumber} from '../../dom/document-util.js'; import {DOMDataBinder} from '../../dom/dom-data-binder.js'; export class GenericSettingController { @@ -328,7 +328,7 @@ export class GenericSettingController { _toNumber(value, data) { /** @type {import('document-util').ToNumberConstraints} */ const constraints = typeof data.constraints === 'object' && data.constraints !== null ? data.constraints : {}; - return typeof value === 'string' ? DocumentUtil.convertElementValueToNumber(value, constraints) : 0; + return typeof value === 'string' ? convertElementValueToNumber(value, constraints) : 0; } /** diff --git a/ext/js/pages/settings/keyboard-mouse-input-field.js b/ext/js/pages/settings/keyboard-mouse-input-field.js index 310cbb19..0c45d4bb 100644 --- a/ext/js/pages/settings/keyboard-mouse-input-field.js +++ b/ext/js/pages/settings/keyboard-mouse-input-field.js @@ -18,7 +18,7 @@ import {EventDispatcher} from '../../core/event-dispatcher.js'; import {EventListenerCollection} from '../../core/event-listener-collection.js'; -import {DocumentUtil} from '../../dom/document-util.js'; +import {getActiveButtons, getActiveModifiers} from '../../dom/document-util.js'; import {HotkeyUtil} from '../../input/hotkey-util.js'; /** @@ -139,7 +139,7 @@ export class KeyboardMouseInputField extends EventDispatcher { * @returns {Set<import('input').ModifierKey>} */ _getModifierKeys(e) { - const modifiers = new Set(DocumentUtil.getActiveModifiers(e)); + const modifiers = new Set(getActiveModifiers(e)); // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/metaKey // https://askubuntu.com/questions/567731/why-is-shift-alt-being-mapped-to-meta // It works with mouse events on some platforms, so try to determine if metaKey is pressed. @@ -216,7 +216,7 @@ export class KeyboardMouseInputField extends EventDispatcher { */ _onMouseButtonMouseDown(e) { e.preventDefault(); - this._addModifiers(DocumentUtil.getActiveButtons(e)); + this._addModifiers(getActiveButtons(e)); } /** @@ -236,7 +236,7 @@ export class KeyboardMouseInputField extends EventDispatcher { return; } e.preventDefault(); - this._addModifiers(DocumentUtil.getActiveButtons(e)); + this._addModifiers(getActiveButtons(e)); } /** diff --git a/ext/js/pages/settings/keyboard-shortcuts-controller.js b/ext/js/pages/settings/keyboard-shortcuts-controller.js index 907cf4a1..0a01b836 100644 --- a/ext/js/pages/settings/keyboard-shortcuts-controller.js +++ b/ext/js/pages/settings/keyboard-shortcuts-controller.js @@ -17,7 +17,7 @@ */ import {EventListenerCollection} from '../../core/event-listener-collection.js'; -import {DocumentUtil} from '../../dom/document-util.js'; +import {convertElementValueToNumber, normalizeModifierKey} from '../../dom/document-util.js'; import {querySelectorNotNull} from '../../dom/query-selector.js'; import {ObjectPropertyAccessor} from '../../general/object-property-accessor.js'; import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; @@ -400,7 +400,7 @@ class KeyboardShortcutHotkeyEntry { /** @type {import('input').ModifierKey[]} */ const modifiers2 = []; for (const modifier of modifiers) { - const modifier2 = DocumentUtil.normalizeModifierKey(modifier); + const modifier2 = normalizeModifierKey(modifier); if (modifier2 === null) { continue; } modifiers2.push(modifier2); } @@ -435,7 +435,7 @@ class KeyboardShortcutHotkeyEntry { let value = this._getArgumentInputValue(node); switch (template) { case 'hotkey-argument-move-offset': - value = `${DocumentUtil.convertElementValueToNumber(value, node)}`; + value = `${convertElementValueToNumber(value, node)}`; break; } this._setArgument(value); diff --git a/ext/js/pages/settings/nested-popups-controller.js b/ext/js/pages/settings/nested-popups-controller.js index ccdc3c9c..077b1a66 100644 --- a/ext/js/pages/settings/nested-popups-controller.js +++ b/ext/js/pages/settings/nested-popups-controller.js @@ -16,7 +16,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import {DocumentUtil} from '../../dom/document-util.js'; +import {convertElementValueToNumber} from '../../dom/document-util.js'; import {querySelectorNotNull} from '../../dom/query-selector.js'; export class NestedPopupsController { @@ -71,7 +71,7 @@ export class NestedPopupsController { */ _onNestedPopupsCountChange(e) { const node = /** @type {HTMLInputElement} */ (e.currentTarget); - const value = Math.max(1, DocumentUtil.convertElementValueToNumber(node.value, node)); + const value = Math.max(1, convertElementValueToNumber(node.value, node)); this._setPopupNestingMaxDepth(value); } diff --git a/ext/js/pages/settings/profile-conditions-ui.js b/ext/js/pages/settings/profile-conditions-ui.js index 5801af17..d2bf03bf 100644 --- a/ext/js/pages/settings/profile-conditions-ui.js +++ b/ext/js/pages/settings/profile-conditions-ui.js @@ -18,7 +18,7 @@ import {EventDispatcher} from '../../core/event-dispatcher.js'; import {EventListenerCollection} from '../../core/event-listener-collection.js'; -import {DocumentUtil} from '../../dom/document-util.js'; +import {normalizeModifier} from '../../dom/document-util.js'; import {querySelectorNotNull} from '../../dom/query-selector.js'; import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; @@ -941,7 +941,7 @@ class ProfileConditionUI { /** @type {import('input').Modifier[]} */ const results = []; for (const item of modifiersString.split(/[,;\s]+/)) { - const modifier = DocumentUtil.normalizeModifier(item.trim().toLowerCase()); + const modifier = normalizeModifier(item.trim().toLowerCase()); if (modifier !== null) { results.push(modifier); } } return results; diff --git a/ext/js/pages/settings/scan-inputs-controller.js b/ext/js/pages/settings/scan-inputs-controller.js index f1547fe4..144eae9f 100644 --- a/ext/js/pages/settings/scan-inputs-controller.js +++ b/ext/js/pages/settings/scan-inputs-controller.js @@ -17,7 +17,7 @@ */ import {EventListenerCollection} from '../../core/event-listener-collection.js'; -import {DocumentUtil} from '../../dom/document-util.js'; +import {normalizeModifier} from '../../dom/document-util.js'; import {querySelectorNotNull} from '../../dom/query-selector.js'; import {KeyboardMouseInputField} from './keyboard-mouse-input-field.js'; @@ -417,7 +417,7 @@ class ScanInputField { /** @type {import('input').Modifier[]} */ const results = []; for (const modifier of modifiersString.split(/[,;\s]+/)) { - const modifier2 = DocumentUtil.normalizeModifier(modifier.trim().toLowerCase()); + const modifier2 = normalizeModifier(modifier.trim().toLowerCase()); if (modifier2 === null) { continue; } results.push(modifier2); } diff --git a/ext/js/pages/settings/settings-display-controller.js b/ext/js/pages/settings/settings-display-controller.js index 47aa9c9c..6e740e13 100644 --- a/ext/js/pages/settings/settings-display-controller.js +++ b/ext/js/pages/settings/settings-display-controller.js @@ -16,7 +16,7 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import {DocumentUtil} from '../../dom/document-util.js'; +import {isInputElementFocused} from '../../dom/document-util.js'; import {PopupMenu} from '../../dom/popup-menu.js'; import {querySelectorNotNull} from '../../dom/query-selector.js'; import {SelectorObserver} from '../../dom/selector-observer.js'; @@ -184,7 +184,7 @@ export class SettingsDisplayController { _onKeyDown(e) { switch (e.code) { case 'Escape': - if (!DocumentUtil.isInputElementFocused()) { + if (!isInputElementFocused()) { this._closeTopMenuOrModal(); e.preventDefault(); } |