Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4335 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

Scriptaculous.js dynamic file include trick breaks if used twice in Firefox

Reported by: petermichaux@gmail.com Assigned to: thomas@fesch.at
Priority: high Milestone:
Component: script.aculo.us Version:
Severity: major Keywords:
Cc:

Description

Hi,

I have tried to use the same trick that Scriptaculous uses to dynamically include the various javascript files in the library (effect.js, dragdrop.js, etc). The following works in Safari but not in Firefox 1.5.0.1 on OS X. Expected result is the burp div is red background. Actual result is no red background.

I posted an even more stripped down version of the problem to bugzilla.

https://bugzilla.mozilla.org/show_bug.cgi?id=331174

Maybe a new workaround for the dynamic include problem for Scriptaculous needs to be found. If you turn my example around by swaping the order of the scriptaculous.js and burp.js <script> tags then the div will be red. However that means that Scriptaculous doesn't load properly. If someone uses this trick before they src scriptaculous.js then scriptaculous.js will not work.

Peter

test.html

<html>
<head>
	
  <script type="text/javascript" src="prototype.js"></script>
  <script type="text/javascript" src="scriptaculous.js"></script>

  <script type="text/javascript" src="burp.js"></script>
	
	
</head>
<body>
  <div id="grof">Grof</div>
  <div id="burp">Burp</div>
</body>
</html>

burp.js

var scriptTags = document.getElementsByTagName("script");
for(var i=0;i<scriptTags.length;i++) {
  if(scriptTags[i].src && scriptTags[i].src.match(/burp\.js(\?.*)?$/)) {
    var path = scriptTags[i].src.replace(/burp\.js(\?.*)?$/,'');
    document.write('<script type="text/javascript" src="'+path+'burp2.js"></script>');
  }
}  

burp2.js

function b(){
  var burp = document.getElementById("burp");
  burp.style.background="red";
}

window.addEventListener("load", b, false);

Attachments

scriptaculous.js (2.3 kB) - added by petermichaux on 12/15/06 00:27:24.
new scriptaculous.js

Change History

03/22/06 20:21:49 changed by petermichaux@gmail.com

  • priority changed from normal to high.
  • severity changed from normal to major.

You could test the existance of this bug by splitting scriptaculous.js into two files. The second one only loads dragdrop.js. Then include scriptaculous1.js and scriptaculous2.js in an html doc and try to use dragdrop in Firefox 1.5.0.1 for OS X. I bet it won't work.

This firefox bug makes scriptaculous.js a bad citizen in an html doc since it is breaking things in the DOM.

Below is a idea for an alternate method of walking the DOM to scrape for the library's location on the server without using getElementsByTag("script"). This works in Firefox and Safari on OS X.

Apparently Firefox has been moving the location of script elements in the dom over past months and this might be causing problems.

- Peter

function check_is_script(element){

if(element.src && element.src.match(/burp\.js(\?.*)?$/)){

return element;

}

var children = element.childNodes; for(var i=0;i<children.length;i++) {

var found = check_is_script(children[i]); if (found != null) {

return found;

}

}

return null;

}

var asdf = check_is_script(document); if(asdf != null) {

var path = asdf.src.replace(/burp\.js(\?.*)?$/,); document.write('<script type="text/javascript" src="'+path+'burp2.js"></script>');

}

04/01/06 22:35:30 changed by madrobby

  • status changed from new to closed.
  • resolution set to wontfix.

You can just include the various .js files "by hand", if that's a problem. In fact, if I need only "effects.js", i'll just include that. The scriptaculous.js file is only provided for convenience.

12/15/06 00:26:36 changed by petermichaux

  • status changed from closed to reopened.
  • resolution deleted.

new scriptaculous.js file attached

12/15/06 00:27:24 changed by petermichaux

  • attachment scriptaculous.js added.

new scriptaculous.js

12/15/06 07:40:35 changed by aljoscha

I agree this is no "wontfix". The _whole_library_ is there for convenience and should not yield surprises like a loader that can't be used more than one times. But a patch and testcase would be necessary, right?

12/15/06 16:35:08 changed by petermichaux

I have rewritten the entire file so don't think a patch is appropriate in this case.

If someone else want's to write a test case that is fine. I don't know how scriptaculous does testing.

07/20/07 06:34:23 changed by sokrat3s

  • status changed from reopened to closed.
  • resolution set to fixed.

Fixed in #9032.