Skip to content

Instantly share code, notes, and snippets.

@phongjalvn
Last active December 24, 2015 09:59
Show Gist options
  • Save phongjalvn/6780729 to your computer and use it in GitHub Desktop.
Save phongjalvn/6780729 to your computer and use it in GitHub Desktop.
$(function(){
//Get saved items from cookie as string
var readedItemsFromCookie = $.cookie('readedItems'),
readedItems = [],
//Cache links for better performance
newlink = $('.new a');
if(readedItemsFromCookie){
//Use split function to convert from saved string to array
readedItems = readedItemsFromCookie.split(',');
//Loop through saved items
for(var i = 0; i < readedItems.length; i++){
//Get index value from saved item
var index = readedItems[i],
//use jquery .eq() function to get link item with saved index
link = newlink.eq(index);
//and remove span
link.next('span').remove();
//add 'old' class to parent
link.parent().addClass('old');
}
}
//for each link, get index
newlink.each(function(index, ele){
//jquery cache
var $this = $(this);
$this.click(function(){
//Remove icon
$this.next('span').remove();
//add 'old' class to parent
$this.parent().addClass('old');
//Add new readed item to array
readedItems.push(index);
//Save to cookie
$.cookie('readedItems', readedItems.join(','));
// return false;
});
});
//$.cookie('readedItems','');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment