Hello,
I am trying to get my menu system to read a cookie to it can remember the menu state. once remembered the menu would stayopen/close depending on the cookie.
using alert in the javascript ive been able to read the cookie before and after clicks but sadly I cannot get the if statement correct in order to keep open/close the hidden html.
any help much appreciated!
code below:
HTML
<li class="primary"><a href="user/me">My Profile</a></li>
<div class="menu_content">
<ul>
<li class="secondary"><a href="<?php print base_path() ?>user/my-education">My Education History</a></li>
<li class="secondary"><a href="<?php print base_path() ?>user/my-achievements">My Achievements</a>
<ul>
<li><a href="user/school">School</a></li>
<li><a href="user/my-achievements/year1">Year 1</a></li>
</ul>
</li>
<li class="secondary"><a href="user/my-details">My Account Details</a></li>
<li class="secondary"><a href="user/my-settings">My Account Settings</a></li>
</ul>
</div>
<li class="primary"><a href="compare">Compare</a></li>
<div class="menu_content">
<ul>
<li class="secondary"><a href="user/my-scores">My Scores</a></li>
</ul>
</div>
Jquery
var state = $.cookie("panelState");
$("li.primary").click(function(){
if($.cookie("panelState") == "expanded") {
$(this).next().slideToggle('300');
$(this).removeClass("open");
$(this).cookie("panelState", "collapsed");
alert($.cookie("panelState"));
} else if ($.cookie("panelState") == "collapsed") {
$(this).next().slideToggle('300');
$(this).addClass("open");
$(this).cookie("panelState", "expanded");
alert($.cookie("panelState"));
}
});