- Refactoring: Add utilities $q and $qq for querySelector/querySelectorAll

This commit is contained in:
Brett Zamir
2020-07-12 23:11:58 +08:00
parent 533b8ef262
commit 135117ef79
3 changed files with 7 additions and 1 deletions

View File

@@ -137,6 +137,7 @@ module.exports = {
'document.evaluate',
'document.head',
'document.importNode',
'document.querySelector',
'document.querySelectorAll',
'DOMParser',
'Error',

View File

@@ -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`,

View File

@@ -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)];