hexo-theme-shokax 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. package/LICENSE +68 -81
  2. package/README.md +8 -6
  3. package/UsageRestrictions.md +21 -0
  4. package/_config.yml +9 -16
  5. package/layout/_mixin/comment.pug +2 -1
  6. package/layout/_mixin/widgets.pug +2 -1
  7. package/layout/_partials/layout.pug +8 -8
  8. package/layout/post.pug +2 -1
  9. package/package.json +8 -4
  10. package/scripts/generaters/script.js +33 -7
  11. package/scripts/plugin/check.js +30 -0
  12. package/scripts/plugin/index.js +5 -0
  13. package/source/css/_common/components/tags/tabs.styl +0 -2
  14. package/source/js/_app/{components.js → components/sidebar.js} +26 -27
  15. package/source/js/_app/fireworks.js +28 -42
  16. package/source/js/_app/globals/globalVars.js +26 -0
  17. package/source/js/_app/globals/handles.js +105 -0
  18. package/source/js/_app/globals/themeColor.js +48 -0
  19. package/source/js/_app/globals/thirdparty.js +60 -0
  20. package/source/js/_app/globals/tools.js +75 -0
  21. package/source/js/_app/library/anime.js +85 -0
  22. package/source/js/_app/library/dom.js +22 -0
  23. package/source/js/_app/library/loadFile.js +32 -0
  24. package/source/js/_app/library/proto.js +105 -0
  25. package/source/js/_app/library/scriptPjax.js +57 -0
  26. package/source/js/_app/library/storage.js +11 -0
  27. package/source/js/_app/{vue.js → library/vue.js} +6 -6
  28. package/source/js/_app/page/comment.js +19 -0
  29. package/source/js/_app/page/common.js +57 -0
  30. package/source/js/_app/page/fancybox.js +59 -0
  31. package/source/js/_app/page/post.js +232 -0
  32. package/source/js/_app/page/search.js +111 -0
  33. package/source/js/_app/page/tab.js +50 -0
  34. package/source/js/_app/pjax/domInit.js +68 -0
  35. package/source/js/_app/pjax/refresh.js +42 -0
  36. package/source/js/_app/pjax/siteInit.js +34 -0
  37. package/source/js/_app/player.js +87 -91
  38. package/source/js/_app/global.js +0 -314
  39. package/source/js/_app/library.js +0 -312
  40. package/source/js/_app/page.js +0 -674
@@ -1,20 +1,20 @@
1
1
  let NOWPLAYING = null;
2
2
  const isMobile = /mobile/i.test(window.navigator.userAgent);
