これは、1つだけのGoogle機能を持つように改善できますか?クッキーへのトグル保存を使用した表示/非表示
var show = $("#shows ul li");
show.addClass("active");
$(show).each(function(c){
var cvalue = $.cookie('show' + c);
if (cvalue == 'closed' + c) {
$(this).css({display:"none"});
$(this).removeClass('active').addClass('inactive');
};
});
$("#shows li.active").toggle(function(){
var num = show.index(this);
var cookieName = 'show' + num;
var cookieValue = 'closed' + num;
$(this).slideUp(500);
$(this).removeClass('active');
$.cookie(cookieName, cookieValue, { path: '/', expires: 10 });
},function(){
var num = $(this).index(this);
var cookieName = 'show' + num;
$(this).slideDown(500);
$(this).addClass("active");
$.cookie(cookieName, null, { path: '/', expires: 10 });
});
$("#shows li.inactive").toggle(function(){
var num = show.index(this);
var cookieName = 'show' + num;
$(this).slideDown(500);
$(this).addClass("active");
$(this).removeClass('inactive');
$.cookie(cookieName, null, { path: '/', expires: 10 });
},function(){
var num = show.index(this);
var cookieName = 'show' + num;
var cookieValue = 'closed' + num;
$(this).slideUp(500);
$(this).removeClass('active');
$.cookie(cookieName, cookieValue, { path: '/', expires: 10 });
});
この質問は、より良いhttp://codereview.stackexchange.comで対処されるだろう/ – Moses