LeaveItFork/assets/js/main.js
2018-09-14 19:00:48 +08:00

44 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(function(){
'use strict';
var _Blog = window._Blog || {};
_Blog.changeTitle = function() {
var currentTitle = document.title;
window.onblur = function() {
document.title = 'I miss you!';
}
window.onfocus = function() {
document.title = currentTitle;
}
};
_Blog.toggleTheme = function() {
const currentTheme = window.localStorage && window.localStorage.getItem('theme')
const themeSwitchEL = document.querySelector('.theme-switch')
const isDark = currentTheme === 'dark'
document.body.classList.toggle('dark-theme', isDark)
themeSwitchEL.addEventListener('click', () => {
document.body.classList.toggle('dark-theme')
window.localStorage &&
window.localStorage.setItem(
'theme',
document.body.classList.contains('dark-theme') ? 'dark' : 'light',
)
})
}
_Blog.toggleMobileMenu = function(){
const menuToggle = document.querySelector('.menu-toggle')
const mobileMenu = document.querySelector('#mobile-menu')
menuToggle.addEventListener('click', () => {
mobileMenu.classList.toggle('active')
menuToggle.classList.toggle('active')
})
}
_Blog.toggleTheme()
_Blog.changeTitle()
_Blog.toggleMobileMenu()
}());