|
$('.remove_cat').click(function() { |
|
$(this).parent('.applications').hide('slow'); // hides the selected cookie. |
|
checkCookie($(this).parent('.applications').attr("id")); // Runs the checkCookie to store the category in the cookie. |
|
}); |
|
|
|
$('.show_all').click(function() { |
|
$('.applications').show('slow'); //Displays all categories |
|
setCookie("category", "null", -1); //Deletes the category cookie |
|
}); |
|
|
|
function setCookie(cname, cvalue, exdays) { // This function is what sets the cookie. I just use this function to shorten my code. |
|
var d = new Date(); |
|
d.setTime(d.getTime() + (exdays*24*60*60*1000)); |
|
var expires = "expires="+d.toGMTString(); |
|
document.cookie = cname + "=" + cvalue + "; " + expires + "; path=/"; |
|
} |
|
|
|
function getCookie(cname) { |
|
var name = cname + "="; // sets the cookie name as a string |
|
var ca = document.cookie.split(';'); //Gets all the cookies in the browser and splits them by usign the semi-colon setting them in the ca array. |
|
for(var i=0; i<ca.length; i++) { // Loops through the ca array and only returns the cookie with the name matching category |
|
var c = ca[i]; |
|
while (c.charAt(0)==' ') c = c.substring(1); |
|
if (c.indexOf(name) != -1) return c.substring(name.length, c.length); |
|
} |
|
return ""; // If there is no value submited, return blank. |
|
} |
|
|
|
function checkCookie(new_category) { |
|
var category = getCookie("category"); // Gets the category cookie using the getCookie function. |
|
if (category !== "" && category !== null) { // If the category variable is not empty or null it found something. It gets the cookie and then adds to the end of the cookie the new category to be hidden. |
|
category = category + "," + new_category; |
|
setCookie("category", category, 365); // Set a new cookie with the all the categories and an expiration date of a year. |
|
} else { // Didn't find a cookie. |
|
category = new_category; // Get the cartegory to hide. |
|
setCookie("category", category, 365); // Set a new cookie with the category and an expiration date of a year. |
|
} |
|
} |