game/i/clanpanel/tabs_cookies.js

42 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-12-19 20:22:19 +00:00
(function($) {
$(function() {
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
$('ul.tabs').each(function(i) {
var cookie = readCookie('tabCookie'+i);
if (cookie) $(this).find('li').eq(cookie).addClass('current').siblings().removeClass('current')
.parents('div.section').find('div.box').hide().eq(cookie).show();
})
$('ul.tabs').delegate('li:not(.current)', 'click', function() {
$(this).addClass('current').siblings().removeClass('current')
.parents('div.section').find('div.box').eq($(this).index()).fadeIn(150).siblings('div.box').hide();
var ulIndex = $('ul.tabs').index($(this).parents('ul.tabs'));
eraseCookie('tabCookie'+ulIndex);
createCookie('tabCookie'+ulIndex, $(this).index(), 365);
})
})
})(jQuery)