留言板

jQuery in Liferay 7

donino pienni,修改在8 年前。

jQuery in Liferay 7

Junior Member 帖子: 81 加入日期: 11-7-2 最近的帖子
Hi everyone,

I have a portlet plugin which makes use of jquery. For Liferay 6.2 jquery is included through liferay-portlet.xml of the plugin and it works very well. In Liferay 7.0 i noticed jquery is now natively available in variable "$". Can we rely on this? I mean for performance considerations and to avoid conflicts, can we consider that starting from Liferay 7 GA1 jquery is always loaded and thus we don't have to include it anymore in liferay-portlet.xml?

Same question with bootstrap.js: it appears it is loaded in Liferay 7. I have a custom bootstrap component using it, is there a dependency module to invoke in Liferay 7 to take advantage of bootstrap.js?

Thanks!
thumbnail
David H Nebinger,修改在8 年前。

RE: jQuery in Liferay 7

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
Liferay 7 uses BS 3 and (I believe) a lite jquery.

Yes you can rely on it, but as always you are better off avoiding the $ syntax to avoid conflicts with other frameworks. Stick with the fully qualified jQuery() syntax.
donino pienni,修改在8 年前。

RE: jQuery in Liferay 7

Junior Member 帖子: 81 加入日期: 11-7-2 最近的帖子
Great news!

Thank you David.
thumbnail
William Gosse,修改在6 年前。

RE: jQuery in Liferay 7

Liferay Master 帖子: 533 加入日期: 10-7-4 最近的帖子
Do we have an answer on how to avoid a conflict with JQuery being used by the portlets?
thumbnail
David H Nebinger,修改在6 年前。

RE: jQuery in Liferay 7

Liferay Legend 帖子: 14919 加入日期: 06-9-2 最近的帖子
William Gosse:
Do we have an answer on how to avoid a conflict with JQuery being used by the portlets?


Hmm, not following William. What kind of (possible) conflict are you concerned about?
thumbnail
William Gosse,修改在6 年前。

RE: jQuery in Liferay 7

Liferay Master 帖子: 533 加入日期: 10-7-4 最近的帖子
David H Nebinger:
William Gosse:
Do we have an answer on how to avoid a conflict with JQuery being used by the portlets?


Hmm, not following William. What kind of (possible) conflict are you concerned about?


The problem turned out not to jQuery but a bad import statement in a jsp.
thumbnail
Nate Cavanaugh,修改在6 年前。

RE: jQuery in Liferay 7

Junior Member 帖子: 94 加入日期: 06-11-27 最近的帖子
I have a portlet plugin which makes use of jquery. For Liferay 6.2 jquery is included through liferay-portlet.xml of the plugin and it works very well. In Liferay 7.0 i noticed jquery is now natively available in variable "$". Can we rely on this? I mean for performance considerations and to avoid conflicts, can we consider that starting from Liferay 7 GA1 jquery is always loaded and thus we don't have to include it anymore in liferay-portlet.xml?


That is correct, you can leverage it and it will be auto included. However, if you need a different version of jQuery to run because of plugin compatibility or certain features, you can always include yours, and there shouldn't be any conflicts.

What we do is we include it, but we also assign
AUI.$ = jQuery.noConflict();

Internally, we only refer to jQuery via that namespace, that way if you load your own jQuery, we don't have to worry about plugin conflicts between the two versions.

Same question with bootstrap.js: it appears it is loaded in Liferay 7. I have a custom bootstrap component using it, is there a dependency module to invoke in Liferay 7 to take advantage of bootstrap.js?


Bootstrap is a bit trickier because it's tied to the version of Bootstrap, but it's always included, so you shouldn't have to specify any dependencies.

I hope that helps emoticon
Ricardo Vieira,修改在5 年前。

RE: jQuery in Liferay 7

Junior Member 帖子: 54 加入日期: 10-8-16 最近的帖子
Nate Cavanaugh:

What we do is we include it, but we also assign
AUI.$ = jQuery.noConflict();

Internally, we only refer to jQuery via that namespace, that way if you load your own jQuery, we don't have to worry about plugin conflicts between the two versions.


Quick question, if you already set the noConflict option, if we load our own Jquery version, do we need to set that option also ?
thumbnail
Nate Cavanaugh,修改在5 年前。

RE: jQuery in Liferay 7

Junior Member 帖子: 94 加入日期: 06-11-27 最近的帖子
No you don't, as long as you're including your version of jQuery after ours is loaded, which ours are prioritized for the top specifically for things like this, so you should be fine emoticon
Ricardo Vieira,修改在5 年前。

RE: jQuery in Liferay 7

Junior Member 帖子: 54 加入日期: 10-8-16 最近的帖子
Nate Cavanaugh:
No you don't, as long as you're including your version of jQuery after ours is loaded, which ours are prioritized for the top specifically for things like this, so you should be fine emoticon



Tnx Nate, but that brings me to another question, when do you load your version?

I'm actually using Liferay's version, but I couldn't put my jquery datatables loading in the theme cause it was loading before you load your version of jquery, so I put it on my custom portlet, it works fine like that, but for future reference, if I need it in more than 1 portlet, I would prefer to load it in my theme, so where should I load it?

Thanks again