Last active
December 24, 2015 09:59
-
-
Save phongjalvn/6780729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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