2019-02-03 12:30:44 +01:00
|
|
|
jQuery(function($) {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _Blog = window._Blog || {};
|
|
|
|
|
2019-08-11 19:36:19 +02:00
|
|
|
_Blog.toggleMobileMenu = function() {
|
|
|
|
$('.menu-toggle').on('click', () => {
|
|
|
|
$('.menu-toggle').toggleClass('active');
|
|
|
|
$('#mobile-menu').toggleClass('active');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
_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.changeTitle = function() {
|
|
|
|
var currentTitle = document.title;
|
|
|
|
window.onblur = function() {
|
|
|
|
document.title = currentTitle;
|
|
|
|
};
|
|
|
|
window.onfocus = function() {
|
|
|
|
document.title = currentTitle;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
_Blog.chroma = function() {
|
|
|
|
const blocks = document.querySelectorAll('.highlight > .chroma');
|
|
|
|
for (let i = 0; i < blocks.length; i++) {
|
|
|
|
const block = blocks[i];
|
|
|
|
const afterHighLight = block.querySelector('pre.chroma > code');
|
|
|
|
const lang = afterHighLight ? afterHighLight.className : '';
|
|
|
|
block.className += ' ' + lang;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_Blog.countdown = function() {
|
|
|
|
if (window.countdownMap) {
|
2019-08-16 21:40:34 +02:00
|
|
|
Object.keys(countdownMap).forEach(function(id) {
|
2019-08-11 19:36:19 +02:00
|
|
|
$(id).countdown(countdownMap[id], {elapse: true})
|
|
|
|
.on('update.countdown', function(event) {
|
|
|
|
var $this = $(this).html(event.strftime(''
|
|
|
|
+ '<span>%D</span> 天 <br />'
|
|
|
|
+ '<span>%H</span> 时 '
|
|
|
|
+ '<span>%M</span> 分 '
|
|
|
|
+ '<span>%S</span> 秒'));
|
|
|
|
});
|
2019-08-16 21:40:34 +02:00
|
|
|
});
|
2019-08-11 19:36:19 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-07 23:01:18 +02:00
|
|
|
_Blog.typeit = function() {
|
2019-08-16 21:40:34 +02:00
|
|
|
if (window.typeitArr) {
|
|
|
|
for (let i = 0; i < typeitArr.length; i++) {
|
|
|
|
const group = typeitArr[i];
|
|
|
|
(function typeone (i) {
|
|
|
|
if (i === group.length - 1) {
|
|
|
|
new TypeIt(`#${group[i]}`, {
|
2019-08-10 21:26:03 +02:00
|
|
|
strings: document.getElementById(`r${group[i]}`).innerHTML,
|
|
|
|
}).go();
|
2019-08-16 21:40:34 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
let instance = new TypeIt(`#${group[i]}`, {
|
|
|
|
strings: document.getElementById(`r${group[i]}`).innerHTML,
|
|
|
|
afterComplete: () => {
|
|
|
|
instance.destroy();
|
|
|
|
typeone(i + 1);
|
|
|
|
},
|
2019-08-10 21:26:03 +02:00
|
|
|
}).go();
|
2019-08-16 21:40:34 +02:00
|
|
|
})(0);
|
2019-08-07 23:01:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-03 12:30:44 +01:00
|
|
|
$(document).ready(function() {
|
2019-08-11 19:36:19 +02:00
|
|
|
_Blog.toggleMobileMenu();
|
2019-08-09 15:25:13 +02:00
|
|
|
_Blog.toggleTheme();
|
|
|
|
_Blog.changeTitle();
|
2019-08-11 19:36:19 +02:00
|
|
|
_Blog.chroma();
|
|
|
|
_Blog.countdown();
|
2019-08-09 15:25:13 +02:00
|
|
|
_Blog.typeit();
|
2019-02-03 12:30:44 +01:00
|
|
|
});
|
2019-03-11 15:05:27 +01:00
|
|
|
});
|