aboutsummaryrefslogtreecommitdiff
path: root/docs/_static/custom.js
diff options
context:
space:
mode:
authorJosh <[email protected]>2020-05-29 16:57:00 +1000
committerRapptz <[email protected]>2020-12-18 21:18:51 -0500
commite7c6643730a2293f11df4f54e30a0932cb9d48f4 (patch)
tree3f9f592f2530f190b25bc78348d6a6b731c45185 /docs/_static/custom.js
parentProper padding for the copy button (diff)
downloaddiscord.py-e7c6643730a2293f11df4f54e30a0932cb9d48f4.tar.xz
discord.py-e7c6643730a2293f11df4f54e30a0932cb9d48f4.zip
[matrix] Dark Theme
* Apply width restructions to modals and images * Dark theme 2.0 * Add webkit scrollbar * Use Object.keys instead of Object.entries where applicable
Diffstat (limited to 'docs/_static/custom.js')
-rw-r--r--docs/_static/custom.js36
1 files changed, 20 insertions, 16 deletions
diff --git a/docs/_static/custom.js b/docs/_static/custom.js
index ac3ed1e9..3f0e50d1 100644
--- a/docs/_static/custom.js
+++ b/docs/_static/custom.js
@@ -28,17 +28,28 @@ function updateSetting(element) {
}
}
-function getBodyClassToggle(className) {
- function toggleBodyClass(add) {
- document.body.classList.toggle(className, add);
+function getRootAttributeToggle(attributeName, valueName) {
+ function toggleRootAttribute(set) {
+ document.documentElement.setAttribute(`data-${attributeName}`, set ? valueName : null);
}
- return toggleBodyClass;
+ return toggleRootAttribute;
}
const settings = {
- useSansFont: getBodyClassToggle('sans')
+ useSansFont: getRootAttributeToggle('font', 'sans'),
+ useDarkTheme: getRootAttributeToggle('theme', 'dark')
};
+Object.entries(settings).forEach(([name, setter]) => {
+ let value = JSON.parse(localStorage.getItem(name));
+ try {
+ setter(value);
+ } catch (error) {
+ console.error(`Failed to apply setting "${name}" With value:`, value);
+ console.error(error);
+ }
+});
+
document.addEventListener('DOMContentLoaded', () => {
bottomHeightThreshold = document.documentElement.scrollHeight - 30;
@@ -81,18 +92,11 @@ document.addEventListener('DOMContentLoaded', () => {
parent.insertBefore(table, element.nextSibling);
});
- Object.entries(settings).forEach(([name, setter]) => {
+ Object.keys(settings).forEach(name => {
let value = JSON.parse(localStorage.getItem(name));
-
- try {
- setter(value);
- let element = document.querySelector(`input[name=${name}]`);
- if (element) {
- element.checked = value === true;
- }
- } catch (error) {
- console.error(`Failed to apply setting "${name}" With value:`, value);
- console.error(error);
+ let element = document.querySelector(`input[name=${name}]`);
+ if (element) {
+ element.checked = value === true;
}
});
});