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
@@ -0,0 +1,111 @@
1
+ const algoliaSearch = (pjax) => {
2
+ if (CONFIG.search === null) {
3
+ return;
4
+ }
5
+ if (!siteSearch) {
6
+ siteSearch = BODY.createChild('div', {
7
+ id: 'search',
8
+ innerHTML: '<div class="inner"><div class="header"><span class="icon"><i class="ic i-search"></i></span><div class="search-input-container"></div><span class="close-btn"><i class="ic i-times-circle"></i></span></div><div class="results"><div class="inner"><div id="search-stats"></div><div id="search-hits"></div><div id="search-pagination"></div></div></div></div>'
9
+ });
10
+ }
11
+ const search = instantsearch({
12
+ indexName: CONFIG.search.indexName,
13
+ searchClient: algoliasearch(CONFIG.search.appID, CONFIG.search.apiKey),
14
+ searchFunction(helper) {
15
+ const searchInput = $dom('.search-input');
16
+ if (searchInput.value) {
17
+ helper.search();
18
+ }
19
+ }
20
+ });
21
+ search.on('render', () => {
22
+ pjax.refresh($dom('#search-hits'));
23
+ });
24
+ search.addWidgets([
25
+ instantsearch.widgets.configure({
26
+ hitsPerPage: CONFIG.search.hits.per_page || 10
27
+ }),
28
+ instantsearch.widgets.searchBox({
29
+ container: '.search-input-container',
30
+ placeholder: LOCAL.search.placeholder,
31
+ showReset: false,
32
+ showSubmit: false,
33
+ showLoadingIndicator: false,
34
+ cssClasses: {
35
+ input: 'search-input'
36
+ }
37
+ }),
38
+ instantsearch.widgets.stats({
39
+ container: '#search-stats',
40
+ templates: {
41
+ text(data) {
42
+ const stats = LOCAL.search.stats
43
+ .replace(/\$\{hits}/, data.nbHits)
44
+ .replace(/\$\{time}/, data.processingTimeMS);
45
+ return stats + '<span class="algolia-powered"></span><hr>';
46
+ }
47
+ }
48
+ }),
49
+ instantsearch.widgets.hits({
50
+ container: '#search-hits',
51
+ templates: {
52
+ item(data) {
53
+ const cats = data.categories ? '<span>' + data.categories.join('<i class="ic i-angle-right"></i>') + '</span>' : '';
54
+ return '<a href="' + CONFIG.root + data.path + '">' + cats + data._highlightResult.title.value + '</a>';
55
+ },
56
+ empty(data) {
57
+ return '<div id="hits-empty">' +
58
+ LOCAL.search.empty.replace(/\$\{query}/, data.query) +
59
+ '</div>';
60
+ }
61
+ },
62
+ cssClasses: {
63
+ item: 'item'
64
+ }
65
+ }),
66
+ instantsearch.widgets.pagination({
67
+ container: '#search-pagination',
68
+ scrollTo: false,
69
+ showFirst: false,
70
+ showLast: false,
71
+ templates: {
72
+ first: '<i class="ic i-angle-double-left"></i>',
73
+ last: '<i class="ic i-angle-double-right"></i>',
74
+ previous: '<i class="ic i-angle-left"></i>',
75
+ next: '<i class="ic i-angle-right"></i>'
76
+ },
77
+ cssClasses: {
78
+ root: 'pagination',
79
+ item: 'pagination-item',
80
+ link: 'page-number',
81
+ selectedItem: 'current',
82
+ disabledItem: 'disabled-item'
83
+ }
84
+ })
85
+ ]);
86
+ search.start();
87
+ $dom.each('.search', (element) => {
88
+ element.addEventListener('click', () => {
89
+ document.body.style.overflow = 'hidden';
90
+ transition(siteSearch, 'shrinkIn', () => {
91
+ $dom('.search-input').focus();
92
+ });
93
+ });
94
+ });
95
+ const onPopupClose = () => {
96
+ document.body.style.overflow = '';
97
+ transition(siteSearch, 0);
98
+ };
99
+ siteSearch.addEventListener('click', (event) => {
100
+ if (event.target === siteSearch) {
101
+ onPopupClose();
102
+ }
103
+ });
104
+ $dom('.close-btn').addEventListener('click', onPopupClose);
105
+ window.addEventListener('pjax:success', onPopupClose);
106
+ window.addEventListener('keyup', (event) => {
107
+ if (event.key === 'Escape') {
108
+ onPopupClose();
109
+ }
110
+ });
111
+ };
@@ -0,0 +1,50 @@
1
+ const tabFormat = () => {
2
+ let first_tab;
3
+ $dom.each('div.tab', (element) => {
4
+ if (element.attr('data-ready')) {
5
+ return;
6
+ }
7
+ const id = element.attr('data-id');
8
+ const title = element.attr('data-title');
9
+ let box = $dom('#' + id);
10
+ if (!box) {
11
+ box = document.createElement('div');
12
+ box.className = 'tabs';
13
+ box.id = id;
14
+ box.innerHTML = '<div class="show-btn"></div>';
15
+ const showBtn = box.child('.show-btn');
16
+ showBtn.addEventListener('click', () => {
17
+ pageScroll(box);
18
+ });
19
+ element.parentNode.insertBefore(box, element);
20
+ first_tab = true;
21
+ }
22
+ else {
23
+ first_tab = false;
24
+ }
25
+ let ul = box.child('.nav ul');
26
+ if (!ul) {
27
+ ul = box.createChild('div', {
28
+ className: 'nav',
29
+ innerHTML: '<ul></ul>'
30
+ }).child('ul');
31
+ }
32
+ const li = ul.createChild('li', {
33
+ innerHTML: title
34
+ });
35
+ if (first_tab) {
36
+ li.addClass('active');
37
+ element.addClass('active');
38
+ }
39
+ li.addEventListener('click', (event) => {
40
+ const target = event.currentTarget;
41
+ box.find('.active').forEach((el) => {
42
+ el.removeClass('active');
43
+ });
44
+ element.addClass('active');
45
+ target.addClass('active');
46
+ });
47
+ box.appendChild(element);
48
+ element.attr('data-ready', String(true));
49
+ });
50
+ };
@@ -0,0 +1,68 @@
1
+ const domInit = () => {
2
+ $dom.each('.overview .menu > .item', (el) => {
3
+ siteNav.child('.menu').appendChild(el.cloneNode(true));
4
+ });
5
+ loadCat.addEventListener('click', Loader.vanish);
6
+ menuToggle.addEventListener('click', sideBarToggleHandle);
7
+ $dom('.dimmer').addEventListener('click', sideBarToggleHandle);
8
+ quickBtn.child('.down').addEventListener('click', goToBottomHandle);
9
+ quickBtn.child('.up').addEventListener('click', backToTopHandle);
10
+ if (!toolBtn) {
11
+ toolBtn = siteHeader.createChild('div', {
12
+ id: 'tool',
13
+ innerHTML: '<div class="item player"></div><div class="item contents"><i class="ic i-list-ol"></i></div><div class="item chat"><i class="ic i-comments"></i></div><div class="item back-to-top"><i class="ic i-arrow-up"></i><span>0%</span></div>'
14
+ });
15
+ }
16
+ toolPlayer = toolBtn.child('.player');
17
+ backToTop = toolBtn.child('.back-to-top');
18
+ goToComment = toolBtn.child('.chat');
19
+ showContents = toolBtn.child('.contents');
20
+ backToTop.addEventListener('click', backToTopHandle);
21
+ goToComment.addEventListener('click', goToCommentHandle);
22
+ showContents.addEventListener('click', sideBarToggleHandle);
23
+ if (typeof mediaPlayer !== 'undefined') {
24
+ mediaPlayer(toolPlayer);
25
+ $dom('main').addEventListener('click', () => {
26
+ toolPlayer.player.mini();
27
+ });
28
+ }
29
+ const createIntersectionObserver = () => {
30
+ new IntersectionObserver(([entry]) => {
31
+ if (entry.isIntersecting) {
32
+ document.querySelectorAll('.parallax>use').forEach(i => {
33
+ i.classList.remove('stop-animation');
34
+ });
35
+ document.querySelectorAll('#imgs .item').forEach(i => {
36
+ i.classList.remove('stop-animation');
37
+ });
38
+ }
39
+ else {
40
+ document.querySelectorAll('.parallax>use').forEach(i => {
41
+ i.classList.add('stop-animation');
42
+ });
43
+ document.querySelectorAll('#imgs .item').forEach(i => {
44
+ i.classList.add('stop-animation');
45
+ });
46
+ }
47
+ }, {
48
+ root: null,
49
+ threshold: 0.2
50
+ }).observe(document.getElementById('waves'));
51
+ new IntersectionObserver(([entry]) => {
52
+ if (entry.isIntersecting) {
53
+ document.querySelectorAll('.with-love>i').forEach(i => {
54
+ i.classList.remove('stop-animation');
55
+ });
56
+ }
57
+ else {
58
+ document.querySelectorAll('.with-love>i').forEach(i => {
59
+ i.classList.add('stop-animation');
60
+ });
61
+ }
62
+ }, {
63
+ root: null,
64
+ threshold: 0.2
65
+ }).observe(document.querySelector('.with-love'));
66
+ };
67
+ createIntersectionObserver();
68
+ };
@@ -0,0 +1,42 @@
1
+ const pjaxReload = () => {
2
+ pagePosition();
3
+ if (sideBar.hasClass('on')) {
4
+ transition(sideBar, 0, () => {
5
+ sideBar.removeClass('on');
6
+ menuToggle.removeClass('close');
7
+ });
8
+ }
9
+ const mainNode = $dom('#main');
10
+ mainNode.innerHTML = '';
11
+ mainNode.appendChild(loadCat.lastChild.cloneNode(true));
12
+ pageScroll(0);
13
+ };
14
+ const siteRefresh = (reload) => {
15
+ LOCAL_HASH = 0;
16
+ LOCAL_URL = window.location.href;
17
+ vendorCss('katex');
18
+ vendorJs('copy_tex');
19
+ vendorCss('mermaid');
20
+ vendorJs('chart');
21
+ if (reload !== 1) {
22
+ $dom.each('script[data-pjax]', pjaxScript);
23
+ }
24
+ originTitle = document.title;
25
+ resizeHandle();
26
+ menuActive();
27
+ sideBarTab();
28
+ sidebarTOC();
29
+ registerExtURL();
30
+ postBeauty();
31
+ tabFormat();
32
+ if (typeof mediaPlayer !== 'undefined') {
33
+ toolPlayer.player.load(LOCAL.audio || CONFIG.audio || {});
34
+ }
35
+ Loader.hide();
36
+ setTimeout(() => {
37
+ positionInit();
38
+ }, 500);
39
+ cardActive();
40
+ lazyload.observe();
41
+ isOutime();
42
+ };
@@ -0,0 +1,34 @@
1
+ const siteInit = () => {
2
+ domInit();
3
+ pjax = new Pjax({
4
+ selectors: [
5
+ 'head title',
6
+ '.languages',
7
+ '.twikoo',
8
+ '.pjax',
9
+ '.leancloud-recent-comment',
10
+ 'script[data-config]'
11
+ ],
12
+ cacheBust: false
13
+ });
14
+ CONFIG.quicklink.ignores = LOCAL.ignores;
15
+ quicklink.listen(CONFIG.quicklink);
16
+ autoDarkmode();
17
+ if (!CONFIG.disableVL) {
18
+ visibilityListener();
19
+ }
20
+ themeColorListener();
21
+ algoliaSearch(pjax);
22
+ window.addEventListener('scroll', scrollHandle);
23
+ window.addEventListener('resize', resizeHandle);
24
+ window.addEventListener('pjax:send', pjaxReload);
25
+ window.addEventListener('pjax:success', siteRefresh);
26
+ window.addEventListener('beforeunload', () => {
27
+ pagePosition();
28
+ });
29
+ siteRefresh(1);
30
+ };
31
+ window.addEventListener('DOMContentLoaded', siteInit, {
32
+ passive: true
33
+ });
34
+ console.log('%c Theme.ShokaX v' + CONFIG.version + ' %c https://github.com/theme-shoka-x/hexo-theme-shokaX ', 'color: white; background: #e9546b; padding:5px 0;', 'padding:4px;border:1px solid #e9546b;');