A senior software engineer with a PhD degree in Computer Science from USC. Blends research experience in Software Engineering field with diverse practical training in the software industries of Vietnam, S.Korea and U.S. to offer solid skills in software design and development. Experiences include:
This document explains the dark mode feature implementation for your Jekyll academic website.
Ctrl+Shift+D (or Cmd+Shift+D on Mac)stylesheets/dark-mode.css - Main dark mode styles and CSS variablesjs/dark-mode.js - JavaScript functionality for theme switchingdark-mode-demo.html - Demo page showcasing the featureDARK_MODE_README.md - This documentation_includes/head.html - Added dark mode CSS link_includes/footer.html - Added dark mode JavaScriptstylesheets/nak.css - Updated to use CSS custom propertiesindex.html - Added keyboard shortcut tip to floating nav:root {
/* Light Mode Colors */
--bg-primary: #ffffff;
--bg-secondary: #f6f6f6;
--text-primary: #333333;
--accent-color: #337ab7;
/* ... more variables */
}
[data-theme="dark"] {
/* Dark Mode Colors */
--bg-primary: #1a1a1a;
--bg-secondary: #2d2d2d;
--text-primary: #e0e0e0;
--accent-color: #4a9eff;
/* ... more variables */
}
data-theme attribute on <html> elementclass DarkModeToggle {
constructor() {
this.init();
}
init() {
this.createToggleButton();
this.initializeTheme();
this.bindEvents();
this.watchSystemTheme();
}
toggleTheme() {
const newTheme = this.currentTheme === 'light' ? 'dark' : 'light';
this.applyTheme(newTheme);
}
}
localStorage to remember preferenceprefers-color-scheme media queryCtrl+Shift+D (or Cmd+Shift+D on Mac)// Get current theme
const currentTheme = window.darkModeToggle.getCurrentTheme();
// Set theme programmatically
window.darkModeToggle.setTheme('dark');
// Check if dark mode is active
const isDark = window.darkModeToggle.isDarkMode();
/* Use CSS custom properties */
.my-component {
background-color: var(--bg-primary);
color: var(--text-primary);
border: 1px solid var(--border-color);
}
/* Dark mode specific styles */
[data-theme="dark"] .my-component {
/* Override specific properties if needed */
}
Edit CSS variables in stylesheets/dark-mode.css:
:root {
--bg-primary: #ffffff; /* Light background */
--text-primary: #333333; /* Light text */
--accent-color: #337ab7; /* Light accent */
}
[data-theme="dark"] {
--bg-primary: #1a1a1a; /* Dark background */
--text-primary: #e0e0e0; /* Dark text */
--accent-color: #4a9eff; /* Dark accent */
}
.theme-toggle {
position: fixed;
top: 20px; /* Distance from top */
right: 20px; /* Distance from right */
z-index: 1000; /* Layer order */
}
* {
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
@media (max-width: 768px) {
.theme-toggle {
top: 15px;
right: 15px;
width: 45px;
height: 45px;
}
}
title attributes for screen readersTab key navigation to toggle buttonEnter or Space to activate toggleCtrl+Shift+D@media print {
[data-theme="dark"] {
/* Force light mode for printing */
--bg-primary: #ffffff;
--text-primary: #333333;
}
.theme-toggle {
display: none !important;
}
}
Visit /dark-mode-demo.html to see all features in action.
dark-mode.css is loaded<html> element for data-theme attribute// Track theme usage (example)
function trackThemeUsage(theme) {
if (typeof gtag !== 'undefined') {
gtag('event', 'theme_change', {
'theme': theme,
'page_title': document.title
});
}
}
The dark mode implementation provides a modern, accessible, and user-friendly theme switching experience. It enhances user experience while maintaining excellent performance and compatibility across all devices and browsers.
Key Benefits:
Note: This implementation follows modern web standards and best practices for theme switching, ensuring compatibility and maintainability for years to come.