-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
204 lines (185 loc) · 7.55 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
require([], function (){
var isMobileInit = false;
var loadMobile = function(){
require([yiliaConfig.rootUrl + 'js/mobile.js'], function(mobile){
mobile.init();
isMobileInit = true;
})
}
var isPCInit = false;
var loadPC = function(){
require([yiliaConfig.rootUrl + 'js/pc.js'], function(pc){
pc.init();
isPCInit = true;
})
}
var browser = {
versions: function() {
var u = window.navigator.userAgent;
return {
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者安卓QQ浏览器
iPad: u.indexOf('iPad') > -1, //是否为iPad
webApp: u.indexOf('Safari') == -1 ,//是否为web应用程序,没有头部与底部
weixin: u.indexOf('MicroMessenger') == -1 //是否为微信浏览器
};
}()
}
$(window).bind("resize", function() {
if (isMobileInit && isPCInit) {
$(window).unbind("resize");
return;
}
var w = $(window).width();
if (w >= 700) {
loadPC();
} else {
loadMobile();
}
});
if(!!browser.versions.mobile || $(window).width() < 800){
loadMobile();
} else {
loadPC();
}
resetTags = function(){
var tags = $(".tagcloud a");
for(var i = 0; i < tags.length; i++){
var num = Math.floor(Math.random()*7);
tags.eq(i).addClass("color" + num);
}
$(".article-category a:nth-child(-n+2)").attr("class", "color0");
}
// fancyBox
if(!!yiliaConfig.fancybox){
require([yiliaConfig.fancybox_js], function(pc){
var isFancy = $(".isFancy");
if(isFancy.length != 0){
var imgArr = $(".article-inner img");
for(var i=0,len=imgArr.length;i<len;i++){
var src = imgArr.eq(i).attr("src");
var title = imgArr.eq(i).attr("alt");
if(typeof(title) == "undefined"){
var title = imgArr.eq(i).attr("title");
}
var width = imgArr.eq(i).attr("width");
var height = imgArr.eq(i).attr("height");
imgArr.eq(i).replaceWith("<a href='"+src+"' title='"+title+"' rel='fancy-group' class='fancy-ctn fancybox'><img src='"+src+"' width="+width+" height="+height+" title='"+title+"' alt='"+title+"'></a>");
}
$(".article-inner .fancy-ctn").fancybox({ type: "image" });
}
})
}
// Animate on Homepage
if(!!yiliaConfig.animate) {
if(!!yiliaConfig.isHome) {
require([yiliaConfig.scrollreveal], function (ScrollReveal) {
var animationNames = [
"pulse", "fadeIn","fadeInRight", "flipInX", "lightSpeedIn","rotateInUpLeft", "slideInUp","zoomIn",
],
len = animationNames.length,
randomAnimationName = animationNames[Math.ceil(Math.random() * len) - 1];
// Fallback (CSS3 keyframe, requestAnimationFrame)
if (!window.requestAnimationFrame) {
$('.body-wrap > article').css({opacity: 1});
if (navigator.userAgent.match(/Safari/i)) {
function showArticle(){
$(".article").each(function(){
if( $(this).offset().top <= $(window).scrollTop()+$(window).height() && !($(this).hasClass('show')) ) {
$(this).removeClass("hidden").addClass("show");
$(this).addClass("is-hiddened");
} else {
if(!$(this).hasClass("is-hiddened")) {
$(this).addClass("hidden");
}
}
})
}
$(window).on('scroll', function(){
showArticle();
});
showArticle();
}
return;
}
var animateScope = ".body-wrap > article";
var $firstArticle = $(".body-wrap > article:first-child");
if ($firstArticle.height() > $(window).height()) {
var animateScope = ".body-wrap > article:not(:first-child)";
$firstArticle.css({opacity: 1});
}
ScrollReveal({
duration: 0,
afterReveal: function (domEl) {
$(domEl).addClass('animated ' + randomAnimationName).css({opacity: 1})
}
}).reveal(animateScope);
})
} else {
$('.body-wrap > article').css({opacity: 1});
}
}
// TOC
if (yiliaConfig.toc) {
require(['toc'], function(){ })
}
// Random Color 边栏顶部随机颜色
var colorList = ["#6da336", "#ff945c", "#66CC66", "#99CC99", "#CC6666", "#76becc", "#c99979", "#918597", "#4d4d4d"];
var id = Math.ceil(Math.random()*(colorList.length-1));
// PC
$("#container .left-col .overlay").css({"background-color": colorList[id],"opacity": .3});
// Mobile
$("#container #mobile-nav .overlay").css({"background-color": colorList[id],"opacity": .7});
// Table
$("table").wrap("<div class='table-area'></div>");
// Hide Comment Button
$(document).ready(function() {
if ($("#comments").length < 1) {
$("#scroll > a:nth-child(2)").hide();
}
})
// Hide Labels
if(yiliaConfig.isArchive || yiliaConfig.isTag || yiliaConfig.isCategory) {
$(document).ready(function() {
$("#footer").after("<button class='hide-labels'>TAGS</button>");
$(".hide-labels").click(function() {
$(".article-info").toggle(200);
})
})
}
// Task lists in markdown
$('ul > li').each(function() {
var taskList = {
field: this.textContent.substring(0, 2),
check: function(str) {
var re = new RegExp(str);
return this.field.match(re);
}
}
var string = ["[ ]", ["[x]", "checked"]];
var checked = taskList.check(string[1][0]);
var unchecked = taskList.check(string[0]);
var $current = $(this);
function update(str, check) {
var click = ["disabled", ""];
$current.html($current.html().replace(
str, "<input type='checkbox' " + check + " " + click[1] + " >")
)
}
if (checked || unchecked) {
this.classList.add("task-list");
if (checked) {
update(string[1][0], string[1][1]);
this.classList.add("check");
} else {
update(string[0], "");
}
}
})
})