#381 closed enhancement (wontfix)
Enhance dojo.io.bind to execute embedded and linked script files
Reported by: | Owned by: | alex | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | General | Version: | 0.2 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
Add an option into dojo.io.bind to execute any javascript in between <script></script> tags, and to automatically include any external scripts linked via <script src=""></script>
Here's a function that (pretty much) does the trick. Although I'm sure it could be cleaned up substantially. It just needs to be included in the dojo.io.bind function call.
executeScript = function (content) {
handle <script src="foo"> first var src = new RegExp?('<script.*?src=".*?"'); var repl = new RegExp?('<script.*?src="'); var matches = src.exec(content);
var semaphore = 0;
if (matches != null)
{ for (i = 0; i < matches.length; i++)
{
get the src of the script var scriptSrc = matches[i].replace(repl, ); scriptSrc = scriptSrc.substring(0, scriptSrc.length-1);
this evals remote scripts
dojo.io.bind({
url: scriptSrc, load: function(type, evaldObj) {/* do nothing */ }, error: function(type, error) {alert(type); alert(error); /* do nothing */ }, mimetype: "text/javascript", sync: true
});
}
}
Remove the script tags we matched
repl = new RegExp?('<script.*?src=".*?".*?</script>'); content = content.replace(repl, );
Next, handle inline scripts
Clean up content: remove inline script comments repl = new RegExp?('.*?$', 'gm'); content = content.replace(repl, '
');
Clean up content: remove carraige returns repl = new RegExp?('[
]', 'g');
content = content.replace(repl, ' ');
Match anything inside <script> tags
src = new RegExp?('<script.*?</script>', 'g');
matches = content.match(src);
For each match that is found... if (matches != null) { for (i = 0; i < matches.length; i++)
{
Remove begin tag
var repl = new RegExp?('<script.*?>', 'gm'); var script = matches[i].replace(repl, );
Remove end tag
repl = new RegExp?('</script>', 'gm'); script = script.replace(repl, );
Execute commands
setTimeout(script, 250);
}
}
}
Change History (4)
comment:1 Changed 16 years ago by
Milestone: | → 0.3release |
---|---|
Owner: | changed from anonymous to alex |
Status: | new → assigned |
comment:2 Changed 16 years ago by
comment:3 Changed 16 years ago by
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
I'm not sure it does need to be anywhere but ContentPane?. It doesn't make sense in bind().
This is in ContentPane? now (although Josh needs to add a fix to prevent reloading already loaded scripts). Does it need to be in dojo.io.bind, or some other more general place?