7

According to the docs at jQuery UI Framework, to use a JUI library such as sortable, the following code is required: JHtml::_('jquery.ui', array('sortable'));

This apparently works fine if jquery.ui.sortable.js is exists, but there are no equivalent files for other JUI libraries, specifically draggable/droppable.

What is the correct way to use JUI libraries that aren't included with the core J3.x installation?

Solution: With the guidance from @lodder, here are the steps I followed to get the full working JUI library:

  1. Went to JUI Themeroller and created/downloaded the theme and related files
  2. Created the folder component/com_XXX/assets/jquery-ui-1.11.0.custom to contain the theme and libraries from the downloaded zip.
  3. Added the below code to my component, and "tada"...all the JUI features/functions were available.

(This place wouldn't be the same without Lodder)

JHtml::_('jquery.framework');
JHtml::_('script', JUri::root() . 'components/com_XXX/assets/jquery-ui-1.11.0.custom/jquery-ui.min.js');

1 Answer 1

1

To import additional JS libraries, you should use the JHtml method like so:

JHtml::_('script', JUri::root() . 'path/to/the/file/script.js');

There are no CDN links that I know of for separate jQueryUI widgets, which is a shame, else you could have done this:

JHtml::_('script', '//cdnjs.cloudflare.com/ajax/libs/script.js'); 

As for the location of the JS files, I would either create a folder in the "media" folder and put them in there, or add them to the same directory as the core files:

ROOT/media/jui/js

Update 1:

You don't have to replace the JUI library. The one you currently see is the core library which doesn't contain any widgets. Widgets which when imported, come from separate files and is done using the code you provided in your question. To get widgets that aren't provided with the Joomla package, you can either do as I described in my answer, or compile a JUI package on the official website and replace the jquery.ui.core.min file with it. Then, using will import the core along with the widgets that you compiled it with.

JHtml::_('jquery.ui');

This is however not recommended

Update 2:

Having looked at the documentation, you can also add you own libraries and call them using:

JHtml::_('mylibrary.myloader');

I'm not sure exactly how this works as I have never tried it, but it is also another alternative and also in favour of Update 1.

6
  • So am I to understand that the full JUI library should be replaced? And if so, does Joomla "know" to replace the default/running version with the specified version desired?
    – GDP
    Jul 2, 2014 at 14:42
  • @GDP - I've updated my answer. Hope this provides a better insight
    – Lodder
    Jul 2, 2014 at 15:18
  • Ah...found a workaround with your original answer, and it's working, but will now look into this...I'm trying to stick to "only the right way" of doing things in favor of the quick making-it-work approach, lol.
    – GDP
    Jul 2, 2014 at 15:24
  • The first part of my answer and Update 2 are both correct ways :) If you do decide to go along with the Update 2 method, I would really appreciate it if you could share how exactly you do it as it would be good to know for future reference as the documentation for this isn't very detailed
    – Lodder
    Jul 2, 2014 at 15:48
  • @GDP - Any news on your ending results/method used?
    – Lodder
    Jul 6, 2014 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.