Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ website:

format:
html:
theme: flatly
theme:
dark: darkly
light: flatly
css: styles.css
toc: true
include-in-header:
- toggle.js



Binary file added images/stanford-line2-8-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion index.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ format:
page-layout: full
---

<center><a><img src="images/stanford-line2-8.png" alt="Poldracklab logo" width="50%"/></a></center>
<center>
<a>
<img src="images/stanford-line2-8.png" alt="Poldracklab logo" width="50%" class="only-light" />
<img src="images/stanford-line2-8-dark.png" alt="Poldracklab logo" width="50%" class="only-dark" style="display: none" />
</a>
</center>

<br>
<br>
Expand Down
58 changes: 58 additions & 0 deletions toggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<script id="toggle-light-dark-elements" type="application/javascript">
// Extend Quarto theme toggling to allow elements to be displayed/hidden in light/dark themes

// Replicated from https://github.com/quarto-dev/quarto-cli/blob/84d4659/src/resources/formats/html/templates/quarto-html.ejs
const getColorSchemeSentinel = () => {
const localAlternateSentinel = 'default';
if (window.location.protocol !== 'file:') {
const storageValue = window.localStorage.getItem('quarto-color-scheme');
return storageValue != null ? storageValue : localAlternateSentinel;
} else {
return localAlternateSentinel;
}
};

// Function to toggle light and dark elements based on color scheme
const toggleColorSchemeElements = () => {
const scheme = getColorSchemeSentinel();
const lightElements = document.getElementsByClassName('only-light');
const darkElements = document.getElementsByClassName('only-dark');

for (var i = 0; i < lightElements.length; i++) {
lightElements[i].style.display = scheme == 'default' ? 'block' : 'none';
}
for (var i = 0; i < darkElements.length; i++) {
darkElements[i].style.display = scheme == 'default' ? 'none' : 'block';
}
};

// Function to check if the user's browser prefers dark themes
const prefersDarkTheme = () => {
if (window.matchMedia) {
return window.matchMedia('(prefers-color-scheme: dark)').matches;
}
return false;
};

document.addEventListener('readystatechange', function() {
// Set the default color scheme based on browser preference
if (document.readyState === 'interactive' && window.location.protocol !== 'file:') {
const storageValue = window.localStorage.getItem('quarto-color-scheme');
if (storageValue == null && prefersDarkTheme()) {
window.localStorage.setItem('quarto-color-scheme', 'alternate');
}
}
// Add event listener for when the readyState is complete (and default toggler is set)
if (document.readyState === 'complete') {
// Toggle scheme once
toggleColorSchemeElements();
// Append our toggle function to the old one
const oldToggle = window.quartoToggleColorScheme;
window.quartoToggleColorScheme = () => {
oldToggle();
toggleColorSchemeElements();
}
}
});

</script>