joomla/joomla-platform — pull request #736 by beat (2012-01-11 22:49:37+00:00)
Title: Adding 'behavior.jquery' to Joomla Framework with deep non-conflict mode and support for concurrent jQuery versions running

Hi Joomla Framework team,

I have spent last 2 days designing and implementing a method to load jQuery frameworks, plugins and files, and non-conflicting javascript code into the document head.

The files are provided by extensions, and multiple versions are supported concurrently.

There are only 2 new public methods, one to use it and one to check that it is available (or any other JHtml::_() helper.

I have tested it with multiple jQuery frameworks and with a modified Community Builder version too.

I feel that the changes to existing code and functionality (including minor bug fixes and php-lint fixes) are safe enough for Joomla 2.5.

Please review and comment, main description is below:

Best Regards,
Beat

/**
* Method to load jQuery frameworks and non-conflicting javascript code into the document head
* Loading and use is done in "deep non-conflict mode", which allows several concurent versions of jQuery to be loaded and run simultaneously with any other javascript framework, including another conflicting jQuery instance.
* It means that the window's Javascript global namespace is not used in a fixed way: neither $ nor jQuery global variables are used. Reference: http://api.jquery.com/jQuery.noConflict/
*
* Calling and params:
* JHTml::_('behavior.jquery', $fullVersion, $relativePathToRoot, $listofPlugins, $javascriptCodeToRunInNonConflictMode);
*
* Use: Example:
* JHTml::_('behavior.jquery', '1.6.1', 'media/jquery/', null, '$("p").css("color","red")');
* JHTml::_('behavior.jquery', '1.7.0', 'media/othercompon/js/', array('jquery.flot','jquery.form'));;
* JHTml::_('behavior.jquery', '1.7.1', 'media/mycomponent/jquery/', array('jquery.ui-all','jquery.form'),'$("h1,h2,h3").css("color","green")');
* Will load jQuery 1.6.1 with ui and form from the 1.7.1 folder media/mycomponent/jquery, and and jQuery 1.7.1 with flot and form from the 1.7.0 folder media/othercompon/jquery
*
* If debugging mode is on an uncompressed version of jQuery is included for easier debugging.
* Files: 2 files are mandatory for jquery and jQuery plugins, and do follow the jQuery naming:
* jQuery: jquery-1.7.1.js for uncompressed and jquery-1.7.1.min.js
* jQuery plugins: "$path/$pluginname[.min].js"
*
* @param string $version x.y.z jQuery-Version (not jQuery plugins versions, but always jQuery one) corresponding to the file to load (highest sub-version Z of same x.y release will be loaded in the end) [MANDATORY]
* @param string $path Path to file from root of website (no / at start but / at end) so that it can be appended to absolute files path or live site [MANDATORY ONCE AT LEAST]
* @param array|null $jQueryPlugins Array of filenames (without .js or .min.js extension) of jQuery plugins or other Javascript files with jQuery code (which need the jQuery and $ to be defined correctly) [optional]
* @param string|null $jqCode jQuery Javascript code outputed in context with jQuery and $ defined and on dom ready [optional]
*
* @return void
*
* @since 11.5
*/

/**
* Checks if a JHtml::_($key) call can be made.
* If the function is not registered, tries to load the corresponding class without registering the function.
*
* @param string $key The name of helper method to load, (prefix).(class).function
* prefix and class are optional and can be used to load custom
* html helpers.
*
* @return boolean True: $key function is implemented, False: is not.
*/
JHtml::isCallable_($key)