Set cookies - removeClass, addClass.
Im trying to make a toggle menu side bar but i can't fix the cookies.
This is the java im using:
- $(document).ready(function () {
$("#navigationToggle").click(function () {
$(this).addClass("expand");
var closed = $("#left_col_top").is(":hidden");
if (closed)
$("#left_col").removeClass();
$("#left_col_top").show();
else
$("#left_col").addClass("noSidebar");
$("#left_col_top").hide();
setCookie("open", closed, 365);
});
var openToggle = getCookie("open");
if (openToggle=="true") {
$("#left_col").removeClass();
$("#left_col_top").show();
}
else {
$("#left_col").addClass("noSidebar");
$("#left_col_top").hide();
}
});
function setCookie(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
}
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
}
The ideas is that:
When i click #navigationToggle i want to it a class ( .expand ), to add a class to #left_col_top and to #left_col
And when i click it back ( the same id #navigationToggle but now #navigationToggle.expand) to remove the classes that i just added.
- $("#navigationToggle").click(function () {
$(this).addClass('expand');
$("#left_col").addClass('first-class');
$("#left_col_top").addClass('second-class');
});
$("#navigationToggle.expand").click(function () {
$("#left_col").removeClass();
$("#left_col_top").removeClass();
});
But i don't know how to set the cookies because i want to save the effect