Skip to content

Commit

Permalink
Duplicate code in Element.update
Browse files Browse the repository at this point in the history
Duplicate code from `Element.update` extracted to function `updateNodes`
  • Loading branch information
Victor Homyakov committed Sep 21, 2012
1 parent addd725 commit 85e8c31
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/prototype/dom/dom.js
Expand Up @@ -547,6 +547,13 @@
return isBuggy;
})();

function updateNodes(element, nodes) {
while (element.firstChild)
element.removeChild(element.firstChild);
for (var i = 0, node; node = nodes[i]; i++)
element.appendChild(node);
}

/**
* Element.update(@element[, newContent]) -> Element
*
Expand Down Expand Up @@ -664,26 +671,15 @@

if (ANY_INNERHTML_BUGGY) {
if (tagName in INSERTION_TRANSLATIONS.tags) {
while (element.firstChild)
element.removeChild(element.firstChild);

var nodes = getContentFromAnonymousElement(tagName, content.stripScripts());
for (var i = 0, node; node = nodes[i]; i++)
element.appendChild(node);

updateNodes(element, getContentFromAnonymousElement(tagName,
content.stripScripts()));
} else if (LINK_ELEMENT_INNERHTML_BUGGY && Object.isString(content) && content.indexOf('<link') > -1) {
// IE barfs when inserting a string that beings with a LINK
// element. The workaround is to add any content to the beginning
// of the string; we'll be inserting a text node (see
// getContentFromAnonymousElement below).
while (element.firstChild)
element.removeChild(element.firstChild);

var nodes = getContentFromAnonymousElement(tagName,
content.stripScripts(), true);

for (var i = 0, node; node = nodes[i]; i++)
element.appendChild(node);
updateNodes(element, getContentFromAnonymousElement(tagName,
content.stripScripts(), true));
} else {
element.innerHTML = content.stripScripts();
}
Expand Down

0 comments on commit 85e8c31

Please sign in to comment.