Skip to content

Added Basic Dark Mode Support That Utilizes Toggle and Local Storage #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@
//= require_directory ./plugins/
//= require_self

var isLightTheme = true;

document.addEventListener('DOMContentLoaded', function() {
var button = document.getElementById('dark-mode-toggle');

// Check if there's a saved preference in localStorage
if (localStorage.getItem('darkMode') === 'true') {
isLightTheme = false;
document.body.classList.add('dark-mode');
button.textContent = 'Light Mode';
} else {
button.textContent = 'Dark Mode';
}

button.addEventListener('click', function() {
isLightTheme = !isLightTheme;

// Toggle dark mode class on body
if (isLightTheme) {
document.body.classList.remove('dark-mode');
localStorage.setItem('darkMode', 'false');
button.textContent = 'Dark Mode';
} else {
document.body.classList.add('dark-mode');
localStorage.setItem('darkMode', 'true');
button.textContent = 'Light Mode';
}
});
});

$(document).ready(function () {
$('.file_list').dataTable({
order: [[1, "asc"]],
Expand Down
Loading