Solved

Jquery in Joomla Install

Posted on 2013-10-25
11
277 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
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: 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
 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Checkout Page Input Field not aligned 1 23
If condition on Html with Asp 11 18
key press alert 2 19
Add shadow behind div 5 14
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

832 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