PageSourceSearch

https://static-www.adweek.com/wp-content/themes/adweek-next/src/js/light-dark-mode/index.js?ver=1779800310

js adweek.com collected 2026-09-24 07:55:33 UTC 2,926 bytes, 84 lines download raw bytes

1/*!
2 * Color mode toggler for Bootstrap's docs (https://getbootstrap.com/)
3 * Copyright 2011-2024 The Bootstrap Authors
4 * Licensed under the Creative Commons Attribution 3.0 Unported License.
5 */
6
7(() => {
8    'use strict'
9
10    const getStoredTheme = () => localStorage.getItem('aw-theme')
11    const setStoredTheme = theme => localStorage.setItem('aw-theme', theme)
12
13    const getPreferredTheme = () => {
14        const storedTheme = getStoredTheme()
15        if (storedTheme) {
16            return storedTheme
17        }
18
19        return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
20    }
21
22    const setTheme = theme => {
23        if (theme === 'auto') {
24            document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'))
25        } else {
26            document.documentElement.setAttribute('data-bs-theme', theme)
27        }
28    }
29
30    setTheme(getPreferredTheme())
31
32    const showActiveTheme = (theme, focus = false) => {
33        const themeSwitcher = document.querySelector('#bd-theme')
34
35        if (!themeSwitcher) {
36            return
37        }
38
39        const themeSwitcherText = document.querySelector('#bd-theme-text')
40        const activeThemeIcon = document.querySelector('.theme-icon-active use')
41        const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
42        const svgOfActiveBtn = btnToActive.querySelector('svg use').getAttribute('href')
43
44        document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
45            element.classList.remove('active')
46            element.setAttribute('aria-pressed', 'false')
47        })
48
49        btnToActive.classList.add('active')
50        btnToActive.setAttribute('aria-pressed', 'true')
51        activeThemeIcon.setAttribute('href', svgOfActiveBtn)
52        const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`
53        themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)
54
55        if (focus) {
56            themeSwitcher.focus()
57        }
58    }
59
60    window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
61        const storedTheme = getStoredTheme()
62        if (storedTheme !== 'light' && storedTheme !== 'dark') {
63            setTheme(getPreferredTheme())
64        }
65    })
66
67    if( window.adw ){
68        window.adw.setTheme = setTheme;
69    }
70
71    window.addEventListener('DOMContentLoaded', () => {
72        showActiveTheme(getPreferredTheme())
73
74        document.querySelectorAll('[data-bs-theme-value]')
75            .forEach(toggle => {
76                toggle.addEventListener('click', () => {
77                    const theme = toggle.getAttribute('data-bs-theme-value')
78                    setStoredTheme(theme)
79                    setTheme(theme)
80                    showActiveTheme(theme, true)
81                })
82            })
83    })
84})()

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.