Personal-Site/js/main.js

68 lines
2 KiB
JavaScript
Raw Normal View History

2017-12-16 05:09:10 +00:00
var theme = window.localStorage.getItem("theme");
if (theme != null && theme == "true")
2018-01-03 21:48:57 +00:00
$("body").addClass("dark-mode");
2017-12-16 05:09:10 +00:00
$(document).ready(function () {
$("#btnTheme").click(function () {
if ($("#btnTheme").hasClass("btn-light")) {
transitionLight();
} else {
transitionDark();
}
});
var theme = window.localStorage.getItem("theme");
if (theme != null && theme == "true")
setDark();
});
function checkTheme() {
if (theme != null && theme == "true")
setDark();
}
function transitionDark() {
2018-01-03 21:48:57 +00:00
$(".card").addClass("transition");
$(".jumbotron").addClass("transition");
$(".form-control").addClass("transition");
$("a:not(.navbar-brand):not(.nav-link)").addClass("transition");
$("body").addClass("transition dark-mode");
2017-12-16 05:09:10 +00:00
2018-01-03 21:48:57 +00:00
setTimeout(endTransition, 250);
2017-12-16 05:09:10 +00:00
$("#btnTheme").removeClass("btn-dark").addClass("transition btn-light");
$("#themeText").replaceWith($("<span>").attr("id", "themeText").addClass("fas fa-sun"));
window.localStorage.setItem("theme", "true");
}
function transitionLight() {
2018-01-03 21:48:57 +00:00
$(".card").addClass("transition");
$(".jumbotron").addClass("transition");
$(".form-control").addClass("transition");
$("a:not(.navbar-brand):not(.nav-link)").addClass("transition");
$("body").addClass("transition").removeClass("dark-mode");
2017-12-16 05:09:10 +00:00
2018-01-03 21:48:57 +00:00
setTimeout(endTransition, 250);
2017-12-16 05:09:10 +00:00
$("#btnTheme").removeClass("btn-light").addClass("transition btn-dark");
$("#themeText").replaceWith($("<span>").attr("id", "themeText").addClass("fas fa-moon"));
window.localStorage.setItem("theme", "false");
}
2018-01-03 21:48:57 +00:00
function endTransition() {
$("body").removeClass("transition");
$(".card").removeClass("transition");
$(".jumbotron").removeClass("transition");
$("a:not(.navbar-brand):not(.nav-link)").removeClass("transition");
$(".form-control").removeClass("transition");
}
2017-12-16 05:09:10 +00:00
function setDark() {
2018-01-03 21:48:57 +00:00
$("body").addClass("dark-mode");
2017-12-16 05:09:10 +00:00
$("#btnTheme").removeClass("btn-dark").addClass("btn-light");
$("#themeText").replaceWith($("<span>").attr("id", "themeText").addClass("fas fa-sun"));
}