Improved modular JS for the docs (#813)

This commit is contained in:
trgwii 2018-05-24 11:22:52 +02:00 committed by Lonami
parent e5ff534e2e
commit c4c41645e7
2 changed files with 37 additions and 30 deletions

View File

@ -6,13 +6,33 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link id="style" href="css/docs.light.css" rel="stylesheet"> <link id="style" href="css/docs.light.css" rel="stylesheet">
<script> <script>
try { (function () {
which = document.cookie.split('=')[1].split(';')[0]; var style = document.getElementById('style');
if (which) {
document.getElementById("style").href = "css/" + which; // setTheme(<link />, 'light' / 'dark')
} function setTheme(theme) {
} catch (e) { document.cookie = 'css=' + theme + '; path=/';
} return style.href = 'css/docs.' + theme + '.css';
}
// setThemeOnClick(<link />, 'light' / 'dark', <a />)
function setThemeOnClick(theme, button) {
return button.addEventListener('click', function (e) {
setTheme(theme);
e.preventDefault();
return false;
});
}
setTheme(document.cookie
.split(';')[0]
.split('=')[1] || 'light');
document.addEventListener('DOMContentLoaded', function () {
setThemeOnClick('light', document.getElementById('themeLight'));
setThemeOnClick('dark', document.getElementById('themeDark'));
});
})();
</script> </script>
<link href="https://fonts.googleapis.com/css?family=Nunito|Source+Code+Pro" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Nunito|Source+Code+Pro" rel="stylesheet">
<style> <style>
@ -30,7 +50,10 @@
on what the methods, constructors and types mean. Nevertheless, this on what the methods, constructors and types mean. Nevertheless, this
page aims to provide easy access to all the available methods, their page aims to provide easy access to all the available methods, their
definition and parameters.</p> definition and parameters.</p>
<p id="themeSelect"></p> <p id="themeSelect">
<a href="#" id="themeLight">light</a> /
<a href="#" id="themeDark">dark</a> theme.
</p>
<p>Please note that when you see this:</p> <p>Please note that when you see this:</p>
<pre>---functions--- <pre>---functions---
users.getUsers#0d91a548 id:Vector&lt;InputUser&gt; = Vector&lt;User&gt;</pre> users.getUsers#0d91a548 id:Vector&lt;InputUser&gt; = Vector&lt;User&gt;</pre>
@ -154,17 +177,5 @@ users.getUsers#0d91a548 id:Vector&lt;InputUser&gt; = Vector&lt;User&gt;</pre>
</p> </p>
</div> </div>
<script src="js/search.js"></script> <script src="js/search.js"></script>
<script>
document.getElementById("themeSelect").innerHTML = `
Select
<a href="#" onclick="setTheme('docs.light.css')">light</a> /
<a href="#" onclick="setTheme('docs.dark.css')">dark</a> theme.
`;
function setTheme(which) {
style.href = "css/" + which;
document.cookie = "css=" + which + "; path=/";
}
</script>
</body> </body>
</html> </html>

View File

@ -48,20 +48,16 @@ class DocsWriter:
<link id="style" href="''') <link id="style" href="''')
self.write(relative_css_path) self.write(relative_css_path)
self.write('/') self.write('/docs.')
self.write(default_css) self.write(default_css)
self.write('''" rel="stylesheet"> self.write('''.css" rel="stylesheet">
<script> <script>
try { document.getElementById("style").href = "''')
which = document.cookie.split('=')[1].split(';')[0];
if (which) {
document.getElementById("style").href = "''')
self.write(relative_css_path) self.write(relative_css_path)
self.write('''/" + which; self.write('/docs.')
} self.write('''" + (document.cookie
} catch (e) { .split(";")[0].split("=")[1] || "light") + ".css";
}
</script> </script>
<link href="https://fonts.googleapis.com/css?family=Nunito|Source+Code+Pro" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Nunito|Source+Code+Pro" rel="stylesheet">
</head> </head>