yipengshu 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/.DS_Store +0 -0
  2. package/.npmignore +6 -0
  3. package/2020/01/30//351/227/256/351/242/2303/index.html +540 -0
  4. package/2020/05/05//351/227/256/351/242/2302/index.html +540 -0
  5. package/2022/10/28//351/227/256/351/242/2304/index.html +539 -0
  6. package/2022/10/30//351/227/256/351/242/2301/index.html +540 -0
  7. package/README.md +3 -0
  8. package/about/index.html +535 -0
  9. package/api/articles//351/227/256/351/242/2301.json +1 -0
  10. package/api/articles//351/227/256/351/242/2302.json +1 -0
  11. package/api/articles//351/227/256/351/242/2303.json +1 -0
  12. package/api/articles//351/227/256/351/242/2304.json +1 -0
  13. package/api/categories//351/241/271/347/233/256.json +1 -0
  14. package/api/categories.json +1 -0
  15. package/api/galleries/all.json +1 -0
  16. package/api/galleries/babecue.json +1 -0
  17. package/api/galleries/colorful.json +1 -0
  18. package/api/galleries//345/274/200/344/274/232.json +1 -0
  19. package/api/galleries//346/227/245/345/270/270/347/224/237/346/264/273/347/232/204/346/202/240/350/277/234/346/203/205/346/204/217/347/232/204/346/267/261/351/225/277.json +1 -0
  20. package/api/galleries//347/242/216/345/261/217/346/211/213/346/234/272/357/274/214mac/357/274/214iPad/357/274/214windows/345/276/205/345/224/256.json +1 -0
  21. package/api/galleries.json +1 -0
  22. package/api/pages/------------.json +1 -0
  23. package/api/pages/-----mac-ipad-windows--.json +1 -0
  24. package/api/pages/--.json +1 -0
  25. package/api/pages/babecue.json +1 -0
  26. package/api/pages/colorful.json +1 -0
  27. package/api/posts/1.json +1 -0
  28. package/api/posts.json +1 -0
  29. package/api/site.json +1 -0
  30. package/api/tags/1.json +1 -0
  31. package/api/tags/2.json +1 -0
  32. package/api/tags/4.json +1 -0
  33. package/api/tags/5.json +1 -0
  34. package/api/tags/9.json +1 -0
  35. package/api/tags.json +1 -0
  36. package/archives/2020/01/index.html +457 -0
  37. package/archives/2020/05/index.html +457 -0
  38. package/archives/2020/index.html +457 -0
  39. package/archives/2022/10/index.html +457 -0
  40. package/archives/2022/index.html +457 -0
  41. package/archives/index.html +457 -0
  42. package/categories/index.html +427 -0
  43. package/categories//351/241/271/347/233/256/index.html +457 -0
  44. package/css/style.css +2118 -0
  45. package/galleries/babecue/index.html +499 -0
  46. package/galleries/colorful/index.html +499 -0
  47. package/galleries/index.html +482 -0
  48. package/galleries//345/274/200/344/274/232/index.html +499 -0
  49. package/galleries//346/227/245/345/270/270/347/224/237/346/264/273/347/232/204/346/202/240/350/277/234/346/203/205/346/204/217/347/232/204/346/267/261/351/225/277/index.html +499 -0
  50. package/galleries//347/242/216/345/261/217/346/211/213/346/234/272/357/274/214mac/357/274/214iPad/357/274/214windows/345/276/205/345/224/256/index.html +499 -0
  51. package/images/donate/alipay.jpg +0 -0
  52. package/images/donate/wechat.jpg +0 -0
  53. package/images/icons/128x128.png +0 -0
  54. package/images/icons/16x16.png +0 -0
  55. package/images/icons/16x16wo.png +0 -0
  56. package/images/icons/32x32.png +0 -0
  57. package/images/icons/32x32wo.png +0 -0
  58. package/images/icons/500x500.png +0 -0
  59. package/images/icons/80x80.png +0 -0
  60. package/images/icons/960x960.png +0 -0
  61. package/images/icons/apple-touch-icon180x180.png +0 -0
  62. package/images/icons/favicon-144x144.png +0 -0
  63. package/images/icons//347/254/224/350/256/260.tex +9 -0
  64. package/images/theme/01.webp +0 -0
  65. package/images/theme/Mountains.jpg +0 -0
  66. package/images/theme/Sea.jpg +0 -0
  67. package/images/theme/babecue.jpg +0 -0
  68. package/images/theme/bingshan.jpeg +0 -0
  69. package/images/theme/cloud.png +0 -0
  70. package/images/theme/google-blue.png +0 -0
  71. package/images/theme/hong.jpg +0 -0
  72. package/images/theme/jidan.jpg +0 -0
  73. package/images/theme/kh.jpeg +0 -0
  74. package/images/theme/kh1.jpg +0 -0
  75. package/images/theme/loading.gif +0 -0
  76. package/images/theme/nujiangxiagu.jpg +0 -0
  77. package/images/theme/nujiangxiagu.webp +0 -0
  78. package/images/theme/nujiangxiagu02.webp +0 -0
  79. package/images/theme/photo_2022-11-01_11-55-52.jpg +0 -0
  80. package/images/theme/post-image-01.gif +0 -0
  81. package/images/theme/post-image-02.jpg +0 -0
  82. package/images/theme/post-image-03.png +0 -0
  83. package/images/theme/post-image-04.gif +0 -0
  84. package/images/theme/post-image-04.png +0 -0
  85. package/images/theme/post-image-99.png +0 -0
  86. package/images/theme/post-image.JPEG +0 -0
  87. package/images/theme/post-image.jpg.png +0 -0
  88. package/images/theme/s.webp +0 -0
  89. package/images/theme/s1.webp +0 -0
  90. package/images/theme/s2.jpg +0 -0
  91. package/images/theme/s3.jpg +0 -0
  92. package/images/theme/shengbidebao.jpg +0 -0
  93. package/images/theme/shoubiao.jpg +0 -0
  94. package/images/theme/shouxin.jpg +0 -0
  95. package/images/theme/taolun.jpg +0 -0
  96. package/images/theme/taolun1.jpg +0 -0
  97. package/images/theme/tengxuntuxiaochao.png +0 -0
  98. package/images/theme/welcome-image.jpg +0 -0
  99. package/images/theme/xiong.jpg +0 -0
  100. package/images/theme/y.jpeg +0 -0
  101. package/images/theme/yao.jpg +0 -0
  102. package/index.html +600 -0
  103. package/js/color-mode.js +75 -0
  104. package/js/script.js +492 -0
  105. package/js/utils.js +167 -0
  106. package/lib/daovoice/daovoice.js +21 -0
  107. package/lib/fancybox/fancybox.css +1 -0
  108. package/lib/fancybox/fancybox.js +13 -0
  109. package/lib/gitalk/gitalk.css +1211 -0
  110. package/lib/gitalk/gitalk.js +25 -0
  111. package/lib/highlight/a11y-dark.css +1 -0
  112. package/lib/highlight/highlight.js +2 -0
  113. package/lib/jquery/jquery.js +2 -0
  114. package/lib/lazyload/lazyload.js +2 -0
  115. package/lib/lottie/lottie.js +15 -0
  116. package/lib/pjax/pjax.js +2 -0
  117. package/lib/qrcode/qrcode.js +28 -0
  118. package/package.json +10 -0
  119. package/tags/1/index.html +451 -0
  120. package/tags/2/index.html +445 -0
  121. package/tags/4/index.html +437 -0
  122. package/tags/5/index.html +437 -0
  123. package/tags/9/index.html +437 -0
  124. package/tags/index.html +429 -0
