Skip to content

Commit

Permalink
Theme Mode v2
Browse files Browse the repository at this point in the history
Added feature support for theme by cookies and theme by browser.
  • Loading branch information
dberezansky committed Dec 21, 2021
1 parent d83332f commit c468a81
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 93 deletions.
6 changes: 0 additions & 6 deletions .vscode/extensions.json

This file was deleted.

13 changes: 0 additions & 13 deletions .vscode/launch.json

This file was deleted.

9 changes: 0 additions & 9 deletions .vscode/settings.json

This file was deleted.

27 changes: 0 additions & 27 deletions .vscode/tasks.json

This file was deleted.

5 changes: 0 additions & 5 deletions Front-End/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,6 @@ option {
height: 160px;
}

#currentMode {
display: none;
}

#aboutSection {
margin-left: 40px;
color: whitesmoke;
Expand Down Expand Up @@ -643,7 +639,6 @@ option {
#weatherDiv,
#locationIconDiv,
.githubIconDiv,
#currentMode,
#slider,
#themeCheckbox,
#switch,
Expand Down
3 changes: 1 addition & 2 deletions Front-End/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ <h6 id="aboutHeader" class="header"> ABOUT US </h6>
</div>
-->
<!-- Color Theme Switcher -->
<p id="currentMode">Light</p>
<label id="switch">
<input aria-label="Checkbox" id="themeCheckbox" type="checkbox">
<input aria-label="checkbox" id="themeCheckbox" type="checkbox">
<span id="slider"></span>
</label>
</div>
Expand Down
87 changes: 58 additions & 29 deletions Front-End/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,41 +257,70 @@ function toggleWeatherPopup() {
}
}

// Toggles the overall color theme.
// Sets theme by cookie if exists or by OS theme if no cookie exists.
window.onload=function() {
var cookie_pos = document.cookie.indexOf('theme='); // locates cookie
if (cookie_pos != -1) { // if exists cookie
var cookieTheme = substr(cookie_pos + 10, document.cookie.indexOf(';', cookie_pos)); // extracts cookie
if (cookieTheme == "dark") {
darkMode();
} else {
lightMode();
}
} else {
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
darkMode();
}
}
}

// Toggles the overall site theme.
function toggleTheme() {
if (this.checked) { // Represents dark mode.
horizontalBar.style.backgroundColor = "#202225";
leftSideBar.style.backgroundColor = "#202225";
titleElements.style.backgroundColor = "#202225";
weatherArrow.style.fill = "#202225";
weatherPopupBody.style.backgroundColor = "#202225";
wordmark.src = "uwWordmarks/UnivWaWordmark.png";
title.style.color = "whitesmoke";
logo.src = "logos/HuskyNavLogoDarker.png";
logo.style.borderWidth = "0px";
logo.style.width = "70px";
logo.style.height = "70px";
logo.style.marginLeft = "0px";
logo.style.marginTop = "10px";
expandIcon.style.background = "#202225";
devResources.style.background = "#202225";
darkMode();
} else { // Represents light mode.
horizontalBar.style.backgroundColor = "#4b2e83";
leftSideBar.style.backgroundColor = "#4b2e83";
titleElements.style.backgroundColor = "whitesmoke";
weatherArrow.style.fill = "#4b2e83";
weatherPopupBody.style.backgroundColor = "#4b2e83"
wordmark.src = "uwWordmarks/UnivWaWordmarkPurple.png";
title.style.color = "#4b2e83";
logo.src = "logos/HuskyNavLogoWhite.png";
logo.style.borderWidth = "5px";
logo.style.width = "60px";
logo.style.height = "60px";
expandIcon.style.background = "#4b2e83";
devResources.style.background = "#4b2e83";
lightMode();
}
}

// Sets site UI to dark mode.
function darkMode() {
horizontalBar.style.backgroundColor = "#202225";
leftSideBar.style.backgroundColor = "#202225";
titleElements.style.backgroundColor = "#202225";
weatherArrow.style.fill = "#202225";
weatherPopupBody.style.backgroundColor = "#202225";
wordmark.src = "uwWordmarks/UnivWaWordmark.png";
title.style.color = "whitesmoke";
logo.src = "logos/HuskyNavLogoDarker.png";
logo.style.borderWidth = "0px";
logo.style.width = "70px";
logo.style.height = "70px";
logo.style.marginLeft = "0px";
logo.style.marginTop = "10px";
expandIcon.style.background = "#202225";
devResources.style.background = "#202225";
document.cookie = 'theme=dark;';
}

// Sets site UI to light mode.
function lightMode() {
horizontalBar.style.backgroundColor = "#4b2e83";
leftSideBar.style.backgroundColor = "#4b2e83";
titleElements.style.backgroundColor = "whitesmoke";
weatherArrow.style.fill = "#4b2e83";
weatherPopupBody.style.backgroundColor = "#4b2e83"
wordmark.src = "uwWordmarks/UnivWaWordmarkPurple.png";
title.style.color = "#4b2e83";
logo.src = "logos/HuskyNavLogoWhite.png";
logo.style.borderWidth = "5px";
logo.style.width = "60px";
logo.style.height = "60px";
expandIcon.style.background = "#4b2e83";
devResources.style.background = "#4b2e83";
document.cookie = 'theme=light;';
}

// Handles new input in a search bar. Scrolls to the matching location element in the
// search bar's corresponding list of location elements using the prefix.
function handleNewInput() {
Expand Down
3 changes: 1 addition & 2 deletions Front-End/secondaryStylesheets/toggleSwitch.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ https://www.w3schools.com/howto/howto_css_switch.asp

/* Hide default HTML checkbox */
#switch input {

opacity: 0;
width: 0;
height: 0;
}

/* The slider */
/* Theme Slider */
#slider {
position: absolute;
cursor: pointer;
Expand Down

0 comments on commit c468a81

Please sign in to comment.