This may be as much a style question as anything, but: I'm building a site that uses the Bootstrap theme and a bunch of Bootstrap features -- popovers, dialogs, and the like. This means that I often need to run little bits of initialization code when the page loads; I'm doing these by using drupal_add_js
to add the needed bits of jQuery, wrapped in a document.ready()
handler. The usual sort of thing, I think.
This works fine, but they are all being added to the page in their own SCRIPT and document.ready
blocks. Thus the page looks like:
<script>(function ($) {
$(document).ready(function() {
somejQueryCode();
});
})(jQuery);
</script>
<script>(function ($) {
$(document).ready(function() {
someMorejQueryCode();
});
})(jQuery);
</script>
<script>(function ($) {
$(document).ready(function() {
stillSomeMorejQueryCode();
});
})(jQuery);
</script>
as to what it seems like it might be:
<script>(function ($) {
$(document).ready(function() {
somejQueryCode();
someMorejQueryCode();
stillSomeMorejQueryCode();
});
})(jQuery);
</script>
You get the idea. Like I said, the individual blocks are working, but it seems a little wrong -- you'd surely never write the code by hand like that. I've explored various arguments to drupal_add_js
, and have started experimenting with the AdvAgg module, but haven't found anything that works. Is there a better way to do this? Comments to the effect of "this isn't a big deal, don't worry about it" will also be accepted... Thanks!