jQuery ... is not a function error when adding in a sliding menu script.

Permalink
Hi

On trying to add the jQuery sliding menu fromhttp://www.geektantra.com/2010/02/jquery-sliding-menu/... to my menu nav in the header.php file, I am getting the following error flagged up in Firebug:

jQuery("#HorizontalSlidingMenu .SlidingMenu").slidingMenu is not a function

The C5 site is:

http://www.treadmark.org.php5-16.websitetestlink.com/...

Using Concrete5 5.4

I have included the jQuery sliding menu .js file in the header, and jQuery is loaded according to jquerify.

Any ideas where I may be going wrong?

kelbyuk
View Replies:
jgarcia replied on at Permalink Reply
jgarcia
I responded on Twitter to you, but more than 140 characters might be helpful:

jQuery is already included in C5, so there's no need to add it to your theme, as it looks like you have, from this line:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>

You can just take that out. Also, move Loader::element('header_required') so that it is before your reference jquery.sliding-menu.js. It should be the first thing after the HTML <head> tag.
jgarcia replied on at Permalink Reply
jgarcia
The forum code block kinda junked up the jquery line I was referring to, but hopefully you know what I am referring to.
kelbyuk replied on at Permalink Reply
kelbyuk
So is jQuery UI also loaded by C5? I thought that was only when it was in edit mode?

Taken the link to jQuery out and moved the Loader line to just after the <head> tag. Now the script doesnt return an error for the function, however the default theme image slide show now doesnt show.

do I have to closedown my jQuery script? And if so how is that done?

Thanks for the help with this :)
kelbyuk replied on at Permalink Reply
kelbyuk
Also after making the changes, when in edit mode I am now unable to click on the red dotted areas.
Mnkras replied on at Permalink Reply
Mnkras
Then you are loading something twice (js wise)

use a check to see if its in editmode
kelbyuk replied on at Permalink Reply
kelbyuk
putting the <?php Loader::element('header_required'); ?>
line back before the end of the head block fixes the issues with editing.

However breaks the jQuery again with the error:

jQuery is not defined
jQuery(function(){
kelbyuk replied on at Permalink Reply
kelbyuk
Shouldn't be in edit mode if I am logged out.
jgarcia replied on at Permalink Reply
jgarcia
Trust me - the 'header_required' code has to come BEFORE you refer to jQuery UI and jquery.sliding-menu.js. Those two scripts are useless without jQuery being loaded. The fact that you can't edit the selected errors is apparently a different error - I would guess related to the fact that you are loading jQuery UI twice.
Mnkras replied on at Permalink Reply
Mnkras
i don;t think the jquery UI is loaded by default out of edit mode, do an if else maybe for the editmode
kelbyuk replied on at Permalink Reply
kelbyuk
So far have the following:

<head>
<!-- Site Header Content //-->
<?php  Loader::element('header_required'); ?>
<?php $html = Loader::helper('html');
$this->addHeaderItem($html->javascript('jquery.js', 'CORE')); ?>
<link rel="stylesheet" media="screen" type="text/css" href="<?php echo $this->getStyleSheet('main.css')?>" />
<link rel="stylesheet" media="screen" type="text/css" href="<?php echo $this->getStyleSheet('typography.css')?>" />
<?php  if ($c->isEditMode()) { 
   echo"edit mode" ?>
<?php  } else { echo"display mode"?>
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script> 
<?php  } ?>
<script type="text/javascript" src="<?php echo $this->getThemePath()?>/js/jquery.sliding-menu.js"></script>
<script type="text/javascript">
jQuery(function(){


still getting the error in firebug:

jQuery("#HorizontalSlidingMenu .slidingMenu").slidingMenu is not a function

don't know where to go from here, any more ideas or have I done something fundamentaly wrong in my header?
JimboJetset replied on at Permalink Reply
JimboJetset
I have attached a possible solution to this in your other post...
http://www.concrete5.org/community/forums/block_requests/jquery-lav...
mkharisecario replied on at Permalink Reply
mkharisecario
well, I must say thanks for jgarcia...

I had some problem with adding html code including java inside, but when I put it in html block it always make editor bar dissapear and I can't edit that page anymore! even I can't restore it to older version of my page...

But it solved when I delete
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>


After I read this discussion, I think the main problem when we got error from put javascript is because of that script...maybe?

anyway, thanks all...