Skip to content
This repository was 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 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
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheets/styles.css">
<link rel="stylesheet" type="text/css" href="stylesheets/themes/dark.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 +16,6 @@ <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;</div>
</body>
</html>
43 changes: 43 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var themes = [
{ id: 'default', label: 'Default' },
{ id: 'dark', label: 'Dark' }
/*
* Add more themes here. Match 'id' property
* with the class name in the CSS file. See
* 1pr/stylesheets/themes/dark.css for example.
*/
];

// aggregate string to remove all theme classes on theme change
var allThemeClasses = '';
themes.forEach(function(theme) {
allThemeClasses = allThemeClasses + ' ' + theme.id;
});

function setTheme(theme) {
$('body').removeClass(allThemeClasses);
$('.theme-buttons > button').removeClass('selected-theme');
if (theme !== 'default') {
$('body').addClass(theme);
}
localStorage.setItem('theme', theme);
$('#theme-select-' + theme).addClass('selected-theme');
}

$(document).ready(function() {
themes.forEach(function(theme) {
var themeButton = document.createElement('button');
themeButton.id = 'theme-select-' + theme.id;
themeButton.innerHTML = theme.label;
themeButton.onclick = function() {
setTheme(theme.id);
};
$('.theme-buttons').append(themeButton);
});

if (localStorage.getItem('theme')) {
setTheme(localStorage.getItem('theme'));
} else {
setTheme('default');
}
});
23 changes: 23 additions & 0 deletions stylesheets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,26 @@ 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;
}

.theme-buttons > button {
margin-right: 5px;
}

button.selected-theme {
background-color: #AAA;
border-color: #666
}
30 changes: 30 additions & 0 deletions stylesheets/themes/dark.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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: #555;
border-color: #555;
color: #DDD;
}

.dark button.selected-theme {
background-color: #444;
border-color: #222
}