Fix style switching problem in the updated JavaScript.

This commit is contained in:
mtail 2019-02-13 20:24:41 -08:00
parent 995ade5d61
commit 0077232110
8 changed files with 14 additions and 13 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,3 @@
"use strict";function applyStyleSheet(b){let c,d;for(c=0;d=document.getElementsByTagName("link")[c];c++)-1!==d.getAttribute("rel").indexOf("style")&&d.getAttribute("title")&&(d.disabled=d.getAttribute("title")!==b);let e=document.getElementById("light-theme-item");null!==e&&("light"===b?e.classList.add("active"):e.classList.remove("active")),e=document.getElementById("dark-theme-item"),null!==e&&("dark"===b?e.classList.add("active"):e.classList.remove("active"))}function getPreferredStyleSheet(){let b,c;for(b=0;c=document.getElementsByTagName("link")[b];b++)if(-1!==c.getAttribute("rel").indexOf("style")&&-1===c.getAttribute("rel").indexOf("alt")&&c.getAttribute("title"))return c.getAttribute("title");return null}function createCookie(a,b,c){let d="";if(c){const a=new Date;a.setTime(a.getTime()+1e3*(60*(60*(24*c)))),d="; expires="+a.toGMTString()}document.cookie=a+"="+b+d+"; path=/"}function readCookie(a){const b=a+"=",d=document.cookie.split(";");for(let e,c=0;c<d.length;c++){for(e=d[c];" "===e.charAt(0);)e=e.substring(1,e.length);if(0===e.indexOf(b))return e.substring(b.length,e.length)}return null}function setActiveStyleSheet(a){applyStyleSheet(a),createCookie("style",a)}function loadActiveStyleSheet(){let a=readCookie("style");null===a?applyStyleSheet(getPreferredStyleSheet()):applyStyleSheet(a)}window.onload=function(){loadActiveStyleSheet()},loadActiveStyleSheet();
"use strict";function applyStyleSheet(a){const b=document.getElementsByTagName("link");for(let c=0;c<b.length;c++){const d=b[c];d.getAttribute("rel").includes("stylesheet")&&d.getAttribute("title")&&(d.disabled=!0,d.getAttribute("title")===a&&(d.disabled=!1))}let c=document.getElementById("light-theme-item");null!==c&&("Light Theme"===a?c.classList.add("active"):c.classList.remove("active")),c=document.getElementById("dark-theme-item"),null!==c&&("Dark Theme"===a?c.classList.add("active"):c.classList.remove("active"))}function getPreferredStyleSheet(){const a=document.getElementsByTagName("link");for(let b=0;b<a.length;b++){const b=a[0];if(b.getAttribute("rel").includes("stylesheet")&&!b.getAttribute("rel").includes("alternate")&&b.getAttribute("title"))return b.getAttribute("title")}return null}function createCookie(a,b,c){let d="";if(c){const a=new Date;a.setTime(a.getTime()+1e3*(60*(60*(24*c)))),d="; expires="+a.toGMTString()}document.cookie=a+"="+b+d+"; path=/"}function readCookie(a){const b=a+"=",d=document.cookie.split(";");for(let e,c=0;c<d.length;c++){for(e=d[c];" "===e.charAt(0);)e=e.substring(1,e.length);if(0===e.indexOf(b))return e.substring(b.length,e.length)}return null}function setActiveStyleSheet(a){applyStyleSheet(a),createCookie("style",a)}function loadActiveStyleSheet(){let a=readCookie("style");null===a?applyStyleSheet(getPreferredStyleSheet()):applyStyleSheet(a)}loadActiveStyleSheet();
//# sourceMappingURL=styleSwitcher.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -114,14 +114,14 @@
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
{{ if .Site.Data.args.archive }}
<link rel="stylesheet" href="/css/light_theme_archive.css" title="light">
<link rel="alternate stylesheet" href="/css/dark_theme_archive.css" title="dark">
<link rel="stylesheet" href="/css/light_theme_archive.css" title="Light Theme">
<link rel="alternate stylesheet" href="/css/dark_theme_archive.css" title="Dark Theme">
{{ else if .Site.Data.args.preliminary }}
<link rel="stylesheet" href="/css/light_theme_preliminary.css" title="light">
<link rel="alternate stylesheet" href="/css/dark_theme_preliminary.css" title="dark">
<link rel="stylesheet" href="/css/light_theme_preliminary.css" title="Light Theme">
<link rel="alternate stylesheet" href="/css/dark_theme_preliminary.css" title="Dark Theme">
{{ else }}
<link rel="stylesheet" href="/css/light_theme_normal.css" title="light">
<link rel="alternate stylesheet" href="/css/dark_theme_normal.css" title="dark">
<link rel="stylesheet" href="/css/light_theme_normal.css" title="Light Theme">
<link rel="alternate stylesheet" href="/css/dark_theme_normal.css" title="Dark Theme">
{{ end }}
<script src="/js/styleSwitcher.min.js"></script>

