diff --git a/CHANGELOG b/CHANGELOG index 5788fc9..c9ba5a9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* `Element#update` now takes care of SCRIPT elements in IE. [#573 state:resolved] (Martin, Tobie Langel, kangax) + * Remove unused local variables from `Element.extend`. Fix one of the form tests to remove `_extendedByPrototype` by setting it to `undefined` rather than `false` (`_extendedByPrototype` being `false` does not force `Element.extend` to re-extend element). (T.J. Crowder, kangax) * Make test for `escapeHTML`/`unescapeHTML` more strict. (Chrome 1.x escapes "<" and "&" with `innerHTML`, but not ">") (kangax) diff --git a/src/dom/dom.js b/src/dom/dom.js index f7c8d09..c6cea5a 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -203,6 +203,20 @@ Element.Methods = { } })(); + var SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING = (function () { + var s = document.createElement("script"), + isBuggy = false; + try { + s.appendChild(document.createTextNode("")); + isBuggy = !s.firstChild || + s.firstChild && s.firstChild.nodeType !== 3; + } catch (e) { + isBuggy = true; + } + s = null; + return isBuggy; + })(); + function update(element, content) { element = $(element); @@ -213,9 +227,16 @@ Element.Methods = { return element.update().insert(content); content = Object.toHTML(content); + + var tagName = element.tagName.toUpperCase(); + + if (tagName === 'SCRIPT' && SCRIPT_ELEMENT_REJECTS_TEXTNODE_APPENDING) { + // scripts are not evaluated when updating SCRIPT element + element.text = content; + return element; + } if (SELECT_ELEMENT_INNERHTML_BUGGY || TABLE_ELEMENT_INNERHTML_BUGGY) { - var tagName = element.tagName.toUpperCase(); if (tagName in Element._insertionTranslations.tags) { $A(element.childNodes).each(function(node) { element.removeChild(node); diff --git a/test/unit/dom_test.js b/test/unit/dom_test.js index 0fdaf9f..d9e2e30 100644 --- a/test/unit/dom_test.js +++ b/test/unit/dom_test.js @@ -378,6 +378,15 @@ new Test.Unit.Runner({ this.assertEqual('hello world', getInnerHTML('testdiv')); }, + testElementUpdateScriptElement: function() { + var el = new Element('script', { + type: 'text/javascript' + }); + this.assertNothingRaised(function(){ + el.update('(function(){})'); + }) + }, + testElementReplace: function() { $('testdiv-replace-1').replace('hello from div!'); this.assertEqual('hello from div!', $('testdiv-replace-container-1').innerHTML);