Skip to content
Permalink
Browse files

Fix stylesheet chooser

Add style cookie to privacy policy
  • Loading branch information...
georgewatson committed Apr 11, 2019
1 parent 6bf857d commit dff4bf8f7eda7f2ebd0b37a9f2b890155716faba
Showing with 75 additions and 16 deletions.
  1. +2 −2 _includes/footer.html
  2. +2 −2 _includes/head.html
  3. +62 −12 assets/style_switcher.js
  4. +9 −0 privacy_policy.md
@@ -16,10 +16,10 @@
</p>
<p>
Set style:
<a href="#top" onclick="switchStyle('Default Style');return false;"
<a href="#top" onclick="setActiveStyleSheet('Default');return false;"
name="theme" value="Default Style" id="default-style">Default</a>
&bull;
<a href="#top" onclick="switchStyle('Accessible Style');return false;"
<a href="#top" onclick="setActiveStyleSheet('Accessible');return false;"
name="theme" value="Accessible Style" id="accessible-style">Accessible</a>
<p>autocommand BufWritePost * !git add . &amp;&amp;
git commit -m "Update" &amp;&amp;
@@ -34,9 +34,9 @@

{% seo %}

<link rel="stylesheet" type="text/css" title="Default Style"
<link rel="stylesheet" type="text/css" title="Default"
href="{{ "/assets/main.css" | relative_url }}"/>
<link rel="alternate stylesheet" type="text/css" title="Accessible Style"
<link rel="alternate stylesheet" type="text/css" title="Accessible"
href="{{ "/assets/accessible.css" | relative_url }}"/>

<link rel="apple-touch-icon" sizes="180x180"
@@ -1,15 +1,65 @@
function switchStyle (stylesheetTitle) {
var i
var linkElement
for (i = 0,
linkElement = document.getElementsByTagName('link');
i < linkElement.length; i++) {
if ((linkElement[i].rel.indexOf('stylesheet') !== -1) &&
linkElement[i].title) {
linkElement[i].disabled = true
if (linkElement[i].title === stylesheetTitle) {
linkElement[i].disabled = false
}
function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}

function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
}
return null;
}

function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1
&& a.getAttribute("rel").indexOf("alt") == -1
&& a.getAttribute("title")
) return a.getAttribute("title");
}
return null;
}

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
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;
}

window.onload = function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
}

window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

@@ -53,6 +53,15 @@ For more information, see:
* ["Privacy and the cfduid cookie" --- CloudFlare
Support](https://support.cloudflare.com/hc/en-us/articles/360024915491)

A cookie may also be used to store your stylesheet preference.
This cookie is called `style` and contains your chosen stylesheet,
if you choose to use the links in the page footer to change between the Default
and Accessible stylesheets.
This cookie does not identify you personally and cannot be used to track you.
This cookie is provided purely for your convenience and will not be set
unless you choose a stylesheet.
No cookie will be set if you use your browser's built-in stylesheet selector.

Other cookies may be stored by the following trusted partners.
Links to their cookie policies are provided below.
* [CloudFlare](https://www.cloudflare.com/cookie-policy/)

0 comments on commit dff4bf8

Please sign in to comment.
You can’t perform that action at this time.