`Element#update` now takes care of SCRIPT elements in IE. [#573 state:resolved]

This commit is contained in:
Juriy Zaytsev 2009-03-22 19:04:04 -04:00
parent 2c986d8eaf
commit 71a8663370
3 changed files with 33 additions and 1 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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);