Skip to content

Commit

Permalink
Extract mergeAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
lauriro committed Jan 4, 2025
1 parent 27d68a6 commit f6b19b4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f6b19b4

Please sign in to comment.