Pending

User tests: Successful: Unsuccessful:

avatar rcorral
rcorral
2 Feb 2012

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

avatar rcorral rcorral - open - 2 Feb 2012
avatar infograf768
infograf768 - comment - 3 Feb 2012

Please create a tracker on joomlacode

avatar beat
beat - comment - 3 Feb 2012

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.

avatar AmyStephen
AmyStephen - comment - 3 Feb 2012

@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.

avatar rcorral
rcorral - comment - 3 Feb 2012

Hi Beat,

  1. Could you explain more. I have included jquery and jquery.noconfligt the same way and have not experienced any problems.
  2. This could be added, although I didn't think it was necessary, as the register function allows you to override the previous value. This way developers can just add the jquery library from their extension, but not override it in case the jquery plugin is already enabled.
  3. Honestly, I don't even this is necessary, it adds unnecessary overhead. Joomla doesn't maintain old versions of other javascript libraries, nor does it allow you to load old versions of mootools. You are stuck with the version that it ships with, and I think that fine. It is best to keep up with the latest and greatest. As another note, jquery is much better about backwards compatibility than other libraries.
  4. The plugin would need to get accepted by the CMS, but I would also need to submit a pull request for the platform changes. I guess I need some guidance with what to do in this case.

Cheers,
Rafael

avatar realityking
realityking - comment - 3 Feb 2012

What's the advantage of this over a call like JHtml::_('ljquery.framework'); ?

avatar rcorral
rcorral - comment - 3 Feb 2012

@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.

avatar beat
beat - comment - 13 Feb 2012

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:

joomla/joomla-platform#736

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.

avatar mbabker mbabker - close - 28 Dec 2012
avatar mbabker
mbabker - comment - 28 Dec 2012

Another solution for including jQuery was added with the Bootstrap work. Closing this item.

Add a Comment

Login with GitHub to post a comment