Solved

Jquery in Joomla Install

Posted on 2013-10-25
11
271 Views
Last Modified: 2013-10-28
Hi all,

I have a module in a joomla installation which uses jquery.

Basically I have a link (with url='#') on one side of the page, when the user clicks this I use jquery to slide a div panel containing a form out.

However, when clicking it redirecting to the same url but with the # char appended?

Is this a setting I am missing? Has anyone else seen this?

	$('#profile-slide').click(function(){
		$("#floating-profile").animate({left: parseInt((state % 2 - 1) * (332)) + 'px'}, "slow");
    state++;
  });    

Open in new window


    	<div id="floating-profile">
           	<div class="tab"><a id="profile-slide" href="#"><img src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/images/view-profile.png" alt="View my Profile"/></a></div>
            <div id="floating-content">
            	<jdoc:include type="modules" name="floating-profile"/>
        	</div>
    	</div>

Open in new window

0
Comment
Question by:flynny
  • 6
  • 5
11 Comments
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39600713
Try adding this to your click function:
event.preventDefault();
0
 

Author Comment

by:flynny
ID: 39600726
where abouts please? I have tried adding this to the end of the click function  but it has not worked?
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39600762
$('#profile-slide').click(function(e){
            $("#floating-profile").animate({left: parseInt((state % 2 - 1) * (332)) + 'px'}, "slow");
                e.preventDefault();
    state++;
  });
0
 

Author Comment

by:flynny
ID: 39605195
Many thanks for this.

Ok it seems to be working fine on Chrome,

But in IE and Firefox, clicking to slide out works, but when the button is clicking to slide back in it is not working.

coudl this code cause this issue?

can be seen here, ive setup a default user;

www.asianrishta.co.uk
login: mflynn pass: mflynn

on the left hand side you can see the view profile button.
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39605227
having a look now...
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:flynny
ID: 39605229
hi PierreC,

I have just debugged using jquery and seen that I was missing passing the 'e' event tot he function.

I have changed this re freflect the above, but unfortunately it now still seems to be redirecting?
0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 500 total points
ID: 39605242
refer to:
 $('#profile-slide').click(function(e){
$("#floating-profile").animate({left: parseInt((state % 2 - 1) * (332)) + 'px'}, "slow");
event.preventDefault();
state++;
}); 

Open in new window

you are passing it as "e", but referring to it as "event". So after the call to event.preventDefault() an error occurs and "state++" never gets called which is what is breaking your close/hide action as the formula you are using relies on the state var.
change event.preventDefault();
to e.preventDefault();


another thing, why use that formula and state var? why not just?
if ($("#floating-profile").position().left === 0) { $("#floating-profile").animate({left: "-=332px"}, "slow");}
else { $("#floating-profile").animate({left: "+=332px"}, "slow");}

Open in new window

0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39605263
I see you updated and it is working now :)

I tested using:
Firefox 23
Chrome 28
IE 10

works in all 3
0
 

Author Comment

by:flynny
ID: 39605283
Hi Pierre,

Many thanks for this.

Sorry I should have seen this error. Many thanks.

The slide back is automatically added in to but obviously as it was erroring on the event it was not hooking this up.

Thanks again.
0
 

Author Closing Comment

by:flynny
ID: 39605284
Excellant response and coding.
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 39605285
Glad to help. Good luck.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now