silverstripe-betternavigator/javascript/betternavigator.js
Jono Menz 8fedcf0c21 Fixed cookie path for menu state
Was saving separate collapsed/open menu state for each directory
2014-10-03 13:01:32 -06:00

36 lines
1.1 KiB
JavaScript
Executable File

//For reading cookies
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
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 "";
}
//Do some stuff when the dom is loaded. (Won't work in IE8 or lower)
document.addEventListener("DOMContentLoaded", function() {
//Dom elements
var BetterNavigator = document.getElementById("BetterNavigator");
var BetterNavigatorStatus = document.getElementById("BetterNavigatorStatus");
//Toggle visibility of menu by clicking status
BetterNavigatorStatus.onclick=function(){
BetterNavigator.className = BetterNavigator.className === 'collapsed' ? 'open' : 'collapsed';
//Set cookie to remember state
document.cookie="BetterNavigator=" + BetterNavigator.className + ";path=/";
};
//Restore menu state
if (getCookie('BetterNavigator') === 'open') {
BetterNavigator.className = 'open';
}
});