Posted by Damien Tournoud on June 29, 2009 at 6:34pm
5 followers
| Project: | Drupal core |
| Version: | 7.x-dev |
| Component: | base system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
| Issue tags: | JavaScript, weight |
Issue Summary
#315798: JavaScript Patch #2: Weight added weights to drupal_add_js() included files, but now files of the same weight can be included in a different order then the order of the calls. This is counter intuitive and we need to fix that.
Comments
#1
And here is a patch.
Of course, we need a test... anyone?
#2
Test, it works as advertised. I used the tests described in #315798: JavaScript Patch #2: Weight by Rob Loach (comment #6)..
<?phpdrupal_add_js('(function($){alert("Weight 25 #1");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => 25));
drupal_add_js('(function($){alert("Weight 0 #1");})(jQuery);', array('type' => 'inline', 'scope' => 'footer'));
drupal_add_js('(function($){alert("Weight 0 #2");})(jQuery);', array('type' => 'inline', 'scope' => 'footer'));
drupal_add_js('(function($){alert("Weight -50 #1");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -50));
drupal_add_js('(function($){alert("Weight -50 #2");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -50));
drupal_add_js('(function($){alert("Weight -50 #3");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -50));
drupal_add_js('(function($){alert("Weight -50 #4");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -50));
drupal_add_js('(function($){alert("Weight 25 #2");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => 25));
drupal_add_js('(function($){alert("Weight 0 #3");})(jQuery);', array('type' => 'inline', 'scope' => 'footer'));
?>
Alerts are showing in this order :
Weight -50 #1Weight -50 #2
Weight -50 #3
Weight -50 #4
Weight 0 #1
Weight 0 #2
Weight 0 #3
Weight 25 #1
Weight 25 #2
Which is the expected order. I guess we do not need to test all the other scopes and types since they use the same logic for weight, but if needed just ask and maybe give samples of what should be tested ?
#3
Thanks DamZ! Good find.
#4
Tests, please!
#5
Regex FTW.
#6
Deal.
#7
Thanks, committed to HEAD!
#8
Automatically closed -- issue fixed for 2 weeks with no activity.