From 135117ef7953a2ea00a869c0070010aa6b438432 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sun, 12 Jul 2020 23:11:58 +0800 Subject: [PATCH] - Refactoring: Add utilities `$q` and `$qq` for `querySelector`/`querySelectorAll` --- .eslintrc.js | 1 + editor/svg-editor.js | 4 +++- editor/utilities.js | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 8bf9bd2f..69720bef 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -137,6 +137,7 @@ module.exports = { 'document.evaluate', 'document.head', 'document.importNode', + 'document.querySelector', 'document.querySelectorAll', 'DOMParser', 'Error', diff --git a/editor/svg-editor.js b/editor/svg-editor.js index dffcd8d4..76cc7973 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -45,6 +45,8 @@ import { } from './locale/locale.js'; import loadStylesheets from './external/load-stylesheets/index-es.js'; +const {$q} = Utils; + const editor = {}; const $ = [ @@ -5765,7 +5767,7 @@ editor.init = function () { // Bind function to button let btn; if (opts.sel) { - btn = document.querySelector(opts.sel); + btn = $q(opts.sel); if (btn === null) { return true; } // Skip if markup does not exist if (opts.evt) { // `touch.js` changes `touchstart` to `mousedown`, diff --git a/editor/utilities.js b/editor/utilities.js index 895c562e..e3a64d8c 100644 --- a/editor/utilities.js +++ b/editor/utilities.js @@ -1408,3 +1408,6 @@ export const mock = ({ setHref = setHrefUser; getRotationAngle = getRotationAngleUser; }; + +export const $q = (sel) => document.querySelector(sel); +export const $qq = (sel) => [...document.querySelectorAll(sel)];