1/* 2 * Copyright (c) 2023 Lemur Software Ltd. 3 */ 4 5/*! 6 * Color mode toggler for Bootstrap's docs (https://getbootstrap.com/) 7 * Copyright 2011-2022 The Bootstrap Authors 8 * Licensed under the Creative Commons Attribution 3.0 Unported License. 9 */ 10 11(() => { 12 'use strict' 13 14 let storedTheme = localStorage.getItem('theme'); 15 16 const getPreferredTheme = () => { 17 if (storedTheme) { 18 return storedTheme; 19 } 20 21 return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; 22 } 23 24 const setTheme = function (theme) { 25 if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) { 26 document.documentElement.setAttribute('data-bs-theme', 'dark'); 27 } else { 28 document.documentElement.setAttribute('data-bs-theme', theme); 29 } 30 } 31 32 setTheme(getPreferredTheme()); 33 34 const showActiveTheme = theme => { 35 const activeThemeIcon = document.querySelector('.theme-icon-active'); 36 const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`); 37 const classOfActiveSpan = btnToActive.querySelector('span:first-of-type').getAttribute('class'); 38 39 document.querySelectorAll('[data-bs-theme-value]') 40 .forEach(element => { 41 element.classList.remove('active'); 42 }); 43 btnToActive.classList.add('active'); 44 activeThemeIcon.setAttribute('class', classOfActiveSpan + ' theme-icon-active'); 45 } 46 47 window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { 48 if (storedTheme !== 'light' || storedTheme !== 'dark') { 49 setTheme(getPreferredTheme()); 50 } 51 }) 52 53 window.addEventListener('DOMContentLoaded', () => { 54 showActiveTheme(getPreferredTheme()); 55 56 document.querySelectorAll('[data-bs-theme-value]') 57 .forEach(toggle => { 58 toggle.addEventListener('click', () => { 59 const theme = toggle.getAttribute('data-bs-theme-value'); 60 localStorage.setItem('theme', theme); 61 storedTheme = theme; 62 setTheme(theme); 63 showActiveTheme(theme); 64 }) 65 }); 66 }); 67})()
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.