User tests: Successful: Unsuccessful:
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: rcorral@47e208d
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: rcorral@bf71fa0
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
Hi Rafael,
As not sure where discussion takes place, here the comment i just added on the tracker item:
Thanks for the proposal of separate jQuery core plugin, which wasn't an option
in previous discussions on the list.
The Proposed solution has following problems:
1. jQuery noConflict mode is not initiated correctly and thus mootools collides with it.
2. There is no PHP method to know jQuery version being loaded.
3. There is no management of conflicts between different versions of the javascript libraries
4. It is a pull request at CMS level for PLATFORM feature ?
FYI: These 3 problems were solved in Joomla Platform pull request here:
joomla/joomla-platform#736
Final solution should have best parts of each the 2 proposals merged imho.
@rcorral said "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."
Initially, when I read that comment, I was encouraged, assuming that meant the JS files would not be included with core, a position I very much support. However, after review, I see that the files are actually included which, in my thinking anyway, implies the same degree of support for jQuery as is provided for Mootools.
I think your registration concept is on the right track, but not the plugin, nor the inclusion of jQuery. I'd encourage you to beef up the API a bit and include a version, as Beat is indicating. Then, make certain the API provides adequate interface for extension devs to determine whether or not files exist that can simply be reused, or the extension needs to load those files. Nothing more than that, though, IMO.
It would be great to see the administrator template bundling the UI layer with the CSS, etc., whether it's Bootstrap and jQuery, or MTs and Mocha, it's more of a frontend developer choice and a adopting a JS-agnostic goal to help keep those options open will be very helpful for Joomla users.
Hi Beat,
Cheers,
Rafael
What's the advantage of this over a call like JHtml::_('ljquery.framework'); ?
@AmyStephen Good points, from my talk with Elin, Joomla wouldn't really need to support jQuery as it is in a plugin form.
It would be fine to add more API calls if everyone things they are needed.
@realityking The modifications that I did to JHtmlBehavior allow for other libraries to be added, ie. prototype, colorbox, not just jquery.
Hi Rafael,
Please read description and discussion on my pull request for details on the above 4 points. All has been already replied and detailed there:
e.g. for 1.: noconflict must be called immediately after including jquery, and before any other mootools file is included. My pull request contains proposed changes to allow this.
Another solution for including jQuery was added with the Bootstrap work. Closing this item.
Please create a tracker on joomlacode