Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Duplicate code in `Element.update` #68

Open
wants to merge 1 commit into from

1 participant

@victor-homyakov

Duplicate code from Element.update extracted to function updateNodes

@victor-homyakov victor-homyakov Duplicate code in `Element.update`
Duplicate code from `Element.update` extracted to function `updateNodes`
85e8c31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 21, 2012
  1. @victor-homyakov

    Duplicate code in `Element.update`

    victor-homyakov authored
    Duplicate code from `Element.update` extracted to function `updateNodes`
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 15 deletions.
  1. +11 −15 src/prototype/dom/dom.js
View
26 src/prototype/dom/dom.js
@@ -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
*
@@ -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();
}
Something went wrong with that request. Please try again.