Skip to content

Commit

Permalink
chore: minor syntax tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sampotts committed Mar 11, 2023
1 parent 0202e8e commit 39c6049
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions src/js/utils/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
}
Expand All @@ -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;

Expand All @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 39c6049

Please sign in to comment.