chore: minor syntax tweaks
This commit is contained in:
parent
0202e8efb0
commit
39c6049850
@ -37,9 +37,7 @@ export function wrap(elements, wrapper) {
|
|||||||
|
|
||||||
// Set attributes
|
// Set attributes
|
||||||
export function setAttributes(element, attributes) {
|
export function setAttributes(element, attributes) {
|
||||||
if (!is.element(element) || is.empty(attributes)) {
|
if (!is.element(element) || is.empty(attributes)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assume null and undefined attributes should be left out,
|
// Assume null and undefined attributes should be left out,
|
||||||
// Setting them would otherwise convert them to "null" and "undefined"
|
// 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
|
// Insert an element after another
|
||||||
export function insertAfter(element, target) {
|
export function insertAfter(element, target) {
|
||||||
if (!is.element(element) || !is.element(target)) {
|
if (!is.element(element) || !is.element(target)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.parentNode.insertBefore(element, target.nextSibling);
|
target.parentNode.insertBefore(element, target.nextSibling);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert a DocumentFragment
|
// Insert a DocumentFragment
|
||||||
export function insertElement(type, parent, attributes, text) {
|
export function insertElement(type, parent, attributes, text) {
|
||||||
if (!is.element(parent)) {
|
if (!is.element(parent)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
parent.appendChild(createElement(type, attributes, text));
|
parent.appendChild(createElement(type, attributes, text));
|
||||||
}
|
}
|
||||||
@ -101,9 +95,7 @@ export function removeElement(element) {
|
|||||||
|
|
||||||
// Remove all child elements
|
// Remove all child elements
|
||||||
export function emptyElement(element) {
|
export function emptyElement(element) {
|
||||||
if (!is.element(element)) {
|
if (!is.element(element)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { length } = element.childNodes;
|
let { length } = element.childNodes;
|
||||||
|
|
||||||
@ -115,9 +107,7 @@ export function emptyElement(element) {
|
|||||||
|
|
||||||
// Replace element
|
// Replace element
|
||||||
export function replaceElement(newChild, oldChild) {
|
export function replaceElement(newChild, oldChild) {
|
||||||
if (!is.element(oldChild) || !is.element(oldChild.parentNode) || !is.element(newChild)) {
|
if (!is.element(oldChild) || !is.element(oldChild.parentNode) || !is.element(newChild)) return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
oldChild.parentNode.replaceChild(newChild, oldChild);
|
oldChild.parentNode.replaceChild(newChild, oldChild);
|
||||||
|
|
||||||
@ -131,9 +121,7 @@ export function getAttributesFromSelector(sel, existingAttributes) {
|
|||||||
// '#test' to { id: 'test' }
|
// '#test' to { id: 'test' }
|
||||||
// '[data-test="test"]' to { 'data-test': 'test' }
|
// '[data-test="test"]' to { 'data-test': 'test' }
|
||||||
|
|
||||||
if (!is.string(sel) || is.empty(sel)) {
|
if (!is.string(sel) || is.empty(sel)) return {};
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const attributes = {};
|
const attributes = {};
|
||||||
const existing = extend({}, existingAttributes);
|
const existing = extend({}, existingAttributes);
|
||||||
@ -181,9 +169,7 @@ export function getAttributesFromSelector(sel, existingAttributes) {
|
|||||||
|
|
||||||
// Toggle hidden
|
// Toggle hidden
|
||||||
export function toggleHidden(element, hidden) {
|
export function toggleHidden(element, hidden) {
|
||||||
if (!is.element(element)) {
|
if (!is.element(element)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let hide = hidden;
|
let hide = hidden;
|
||||||
|
|
||||||
@ -269,9 +255,7 @@ export function getElement(selector) {
|
|||||||
|
|
||||||
// Set focus and tab focus class
|
// Set focus and tab focus class
|
||||||
export function setFocus(element = null, focusVisible = false) {
|
export function setFocus(element = null, focusVisible = false) {
|
||||||
if (!is.element(element)) {
|
if (!is.element(element)) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set regular focus
|
// Set regular focus
|
||||||
element.focus({ preventScroll: true, focusVisible });
|
element.focus({ preventScroll: true, focusVisible });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user