2

I would like to change the order of my javascript files, and specifically move the jwplayer.js file so that it gets included after the jquery_ui*.js files. Does anyone know how to do this? I see how to do this in Drupal 7, using hook_js_alter(). But I do not see how to do this in Drupal 6.

UPDATE: Here is some more information on my setup, that might be relevant: - I call drupal_add_js('jwplayer.js') from within a custom views template. The template adds jwplayer.js conditionally, depending on whether the views data includes any videos.

3 Answers 3

5

If you look at drupal_add_js() and drupal_get_js(), you will see the details. Unfortunately, module_invoke_all() or it's cousins, don't get called, which means there are no hooks. Boo. A related issue is that when you aggregate, you loose the ability to do string manipulation (eg, explode, reorder, implode).

The best way to handle this is to alter the weight of the JW Player Module. One way to do this is to edit the {system} table and edit the weight column value. With the weights, lower numbers run earlier, higher numbers later, and where there is a tie, they run alphabetically. Make sure you clear cache when you do this. See Change module's weight - by module or manualy for some more details.

If this doesn't fix the problem, then the JS files aren't being added by the same hook. I am not sure what can be done it in this case w/o hacking the module.

A total sledgehammer approach would be to not include the your code, but to add it in the theme's .info file. This should add it after all modules.

4
  • If I want jwplayer.js to appear after the jquery_ui javascript, then I should give the module that includes jwplayer.js (my custom module) a higher weight than the jquery_ui.module weight. Is that correct? I tried this, but it's not having an affect on the order of the javascript files. (I also tried clearing the cache.) Any suggestions on anything else I might try? (I set the weight of my custom module to 100, and the weight of jquery_ui to 0).
    – user606696
    Commented Aug 21, 2012 at 2:57
  • I edited to clarify a bit.
    – mpdonadio
    Commented Aug 21, 2012 at 10:36
  • I added some more information about my setup in the "Update" above. Do you have any suggestions on a hack that might work?
    – user606696
    Commented Aug 22, 2012 at 14:55
  • Thanks for the sledgehammer suggestion. If nothing else works, then I may resort to this. (Though I hate to add jwplayer.js to every page when it is needed only occasionally. I have been adding jwplayer.js conditionally, from within the views template, depending on whether the views data contained any videos.)
    – user606696
    Commented Aug 22, 2012 at 17:25
1

I think you need to unset and attached it again in the order you prepared. See my post here which is a bit similar - How can I remove Javascript files?

1
  • I gave this a try. But I don't think this will work for me because I am adding jwplayer.js from within a views template (because I do not know until I see the views data whether jwplayer is needed). When $variables get passed to hook_preprocess_page, jwplayer.js (the file I am trying to move to the bottom) has not yet been added. Do you have any suggestions?
    – user606696
    Commented Aug 22, 2012 at 20:31
1

JS Alter module for D6: http://drupal.org/project/jsalter

This module adds a hook_js_alter() hook that other modules can use to modify the javascript that gets output to the page.

1
  • I gave this a try, but it is not working for me. The hook gets executed but seems to have no effect on the included javascript files. I filed a bug report here: drupal.org/node/1744396
    – user606696
    Commented Aug 22, 2012 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.