View File

@ -57,8 +57,8 @@
<div class="dropdown-divider"></div>
<a class="dropdown-item" id="light-theme-item" href="" onclick="setActiveStyleSheet('light');return false;">{{ i18n "light_theme" }}</a>
<a class="dropdown-item" id="dark-theme-item" href="" onclick="setActiveStyleSheet('dark');return false;">{{ i18n "dark_theme" }}</a>
<a class="dropdown-item" id="light-theme-item" href="" onclick="setActiveStyleSheet('Light Theme');return false;">{{ i18n "light_theme" }}</a>
<a class="dropdown-item" id="dark-theme-item" href="" onclick="setActiveStyleSheet('Dark Theme');return false;">{{ i18n "dark_theme" }}</a>
{{ if not .Site.Data.args.archive }}
<div class="dropdown-divider"></div>

View File

@ -504,6 +504,7 @@ function handleDOMLoaded() {
attachSidebarHandlers();
attachTabHandlers();
enablePopovers();
loadActiveStyleSheet();
// one forced call here to make sure everything looks right
handlePageScroll();

View File

@ -1 +1 @@
"use strict"; function applyStyleSheet(title) { let i, a; for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) { if (a.getAttribute("rel").indexOf("style") !== -1 && a.getAttribute("title")) { a.disabled = a.getAttribute("title") !== title; } } // set the active theme menu item let item = document.getElementById("light-theme-item"); if (item !== null) { let i, a; for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) { item.classList.add("active"); } else { item.classList.remove("active"); } } item = document.getElementById("dark-theme-item"); if (item !== null) { if (title === "dark") { item.classList.add("active"); } else { item.classList.remove("active"); } } } function getPreferredStyleSheet() { let 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) { let expires = ""; if (days) { const date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } document.cookie = name + "=" + value + expires + "; path=/"; } function readCookie(name) { const nameEQ = name + "="; const ca = document.cookie.split(';'); for (let i = 0; i < ca.length; i++) { let 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 setActiveStyleSheet(title) { applyStyleSheet(title); createCookie("style", title); } function loadActiveStyleSheet() { let cookie = readCookie("style"); if (cookie === null) { applyStyleSheet(getPreferredStyleSheet()); } else { applyStyleSheet(cookie); } } window.onload = function (e) { loadActiveStyleSheet(); }; loadActiveStyleSheet();
"use strict"; function applyStyleSheet(title) { const links = document.getElementsByTagName('link'); for (let i = 0; i < links.length; i++) { const link = links[i]; if (link.getAttribute("rel").includes("stylesheet") && link.getAttribute("title")) { link.disabled = true; if (link.getAttribute("title") === title) { link.disabled = false; } } } // set the active theme menu item let item = document.getElementById("light-theme-item"); if (item !== null) { } for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) { item.classList.add("active"); } else { item.classList.remove("active"); } } item = document.getElementById("dark-theme-item"); if (item !== null) { if (title === "Dark Theme") { item.classList.add("active"); } else { item.classList.remove("active"); } } } function getPreferredStyleSheet() { const links = document.getElementsByTagName('link'); for (let i = 0; i < links.length; i++) { const link = links[0]; if (link.getAttribute("rel").includes("stylesheet") && !link.getAttribute("rel").includes("alternate") && link.getAttribute("title")) { return link.getAttribute("title"); } } return null; } function createCookie(name, value, days) { let expires = ""; if (days) { const date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } document.cookie = name + "=" + value + expires + "; path=/"; } function readCookie(name) { const nameEQ = name + "="; const ca = document.cookie.split(';'); for (let i = 0; i < ca.length; i++) { let 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 setActiveStyleSheet(title) { applyStyleSheet(title); createCookie("style", title); } function loadActiveStyleSheet() { let cookie = readCookie("style"); if (cookie === null) { applyStyleSheet(getPreferredStyleSheet()); } else { applyStyleSheet(cookie); } loadActiveStyleSheet();