From f6b19b40e483f58f0c653ac57bde9e4ab15238e5 Mon Sep 17 00:00:00 2001 From: Lauri Rooden Date: Sat, 4 Jan 2025 12:56:30 +0200 Subject: [PATCH] Extract mergeAttributes --- dom.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dom.js b/dom.js index d49a657..0252079 100644 --- a/dom.js +++ b/dom.js @@ -168,9 +168,7 @@ var boolAttrs = { , clone = new node.constructor(node.tagName || node.data) clone.ownerDocument = node.ownerDocument - if (node.attributes) { - node.attributes.names().forEach(attr => clone.setAttribute(attr, node.getAttribute(attr))) - } + mergeAttributes(node, clone) if (deep && node.hasChildNodes()) { node.childNodes.forEach(child => clone.appendChild(child.cloneNode(deep))) @@ -486,8 +484,15 @@ function getSibling(node, step, type) { return type > 0 ? getElement(silbings, index + step, step, type) : silbings && silbings[index + step] || null } +function mergeAttributes(source, target) { + if (source && target && source.attributes) { + source.attributes.names().forEach(attr => target.setAttribute(attr, source.getAttribute(attr))) + } +} + exports.document = new Document() exports.entities = entities +exports.mergeAttributes = mergeAttributes exports.selectorSplit = selectorSplit exports.CSSStyleDeclaration = CSSStyleDeclaration exports.CSSStyleSheet = CSSStyleSheet