PDA

View Full Version : Element.update()



Animal
22 Oct 2006, 11:22 PM
There's a scoping problem in the script loading function.

The code needs to be



var _parseScripts = function(){
var s = this.dom.getElementsByTagName("script");
var docHead = document.getElementsByTagName("head")[0];

// For browsers which discard scripts when inserting innerHTML, extract the scripts using a RegExp
if(s.length == 0){
var re = /(?:<script.*(?:src=[\"\'](.*)[\"\']).*>.*<\/script>)|(?:<script.*>([\S\s]*?)<\/script>)/ig; // assumes HTML well formed and then loop through it.
var match;
while(match = re.exec(html)){
var s0 = document.createElement("script");
if (match[1])
s0.src = match[1];
else if (match[2])
s0.text = match[2];
else
continue;
docHead.appendChild(s0);
}
}else {
for(var i = 0; i < s.length; i++){
var s0 = document.createElement("script");
s0.type = s[i].type;
if (s[i].text) {
s0.text = s[i].text;
} else {
s0.src = s[i].src;
}
docHead.appendChild(s0);
}
}
}.createDelegate(this);


That createDelegate function is a fantastic addition. It helps so much when using DWR callbacks!

jack.slocum
23 Oct 2006, 12:59 PM
Thanks for reporting this. I just removed the reference to this since it wasn't needed.

var dom = this.dom; <-- local variable gets closured
var _parseScripts = function(){
var s = dom.getElementsByTagName("script");