Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

add dark theme option #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheets/styles.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src='script.js' type='text/javascript'></script>
<title>One PR A Day</title>
</head>
<body>
Expand All @@ -13,5 +15,9 @@ <h1>I will be accepting up to one pull request per day on <a href="https://githu
<li>Find some inspiration for cool ideas on what you can add to the project <a href="https://medium.freecodecamp.com/6-absurd-ideas-for-building-your-first-web-application-24afca35e519#.do2wbrk4s">from this medium post</a></li>
</ul>
</div>
<div class='theme-buttons'>Theme:&nbsp;
<button id='light-button'>Dark</button>
<button id='dark-button'>Light</button>
</div>
</body>
</html>
25 changes: 25 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$(document).ready(function() {
function setDarkTheme() {
$('body').addClass('dark');
$('#dark-button').hide();
$('#light-button').show();

Choose a reason for hiding this comment

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

I think the buttons visibility can be set in CSS like so:

body.dark #dark-button {
    visible: false; /* or alternatively; display:none */
}

localStorage.setItem('darkThemeEnabled', 1);
}

function setLightTheme() {
$('body').removeClass('dark');
$('#dark-button').show();
$('#light-button').hide();
localStorage.setItem('darkThemeEnabled', 0);
}

if (localStorage.getItem('darkThemeEnabled')
&& localStorage.getItem('darkThemeEnabled') === '1') {
setDarkTheme();
} else {
setLightTheme();
}

$('#light-button').click(setLightTheme);
$('#dark-button').click(setDarkTheme);
});
40 changes: 40 additions & 0 deletions stylesheets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,43 @@ div {
margin-left: 25%;
margin-right: 25%;
}

button {
border-style: solid;
border-radius: 2px;
font-size: 14px;
font-weight: bold;

Choose a reason for hiding this comment

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

recommend an outline:none here to prevent the browser from giving the buttons an extra highlight when clicked.

}

.theme-buttons {
position:absolute;
left:10px;
bottom:10px;
margin: 0px;
}

body.dark {
background-color: #333;
}

.dark h1 {
color: #DDD;
}

.dark div {
color: #DDD;
}

.dark a {
color: #AAF;
}

.dark a:visited {
color: #DAC;
}

.dark button {
background-color: #444;
border-color: #444;
color: #DDD;
}