Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting #20

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
292 changes: 146 additions & 146 deletions labconnect/static/css/base.css

Large diffs are not rendered by default.

108 changes: 59 additions & 49 deletions labconnect/static/js/color-modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,86 @@
*/

(() => {
'use strict'
"use strict";

const getStoredTheme = () => localStorage.getItem('theme')
const setStoredTheme = theme => localStorage.setItem('theme', theme)
const getStoredTheme = () => localStorage.getItem("theme");
const setStoredTheme = (theme) => localStorage.setItem("theme", theme);

const getPreferredTheme = () => {
const storedTheme = getStoredTheme()
const storedTheme = getStoredTheme();
if (storedTheme) {
return storedTheme
return storedTheme;
}

return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}
return window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
};

const setTheme = theme => {
if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-bs-theme', 'dark')
const setTheme = (theme) => {
if (
theme === "auto" &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
document.documentElement.setAttribute("data-bs-theme", "dark");
} else {
document.documentElement.setAttribute('data-bs-theme', theme)
document.documentElement.setAttribute("data-bs-theme", theme);
}
}
};

setTheme(getPreferredTheme())
setTheme(getPreferredTheme());

const showActiveTheme = (theme, focus = false) => {
const themeSwitcher = document.querySelector('#bd-theme')
const themeSwitcher = document.querySelector("#bd-theme");

if (!themeSwitcher) {
return
return;
}

const themeSwitcherText = document.querySelector('#bd-theme-text')
const activeThemeIcon = document.querySelector('.theme-icon-active use')
const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
const svgOfActiveBtn = btnToActive.querySelector('svg use').getAttribute('href')
const themeSwitcherText = document.querySelector("#bd-theme-text");
const activeThemeIcon = document.querySelector(".theme-icon-active use");
const btnToActive = document.querySelector(
`[data-bs-theme-value="${theme}"]`
);
const svgOfActiveBtn = btnToActive
.querySelector("svg use")
.getAttribute("href");

document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
element.classList.remove('active')
element.setAttribute('aria-pressed', 'false')
})
document.querySelectorAll("[data-bs-theme-value]").forEach((element) => {
element.classList.remove("active");
element.setAttribute("aria-pressed", "false");
});

btnToActive.classList.add('active')
btnToActive.setAttribute('aria-pressed', 'true')
activeThemeIcon.setAttribute('href', svgOfActiveBtn)
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`
themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)
btnToActive.classList.add("active");
btnToActive.setAttribute("aria-pressed", "true");
activeThemeIcon.setAttribute("href", svgOfActiveBtn);
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`;
themeSwitcher.setAttribute("aria-label", themeSwitcherLabel);

if (focus) {
themeSwitcher.focus()
themeSwitcher.focus();
}
}
};

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
const storedTheme = getStoredTheme()
if (storedTheme !== 'light' && storedTheme !== 'dark') {
setTheme(getPreferredTheme())
}
})
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", () => {
const storedTheme = getStoredTheme();
if (storedTheme !== "light" && storedTheme !== "dark") {
setTheme(getPreferredTheme());
}
});

window.addEventListener('DOMContentLoaded', () => {
showActiveTheme(getPreferredTheme())
window.addEventListener("DOMContentLoaded", () => {
showActiveTheme(getPreferredTheme());

document.querySelectorAll('[data-bs-theme-value]')
.forEach(toggle => {
toggle.addEventListener('click', () => {
const theme = toggle.getAttribute('data-bs-theme-value')
setStoredTheme(theme)
setTheme(theme)
showActiveTheme(theme, true)
})
})
})
})()
document.querySelectorAll("[data-bs-theme-value]").forEach((toggle) => {
toggle.addEventListener("click", () => {
const theme = toggle.getAttribute("data-bs-theme-value");
setStoredTheme(theme);
setTheme(theme);
showActiveTheme(theme, true);
});
});
});
})();
3 changes: 2 additions & 1 deletion labconnect/templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<h1>404 Not Found</h1>
<p>This page was not found</p>
<p><a href="{{ url_for('main.index') }}">Return Home</a></p>
<p>If you believe this is a bug or error please create an <a href="https://github.com/RafaelCenzano/LabConnect/issues">Issue</a></p>
<p>If you believe this is a bug or error please create an <a
href="https://github.com/RafaelCenzano/LabConnect/issues">Issue</a></p>
{% endblock %}
3 changes: 2 additions & 1 deletion labconnect/templates/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<h1>500 Server Error</h1>
<p>The server had an error</p>
<p><a href="{{ url_for('main.index') }}">Return Home</a></p>
<p>If you believe this is a bug or error please create an <a href="https://github.com/RafaelCenzano/LabConnect/issues">Issue</a></p>
<p>If you believe this is a bug or error please create an <a
href="https://github.com/RafaelCenzano/LabConnect/issues">Issue</a></p>
{% endblock %}
Loading