Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Меню аккордеон на jQuery + cookie (https://javascript.ru/forum/jquery/38049-menyu-akkordeon-na-jquery-cookie.html)

SergeyMiracle 16.05.2013 22:58

Меню аккордеон на jQuery + cookie
 
Привет всем, ребят сам не сильно разбираюсь в java, настроил менюшку и код собрал с просторов интернета, все вроде работает, но иногда проскакивает глюк, положение не сохраняет... Прошу гуру глянуть на код и подсказать где не то... За ранее спасибо :)
$(document).ready(function() {

	$('ul#accordion 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#accordion ul').index($(this).next()); // The index of the submenu of the clicked link
			if ($(this).next().css('display') == 'none') {
				$(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#my-menu 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):
}

$(function(){
       $("#accordion a").each(function(){
               if ($(this).attr("href") == window.location.pathname){
                       $(this).addClass("current");
               }
       });
});

SergeyMiracle 17.05.2013 16:35

Ответов 0 значит все ок? :)


Часовой пояс GMT +3, время: 12:37.