mirror of https://github.com/docker/docs.git
Add cookie saving for day/night mode
This commit is contained in:
parent
12c25322c3
commit
20c91a529b
39
js/docs.js
39
js/docs.js
|
@ -1,3 +1,37 @@
|
|||
// Cookie functions
|
||||
function createCookie(name,value,days) {
|
||||
var expires = "";
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days*24*60*60*1000));
|
||||
expires = "; expires=" + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + "=" + value + expires + "; path=/";
|
||||
}
|
||||
|
||||
function readCookie(name) {
|
||||
var nameEQ = name + "=";
|
||||
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,c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function eraseCookie(name) {
|
||||
createCookie(name,"",-1);
|
||||
}
|
||||
if (readCookie("night") == "true") {
|
||||
document.getElementById('pagestyle').setAttribute('href', '/css/style-alt.css');
|
||||
$('#switch-style').prop('checked', true);
|
||||
} else {
|
||||
document.getElementById('pagestyle').setAttribute('href', '/css/style.css');
|
||||
$('#switch-style').prop('checked', false);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* swapStyleSheet*********************************************************************
|
||||
|
@ -97,11 +131,10 @@ $('#switch-style').change(function() {
|
|||
|
||||
if ($(this).is(':checked')) {
|
||||
swapStyleSheet('/css/style-alt.css');
|
||||
|
||||
|
||||
createCookie("night",true,999)
|
||||
} else {
|
||||
swapStyleSheet('/css/style.css');
|
||||
|
||||
eraseCookie("night")
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue