joomla/joomla-cms — pull request #116 by rcorral (2012-02-02 18:36:55+00:00)
Title: Added behavior.load to allow for a single go-to place to add/load javascript libraries. Also added jQuery plugin for loading jQuery library.

I have been working with Elin on a solution to add jQuery to Joomla to avoid multiple versions of jQuery running on a single site.

My first commit: https://github.com/rcorral/joomla-cms/commit/47e208d8468851df3775205dc5bc6126ac55853d
With this I added a central place where javascript libraries can be registered with their css and js files.
An example of this would be doing this:
JHtmlBehavior::register('modal', array(
'script' => array('system/modal.js' => array()),
'stylesheet' => array('system/modal.css' => array(array(), true, false, true))
)
);

If more CSS or JS files need to be included, they can be added to the 'script' or 'stylesheet' array. For each element in the array the key is the path to the file, this file will get parsed by JHtml::_includeRelativeFiles, and the value for the key is an array of arguments that you would liked passed to JHtml::script or JHtml::stylesheet respectively.

I modified JHtmlBehavior::modal as an example of how this new feature can be implemented. It makes a call to self::load('modal'); to add the library to the document.

With the second commit: https://github.com/rcorral/joomla-cms/commit/bf71fa00ede7620c67367ae05a5b3d6dc7b410c5
I added a Joomla plugin to register the jQuery library using the previous functions. It only registers the library if the plugin is enabled. It would be up to any Joomla extension to load it with the following code:
JHtml::_('load', 'jquery');

The reason for creating a plugin is to avoid all of the support that the Joomla team would have to do by supporting another JS library.
I think this is a great solution for a problem that many developers have been trying to overcome for years.

Please review and comment.

Cheers,
Rafael