Skip to content

Commit

Permalink
keep contains text function in decorate js
Browse files Browse the repository at this point in the history
  • Loading branch information
Sartxi committed Oct 28, 2024
1 parent 3d83484 commit 3db81be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 9 additions & 1 deletion libs/utils/decorate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createTag, loadStyle, getConfig, createIntersectionObserver, elContainsText } from './utils.js';
import { createTag, loadStyle, getConfig, createIntersectionObserver } from './utils.js';

const { miloLibs, codeRoot } = getConfig();

Expand Down Expand Up @@ -65,6 +65,14 @@ export function decorateIconArea(el) {
});
}

function elContainsText(el) {
return !![...el.childNodes].filter((childNode) => {
const { innerText, nodeType, textContent } = childNode;
if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== '';
return nodeType === Node.TEXT_NODE && textContent.trim() !== '';
}).length;
}

export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) {
let headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6');
if (!el.classList.contains('default')) {
Expand Down
8 changes: 0 additions & 8 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,6 @@ export function isInTextNode(node) {
return node.parentElement.firstChild.nodeType === Node.TEXT_NODE;
}

export function elContainsText(el) {
return !![...el.childNodes].filter((childNode) => {
const { innerText, nodeType, textContent } = childNode;
if (nodeType === Node.ELEMENT_NODE) return innerText.trim() !== '';
return nodeType === Node.TEXT_NODE && textContent.trim() !== '';
}).length;
}

export function createTag(tag, attributes, html, options = {}) {
const el = document.createElement(tag);
if (html) {
Expand Down

0 comments on commit 3db81be

Please sign in to comment.