mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-07-21 22:18:58 -04:00
initial work on a bootstrap 5 template
current status: - renders without PHP errors & passes unit tests - displays pastes - responsive navbar - right-to-left support - auto dark mode with toggle to be done: - add "Dark Mode" to translation strings - get expiration and format selections to work - fix modals (password, QR-code, etc.) - replace glyphicons with Bootstrap Icons (no longer included) - test all the different settings and combinations - check tab alignment in HTML source
This commit is contained in:
parent
3bc09ed561
commit
7565be8ed5
7 changed files with 565 additions and 1 deletions
50
js/dark-mode-switch.js
Normal file
50
js/dark-mode-switch.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*!
|
||||
* Color mode toggler for Bootstrap's docs (https://getbootstrap.com/)
|
||||
* Copyright 2011-2024 The Bootstrap Authors
|
||||
* Licensed under the Creative Commons Attribution 3.0 Unported License.
|
||||
* Modified to work with a simpler checkbox toggle
|
||||
*/
|
||||
|
||||
(() => {
|
||||
'use strict'
|
||||
|
||||
const getStoredTheme = () => localStorage.getItem('theme')
|
||||
const setStoredTheme = theme => localStorage.setItem('theme', theme)
|
||||
const getPreferredTheme = () => window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
||||
|
||||
const getStoredPreferredTheme = () => {
|
||||
const storedTheme = getStoredTheme()
|
||||
if (storedTheme) {
|
||||
return storedTheme
|
||||
}
|
||||
return getPreferredTheme()
|
||||
}
|
||||
|
||||
const setTheme = theme => {
|
||||
if (theme === 'auto') {
|
||||
document.documentElement.setAttribute('data-bs-theme', getPreferredTheme())
|
||||
} else {
|
||||
document.documentElement.setAttribute('data-bs-theme', theme)
|
||||
}
|
||||
}
|
||||
|
||||
setTheme(getStoredPreferredTheme())
|
||||
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
||||
const storedTheme = getStoredTheme()
|
||||
if (storedTheme !== 'light' && storedTheme !== 'dark') {
|
||||
setTheme(getStoredPreferredTheme())
|
||||
}
|
||||
})
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
const toggle = document.querySelector('#bd-theme')
|
||||
toggle.checked = getStoredTheme() === 'dark'
|
||||
toggle.addEventListener('change', (event) => {
|
||||
const theme = event.currentTarget.checked ? 'dark' : 'light'
|
||||
setStoredTheme(theme)
|
||||
setTheme(theme)
|
||||
event.currentTarget.focus()
|
||||
})
|
||||
})
|
||||
})()
|
Loading…
Add table
Add a link
Reference in a new issue