Browse Source

Merge remote-tracking branch 'origin/docs/faq-n-patches' into docs/faq-n-patches

pull/988/head
Still Hsu 7 years ago
parent
commit
4514bcde0d
3 changed files with 25 additions and 64 deletions
  1. +4
    -4
      docs/_template/light-dark-theme/partials/affix.tmpl.partial
  2. +2
    -2
      docs/_template/light-dark-theme/partials/head.tmpl.partial
  3. +19
    -58
      docs/_template/light-dark-theme/styles/styleswitcher.js

+ 4
- 4
docs/_template/light-dark-theme/partials/affix.tmpl.partial View File

@@ -4,10 +4,10 @@
<div class="sideaffix">
<div class="theme-switch-field">
<p>Theme</p>
<select onchange="getSelectionChange(this);" id="theme-switcher">
<option value="theme_dark">Dark</option>
<option value="theme_light">Light</option>
</select>
<select id="theme-switcher">
<option value="dark">Dark</option>
<option value="light">Light</option>
</select>
</div>
{{^_disableContribution}}
<div class="contribution">


+ 2
- 2
docs/_template/light-dark-theme/partials/head.tmpl.partial View File

@@ -12,14 +12,14 @@
<link rel="stylesheet" href="{{_rel}}styles/docfx.vendor.css">
<link rel="stylesheet" href="{{_rel}}styles/docfx.css">
<link rel="stylesheet" href="{{_rel}}styles/master.css">
<link rel="stylesheet" href="{{_rel}}styles/dark.css" title="theme_dark" >
<link rel="alternate stylesheet" href="{{_rel}}styles/light.css" title="theme_light">
<link rel="stylesheet" href="{{_rel}}styles/main.css">
<link rel="stylesheet" href="{{_rel}}styles/theme-switcher.css">
<link href="//cdn.rawgit.com/noelboss/featherlight/1.7.6/release/featherlight.min.css" type="text/css" rel="stylesheet" />
<meta property="docfx:navrel" content="{{_navRel}}">
<meta property="docfx:tocrel" content="{{_tocRel}}">
<meta id="docfx-style:rel" content="{{_rel}}">
{{#_noindex}}<meta name="searchOption" content="noindex">{{/_noindex}}
{{#_enableSearch}}<meta property="docfx:rel" content="{{_rel}}">{{/_enableSearch}}
{{#_enableNewTab}}<meta property="docfx:newtab" content="true">{{/_enableNewTab}}
<script type="text/javascript" src="{{_rel}}styles/styleswitcher.js"></script>
</head>

+ 19
- 58
docs/_template/light-dark-theme/styles/styleswitcher.js View File

@@ -1,66 +1,27 @@
function getSelectionChange(e){
var selectValue = e.options[e.selectedIndex].value;
if (selectValue != null) setActiveStyleSheet(selectValue);
}

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;
}
}
}
const baseUrl = document.getElementById("docfx-style:rel").content;
var themeElement;

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 onThemeSelect(event) {
const theme = event.target.value;
window.localStorage.setItem("theme", theme);
window.themeElement.href = getUrl(theme);
}

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 getUrl(slug) {
return baseUrl + "styles/" + slug + ".css";
}

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=/";
}
const themeElement = document.createElement("link");
themeElement.rel = "stylesheet";

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;
}
const theme = window.localStorage.getItem("theme") || "light";
themeElement.href = getUrl(theme);

window.onload = function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
document.getElementById("theme-switcher").value = title;
}
document.head.appendChild(themeElement);
window.themeElement = themeElement;

window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
}
document.addEventListener("DOMContentLoaded", function() {
const themeSwitcher = document.getElementById("theme-switcher");
themeSwitcher.onchange = onThemeSelect;
themeSwitcher.value = theme;
}, false);

Loading…
Cancel
Save