3
- const mediaPlayer = function (t, config) {
3
+ const mediaPlayer = (t, config) => {
4
4
  const buttons = {
5
5
  el: {},
6
- create: function () {
6
+ create() {
7
7
  if (!t.player.options.btns) {
8
8
  return;
9
9
  }
10
- t.player.options.btns.forEach(function (item) {
10
+ t.player.options.btns.forEach((item) => {
11
11
  if (buttons.el[item]) {
12
12
  return;
13
13
  }
14
14
  buttons.el[item] = t.createChild('div', {
15
15
  className: item + ' btn',
16
- onclick: function (event) {
17
- t.player.fetch().then(function () {
16
+ onclick(event) {
17
+ t.player.fetch().then(() => {
18
18
  t.player.options.events[item](event);
19
19
  });
20
20
  }
@@ -34,12 +34,12 @@ const mediaPlayer = function (t, config) {
34
34
  return;
35
35
  }
36
36
  const that = controller;
37
- t.player.options.controls.forEach(function (item) {
37
+ t.player.options.controls.forEach((item) => {
38
38
  if (that.btns[item]) {
39
39
  return;
40
40
  }
41
41
  const opt = {
42
- onclick: function (event) {
42
+ onclick(event) {
43
43
  that.events[item] ? that.events[item](event) : t.player.options.events[item](event);
44
44
  }
45
45
  };
@@ -63,7 +63,7 @@ const mediaPlayer = function (t, config) {
63
63
  that.btns.volume.bar = that.btns.volume.child('.bar');
64
64
  },
65
65
  events: {
66
- mode: function (e) {
66
+ mode(e) {
67
67
  switch (t.player.options.mode) {
68
68
  case 'loop':
69
69
  t.player.options.mode = 'random';
@@ -77,16 +77,16 @@ const mediaPlayer = function (t, config) {
77
77
  controller.btns.mode.className = 'mode ' + t.player.options.mode + ' btn';
78
78
  $storage.set('_PlayerMode', t.player.options.mode);
79
79
  },
80
- volume: function (e) {
80
+ volume(e) {
81
81
  e.preventDefault();
82
82
  const current = e.currentTarget;
83
83
  let drag = false;
84
- const thumbMove = function (e) {
84
+ const thumbMove = (e) => {
85
85
  e.preventDefault();
86
86
  t.player.volume(controller.percent(e, current));
87
87
  drag = true;
88
88
  };
89
- const thumbUp = function (e) {
89
+ const thumbUp = (e) => {
90
90
  e.preventDefault();
91
91
  current.removeEventListener(utils.nameMap.dragEnd, thumbUp);
92
92
  current.removeEventListener(utils.nameMap.dragMove, thumbMove);
@@ -108,20 +108,20 @@ const mediaPlayer = function (t, config) {
108
108
  current.addEventListener(utils.nameMap.dragMove, thumbMove);
109
109
  current.addEventListener(utils.nameMap.dragEnd, thumbUp);
110
110
  },
111
- backward: function (e) {
111
+ backward(e) {
112
112
  controller.step = 'prev';
113
113
  t.player.mode();
114
114
  },
115
- forward: function (e) {
115
+ forward(e) {
116
116
  controller.step = 'next';
117
117
  t.player.mode();
118
118
  }
119
119
  },
120
- update: function (percent) {
120
+ update(percent) {
121
121
  controller.btns.volume.className = 'volume ' + (!source.muted && percent > 0 ? 'on' : 'off') + ' btn';
122
122
  controller.btns.volume.bar.changeOrGetWidth(Math.floor(percent * 100) + '%');
123
123
  },
124
- percent: function (e, el) {
124
+ percent(e, el) {
125
125
  let percentage = ((e.clientX || e.changedTouches[0].clientX) - el.left()) / el.changeOrGetWidth();
126
126
  percentage = Math.max(percentage, 0);
127
127
  return Math.min(percentage, 1);
@@ -130,7 +130,7 @@ const mediaPlayer = function (t, config) {
130
130
  const progress = {
131
131
  el: null,
132
132
  bar: null,
133
- create: function () {
133
+ create() {
134
134
  const current = playlist.current().el;
135
135
  if (current) {
136
136
  if (progress.el) {
@@ -150,11 +150,11 @@ const mediaPlayer = function (t, config) {
150
150
  playlist.scroll();
151
151
  }
152
152
  },
153
- update: function (percent) {
153
+ update(percent) {
154
154
  progress.bar.changeOrGetWidth(Math.floor(percent * 100) + '%');
155
155
  progress.el.attr('data-ptime', utils.secondToTime(percent * source.duration));
156
156
  },
157
- seeking: function (type) {
157
+ seeking(type) {
158
158
  if (type) {
159
159
  progress.el.addClass('seeking');
160
160
  }
@@ -162,21 +162,21 @@ const mediaPlayer = function (t, config) {
162
162
  progress.el.removeClass('seeking');
163
163
  }
164
164
  },
165
- percent: function (e, el) {
165
+ percent(e, el) {
166
166
  let percentage = ((e.clientX || e.changedTouches[0].clientX) - el.left()) / el.changeOrGetWidth();
167
167
  percentage = Math.max(percentage, 0);
168
168
  return Math.min(percentage, 1);
169
169
  },
170
- drag: function (e) {
170
+ drag(e) {
171
171
  e.preventDefault();
172
172
  const current = playlist.current().el;
173
- const thumbMove = function (e) {
173
+ const thumbMove = (e) => {
174
174
  e.preventDefault();
175
175
  const percentage = progress.percent(e, current);
176
176
  progress.update(percentage);
177
177
  lyrics.update(percentage * source.duration);
178
178
  };
179
- const thumbUp = function (e) {
179
+ const thumbUp = (e) => {
180
180
  e.preventDefault();
181
181
  current.removeEventListener(utils.nameMap.dragEnd, thumbUp);
182
182
  current.removeEventListener(utils.nameMap.dragMove, thumbMove);
@@ -194,7 +194,7 @@ const mediaPlayer = function (t, config) {
194
194
  };
195
195
  const preview = {
196
196
  el: null,
197
- create: function () {
197
+ create() {
198
198
  const current = playlist.current();
199
199
  preview.el.innerHTML = '<div class="cover"><div class="disc"><img src="' + (current.cover) + '" class="blur" alt="music cover"/></div></div>' +
200
200
  '<div class="info"><h4 class="title">' + current.name + '</h4><span>' + current.artist + '</span>' +
@@ -210,7 +210,7 @@ const mediaPlayer = function (t, config) {
210
210
  index: -1,
211
211
  errnum: 0,
212
212
  add: (group, list) => {
213
- list.forEach(function (item, i) {
213
+ list.forEach((item) => {
214
214
  item.group = group;
215
215
  item.name = item.name || item.title || 'Meida name';
216
216
  item.artist = item.artist || item.author || 'Anonymous';
@@ -219,7 +219,7 @@ const mediaPlayer = function (t, config) {
219
219
  playlist.data.push(item);
220
220
  });
221
221
  },
222
- clear: function () {
222
+ clear() {
223
223
  playlist.data = [];
224
224
  playlist.el.innerHTML = '';
225
225
  if (playlist.index !== -1) {
@@ -227,9 +227,9 @@ const mediaPlayer = function (t, config) {
227
227
  t.player.fetch();
228
228
  }
229
229
  },
230
- create: function () {
230
+ create() {
231
231
  const el = playlist.el;
232
- playlist.data.map(function (item, index) {
232
+ playlist.data.map((item, index) => {
233
233
  if (item.el) {
234
234
  return null;
235
235
  }
@@ -249,7 +249,7 @@ const mediaPlayer = function (t, config) {
249
249
  item.el = tab.child('ol').createChild('li', {
250
250
  title: item.name + ' - ' + item.artist,
251
251
  innerHTML: '<span class="info"><span>' + item.name + '</span><span>' + item.artist + '</span></span>',
252
- onclick: function (event) {
252
+ onclick(event) {
253
253
  const current = event.currentTarget;
254
254
  if (playlist.index === index && progress.el) {
255
255
  if (source.paused) {
@@ -268,10 +268,10 @@ const mediaPlayer = function (t, config) {
268
268
  });
269
269
  tabFormat();
270
270
  },
271
- current: function () {
271
+ current() {
272
272
  return this.data[this.index];
273
273
  },
274
- scroll: function () {
274
+ scroll() {
275
275
  const item = this.current();
276
276
  let li = this.el.child('li.active');
277
277
  li && li.removeClass('active');
@@ -284,14 +284,14 @@ const mediaPlayer = function (t, config) {
284
284
  pageScroll(item.el, item.el.offsetTop);
285
285
  return this;
286
286
  },
287
- title: function () {
287
+ title() {
288
288
  if (source.paused) {
289
289
  return;
290
290
  }
291
291
  const current = this.current();
292
292
  document.title = 'Now Playing...' + current.name + ' - ' + current.artist + ' | ' + originTitle;
293
293
  },
294
- error: function () {
294
+ error() {
295
295
  const current = this.current();
296
296
  current.el.removeClass('current').addClass('error');
297
297
  current.error = true;
@@ -300,7 +300,7 @@ const mediaPlayer = function (t, config) {
300
300
  };
301
301
  const info = {
302
302
  el: null,
303
- create: function () {
303
+ create() {
304
304
  if (this.el) {
305
305
  return;
306
306
  }
@@ -312,10 +312,10 @@ const mediaPlayer = function (t, config) {
312
312
  playlist.el = this.el.child('.playlist');
313
313
  controller.el = this.el.child('.controller');
314
314
  },
315
- hide: function () {
315
+ hide() {
316
316
  const el = this.el;
317
317
  el.addClass('hide');
318
- window.setTimeout(function () {
318
+ window.setTimeout(() => {
319
319
  el.removeClass('show hide');
320
320
  }, 300);
321
321
  }
@@ -326,7 +326,7 @@ const mediaPlayer = function (t, config) {
326
326
  btns: ['play-pause', 'music'],
327
327
  controls: ['mode', 'backward', 'play-pause', 'forward', 'volume'],
328
328
  events: {
329
- 'play-pause': function (event) {
329
+ 'play-pause'(event) {
330
330
  if (source.paused) {
331
331
  t.player.play();
332
332
  }
@@ -334,7 +334,7 @@ const mediaPlayer = function (t, config) {
334
334
  t.player.pause();
335
335
  }
336
336
  },
337
- music: function (event) {
337
+ music(event) {
338
338
  if (info.el.hasClass('show')) {
339
339
  info.hide();
340
340
  }
@@ -346,10 +346,10 @@ const mediaPlayer = function (t, config) {
346
346
  }
347
347
  };
348
348
  const utils = {
349
- random: function (len) {
349
+ random(len) {
350
350
  return Math.floor((Math.random() * len));
351
351
  },
352
- parse: function (link) {
352
+ parse(link) {
353
353
  let result = [];
354
354
  [
355
355
  ['music.163.com.*song.*id=(\\d+)', 'netease', 'song'],
@@ -366,7 +366,7 @@ const mediaPlayer = function (t, config) {
366
366
  ['xiami.com.*album/(\\w+)', 'xiami', 'album'],
367
367
  ['xiami.com.*artist/(\\w+)', 'xiami', 'artist'],
368
368
  ['xiami.com.*collect/(\\w+)', 'xiami', 'playlist']
369
- ].forEach(function (rule) {
369
+ ].forEach((rule) => {
370
370
  const patt = new RegExp(rule[0]);
371
371
  const res = patt.exec(link);
372
372
  if (res !== null) {
@@ -375,10 +375,10 @@ const mediaPlayer = function (t, config) {
375
375
  });
376
376
  return result;
377
377
  },
378
- fetch: function (source) {
378
+ fetch(source) {
379
379
  const list = [];
380
- return new Promise(function (resolve, reject) {
381
- source.forEach(function (raw) {
380
+ return new Promise((resolve, reject) => {
381
+ source.forEach((raw) => {
382
382
  const meta = utils.parse(raw);
383
383
  if (meta[0]) {
384
384
  const skey = JSON.stringify(meta);
@@ -389,9 +389,9 @@ const mediaPlayer = function (t, config) {
389
389
  }
390
390
  else {
391
391
  fetch(`${CONFIG.playerAPI}/meting/?server=` + meta[0] + '&type=' + meta[1] + '&id=' + meta[2] + '&r=' + Math.random())
392
- .then(function (response) {
392
+ .then((response) => {
393
393
  return response.json();
394
- }).then(function (json) {
394
+ }).then((json) => {
395
395
  $storage.set(skey, JSON.stringify(json));
396
396
  list.push(...json);
397
397
  resolve(list);
@@ -406,8 +406,8 @@ const mediaPlayer = function (t, config) {
406
406
  });
407
407
  });
408
408
  },
409
- secondToTime: function (second) {
410
- const add0 = function (num) {
409
+ secondToTime(second) {
410
+ const add0 = (num) => {
411
411
  return isNaN(num) ? '00' : (num < 10 ? '0' + num : '' + num);
412
412
  };
413
413
  const hour = Math.floor(second / 3600);
@@ -425,7 +425,7 @@ const mediaPlayer = function (t, config) {
425
425
  t.player = {
426
426
  _id: utils.random(999999),
427
427
  group: true,
428
- load: function (newList) {
428
+ load(newList) {
429
429
  let d = '';
430
430
  if (newList && newList.length > 0) {
431
431
  if (this.options.rawList !== newList) {
@@ -443,7 +443,7 @@ const mediaPlayer = function (t, config) {
443
443
  }
444
444
  return this;
445
445
  },
446
- fetch: function () {
446
+ fetch() {
447
447
  return new Promise((resolve, reject) => {
448
448
  if (playlist.data.length > 0) {
449
449
  resolve(true);
@@ -451,8 +451,8 @@ const mediaPlayer = function (t, config) {
451
451
  else {
452
452
  if (this.options.rawList) {
453
453
  const promises = [];
454
- this.options.rawList.forEach(function (raw, index) {
455
- promises.push(new Promise(function (resolve, reject) {
454
+ this.options.rawList.forEach((raw, index) => {
455
+ promises.push(new Promise((resolve, reject) => {
456
456
  let group = index;
457
457
  let source;
458
458
  if (!raw.list) {
@@ -464,13 +464,13 @@ const mediaPlayer = function (t, config) {
464
464
  this.group = true;
465
465
  source = raw.list;
466
466
  }
467
- utils.fetch(source).then(function (list) {
467
+ utils.fetch(source).then((list) => {
468
468
  playlist.add(group, list);
469
469
  resolve(0);
470
470
  });
471
471
  }));
472
472
  });
473
- Promise.all(promises).then(function () {
473
+ Promise.all(promises).then(() => {
474
474
  resolve(true);
475
475
  });
476
476
  }
@@ -483,13 +483,13 @@ const mediaPlayer = function (t, config) {
483
483
  }
484
484
  });
485
485
  },
486
- mode: function () {
486
+ mode() {
487
487
  const total = playlist.data.length;
488
488
  if (!total || playlist.errnum === total) {
489
489
  return;
490
490
  }
491
491
  const step = controller.step === 'next' ? 1 : -1;
492
- const next = function () {
492
+ const next = () => {
493
493
  let index = playlist.index + step;
494
494
  if (index > total || index < 0) {
495
495
  index = controller.step === 'next' ? 0 : total - 1;
@@ -523,7 +523,7 @@ const mediaPlayer = function (t, config) {
523
523
  }
524
524
  this.init();
525
525
  },
526
- switch: function (index) {
526
+ switch(index) {
527
527
  if (typeof index === 'number' &&
528
528
  index !== playlist.index &&
529
529
  playlist.current() &&
@@ -532,7 +532,7 @@ const mediaPlayer = function (t, config) {
532
532
  this.init();
533
533
  }
534
534
  },
535
- init: function () {
535
+ init() {
536
536
  const item = playlist.current();
537
537
  if (!item || item.error) {
538
538
  this.mode();
@@ -555,33 +555,33 @@ const mediaPlayer = function (t, config) {
555
555
  this.play();
556
556
  }
557
557
  },
558
- play: function () {
558
+ play() {
559
559
  NOWPLAYING && NOWPLAYING.player.pause();
560
560
  if (playlist.current().error) {
561
561
  this.mode();
562
562
  return;
563
563
  }
564
- source.play().then(function () {
564
+ source.play().then(() => {
565
565
  playlist.scroll();
566
- }).catch(function (e) {
566
+ }).catch((e) => {
567
567
  });
568
568
  },
569
- pause: function () {
569
+ pause() {
570
570
  source.pause();
571
571
  document.title = originTitle;
572
572
  },
573
- stop: function () {
573
+ stop() {
574
574
  source.pause();
575
575
  source.currentTime = 0;
576
576
  document.title = originTitle;
577
577
  },
578
- seek: function (time) {
578
+ seek(time) {
579
579
  time = Math.max(time, 0);
580
580
  time = Math.min(time, source.duration);
581
581
  source.currentTime = time;
582
582
  progress.update(time / source.duration);
583
583
  },
584
- muted: function (status) {
584
+ muted(status) {
585
585
  if (status === 'muted') {
586
586
  source.muted = status;
587
587
  $storage.set('_PlayerMuted', status);
@@ -593,14 +593,14 @@ const mediaPlayer = function (t, config) {
593
593
  controller.update(source.volume);
594
594
  }
595
595
  },
596
- volume: function (percentage) {
596
+ volume(percentage) {
597
597
  if (!isNaN(percentage)) {
598
598
  controller.update(percentage);
599
599
  $storage.set('_PlayerVolume', percentage);
600
600
  source.volume = percentage;
601
601
  }
602
602
  },
603
- mini: function () {
603
+ mini() {
604
604
  info.hide();
605
605
  }
606
606
  };
@@ -608,16 +608,16 @@ const mediaPlayer = function (t, config) {
608
608
  el: null,
609
609
  data: null,
610
610
  index: 0,
611
- create: function (box) {
611
+ create(box) {
612
612
  const current = playlist.index;
613
613
  const raw = playlist.current().lrc;
614
- const callback = function (body) {
614
+ const callback = (body) => {
615
615
  if (current !== playlist.index) {
616
616
  return;
617
617
  }
618
618
  this.data = this.parse(body);
619
619
  let lrc = '';
620
- this.data.forEach(function (line, index) {
620
+ this.data.forEach((line, index) => {
621
621
  lrc += '<p' + (index === 0 ? ' class="current"' : '') + '>' + line[1] + '</p>';
622
622
  });
623
623
  this.el = box.createChild('div', {
@@ -633,7 +633,7 @@ const mediaPlayer = function (t, config) {
633
633
  callback(raw);
634
634
  }
635
635
  },
636
- update: function (currentTime) {
636
+ update(currentTime) {
637
637
  if (!this.data) {
638
638
  return;
639
639
  }
@@ -649,9 +649,9 @@ const mediaPlayer = function (t, config) {
649
649
  }
650
650
  }
651
651
  },
652
- parse: function (lrc_s) {
652
+ parse(lrc_s) {
653
653
  if (lrc_s) {
654
- lrc_s = lrc_s.replace(/([^\]^\n])\[/g, function (match, p1) {
654
+ lrc_s = lrc_s.replace(/([^\]^\n])\[/g, (match, p1) => {
655
655
  return p1 + '\n[';
656
656
  });
657
657
  const lyric = lrc_s.split('\n');
@@ -662,7 +662,7 @@ const mediaPlayer = function (t, config) {
662
662
  const lrcText = lyric[i]
663
663
  .replace(/.*\[(\d{2}):(\d{2})(\.(\d{2,3}))?]/g, '')
664
664
  .replace(/<(\d{2}):(\d{2})(\.(\d{2,3}))?>/g, '')
665
- .replace(/^\s+|\s+$/g, '');
665
+ .trim();
666
666
  if (lrcTimes) {
667
667
  const timeLen = lrcTimes.length;
668
668
  for (let j = 0; j < timeLen; j++) {
@@ -675,63 +675,59 @@ const mediaPlayer = function (t, config) {
675
675
  }
676
676
  }
677
677
  }
678
- lrc = lrc.filter(function (item) {
679
- return item[1];
680
- });
681
- lrc.sort(function (a, b) {
682
- return a[0] - b[0];
683
- });
678
+ lrc = lrc.filter((item) => item[1]);
679
+ lrc.sort((a, b) => a[0] - b[0]);
684
680
  return lrc;
685
681
  }
686
682
  else {
687
683
  return [];
688
684
  }
689
685
  },
690
- fetch: function (url, callback) {
686
+ fetch(url, callback) {
691
687
  fetch(url)
692
- .then(function (response) {
688
+ .then((response) => {
693
689
  return response.text();
694
- }).then(function (body) {
690
+ }).then((body) => {
695
691
  callback(body);
696
- }).catch(function (ex) {
692
+ }).catch((ex) => {
697
693
  });
698
694
  }
699
695
  };
700
696
  const events = {
701
- onerror: function () {
697
+ onerror() {
702
698
  playlist.error();
703
699
  t.player.mode();
704
700
  },
705
- ondurationchange: function () {
701
+ ondurationchange() {
706
702
  if (source.duration !== 1) {
707
703
  progress.el.attr('data-dtime', utils.secondToTime(source.duration));
708
704
  }
709
705
  },
710
- onloadedmetadata: function () {
706
+ onloadedmetadata() {
711
707
  t.player.seek(0);
712
708
  progress.el.attr('data-dtime', utils.secondToTime(source.duration));
713
709
  },
714
- onplay: function () {
710
+ onplay() {
715
711
  t.parentNode.addClass('playing');
716
712
  showtip(this.attr('title'));
717
713
  NOWPLAYING = t;
718
714
  },
719
- onpause: function () {
715
+ onpause() {
720
716
  t.parentNode.removeClass('playing');
721
717
  NOWPLAYING = null;
722
718
  },
723
- ontimeupdate: function () {
719
+ ontimeupdate() {
724
720
  if (!this.disableTimeupdate) {
725
721
  progress.update(this.currentTime / this.duration);
726
722
  lyrics.update(this.currentTime);
727
723
  }
728
724
  },
729
- onended: function (argument) {
725
+ onended(argument) {
730
726
  t.player.mode();
731
727
  t.player.play();
732
728
  }
733
729
  };
734
- const init = function (config) {
730
+ const init = (config) => {
735
731
  if (t.player.created) {
736
732
  return;
737
733
  }