Solved

Jquery in Joomla Install

Posted on 2013-10-25
11
273 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

919 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

14 Experts available now in Live!

Get 1:1 Help Now