Adding JavaScript file to package install - Best way?

Permalink
I'm trying to determine the best way to distribute a Javascript file with an addon package (happens to be a jQuery plugin).

I know I can add the file as a single page; however, that doesn't seem consistent with the HTML helper method, e.g.: $html->javascript('jquery.form.js')

Of course instructions could be provided to manually install into /concrete/js/ however, I'd like to automate this procedure during the package install if at all possible.

Thanks for any assistance!

ace
 
mdzoidberg replied on at Permalink Reply
mdzoidberg
You can call a JS script that is inside a package in a folder called js like this;

$assetsURL= Loader::helper('html');
// LOAD THE TABLE SORTER PLUGIN //
echo $assetsURL->javascript('jquery.tablesorter.js', 'youpackage_handle');


You would do this from within your package single page. Was this what you were referring to?
ace replied on at Permalink Reply
ace
Yes, thank you, that should do the trick. I should have suspected that $pkg was an optional argument as elsewhere.
Thanks!
Shotster replied on at Permalink Reply
Shotster
@mdzoidberg...

If I understand you correctly, that approach means that the same script (actually, two different copies of the same script) could potentially be referenced/loaded more than once if it's used in different packages by different developers and the package resources utilizing the script happen to be used on the same page. There must be a better (more efficient) way to handle this scenario.

Requiring the user to manually place it in the root JS folder seems to be a better approach from that standpoint, but of course it's not automated.

It makes perfect sense to include original scripts with a package, but widely used libraries (and plug-ins for same) should be handled differently I think. Anyone know of a better way that's automated?

-Steve
Remo replied on at Permalink Reply
Remo
sure, addHeaderItem checks for duplicate items and filters them.

It might be useful to have a way how we name scripts.

swfobject.js
jquery.js

etc.

By having an agreement about script names, we could make sure there's just one include. However, if the core includes jquery 1.4 but your package uses jquery 1.3.2 you have a problem.. But that's something which is hard to avoid.