Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions evap/evaluation/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<script type="text/javascript" src="{% static 'js/tom-select.complete.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/plugins/jquery.formset.js' %}"></script>
<script type="text/javascript" src="{% static 'js/Sortable.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/color-mode-toggler.js' %}"></script>

<script type="module" src="{% static 'js/csrf-utils.js' %}"></script>
<script type="module" src="{% static 'js/utils.js' %}"></script>
Expand Down
10 changes: 10 additions & 0 deletions evap/evaluation/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@
</div>
</li>
{% endif %}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" id="bd-theme" data-bs-toggle="dropdown">
<span id="span-toggle-color-mode-dropdown" class="fas fa-circle-half-stroke"></span>
</a>
<div class="dropdown-menu dropdown-menu-end dropdown-menu-tight" aria-labelledby="bd-theme">
<button type="button" class="dropdown-item" data-bs-theme-value="light">{% translate 'Light' %}</button>
<button type="button" class="dropdown-item" data-bs-theme-value="dark">{% translate 'Dark' %}</button>
<button type="button" class="dropdown-item" data-bs-theme-value="auto">{% translate 'Auto' %}</button>
</div>
</li>
</ul>
</div>
</nav>
155 changes: 155 additions & 0 deletions evap/static/images/triangles_dark_gray.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions evap/static/scss/evap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import "adjustments";
@import "utilities";

$color-mode-type: data;
html {
position: relative;
min-height: 100%;
Expand All @@ -24,6 +25,12 @@ body {
}
}

@include color-mode(dark) {
body {
background-image: url("../images/triangles_dark_gray.svg");
}
}

.hide {
opacity: 0;
cursor: inherit;
Expand Down
62 changes: 62 additions & 0 deletions evap/static/ts/src/color-mode-toggler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*!
* Adapted color mode toggler from Bootstrap's docs (https://getbootstrap.com/)
*/

Comment on lines +1 to +4

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this about? This reads like copyright trouble

(() => {
'use strict'

const storedTheme = localStorage.getItem('theme')

const getPreferredTheme = () => {
console.log("getPreferredTheme");
if (storedTheme) {
return storedTheme
}

return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}

const setTheme = function (theme) {
console.log("setTheme");
console.log(theme);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove these, I think the document.setAttribute below should always work and not trigger too many debugging scenarios (applies to all console.logs here)

/*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)
//}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code (repeated below)

}

setTheme(getPreferredTheme())

const showActiveTheme = theme => {
console.log("showActiveTheme");
console.log(theme);
const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)

document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
element.classList.remove('active')
})

btnToActive.classList.add('active')
}

/* window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
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')
localStorage.setItem('theme', theme)
setTheme(theme)
showActiveTheme(theme)
})
})
})
})()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing trailing newline

Loading