package/js/script.js ADDED
@@ -0,0 +1,492 @@
1
+ console.log("%c Github %c", "background:#333333; color:#ffffff", "", "https://github.com/izhaoo/hexo-theme-zhaoo");
2
+
3
+ (function ($) {
4
+ "use strict";
5
+
6
+ var fn = {
7
+ showMenu: function () {
8
+ $(".menu").fadeIn(300);
9
+ $("body").addClass("lock-screen");
10
+ fn.hideFab();
11
+ ZHAOO.utils.bindKeyup(27, function () {
12
+ fn.hideMenu();
13
+ $(".navbar").removeClass("hide");
14
+ });
15
+ },
16
+ hideMenu: function () {
17
+ $(".menu").fadeOut(300);
18
+ $("body").removeClass("lock-screen");
19
+ },
20
+ showSearch: function () {
21
+ $(".search").fadeIn(300);
22
+ $("body").addClass("lock-screen");
23
+ fn.hideFab();
24
+ ZHAOO.utils.bindKeyup(27, function () {
25
+ fn.hideSearch();
26
+ $(".navbar").removeClass("hide");
27
+ });
28
+ },
29
+ hideSearch: function () {
30
+ $(".search").fadeOut(300);
31
+ $("body").removeClass("lock-screen");
32
+ },
33
+ activeFab: function () {
34
+ $(".fab-up").addClass("fab-up-active");
35
+ $(".fab-plus").addClass("fab-plus-active");
36
+ $(".fab-daovoice").addClass("fab-daovoice-active");
37
+ $(".fab-tencent-chao").addClass("fab-tencent-chao-active");
38
+ $(".fab-like").addClass("fab-like-active");
39
+ },
40
+ freezeFab: function () {
41
+ $(".fab-up").removeClass("fab-up-active");
42
+ $(".fab-plus").removeClass("fab-plus-active");
43
+ $(".fab-daovoice").removeClass("fab-daovoice-active");
44
+ $(".fab-tencent-chao").removeClass("fab-tencent-chao-active");
45
+ $(".fab-like").removeClass("fab-like-active");
46
+ },
47
+ showFab: function () {
48
+ $(".fab").removeClass("fab-hide").addClass("fab-show");
49
+ },
50
+ hideFab: function () {
51
+ $(".fab").addClass("fab-hide").removeClass("fab-show");
52
+ },
53
+ scroolFab: function () {
54
+ var height = $(window).height();
55
+ var scrollTop = $(window).scrollTop();
56
+ if (scrollTop > height) {
57
+ fn.showFab();
58
+ } else {
59
+ fn.freezeFab();
60
+ fn.hideFab();
61
+ }
62
+ },
63
+ scroolToTop: function () {
64
+ $('body,html').animate({
65
+ scrollTop: '0px'
66
+ }, 800);
67
+ },
68
+ navbar: {
69
+ mobile: function () {
70
+ var height = $(window).height();
71
+ if (CONFIG.isHome) {
72
+ $(".navbar").addClass("transparent");
73
+ } else {
74
+ $(".navbar").addClass("hide");
75
+ }
76
+ $(window).on("scroll", ZHAOO.utils.throttle(function () {
77
+ var before = $(this).scrollTop();
78
+ $(window).on("scroll", function () {
79
+ var after = $(this).scrollTop();
80
+ if (!CONFIG.isHome) {
81
+ if (before > after && after > 300) {
82
+ $(".navbar").removeClass("hide");
83
+ } else if (before < after || after < 300) {
84
+ $(".navbar").addClass("hide");
85
+ }
86
+ }
87
+ if (CONFIG.isHome) {
88
+ if (before < after && after > height) {
89
+ $(".navbar").removeClass("transparent");
90
+ } else if (before > after && after < height) {
91
+ $(".navbar").addClass("transparent");
92
+ } else if (before > after) {
93
+ $(".navbar").removeClass("hide");
94
+ } else if (before < after) {
95
+ $(".navbar").addClass("hide");
96
+ }
97
+ }
98
+ before = after;
99
+ })
100
+ }, 500));
101
+ },
102
+ desktop: function () {
103
+ $(".navbar").addClass("transparent");
104
+ function center() {
105
+ if ($(window).scrollTop() > 60) {
106
+ $(".navbar .center").addClass("hide");
107
+ } else {
108
+ $(".navbar .center").removeClass("hide");
109
+ if (!CONFIG.isHome) {
110
+ $(".navbar").removeClass("transparent");
111
+ }
112
+ }
113
+ }
114
+ center();
115
+ $(window).on("scroll", ZHAOO.utils.throttle(function () {
116
+ center();
117
+ var before = $(this).scrollTop();
118
+ $(window).on("scroll", function () {
119
+ var after = $(this).scrollTop();
120
+ if (before > after) {
121
+ $(".navbar").removeClass("hide");
122
+ } else if (before < after) {
123
+ $(".navbar").addClass("hide");
124
+ }
125
+ before = after;
126
+ })
127
+ }, 500));
128
+ },
129
+ },
130
+ motto: function () {
131
+ if (CONFIG.preview.motto.api) {
132
+ var data_contents = CONFIG.preview.motto.data_contents && JSON.parse(CONFIG.preview.motto.data_contents);
133
+ $.get(CONFIG.preview.motto.api, function (result) {
134
+ if (data_contents.length > 0) {
135
+ data_contents.forEach(function (item) {
136
+ result = result[item];
137
+ });
138
+ }
139
+ if (result) {
140
+ fn.printMotto(result);
141
+ }
142
+ });
143
+ } else {
144
+ fn.printMotto(CONFIG.preview.motto.default);
145
+ }
146
+ },
147
+ printMotto: function (text) {
148
+ if (CONFIG.preview.motto.typing) {
149
+ if (text.charAt(text.length - 1) === '。') {
150
+ text = text.substr(0, text.length - 1);
151
+ }
152
+ var i = 0;
153
+ var timer = setInterval(function () {
154
+ if (i >= text.length) {
155
+ clearInterval(timer);
156
+ }
157
+ $("#motto").text(text.slice(0, i++));
158
+ }, 100);
159
+ } else {
160
+ $("#motto").text(text);
161
+ }
162
+ },
163
+ background: function () {
164
+ if (!CONFIG.preview.background.api) return;
165
+ $(".preview-image").css("background-image", "url(" + CONFIG.preview.background.api + ")");
166
+ },
167
+ doSearch: function (path, search_id, content_id) {
168
+ // https://segmentfault.com/a/1190000011917419
169
+ $.ajax({
170
+ url: path,
171
+ dataType: "xml",
172
+ success: function (xmlResponse) {
173
+ var datas = $("entry", xmlResponse).map(function () {
174
+ return {
175
+ title: $("title", this).text(),
176
+ content: $("content", this).text(),
177
+ url: $("url", this).text()
178
+ };
179
+ }).get();
180
+ var $input = document.getElementById(search_id);
181
+ var $resultContent = document.getElementById(content_id);
182
+ $input.addEventListener('input', function () {
183
+ var str = '<ul class=\"search-result-list\">';
184
+ var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
185
+ $resultContent.innerHTML = "";
186
+ if (this.value.trim().length <= 0) {
187
+ return;
188
+ }
189
+ datas.forEach(function (data) {
190
+ var isMatch = true;
191
+ var content_index = [];
192
+ var data_title = data.title.trim().toLowerCase();
193
+ var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
194
+ var data_url = data.url;
195
+ var index_title = -1;
196
+ var index_content = -1;
197
+ var first_occur = -1;
198
+ if (data_title != '' && data_content != '') {
199
+ keywords.forEach(function (keyword, i) {
200
+ index_title = data_title.indexOf(keyword);
201
+ index_content = data_content.indexOf(keyword);
202
+ if (index_title < 0 && index_content < 0) {
203
+ isMatch = false;
204
+ } else {
205
+ if (index_content < 0) {
206
+ index_content = 0;
207
+ }
208
+ if (i == 0) {
209
+ first_occur = index_content;
210
+ }
211
+ }
212
+ });
213
+ }
214
+ if (isMatch) {
215
+ str += "<li><a href='" + data_url + "' class='search-result-title' target='_blank'>" + data_title + "</a>";
216
+ var content = data.content.trim().replace(/<[^>]+>/g, "");
217
+ if (first_occur >= 0) {
218
+ var start = first_occur - 6;
219
+ var end = first_occur + 6;
220
+ if (start < 0) {
221
+ start = 0;
222
+ }
223
+ if (start == 0) {
224
+ end = 10;
225
+ }
226
+ if (end > content.length) {
227
+ end = content.length;
228
+ }
229
+ var match_content = content.substr(start, end);
230
+ keywords.forEach(function (keyword) {
231
+ var regS = new RegExp(keyword, "gi");
232
+ match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
233
+ })
234
+ str += "<p class=\"search-result\">" + match_content + "...</p>"
235
+ }
236
+ }
237
+ })
238
+ $resultContent.innerHTML = str;
239
+ })
240
+ }
241
+ })
242
+ }
243
+ }
244
+
245
+ var action = {
246
+ smoothScroll: function () {
247
+ // a[href *=#], area[href *=#]
248
+ $(".smooth-scroll, .toc-link").click(function () {
249
+ if (location.pathname.replace(/^\//, "") == this.pathname.replace(/^\//, "") && location.hostname == this.hostname) {
250
+ var $target = $(decodeURIComponent(this.hash));
251
+ $target = $target.length && $target || $("[name=" + this.hash.slice(1) + "]");
252
+ if ($target.length) {
253
+ var targetOffset = $target.offset().top;
254
+ $("html,body").animate({
255
+ scrollTop: targetOffset
256
+ }, 500);
257
+ location.hash = this.hash;
258
+ return false;
259
+ }
260
+ }
261
+ });
262
+ },
263
+ loading: function () {
264
+ $(".loading").delay(500).fadeOut(300);
265
+ $("body").removeClass("lock-screen");
266
+ },
267
+ fab: function () {
268
+ $(".fab-plus").on("click", function () {
269
+ if ($(this).hasClass("fab-plus-active")) {
270
+ fn.freezeFab();
271
+ } else {
272
+ fn.activeFab();
273
+ }
274
+ });
275
+ $(".fab-daovoice").on("click", function () {
276
+ daovoice('openMessages');
277
+ });
278
+ $(".fab-up, .fab-daovoice, fab-tencent-chao").on("click", function () {
279
+ fn.freezeFab();
280
+ });
281
+ if (CONFIG.fab.always_show) {
282
+ fn.showFab();
283
+ } else {
284
+ $(window).scroll(fn.scroolFab);
285
+ }
286
+ },
287
+ menu: function () {
288
+ $(".menu-close").on("click", function () {
289
+ fn.hideMenu();
290
+ $(".navbar").removeClass("hide");
291
+ });
292
+ },
293
+ scroolToTop: function () {
294
+ $(".fab-up").on("click", function () {
295
+ fn.scroolToTop();
296
+ })
297
+ },
298
+ fancybox: function () {
299
+ $(".fancybox").fancybox();
300
+ $(".article .content img").each(function () {
301
+ var e = document.createElement("a");
302
+ $(e).attr("data-fancybox", "images");
303
+ $(e).attr("href", $(this).attr("src"));
304
+ $(this).wrap(e);
305
+ });
306
+ },
307
+ pjax: function () {
308
+ $(function () {
309
+ $(document).pjax("a:not(.menu *)", '#main', {
310
+ fragment: '#main',
311
+ timeout: 6000
312
+ });
313
+ });
314
+ $(document).on('pjax:complete', function () {
315
+ CONFIG.fancybox && action.fancybox();
316
+ });
317
+ },
318
+ donate: function () {
319
+ $(".donate .icon").on("mouseover", function () {
320
+ $("#qrcode-donate").show();
321
+ });
322
+ $(".donate .icon").children("a").on("mouseover", function () {
323
+ $("#qrcode-donate img").attr('src', eval('CONFIG.donate.' + $(this).attr('id')))
324
+ });
325
+ $(".donate .icon").on("mouseout", function () {
326
+ $("#qrcode-donate").hide();
327
+ });
328
+ },
329
+ lazyload: function () {
330
+ $("img.lazyload").lazyload({
331
+ effect: "fadeIn",
332
+ threshold: 200,
333
+ });
334
+ },
335
+ fixLazyloadFancybox: function () {
336
+ $(document).find('.article img[data-original]').each(function () {
337
+ $(this).parent().attr("href", $(this).attr("data-original"));
338
+ });
339
+ },
340
+ carrier: function () {
341
+ $(".j-carrier-btn").on("click", ZHAOO.utils.throttle(function () {
342
+ $(".j-carrier-data").select();
343
+ document.execCommand("Copy");
344
+ ZHAOO.zui.message({ text: '已复制到剪切板', type: 'success' });
345
+ }, 1000));
346
+ },
347
+ navbar: function () {
348
+ $(window).resize(ZHAOO.utils.throttle(function () {
349
+ ZHAOO.utils.isDesktop() && fn.navbar.desktop();
350
+ ZHAOO.utils.isMobile() && fn.navbar.mobile();
351
+ }, 1000)).resize();
352
+ $(".j-navbar-menu").on("click", function () {
353
+ fn.showMenu();
354
+ $(".navbar").addClass("hide");
355
+ $(".qrcode").fadeOut(300);
356
+ });
357
+ $(".j-navbar-qrcode").on("click", function () {
358
+ if ($("#qrcode-navbar").is(":hidden")) {
359
+ $("#qrcode-navbar").fadeIn(300);
360
+ } else {
361
+ $("#qrcode-navbar").fadeOut(300);
362
+ }
363
+ });
364
+ $(".j-navbar-back-home").on("click", function () {
365
+ window.location.href = "/";
366
+ });
367
+ $(".j-navbar-search").on("click", function () {
368
+ fn.showSearch();
369
+ $(".navbar").addClass("hide");
370
+ $(".qrcode").fadeOut(300);
371
+ });
372
+ },
373
+ preview: function () {
374
+ fn.background();
375
+ fn.motto();
376
+ },
377
+ qrcode: function () {
378
+ if (CONFIG.qrcode.type === 'url') {
379
+ $("#qrcode-navbar").qrcode({
380
+ text: window.location.href,
381
+ width: 150,
382
+ height: 150
383
+ });
384
+ } else if (CONFIG.qrcode.type === 'image') {
385
+ $("#qrcode-navbar").append('<img src="' + CONFIG.qrcode.image + '" alt="qrcode" />');
386
+ }
387
+ },
388
+ toc: function () {
389
+ var current = [];
390
+ var titleList = new Map();
391
+ $("article .content h1,h2,h3,h4,h5,h6").each(function () {
392
+ var title = $(this).attr("id");
393
+ var height = $(this).offset().top;
394
+ titleList.set(height, title);
395
+ });
396
+ $(window).on("scroll", f);
397
+ function f() {
398
+ var height = $(this).scrollTop() || $(window).scrollTop();
399
+ for (var item of titleList) {
400
+ if (item[0] >= height) {
401
+ current = item;
402
+ break;
403
+ }
404
+ }
405
+ $(".toc-link").removeClass("active");
406
+ $(".toc-link[href='#" + current[1] + "']").addClass("active");
407
+ };
408
+ f();
409
+ },
410
+ scrollbar: function () {
411
+ var totalH = $(document).height();
412
+ var clientH = $(window).height();
413
+ $(window).on("scroll", f);
414
+ function f() {
415
+ var validH = totalH - clientH;
416
+ var scrollH = $(document).scrollTop();
417
+ var height = scrollH / validH * 100;
418
+ $(".j-scrollbar-current").css("height", height + '%');
419
+ }
420
+ f();
421
+ $(".j-scrollbar").mousedown(function (e) {
422
+ var scrollH = e.offsetY * totalH / 100;
423
+ $("html,body").animate({ scrollTop: scrollH }, 300);
424
+ $(document).mousemove(function (e) {
425
+ var scrollH = (1 - ((clientH - e.clientY) / clientH)) * totalH;
426
+ $("html,body").scrollTop(scrollH);
427
+ $("html,body").css({ "user-select": "none", "cursor": "move" });
428
+ });
429
+ $(document).mouseup(function () {
430
+ $(document).off('mousemove');
431
+ $("html,body").css({ "user-select": "auto", "cursor": "default" });
432
+ });
433
+ });
434
+ },
435
+ notification: function () {
436
+ if (!CONFIG.notification.list) return;
437
+ var page_white_list = CONFIG.notification.page_white_list && JSON.parse(CONFIG.notification.page_white_list);
438
+ var page_black_list = CONFIG.notification.page_black_list && JSON.parse(CONFIG.notification.page_black_list);
439
+ var path = window.location.pathname;
440
+ if ((page_white_list && page_white_list.indexOf(path) < 0) || (page_black_list && page_black_list.indexOf(path) >= 0)) return;
441
+ var delay = CONFIG.notification.delay;
442
+ var list = JSON.parse(CONFIG.notification.list);
443
+ var playList = list.filter(function (item) {
444
+ return item.enable && ZHAOO.utils.isDuringDate(item.startTime, item.endTime) && item;
445
+ });
446
+ playList.forEach(function (item) {
447
+ ZHAOO.zui.notification({ title: item.title, content: item.content, delay: delay });
448
+ });
449
+ },
450
+ search: function () {
451
+ var path = CONFIG.search.path;
452
+ if (!path) return;
453
+ $(".search-close").on("click", function () {
454
+ fn.hideSearch();
455
+ $(".navbar").removeClass("hide");
456
+ });
457
+ fn.doSearch(path, 'search-input', 'search-output');
458
+ },
459
+ lottie: function () {
460
+ lottie.loadAnimation({
461
+ container: document.getElementById("loading"),
462
+ renderer: 'svg',
463
+ loop: true,
464
+ autoplay: true,
465
+ path: CONFIG.loading.lottie
466
+ });
467
+ }
468
+ }
469
+
470
+ $(function () {
471
+ action.smoothScroll();
472
+ action.loading();
473
+ action.fab();
474
+ action.navbar();
475
+ action.menu();
476
+ action.scroolToTop();
477
+ action.preview();
478
+ CONFIG.fancybox && action.fancybox();
479
+ CONFIG.pjax && action.pjax();
480
+ CONFIG.lazyload.enable && action.lazyload();
481
+ CONFIG.donate.enable && action.donate();
482
+ (CONFIG.lazyload && CONFIG.fancybox) && action.fixLazyloadFancybox();
483
+ CONFIG.carrier.enable && action.carrier();
484
+ CONFIG.qrcode.enable && action.qrcode();
485
+ CONFIG.toc.enable && action.toc();
486
+ CONFIG.scrollbar.type === 'simple' && action.scrollbar();
487
+ CONFIG.notification.enable && action.notification();
488
+ CONFIG.search.enable && action.search();
489
+ CONFIG.loading.lottie && action.lottie();
490
+ });
491
+
492
+ })(jQuery);
package/js/utils.js ADDED
@@ -0,0 +1,167 @@
1
+ (function ($) {
2
+ "use strict";
3
+
4
+ ZHAOO.utils = {
5
+ debounce: function (func, wait, immediate) {
6
+ var timeout;
7
+ return function () {
8
+ var context = this;
9
+ var args = arguments;
10
+ timeout && clearTimeout(timeout);
11
+ if (immediate) {
12
+ var callNow = !timeout;
13
+ timeout = setTimeout(function () {
14
+ timeout = null;
15
+ }, wait);
16
+ if (callNow) func.apply(context, args);
17
+ } else {
18
+ timeout = setTimeout(function () {
19
+ func.apply(context, args);
20
+ }, wait);
21
+ }
22
+ }
23
+ },
24
+ throttle: function (func, wait, options) {
25
+ var timeout, context, args;
26
+ var previous = 0;
27
+ if (!options) options = {};
28
+ var later = function () {
29
+ previous = options.leading === false ? 0 : new Date().getTime();
30
+ timeout = null;
31
+ func.apply(context, args);
32
+ if (!timeout) context = args = null;
33
+ }
34
+ var throttled = function () {
35
+ var now = new Date().getTime();
36
+ if (!previous && options.leading === false) previous = now;
37
+ var remaining = wait - (now - previous);
38
+ context = this;
39
+ args = arguments;
40
+ if (remaining <= 0 || remaining > wait) {
41
+ if (timeout) {
42
+ clearTimeout(timeout);
43
+ timeout = null;
44
+ }
45
+ previous = now;
46
+ func.apply(context, args);
47
+ if (!timeout) context = args = null;
48
+ } else if (!timeout && options.trailing !== false) {
49
+ timeout = setTimeout(later, remaining);
50
+ }
51
+ }
52
+ return throttled;
53
+ },
54
+ hasMobileUA: function () {
55
+ var nav = window.navigator;
56
+ var ua = nav.userAgent;
57
+ var pa = /iPad|iPhone|Android|Opera Mini|BlackBerry|webOS|UCWEB|Blazer|PSP|IEMobile|Symbian/g;
58
+ return pa.test(ua);
59
+ },
60
+ isTablet: function () {
61
+ return (
62
+ window.screen.width > 767 &&
63
+ window.screen.width < 992 &&
64
+ this.hasMobileUA()
65
+ );
66
+ },
67
+ isMobile: function () {
68
+ return window.screen.width < 767 && this.hasMobileUA();
69
+ },
70
+ isDesktop: function () {
71
+ return !this.isTablet() && !this.isMobile();
72
+ },
73
+ isDuringDate: function (beginDateStr, endDateStr) {
74
+ var curDate = new Date(),
75
+ beginDate = new Date(beginDateStr),
76
+ endDate = new Date(endDateStr);
77
+ if (curDate >= beginDate && curDate <= endDate) {
78
+ return true;
79
+ }
80
+ return false;
81
+ },
82
+ bindKeyup: function (code, fn) {
83
+ $(document).keyup(function (e) {
84
+ var key = e.which || e.keyCode;;
85
+ if (key == code) {
86
+ fn();
87
+ }
88
+ });
89
+ }
90
+ }
91
+
92
+ ZHAOO.zui = {
93
+ message: function ({ text, type, delay }) {
94
+ var message = '<div class="zui-message ' + (type || "info") + '"><p>' + text + '</p></div>';
95
+ $("body").append(message);
96
+ var e = $(".zui-message");
97
+ e.ready(function () {
98
+ e.addClass("in");
99
+ setTimeout(function () {
100
+ e.removeClass("in");
101
+ e.on("transitionend webkitTransitionEnd", function () {
102
+ $(this).remove();
103
+ });
104
+ }, delay || 3000);
105
+ });
106
+ },
107
+ notification: function ({ title, content, type, delay }) {
108
+ var storage = JSON.parse(localStorage.getItem("notification-closed"));
109
+ if (storage && storage.indexOf(title) >= 0) return;
110
+ var notification = '<div class="zui-notification ' + (type || "info") + '"><span>' + title + '</span><p>' + content + '</p><i class="j-notification-close iconfont iconbaseline-close-px"></i></div>';
111
+ $("body").append(notification);
112
+ var e = $(".zui-notification");
113
+ var close = $(".j-notification-close");
114
+ e.ready(function () {
115
+ e.addClass("in");
116
+ setTimeout(function () {
117
+ e.removeClass("in");
118
+ e.on("transitionend webkitTransitionEnd", function () {
119
+ $(this).remove();
120
+ });
121
+ }, delay || 3000);
122
+ close.on("click", function () {
123
+ e.removeClass("in");
124
+ if (storage) {
125
+ (storage.indexOf(title) < 0) && localStorage.setItem("notification-closed", JSON.stringify(storage.concat(title)));
126
+ } else {
127
+ localStorage.setItem("notification-closed", JSON.stringify([title]));
128
+ }
129
+ });
130
+ });
131
+ }
132
+ }
133
+
134
+ })(jQuery);
135
+
136
+ class AsyncLimit {
137
+ constructor(limit) {
138
+ this.limit = Number(limit) || 2;
139
+ this.pool = [];
140
+ this.current = 0;
141
+ }
142
+
143
+ async run(fn) {
144
+ if (!fn || typeof fn !== 'function') {
145
+ throw new Error('Function error.');
146
+ }
147
+ if (this.current >= this.limit) {
148
+ await new Promise(resolve => this.pool.push(resolve));
149
+ }
150
+ return this._handleRun(fn);
151
+ }
152
+
153
+ async _handleRun(fn) {
154
+ this.current++;
155
+ try {
156
+ return await fn();
157
+ } catch (err) {
158
+ return Promise.reject(err);
159
+ } finally {
160
+ this.current--;
161
+ if (this.pool.length) {
162
+ this.pool[0]();
163
+ this.pool.shift();
164
+ }
165
+ }
166
+ }
167
+ }