2019-02-03 12:30:44 +01:00
|
|
|
jQuery(function($) {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var _Blog = window._Blog || {};
|
|
|
|
|
2019-08-07 23:01:18 +02:00
|
|
|
_Blog.typeit = function() {
|
|
|
|
if (window.typeitMap) {
|
|
|
|
for (let id in typeitMap) {
|
2019-08-10 21:26:03 +02:00
|
|
|
if (Array.isArray(typeitMap[id])) {
|
|
|
|
const group = typeitMap[id];
|
|
|
|
(function typeone (i) {
|
|
|
|
if (i === group.length - 1) {
|
|
|
|
new TypeIt(`#${group[i]}`, {
|
|
|
|
strings: document.getElementById(`r${group[i]}`).innerHTML,
|
|
|
|
}).go();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let instance = new TypeIt(`#${group[i]}`, {
|
|
|
|
strings: document.getElementById(`r${group[i]}`).innerHTML,
|
|
|
|
afterComplete: () => {
|
|
|
|
instance.destroy();
|
|
|
|
typeone(i + 1);
|
|
|
|
},
|
|
|
|
}).go();
|
|
|
|
})(0);
|
|
|
|
} else {
|
|
|
|
new TypeIt(`#${id}`, {
|
|
|
|
strings: document.getElementById(`r${id}`).innerHTML,
|
|
|
|
}).go();
|
|
|
|
}
|
2019-08-07 23:01:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_Blog.countdown = function() {
|
|
|
|
if (window.countdownMap) {
|
|
|
|
for (let id in countdownMap) {
|
|
|
|
$(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-02-03 12:30:44 +01:00
|
|
|
_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() {
|
2019-03-11 15:05:27 +01:00
|
|
|
document.title = currentTitle;
|
2019-02-03 12:30:44 +01:00
|
|
|
}
|
|
|
|
window.onfocus = function() {
|
|
|
|
document.title = currentTitle;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_Blog.toggleTheme = function() {
|
2019-08-09 15:25:13 +02:00
|
|
|
const currentTheme = window.localStorage && window.localStorage.getItem('theme');
|
|
|
|
const isDark = currentTheme === 'dark';
|
|
|
|
$('body').toggleClass('dark-theme', isDark);
|
2019-02-03 12:30:44 +01:00
|
|
|
$('.theme-switch').on('click', () => {
|
2019-08-09 15:25:13 +02:00
|
|
|
$('body').toggleClass('dark-theme');
|
2019-02-03 12:30:44 +01:00
|
|
|
window.localStorage &&
|
2019-08-09 15:25:13 +02:00
|
|
|
window.localStorage.setItem('theme', document.body.classList.contains('dark-theme') ? 'dark' : 'light', );
|
|
|
|
});
|
2019-02-03 12:30:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_Blog.toggleMobileMenu = function() {
|
|
|
|
$('.menu-toggle').on('click', () => {
|
2019-08-09 15:25:13 +02:00
|
|
|
$('.menu-toggle').toggleClass('active');
|
|
|
|
$('#mobile-menu').toggleClass('active');
|
|
|
|
});
|
2019-02-03 12:30:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2019-08-09 15:25:13 +02:00
|
|
|
_Blog.toggleTheme();
|
|
|
|
_Blog.countdown();
|
|
|
|
_Blog.changeTitle();
|
|
|
|
_Blog.toggleMobileMenu();
|
|
|
|
_Blog.typeit();
|
2019-02-03 12:30:44 +01:00
|
|
|
});
|
2019-03-11 15:05:27 +01:00
|
|
|
});
|