From 85e8c31d90f2d0cf0984ff9a6047f4b5348e318e Mon Sep 17 00:00:00 2001 From: Victor Homyakov Date: Fri, 21 Sep 2012 14:10:39 +0300 Subject: [PATCH] Duplicate code in `Element.update` Duplicate code from `Element.update` extracted to function `updateNodes` --- src/prototype/dom/dom.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/prototype/dom/dom.js b/src/prototype/dom/dom.js index 8cc030dc9..6057ef81c 100644 --- a/src/prototype/dom/dom.js +++ b/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(' -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(); }