Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Delph SA
Pb loading jQuery in liferay portlet
May 16, 2012 6:44 AM
Answer

Delph SA

Rank: New Member

Posts: 3

Join Date: May 16, 2012

Recent Posts

Hi,

I want to use jQuery in a portlet, i found a way to do this in this blog :
http://www.liferay.com/web/jonas.yuan/blog/-/blogs/building-jquery-based-plugins-in-liferay-6

I add this two line in liferay-portlet.xml :
1<header-portlet-javascript>/js/slidecarousel.js</header-portlet-javascript>
2<footer-portlet-javascript>http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js</footer-portlet-javascript>


Here my js code :
 1$(document).ready(function() {
 2    alert(jQuery(document).jquery); // whithout this line it doesn't work
 3   
 4    $(".v-caption-flecheJauneGauche").click(function() {
 5        $(".carousel").animate({"left": "-=104px"}, "slow");
 6    });
 7   
 8    $(".v-caption-flecheJauneDroite").click(function() {
 9        $(".carousel").animate({"left": "+=104px"}, "slow");
10    });
11   
12    $(".detail").click(function() {
13        alert("detail");
14    });
15});


Without the first alert it doesn't work, and this code (the animations) only work in Firefox i don't no why...

Thanks in advance for your help.
Delphin.
David H Nebinger
RE: Pb loading jQuery in liferay portlet
May 23, 2012 8:25 AM
Answer

David H Nebinger

Rank: Liferay Legend

Posts: 6557

Join Date: September 1, 2006

Recent Posts

Try using a local copy of jquery.min.js rather than pulling from the web.
Hitoshi Ozawa
RE: Pb loading jQuery in liferay portlet
May 23, 2012 5:06 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

What David means is download jquery from the following url and save it in your /js folder.
http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js

set
<header-portlet-javascript>/js/jquery.js</header-portlet-javascript>
<footer-portlet-javascript>/js/slidecarousel.js</footer-portlet-javascript>
Delph SA
RE: Pb loading jQuery in liferay portlet
June 8, 2012 6:10 AM
Answer

Delph SA

Rank: New Member

Posts: 3

Join Date: May 16, 2012

Recent Posts

I found a solution but it doesn't work everytime, i have to refresh (one or more time) the page to use it.

 1
 2AUI().use('get', function(A){
 3    A.Get.script('http://code.jquery.com/jquery-1.7.2.min.js', {
 4        onSuccess: function(){
 5            // my code
 6      }
 7
 8 });
 9});


I also try to download jquery and put it in js folder with this line :
<header-portlet-javascript>/js/jquery.js</header-portlet-javascript>
but it doesn't work.
Arya Nugroho
RE: Pb loading jQuery in liferay portlet
June 9, 2012 1:27 AM
Answer

Arya Nugroho

Rank: New Member

Posts: 11

Join Date: October 11, 2011

Recent Posts

delps hi, my suggestions may help you. try using the specific selector for jQuery library (jQuery), because Liferay also has a javascript library like yui and others.
if you use ($) selector, that's can make your function not run well.
Example :

<script type="text/javascript">
jQuery(function(){
jQuery("something").yourFuction({
})
});
</script>

and if you put a jQuery function in jsp file, try to put at the bottom of your jsp code.

Salam,
Arya
Delph SA
RE: Pb loading jQuery in liferay portlet
June 12, 2012 1:00 AM
Answer

Delph SA

Rank: New Member

Posts: 3

Join Date: May 16, 2012

Recent Posts

I replace all '$' by 'jQuery', there is no difference emoticon