Skip to content

Commit

Permalink
Add cookie saving for day/night mode
Browse files Browse the repository at this point in the history
  • Loading branch information
johndmulhausen committed Feb 25, 2017
1 parent 12c2532 commit 20c91a5
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions js/docs.js
Original file line number Diff line number Diff line change
@@ -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*********************************************************************
Expand Down Expand Up @@ -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")
}
});

Expand Down

0 comments on commit 20c91a5

Please sign in to comment.