mirror of https://github.com/istio/istio.io.git
Simplify theme loading.
This commit is contained in:
parent
bcc6a61f25
commit
3102359979
|
@ -1,3 +1,3 @@
|
|||
"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)){let a=e.substring(b.length,e.length);return"light"===a?a="Light Theme":"dark"==a&&(a="Dark Theme"),a}}return null}function setActiveStyleSheet(a){applyStyleSheet(a),createCookie("style",a)}function loadActiveStyleSheet(){let a=readCookie("style");null===a?applyStyleSheet(getPreferredStyleSheet()):applyStyleSheet(a)}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 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)){let a=e.substring(b.length,e.length);return"light"===a?a="Light Theme":"dark"==a&&(a="Dark Theme"),a}}return null}function setActiveStyleSheet(a){applyStyleSheet(a),createCookie("style",a)}function loadActiveStyleSheet(){let a=readCookie("style");null!==a&&applyStyleSheet(a)}loadActiveStyleSheet();
|
||||
|
||||
//# sourceMappingURL=styleSwitcher.min.js.map
|
File diff suppressed because one or more lines are too long
|
@ -57,7 +57,7 @@
|
|||
|
||||
<div class="dropdown-divider"></div>
|
||||
|
||||
<a class="dropdown-item" id="light-theme-item" href="" onclick="setActiveStyleSheet('Light Theme');return false;">{{ i18n "light_theme" }}</a>
|
||||
<a class="dropdown-item active" 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 }}
|
||||
|
|
|
@ -1 +1 @@
|
|||
"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) {
if (title === "Light Theme") {
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) {
let result = c.substring(nameEQ.length, c.length);
// convert legacy cookie values
if (result === "light") {
result = "Light Theme";
} else if (result === "dark") {
result = "Dark Theme";
}
return result;
}
}
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();
|
||||
"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")) {
// This needs to go to the disabled state first, and then adjusted below. Not sure why, but
// not doing this first leads to states where no style sheet is loaded at all.
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) {
if (title === "Light Theme") {
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 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) {
let result = c.substring(nameEQ.length, c.length);
// convert legacy cookie values
if (result === "light") {
result = "Light Theme";
} else if (result === "dark") {
result = "Dark Theme";
}
return result;
}
}
return null;
}
function setActiveStyleSheet(title) {
applyStyleSheet(title);
createCookie("style", title);
}
function loadActiveStyleSheet() {
let cookie = readCookie("style");
if (cookie !== null) {
applyStyleSheet(cookie);
}
}
loadActiveStyleSheet();
|
Loading…
Reference in New Issue