Markup such as
<div id="Player1"></div> <div id="Player2"></div> ... <div id="Player100"></div> Browser cookies are written id blocks for example
Player1 Player5 Player30 etc
How to display blocks with id that are not in cookies? Or register display:none; for blocks that are in cookies.
I write to cookies by this script.
var views = { save: function(b){ var a = localStorage['level']; a = a ? JSON.parse(a) : new Object; var i = a[b] ? a[b] : new Object; i[b] = b; a[b] = i; if(b && !$('#Player' + b).hasClass('views')){ $('#Player' + b).addClass('views'); localStorage['level'] = JSON.stringify(a); console.log('#Player' + b + ' addClass views'); } }, check: function(b){ var a = localStorage['level']; a = a ? JSON.parse(a) : new Object; $(b).find('a').each(function(){ var id = $(this).attr('id').replace('Player', ''); if(a[id]){ $('#Player' + id).addClass('views'); console.log('#Player' + id + ' addClass views'); } }); } } views.check('.play_list'); $(function(){ $('.play').click(function(e){ var id = $(this).attr('id').replace('Player', ''); views.save(id); e.preventDefault(); }); $('.clear').click(function(e){ localStorage['level'] = ''; $('.play_list').find('a').each(function(){ var id = $(this).attr('id').replace('Player', ''); if(id && $('#Player' + id).hasClass('views')){ $('#Player' + id).removeClass('views'); console.log('#Player' + id + ' removeClass views'); } }); e.preventDefault(); }); });
var i = a[b] ? a[b] : new Object; i[b] = b; a[b] = i;It feels like I'm reading minified code :) - Michael P. Bazos