Skip to content

Commit

Permalink
Invert colors works in ie8. Fix a lame js error that stopped the dark…
Browse files Browse the repository at this point in the history
…/light mode from being persisted across refreshes.
  • Loading branch information
ggreer committed May 18, 2013
1 parent 39166cb commit f2a8826
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<script type="text/javascript">
var _gaq = _gaq || [];
var main_css = document.getElementById("main-css");
var code_css = document.getElementById("code-css");
var styles = {
light: ["Light", "", "/styles/main.css", "/styles/solarized-light.css"],
dark: ["Dark", "#000", "/styles/main-inverted.css", "/styles/solarized-dark.css"]
Expand All @@ -29,19 +28,20 @@
_gaq.push(["_setCustomVar", 1, "Color", style[0], 1]);
document.body.style.background = style[1];
main_css.attributes.href.value = style[2];
code_css.attributes.href.value = style[3];
date.setTime(date.getTime() + 30 * 24 * 60 * 60 * 1000);
document.cookie = "main-css=" + main_css.attributes.href.value + "; expires=" + date.toGMTString() + "; path=/";
return style;
}
function set_colors() {
document.cookie.split("; ").forEach(function (cookie) {
var key = cookie.split("=")[0];
var value = cookie.split("=")[1];
var i, cookies, key, value;
cookies = document.cookie.split("; ");
for (i = 0; i < cookies.length; i++) {
key = cookies[i].split("=")[0];
value = cookies[i].split("=")[1];
if (key === "main-css" && value === "/styles/main-inverted.css") {
set_style(styles.dark);
}
});
}
if (window.location.hash.slice(1) === "dark") {
set_style(styles.dark);
} else if (window.location.hash.slice(1) === "light") {
Expand Down Expand Up @@ -178,7 +178,9 @@
</div>

<p>
<div id="beast-mode" onclick="invert_colors()">Invert colors.</div>
<div id="beast-mode" onclick="invert_colors()">
<span>Invert colors.</span>
</div>
<a href="https://github.com/ggreer/lscolors">
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub" /></a>
</p>
Expand Down

0 comments on commit f2a8826

Please sign in to comment.