<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.1.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: A simple jQuery menu with persistence using cookies</title>
	<link>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/</link>
	<description>Stuff</description>
	<pubDate>Thu, 08 Jan 2009 12:07:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.3</generator>

	<item>
		<title>By: Jon</title>
		<link>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/#comment-9028</link>
		<author>Jon</author>
		<pubDate>Sun, 20 Jan 2008 05:35:37 +0000</pubDate>
		<guid>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/#comment-9028</guid>
					<description>I added a third level navigation under item 3.1 but it always starts opened when item three is clicked.  Can it be made to start closed?  Also, my preference would be to close item three if, for example, item five were clicked.  Can that be accomplished?  Thank you.</description>
		<content:encoded><![CDATA[<p>I added a third level navigation under item 3.1 but it always starts opened when item three is clicked.  Can it be made to start closed?  Also, my preference would be to close item three if, for example, item five were clicked.  Can that be accomplished?  Thank you.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Flipflops</title>
		<link>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/#comment-9089</link>
		<author>Flipflops</author>
		<pubDate>Tue, 22 Jan 2008 15:17:08 +0000</pubDate>
		<guid>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/#comment-9089</guid>
					<description>Hi Jon

In principle it could do both of these thing, but it would need tweaking - but I do intend to keep adding / modifying the code - particularly the multi level code. The multi level code should be easy enough - just need to make the function recursive somehow (adjusting the jquery selector to allow this I suppose) 

I think the best way to have the menu start closed is to just apply a class to the sub menu(s) so that when the page loads but before any JavaScript runs the sub menu is hidden purely by CSS.</description>
		<content:encoded><![CDATA[<p>Hi Jon</p>
<p>In principle it could do both of these thing, but it would need tweaking - but I do intend to keep adding / modifying the code - particularly the multi level code. The multi level code should be easy enough - just need to make the function recursive somehow (adjusting the jquery selector to allow this I suppose) </p>
<p>I think the best way to have the menu start closed is to just apply a class to the sub menu(s) so that when the page loads but before any JavaScript runs the sub menu is hidden purely by CSS.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Christopher</title>
		<link>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/#comment-9348</link>
		<author>Christopher</author>
		<pubDate>Tue, 10 Jun 2008 23:07:36 +0000</pubDate>
		<guid>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/#comment-9348</guid>
					<description>Have you taken a look back at your code since you wrote that last comment in January?

I too am interested in accomplishing what Jon was asking about ... having the sub menus closed on page loading, and also some way of having only one sub menu opened at a time -- having it automatically close any other sub menu that is currently active.

I've tried tweaking the code to no avail, and I just don't know enough about jquery to be able to write the proper functions to accomplish this.

Do you think you could please help?</description>
		<content:encoded><![CDATA[<p>Have you taken a look back at your code since you wrote that last comment in January?</p>
<p>I too am interested in accomplishing what Jon was asking about &#8230; having the sub menus closed on page loading, and also some way of having only one sub menu opened at a time &#8212; having it automatically close any other sub menu that is currently active.</p>
<p>I&#8217;ve tried tweaking the code to no avail, and I just don&#8217;t know enough about jquery to be able to write the proper functions to accomplish this.</p>
<p>Do you think you could please help?</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Flipflops</title>
		<link>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/#comment-9349</link>
		<author>Flipflops</author>
		<pubDate>Thu, 12 Jun 2008 08:15:41 +0000</pubDate>
		<guid>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/#comment-9349</guid>
					<description>Hi Christopher

Sorry started fiddling around, found that what I wanted to do was harder than it looked and forgot about it. But I'll have a look for you.

Making the menu closed when the page loads basically just involves removing the cookie code, so the menu has no memory...

Makings sure that only one sub menu opens at a time should just involve closing all the sub menus first or something like that...</description>
		<content:encoded><![CDATA[<p>Hi Christopher</p>
<p>Sorry started fiddling around, found that what I wanted to do was harder than it looked and forgot about it. But I&#8217;ll have a look for you.</p>
<p>Making the menu closed when the page loads basically just involves removing the cookie code, so the menu has no memory&#8230;</p>
<p>Makings sure that only one sub menu opens at a time should just involve closing all the sub menus first or something like that&#8230;</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Flipflops</title>
		<link>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/#comment-9350</link>
		<author>Flipflops</author>
		<pubDate>Thu, 12 Jun 2008 09:27:56 +0000</pubDate>
		<guid>http://www.flipflops.org/2008/01/19/a-simple-jquery-menu-with-persistence-using-cookies/#comment-9350</guid>
					<description>Hi Christopher

Have got a solution for you.

&lt;pre lang="javascript" line="1"&gt;
&lt;script langauge="javascript"&gt;
$(document).ready(function() {

	$("#demo-menu &gt; li &gt; a").not(":first").find("+ ul").slideUp(1);
			
	$("#demo-menu &gt; li &gt; a &gt; span").text('+'); // add an indicator to the menu items to show there is a child menu
	
	$("#demo-menu &gt; li&gt; a").each(function() {
		toggleMenu(this);
	
	});


	function toggleMenu(id) {
		$(id).click(function() {
			var flag = 1;
			
			if($(this).find("+ ul").is(':visible')) {
				// set flag to hide the menu we have just clicked on if it is open - as we have clicked to close it.
				flag = 0;
			}
			
		$("#demo-menu &gt; li&gt; a").each(function() {
		
			/*
			* hide all the menus
			*/
			
			if($(this).find("+ ul").is(':visible')) {
					$(this).find("+ ul").hide();
					$(this).children("span").text('+');
			}
		});

		if(flag == 1) {
			$(this).find("+ ul").slideDown(500);
			$(this).children("span").text('-');
		}

			});
	}

});
&lt;/script&gt;
&lt;/pre&gt;

Just drop the above script in place of the cookie using code. This will have all the menus closed on startup and will only allow one sub menu to be open at a time.

John</description>
		<content:encoded><![CDATA[<p>Hi Christopher</p>
<p>Have got a solution for you.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="javascript">&lt;script langauge=<span style="color: #3366CC;">&quot;javascript&quot;</span>&gt;
$<span style="color: #66cc66;">&#40;</span>document<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">ready</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#demo-menu &gt; li &gt; a&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">not</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;:first&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;+ ul&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">slideUp</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#demo-menu &gt; li &gt; a &gt; span&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">text</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'+'</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #009900; font-style: italic;">// add an indicator to the menu items to show there is a child menu</span>
&nbsp;
	$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#demo-menu &gt; li&gt; a&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		toggleMenu<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> toggleMenu<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		$<span style="color: #66cc66;">&#40;</span>id<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">click</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> flag = <span style="color: #CC0000;">1</span>;
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;+ ul&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">':visible'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// set flag to hide the menu we have just clicked on if it is open - as we have clicked to close it.</span>
				flag = <span style="color: #CC0000;">0</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		$<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;#demo-menu &gt; li&gt; a&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">/*
			* hide all the menus
			*/</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;+ ul&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #000066; font-weight: bold;">is</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">':visible'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;+ ul&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">hide</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
					$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;span&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">text</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'+'</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>flag == <span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">find</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;+ ul&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">slideDown</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">500</span><span style="color: #66cc66;">&#41;</span>;
			$<span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">children</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;span&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">text</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'-'</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&lt;/script&gt;</pre></td></tr></table></div>

<p>Just drop the above script in place of the cookie using code. This will have all the menus closed on startup and will only allow one sub menu to be open at a time.</p>
<p>John</p>
]]></content:encoded>
				</item>
</channel>
</rss>
