From 39c60498504d53f73d3106ac6bb730ec75c090ef Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sat, 11 Mar 2023 22:28:24 +1100 Subject: [PATCH] chore: minor syntax tweaks --- src/js/utils/elements.js | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/js/utils/elements.js b/src/js/utils/elements.js index 3cbd0e0c0..96bfc2deb 100644 --- a/src/js/utils/elements.js +++ b/src/js/utils/elements.js @@ -37,9 +37,7 @@ export function wrap(elements, wrapper) { // Set attributes export function setAttributes(element, attributes) { - if (!is.element(element) || is.empty(attributes)) { - return; - } + if (!is.element(element) || is.empty(attributes)) return; // Assume null and undefined attributes should be left out, // Setting them would otherwise convert them to "null" and "undefined" @@ -69,18 +67,14 @@ export function createElement(type, attributes, text) { // Insert an element after another export function insertAfter(element, target) { - if (!is.element(element) || !is.element(target)) { - return; - } + if (!is.element(element) || !is.element(target)) return; target.parentNode.insertBefore(element, target.nextSibling); } // Insert a DocumentFragment export function insertElement(type, parent, attributes, text) { - if (!is.element(parent)) { - return; - } + if (!is.element(parent)) return; parent.appendChild(createElement(type, attributes, text)); } @@ -101,9 +95,7 @@ export function removeElement(element) { // Remove all child elements export function emptyElement(element) { - if (!is.element(element)) { - return; - } + if (!is.element(element)) return; let { length } = element.childNodes; @@ -115,9 +107,7 @@ export function emptyElement(element) { // Replace element export function replaceElement(newChild, oldChild) { - if (!is.element(oldChild) || !is.element(oldChild.parentNode) || !is.element(newChild)) { - return null; - } + if (!is.element(oldChild) || !is.element(oldChild.parentNode) || !is.element(newChild)) return null; oldChild.parentNode.replaceChild(newChild, oldChild); @@ -131,9 +121,7 @@ export function getAttributesFromSelector(sel, existingAttributes) { // '#test' to { id: 'test' } // '[data-test="test"]' to { 'data-test': 'test' } - if (!is.string(sel) || is.empty(sel)) { - return {}; - } + if (!is.string(sel) || is.empty(sel)) return {}; const attributes = {}; const existing = extend({}, existingAttributes); @@ -181,9 +169,7 @@ export function getAttributesFromSelector(sel, existingAttributes) { // Toggle hidden export function toggleHidden(element, hidden) { - if (!is.element(element)) { - return; - } + if (!is.element(element)) return; let hide = hidden; @@ -269,9 +255,7 @@ export function getElement(selector) { // Set focus and tab focus class export function setFocus(element = null, focusVisible = false) { - if (!is.element(element)) { - return; - } + if (!is.element(element)) return; // Set regular focus element.focus({ preventScroll: true, focusVisible });