diff options
Diffstat (limited to 'vendor/twbs/bootstrap/site/static/docs/5.3/assets/js/color-modes.js')
-rw-r--r-- | vendor/twbs/bootstrap/site/static/docs/5.3/assets/js/color-modes.js | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/vendor/twbs/bootstrap/site/static/docs/5.3/assets/js/color-modes.js b/vendor/twbs/bootstrap/site/static/docs/5.3/assets/js/color-modes.js index 41b6b893e..4528ba36b 100644 --- a/vendor/twbs/bootstrap/site/static/docs/5.3/assets/js/color-modes.js +++ b/vendor/twbs/bootstrap/site/static/docs/5.3/assets/js/color-modes.js @@ -1,6 +1,6 @@ /*! * Color mode toggler for Bootstrap's docs (https://getbootstrap.com/) - * Copyright 2011-2022 The Bootstrap Authors + * Copyright 2011-2023 The Bootstrap Authors * Licensed under the Creative Commons Attribution 3.0 Unported License. */ @@ -27,17 +27,32 @@ setTheme(getPreferredTheme()) - const showActiveTheme = theme => { + const showActiveTheme = (theme, focus = false) => { + const themeSwitcher = document.querySelector('#bd-theme') + + if (!themeSwitcher) { + 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') 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) + + if (focus) { + themeSwitcher.focus() + } } window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { @@ -55,7 +70,7 @@ const theme = toggle.getAttribute('data-bs-theme-value') localStorage.setItem('theme', theme) setTheme(theme) - showActiveTheme(theme) + showActiveTheme(theme, true) }) }) }) |