-
Notifications
You must be signed in to change notification settings - Fork 123
/
main.js
56 lines (47 loc) · 1.66 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
jQuery(function($) {
'use strict';
var _Blog = window._Blog || {};
_Blog.prettify = function() {
$('pre').addClass('prettyprint linenums').attr('style', 'overflow:auto;');
window.prettyPrint && prettyPrint();
};
_Blog.externalUrl = function() {
$.expr[':'].external = function(obj) {
return !obj.href.match(/^mailto\:/) &&
(obj.hostname != location.hostname);
};
$('a:external').addClass('external');
$(".external").attr('target', '_blank');
}
_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 isDark = currentTheme === 'dark'
$('body').toggleClass('dark-theme', isDark)
$('.theme-switch').on('click', () => {
$('body').toggleClass('dark-theme')
window.localStorage &&
window.localStorage.setItem('theme', document.body.classList.contains('dark-theme') ? 'dark' : 'light', )
})
}
_Blog.toggleMobileMenu = function() {
$('.menu-toggle').on('click', () => {
$('.menu-toggle').toggleClass('active')
$('#mobile-menu').toggleClass('active')
})
}
$(document).ready(function() {
_Blog.prettify()
_Blog.changeTitle()
_Blog.toggleTheme()
_Blog.toggleMobileMenu()
});
});