Skip to content

Commit

Permalink
Merge pull request #248 from IACR/addDarkMode
Browse files Browse the repository at this point in the history
dark mode started
  • Loading branch information
kaymckelly authored Mar 21, 2024
2 parents ff7e9b3 + c2beeee commit 2765d14
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 30 deletions.
3 changes: 3 additions & 0 deletions images/icons/dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/icons/light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/icons/modePicker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions includes/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ function rootPath()
<!-- Styling -->
<link rel="stylesheet" href="<?php echo rootPath(); ?>styles/main.css?v=2">
<link id="style" rel="stylesheet" href="<?php echo rootPath(); ?>styles/orange_theme.css">
<!-- dark mode! coming soon...I hope -->
<!-- <script type="module" src="<?php echo rootPath(); ?>js/color-modes.js"></script> -->
<!-- metadata for googlebot -->
<script type="application/ld+json">
{
Expand Down
80 changes: 65 additions & 15 deletions includes/nav.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!-- stop nasty flash when dark mode loads -->
<!-- <script>
const theme = localStorage.getItem('theme') || 'light';
document.documentElement.dataset.appliedMode = theme;
</script> -->

<!-- BEGIN nav -->
<div id="pageTop">
<header id="conf_id" class="headerImg">
Expand Down Expand Up @@ -26,6 +32,7 @@
</div>
</div>
</header>

<nav id="mainNavRow" class="navbar navbar-expand-md">
<div class="container">
<button class="navbar-toggler mt-1 collapsed nofocus" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
Expand All @@ -44,7 +51,7 @@
<a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" href="#">
Technical Program
</a>
<div class="dropdown-menu mx-md-3 mx-lg-5">
<div class="dropdown-menu mx-md-3 mx-lg-4 mx-xl-5">
<!-- <a class="dropdown-item" href="<?php echo rootPath() . 'program.php' ?>">
Main program
</a> -->
Expand Down Expand Up @@ -76,35 +83,35 @@
<a class="nav-link dropdown-toggle" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" href="#">
Attend
</a>
<div class="dropdown-menu mx-md-3 mx-lg-5">
<a class="dropdown-item" href="<?php echo rootPath() . 'registration.php' ?>">
Registration
</a>
<a class="dropdown-item" href="<?php echo rootPath() . 'travel.php' ?>">
<div class="dropdown-menu mx-md-3 mx-lg-4 mx-xl-5"> -->
<!-- <a class="dropdown-item" href="<?php echo rootPath() . 'registration.php' ?>">
Registration
</a> -->
<!-- <a class="dropdown-item" href="<?php echo rootPath() . 'travel.php' ?>">
Venue & travel
</a>
<a class="dropdown-item" href="<?php echo rootPath() . 'accommodations.php' ?>">
</a> -->
<!-- <a class="dropdown-item" href="<?php echo rootPath() . 'accommodations.php' ?>">
Accommodations
</a>
<a class="dropdown-item" href="<?php echo rootPath() . 'tourism.php' ?>">
Tourism
</a>
<a class="dropdown-item" href="<?php echo rootPath() . 'support.php' ?>">
</a> -->
<!-- <a class="dropdown-item" href="<?php echo rootPath() . 'support.php' ?>">
Financial support
</a>
<a class="dropdown-item" href="<?php echo rootPath() . 'visas.php' ?>">
Visas
</a>
<a class="dropdown-item" href="<?php echo rootPath() . 'virtual.php' ?>">
</a> -->
<!-- <a class="dropdown-item" href="<?php echo rootPath() . 'virtual.php' ?>">
Remote attendance
</a>
<a class="dropdown-item" href="<?php echo rootPath() . 'swag.php' ?>">
Swag
</a>
<a class="dropdown-item" href="<?php echo rootPath() . 'conduct.php' ?>">
Code of conduct
</a>
</div>
</a> -->
<!-- </div>
</li> -->
<li class="nav-item">
<a class="nav-link" href="<?php echo rootPath() . 'sponsors.php' ?>">
Expand All @@ -116,12 +123,55 @@
Contact
</a>
</li>
<!-- <li class="nav-item dropdown color-modes">
<a class="nav-link" id="bd-theme" type="button" aria-expanded="false" data-bs-toggle="dropdown" data-bs-display="static">
<svg class="bi my-1 theme-icon-active">
<use href="#circle-half"></use>
</svg>
<span id="bd-theme-text"></span>
</a>
<ul class="dropdown-menu" aria-labelledby="bd-theme" style="--bs-dropdown-min-width: 8rem;">
<li>
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="light">
<svg class="bi me-2 opacity-50 theme-icon">
<use href="#sun-fill"></use>
</svg>
Light
<svg class="bi ms-auto d-none">
<use href="#check2"></use>
</svg>
</button>
</li>
<li>
<button type="button" class="dropdown-item d-flex align-items-center" data-bs-theme-value="dark">
<svg class="bi me-2 opacity-50 theme-icon">
<use href="#moon-stars-fill"></use>
</svg>
Dark
<svg class="bi ms-auto d-none">
<use href="#check2"></use>
</svg>
</button>
</li>
<li>
<button type="button" class="dropdown-item d-flex align-items-center active" data-bs-theme-value="auto">
<svg class="bi me-2 opacity-50 theme-icon">
<use href="#circle-half"></use>
</svg>
Auto
<svg class="bi ms-auto d-none">
<use href="#check2"></use>
</svg>
</button>
</li>
</ul>
</li> -->
</ul>
</div>
</div>
</nav>
</div>
<!-- END OF pagetop (contains header and nav) -->
<!-- END OF nav -->

<noscript>
<div class="container">
Expand Down
45 changes: 45 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,56 @@
<?php echo $META['shortName']; ?>
</title>

<style>
.bi {
width: 1em;
height: 1em;
fill: currentcolor;
}

.color-modes .dropdown-menu {
padding: 0.25rem;
}

.color-modes .dropdown-menu li+li {
margin-top: 0.125rem;
}

.color-modes .dropdown-item {
border-radius: 0.25rem;
}

.color-modes .active {
font-weight: 600;
}

.color-modes .active .bi {
display: block !important;
}
</style>

</head>

<body class="home">
<?php require "includes/nav.php"; ?>
<!-- for dark mode -->
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="check2" viewBox="0 0 16 16">
<path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z" />
</symbol>
<symbol id="circle-half" viewBox="0 0 16 16">
<path d="M8 15A7 7 0 1 0 8 1v14zm0 1A8 8 0 1 1 8 0a8 8 0 0 1 0 16z" />
</symbol>
<symbol id="moon-stars-fill" viewBox="0 0 16 16">
<path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278z" />
<path d="M10.794 3.148a.217.217 0 0 1 .412 0l.387 1.162c.173.518.579.924 1.097 1.097l1.162.387a.217.217 0 0 1 0 .412l-1.162.387a1.734 1.734 0 0 0-1.097 1.097l-.387 1.162a.217.217 0 0 1-.412 0l-.387-1.162A1.734 1.734 0 0 0 9.31 6.593l-1.162-.387a.217.217 0 0 1 0-.412l1.162-.387a1.734 1.734 0 0 0 1.097-1.097l.387-1.162zM13.863.099a.145.145 0 0 1 .274 0l.258.774c.115.346.386.617.732.732l.774.258a.145.145 0 0 1 0 .274l-.774.258a1.156 1.156 0 0 0-.732.732l-.258.774a.145.145 0 0 1-.274 0l-.258-.774a1.156 1.156 0 0 0-.732-.732l-.774-.258a.145.145 0 0 1 0-.274l.774-.258c.346-.115.617-.386.732-.732L13.863.1z" />
</symbol>
<symbol id="sun-fill" viewBox="0 0 16 16">
<path d="M8 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z" />
</symbol>
</svg>

<!-- regular content continues below -->
<main class="container">

<!-- NOTE: below is placeholder content. please replace contents with
Expand Down
80 changes: 80 additions & 0 deletions js/color-modes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*!
* Color mode toggler for Bootstrap's docs (https://getbootstrap.com/)
* Copyright 2011-2023 The Bootstrap Authors
* Licensed under the Creative Commons Attribution 3.0 Unported License.
*/

(() => {
'use strict'

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

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

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')
} else {
document.documentElement.setAttribute('data-bs-theme', theme)
}
}

setTheme(getPreferredTheme())

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', () => {
const storedTheme = getStoredTheme()
if (storedTheme !== 'light' && storedTheme !== 'dark') {
setTheme(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)
})
})
})
})()
Loading

0 comments on commit 2765d14

Please sign in to comment.