<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
</script>
<script type="text/javascript">
$(document).ready(function() {
$('ul#nav_menu_content ul').each(function(i) { // Check each submenu:
if ($.cookie('submenuMark-' + i)) { // If index of submenu is marked in cookies:
$(this).show().prev().removeClass('collapsed').addClass('expanded'); // Show it (add apropriate classes)
}else {
$(this).hide().prev().removeClass('expanded').addClass('collapsed'); // Hide it
}
$(this).prev().addClass('collapsible').click(function() { // Attach an event listener
var this_i = $('ul#nav_menu_content ul').index($(this).next()); // The index of the submenu of the clicked link
if ($(this).next().css('display') == 'none') {
// When opening one submenu, we hide all same level submenus:
$(this).parent('li').parent('ul').find('ul').each(function(j) {
if (j != this_i) {
$(this).slideUp(200, function () {
$(this).prev().removeClass('expanded').addClass('collapsed');
cookieDel($('ul#nav_menu_content ul').index($(this)));
});
}
});
// :end
$(this).next().slideDown(200, function () { // Show submenu:
$(this).prev().removeClass('collapsed').addClass('expanded');
cookieSet(this_i);
});
}else {
$(this).next().slideUp(200, function () { // Hide submenu:
$(this).prev().removeClass('expanded').addClass('collapsed');
cookieDel(this_i);
$(this).find('ul').each(function() {
$(this).hide(0, cookieDel($('ul#nav_menu_content ul').index($(this)))).prev().removeClass('expanded').addClass('collapsed');
});
});
}
return false; // Prohibit the browser to follow the link address
});
});
});
function cookieSet(index) {
$.cookie('submenuMark-' + index, 'opened', {expires: null, path: '/'}); // Set mark to cookie (submenu is shown):
}
function cookieDel(index) {
$.cookie('submenuMark-' + index, null, {expires: null, path: '/'}); // Delete mark from cookie (submenu is hidden):
}
</script>
</head>
<body>
<ul class='left_nav_menu' id='nav_menu_content'>
<li><a href='#0'>Категория_1</a>
<ul>
<li><a href="#">Подкатегория_1</a>
<ul>
<li><a href="view_cat.php?...">Подподкатегория_1</a></li>
</ul>
</li>
<li><a href="#">Подкатегория_2</a>
<ul>
<li><a href="view_cat.php?...">Подподкатегория_2</a></li>
<li><a href="view_cat.php?...">Подподкатегория_3</a></li>
</ul>
</li>
<li><a href="#">Подкатегория_3</a>
<ul>
<li><a href="view_cat.php?...">Подподкатегория_4</a></li>
<li><a href="view_cat.php?...">Подподкатегория_5</a></li>
</ul>
</li>
</ul>
</li>
<li><a href='#0'>Категория_2</a>
<ul>
<li><a href="#">Подкатегория_4</a>
<ul class="material_cat">
<li><a href="view_cat.php?...">Подподкатегория_6</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</body>
</html>