-
Notifications
You must be signed in to change notification settings - Fork 748
Added dark mode toggle feature #609
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,64 @@ | ||
<header> | ||
{% include github-corner.html %} | ||
<div class="container"> | ||
<div class="visible-desktop"> | ||
<a class="span3" href="/" id="logo"> | ||
<img alt="Rails Girls Guides" src="/images/railsgirls-guides.png" /> | ||
</a> | ||
<nav class="nav pull-right"> | ||
<a href="https://railsgirls.com/">Home</a> | ||
<a href="https://railsgirls.com/events.html">Events</a> | ||
<a href="https://railsgirls.tumblr.com/">Blog</a> | ||
<a href="/guide">Organizers</a> | ||
<a href="/">Guides</a> | ||
</nav> | ||
</div> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Rails Girls Guides</title> | ||
|
||
</head> | ||
<body> | ||
<header> | ||
{% include github-corner.html %} | ||
<div class="container"> | ||
<div class="visible-desktop"> | ||
<a class="span3" href="/" id="logo"> | ||
<img alt="Rails Girls Guides" src="/images/railsgirls-guides.png" /> | ||
</a> | ||
<nav class="nav pull-right"> | ||
<a href="https://railsgirls.com/">Home</a> | ||
<a href="https://railsgirls.com/events.html">Events</a> | ||
<a href="https://railsgirls.com/tumblr.com/">Blog</a> | ||
<a href="/guide">Organizers</a> | ||
<a href="/">Guides</a> | ||
|
||
<button id="toggle-button" class="btn btn-link" aria-label="Toggle Dark Mode"> | ||
<img id="toggle-icon" src="/images/sun-icon.png" alt="Toggle Dark Mode" /> | ||
</button> | ||
</nav> | ||
</div> | ||
|
||
<!-- Phone/Tablet --> | ||
<div class="visible-tablet visible-phone"> | ||
<div class="nav navbar nav-pills"> | ||
<a class="btn btn-link btn-navbar collapsed" onclick="toggleMobileMenu()"> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</a> | ||
<!-- Phone/Tablet --> | ||
<div class="visible-tablet visible-phone"> | ||
<div class="nav navbar nav-pills"> | ||
<a class="btn btn-link btn-navbar collapsed" onclick="toggleMobileMenu()"> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</a> | ||
|
||
<a class="brand" href="/">Rails Girls Guides</a> | ||
<a class="brand" href="/">Rails Girls Guides</a> | ||
|
||
<div class="nav-collapse navbar-responsive-collapse navbar-collapse" id='navbar-list' style='height: 0;'> | ||
<ul class="nav"> | ||
<li><a href="https://railsgirls.com/">Home</a></li> | ||
<li><a href="https://railsgirls.com/events.html">Events</a></li> | ||
<li><a href="https://railsgirls.tumblr.com/">Blog</a></li> | ||
<li><a href="/guide">Organizers</a></li> | ||
<li><a href="/">Guides</a></li> | ||
</ul> | ||
<div class="nav-collapse navbar-responsive-collapse navbar-collapse" id='navbar-list' style='height: 0;'> | ||
<ul class="nav"> | ||
<li><a href="https://railsgirls.com/">Home</a></li> | ||
<li><a href="https://railsgirls.com/events.html">Events</a></li> | ||
<li><a href="https://railsgirls.tumblr.com/">Blog</a></li> | ||
<li><a href="/guide">Organizers</a></li> | ||
<li><a href="/">Guides</a></li> | ||
|
||
<li> | ||
<button id="toggle-button" class="btn btn-link" aria-label="Toggle Dark Mode"> | ||
<img id="toggle-icon" src="/images/sun-icon.png" alt="Toggle Dark Mode" /> | ||
</button> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</header> | ||
</header> | ||
|
||
|
||
<script src="js/dark-mode-toggle.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
document.addEventListener("DOMContentLoaded", function () { | ||
const toggleButton = document.getElementById("toggle-button"); | ||
const toggleIcon = document.getElementById("toggle-icon"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
const body = document.body; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
|
||
// Check for saved user preference | ||
const darkModeEnabled = localStorage.getItem("dark-mode") === "true"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
if (darkModeEnabled) { | ||
body.classList.add("dark-mode"); | ||
toggleIcon.src = "/images/moon-icon.png"; | ||
} | ||
|
||
toggleButton.addEventListener("click", function () { | ||
body.classList.toggle("dark-mode"); | ||
|
||
// Save user preference | ||
const isDarkMode = body.classList.contains("dark-mode"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
localStorage.setItem("dark-mode", isDarkMode); | ||
|
||
|
||
toggleIcon.src = isDarkMode ? "/images/moon-icon.png" : "/images/sun-icon.png"; | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).