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.
- package/LICENSE +68 -81
- package/README.md +8 -6
- package/UsageRestrictions.md +21 -0
- package/_config.yml +9 -16
- package/layout/_mixin/comment.pug +2 -1
- package/layout/_mixin/widgets.pug +2 -1
- package/layout/_partials/layout.pug +8 -8
- package/layout/post.pug +2 -1
- package/package.json +8 -4
- package/scripts/generaters/script.js +33 -7
- package/scripts/plugin/check.js +30 -0
- package/scripts/plugin/index.js +5 -0
- package/source/css/_common/components/tags/tabs.styl +0 -2
- package/source/js/_app/{components.js → components/sidebar.js} +26 -27
- package/source/js/_app/fireworks.js +28 -42
- package/source/js/_app/globals/globalVars.js +26 -0
- package/source/js/_app/globals/handles.js +105 -0
- package/source/js/_app/globals/themeColor.js +48 -0
- package/source/js/_app/globals/thirdparty.js +60 -0
- package/source/js/_app/globals/tools.js +75 -0
- package/source/js/_app/library/anime.js +85 -0
- package/source/js/_app/library/dom.js +22 -0
- package/source/js/_app/library/loadFile.js +32 -0
- package/source/js/_app/library/proto.js +105 -0
- package/source/js/_app/library/scriptPjax.js +57 -0
- package/source/js/_app/library/storage.js +11 -0
- package/source/js/_app/{vue.js → library/vue.js} +6 -6
- package/source/js/_app/page/comment.js +19 -0
- package/source/js/_app/page/common.js +57 -0
- package/source/js/_app/page/fancybox.js +59 -0
- package/source/js/_app/page/post.js +232 -0
- package/source/js/_app/page/search.js +111 -0
- package/source/js/_app/page/tab.js +50 -0
- package/source/js/_app/pjax/domInit.js +68 -0
- package/source/js/_app/pjax/refresh.js +42 -0
- package/source/js/_app/pjax/siteInit.js +34 -0
- package/source/js/_app/player.js +87 -91
- package/source/js/_app/global.js +0 -314
- package/source/js/_app/library.js +0 -312
- package/source/js/_app/page.js +0 -674
@@ -0,0 +1,22 @@
|
|
1
|
+
const getDocHeight = () => $dom('main > .inner').offsetHeight;
|
2
|
+
const $dom = (selector, element = document) => {
|
3
|
+
if (selector[0] === '#') {
|
4
|
+
return element.getElementById(selector.substring(1));
|
5
|
+
}
|
6
|
+
return element.querySelector(selector);
|
7
|
+
};
|
8
|
+
$dom.all = (selector, element = document) => {
|
9
|
+
return element.querySelectorAll(selector);
|
10
|
+
};
|
11
|
+
$dom.each = (selector, callback, element) => {
|
12
|
+
$dom.all(selector, element).forEach(callback);
|
13
|
+
};
|
14
|
+
$dom.asyncify = async (selector, element = document) => {
|
15
|
+
if (selector[0] === '#') {
|
16
|
+
return element.getElementById(selector.substring(1));
|
17
|
+
}
|
18
|
+
return element.querySelector(selector);
|
19
|
+
};
|
20
|
+
$dom.asyncifyEach = (selector, callback, element) => {
|
21
|
+
$dom.all(selector, element).forEach(callback);
|
22
|
+
};
|
@@ -0,0 +1,32 @@
|
|
1
|
+
const assetUrl = (asset, type) => {
|
2
|
+
const str = CONFIG[asset][type];
|
3
|
+
if (str.includes('gh') || str.includes('combine')) {
|
4
|
+
return `https://cdn.jsdelivr.net/${str}`;
|
5
|
+
}
|
6
|
+
if (str.includes('npm')) {
|
7
|
+
return `https://cdn.jsdelivr.net/${str}`;
|
8
|
+
}
|
9
|
+
if (str.includes('http')) {
|
10
|
+
return str;
|
11
|
+
}
|
12
|
+
return `/${str}`;
|
13
|
+
};
|
14
|
+
const vendorJs = (type, callback, condition) => {
|
15
|
+
if (LOCAL[type]) {
|
16
|
+
getScript(assetUrl('js', type), callback || function () {
|
17
|
+
window[type] = true;
|
18
|
+
}, condition || window[type]);
|
19
|
+
}
|
20
|
+
};
|
21
|
+
const vendorCss = (type, condition) => {
|
22
|
+
if (window['css' + type]) {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
if (LOCAL[type]) {
|
26
|
+
document.head.createChild('link', {
|
27
|
+
rel: 'stylesheet',
|
28
|
+
href: assetUrl('css', type)
|
29
|
+
});
|
30
|
+
window['css' + type] = true;
|
31
|
+
}
|
32
|
+
};
|
@@ -0,0 +1,105 @@
|
|
1
|
+
Object.assign(HTMLElement.prototype, {
|
2
|
+
createChild(tag, obj, positon) {
|
3
|
+
const child = document.createElement(tag);
|
4
|
+
Object.assign(child, obj);
|
5
|
+
switch (positon) {
|
6
|
+
case 'after':
|
7
|
+
this.insertAfter(child);
|
8
|
+
break;
|
9
|
+
case 'replace':
|
10
|
+
this.innerHTML = '';
|
11
|
+
this.appendChild(child);
|
12
|
+
break;
|
13
|
+
default:
|
14
|
+
this.appendChild(child);
|
15
|
+
}
|
16
|
+
return child;
|
17
|
+
},
|
18
|
+
wrapObject(obj) {
|
19
|
+
const box = document.createElement('div');
|
20
|
+
Object.assign(box, obj);
|
21
|
+
this.parentNode.insertBefore(box, this);
|
22
|
+
this.parentNode.removeChild(this);
|
23
|
+
box.appendChild(this);
|
24
|
+
},
|
25
|
+
changeOrGetHeight(h) {
|
26
|
+
if (h) {
|
27
|
+
this.style.height = typeof h === 'number' ? h + 'rem' : h;
|
28
|
+
}
|
29
|
+
return this.getBoundingClientRect().height;
|
30
|
+
},
|
31
|
+
changeOrGetWidth(w) {
|
32
|
+
if (w) {
|
33
|
+
this.style.width = typeof w === 'number' ? w + 'rem' : w;
|
34
|
+
}
|
35
|
+
return this.getBoundingClientRect().width;
|
36
|
+
},
|
37
|
+
getTop() {
|
38
|
+
return this.getBoundingClientRect().top;
|
39
|
+
},
|
40
|
+
left() {
|
41
|
+
return this.getBoundingClientRect().left;
|
42
|
+
},
|
43
|
+
attr(type, value) {
|
44
|
+
if (value === null) {
|
45
|
+
return this.removeAttribute(type);
|
46
|
+
}
|
47
|
+
if (value) {
|
48
|
+
this.setAttribute(type, value);
|
49
|
+
return this;
|
50
|
+
}
|
51
|
+
else {
|
52
|
+
return this.getAttribute(type);
|
53
|
+
}
|
54
|
+
},
|
55
|
+
insertAfter(element) {
|
56
|
+
const parent = this.parentNode;
|
57
|
+
if (parent.lastChild === this) {
|
58
|
+
parent.appendChild(element);
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
parent.insertBefore(element, this.nextSibling);
|
62
|
+
}
|
63
|
+
},
|
64
|
+
display(d) {
|
65
|
+
if (d == null) {
|
66
|
+
return this.style.display;
|
67
|
+
}
|
68
|
+
else {
|
69
|
+
this.style.display = d;
|
70
|
+
return this;
|
71
|
+
}
|
72
|
+
},
|
73
|
+
child(selector) {
|
74
|
+
return $dom(selector, this);
|
75
|
+
},
|
76
|
+
find(selector) {
|
77
|
+
return $dom.all(selector, this);
|
78
|
+
},
|
79
|
+
_class(type, className, display) {
|
80
|
+
const classNames = className.indexOf(' ') ? className.split(' ') : [className];
|
81
|
+
classNames.forEach((name) => {
|
82
|
+
if (type === 'toggle') {
|
83
|
+
this.classList.toggle(name, display);
|
84
|
+
}
|
85
|
+
else {
|
86
|
+
this.classList[type](name);
|
87
|
+
}
|
88
|
+
});
|
89
|
+
},
|
90
|
+
addClass(className) {
|
91
|
+
this._class('add', className);
|
92
|
+
return this;
|
93
|
+
},
|
94
|
+
removeClass(className) {
|
95
|
+
this._class('remove', className);
|
96
|
+
return this;
|
97
|
+
},
|
98
|
+
toggleClass(className, display) {
|
99
|
+
this._class('toggle', className, display);
|
100
|
+
return this;
|
101
|
+
},
|
102
|
+
hasClass(className) {
|
103
|
+
return this.classList.contains(className);
|
104
|
+
}
|
105
|
+
});
|
@@ -0,0 +1,57 @@
|
|
1
|
+
let inCloudFlare = true;
|
2
|
+
window.addEventListener('DOMContentLoaded', function () {
|
3
|
+
inCloudFlare = false;
|
4
|
+
});
|
5
|
+
if (document.readyState === 'loading') {
|
6
|
+
window.addEventListener('load', function () {
|
7
|
+
if (inCloudFlare) {
|
8
|
+
window.dispatchEvent(new Event('DOMContentLoaded'));
|
9
|
+
console.log('%c ☁️cloudflare patch ' + '%c running(rocket & minify)', 'color: white; background: #ff8c00; padding: 5px 3px;', 'padding: 4px;border:1px solid #ff8c00');
|
10
|
+
}
|
11
|
+
});
|
12
|
+
}
|
13
|
+
const getScript = (url, callback, condition) => {
|
14
|
+
if (condition) {
|
15
|
+
callback();
|
16
|
+
}
|
17
|
+
else {
|
18
|
+
let script = document.createElement('script');
|
19
|
+
script.onload = function (_, isAbort) {
|
20
|
+
if (isAbort || !script.readyState) {
|
21
|
+
console.log('abort!');
|
22
|
+
script.onload = null;
|
23
|
+
script = undefined;
|
24
|
+
if (!isAbort && callback)
|
25
|
+
setTimeout(callback, 0);
|
26
|
+
}
|
27
|
+
};
|
28
|
+
script.src = url;
|
29
|
+
document.head.appendChild(script);
|
30
|
+
}
|
31
|
+
};
|
32
|
+
const pjaxScript = (element) => {
|
33
|
+
const { text, parentNode, id, className, type, src, dataset } = element;
|
34
|
+
const code = text || element.textContent || element.innerHTML || '';
|
35
|
+
parentNode.removeChild(element);
|
36
|
+
const script = document.createElement('script');
|
37
|
+
if (id) {
|
38
|
+
script.id = id;
|
39
|
+
}
|
40
|
+
if (className) {
|
41
|
+
script.className = className;
|
42
|
+
}
|
43
|
+
if (type) {
|
44
|
+
script.type = type;
|
45
|
+
}
|
46
|
+
if (src) {
|
47
|
+
script.src = src;
|
48
|
+
script.async = false;
|
49
|
+
}
|
50
|
+
if (dataset.pjax !== undefined) {
|
51
|
+
script.dataset.pjax = '';
|
52
|
+
}
|
53
|
+
if (code !== '') {
|
54
|
+
script.appendChild(document.createTextNode(code));
|
55
|
+
}
|
56
|
+
parentNode.appendChild(script);
|
57
|
+
};
|
@@ -10,16 +10,16 @@ Vue.createApp({
|
|
10
10
|
id: 'neko',
|
11
11
|
innerHTML: '<div class="planet"><div class="sun"></div><div class="moon"></div></div><div class="body"><div class="face"><section class="eyes left"><span class="pupil"></span></section><section class="eyes right"><span class="pupil"></span></section><span class="nose"></span></div></div>'
|
12
12
|
});
|
13
|
-
const hideNeko =
|
13
|
+
const hideNeko = () => {
|
14
14
|
transition(neko, {
|
15
15
|
delay: 2500,
|
16
16
|
opacity: 0
|
17
|
-
},
|
17
|
+
}, () => {
|
18
18
|
BODY.removeChild(neko);
|
19
19
|
});
|
20
20
|
};
|
21
21
|
if (btn.hasClass('i-sun')) {
|
22
|
-
c =
|
22
|
+
c = () => {
|
23
23
|
neko.addClass('dark');
|
24
24
|
changeTheme('dark');
|
25
25
|
$storage.set('theme', 'dark');
|
@@ -28,16 +28,16 @@ Vue.createApp({
|
|
28
28
|
}
|
29
29
|
else {
|
30
30
|
neko.addClass('dark');
|
31
|
-
c =
|
31
|
+
c = () => {
|
32
32
|
neko.removeClass('dark');
|
33
33
|
changeTheme();
|
34
34
|
$storage.set('theme', 'light');
|
35
35
|
hideNeko();
|
36
36
|
};
|
37
37
|
}
|
38
|
-
transition(neko, 1,
|
38
|
+
transition(neko, 1, () => {
|
39
39
|
setTimeout(c, 210);
|
40
|
-
},
|
40
|
+
}, () => {
|
41
41
|
neko.display('block');
|
42
42
|
});
|
43
43
|
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
const loadComments = () => {
|
2
|
+
const element = $dom('#comments');
|
3
|
+
if (!element) {
|
4
|
+
goToComment.display('none');
|
5
|
+
return;
|
6
|
+
}
|
7
|
+
else {
|
8
|
+
goToComment.display('');
|
9
|
+
}
|
10
|
+
const io = new IntersectionObserver((entries, observer) => {
|
11
|
+
const entry = entries[0];
|
12
|
+
vendorCss('valine');
|
13
|
+
if (entry.isIntersecting || entry.intersectionRatio > 0) {
|
14
|
+
transition($dom('#comments'), 'bounceUpIn');
|
15
|
+
observer.disconnect();
|
16
|
+
}
|
17
|
+
});
|
18
|
+
io.observe(element);
|
19
|
+
};
|
@@ -0,0 +1,57 @@
|
|
1
|
+
const cardActive = () => {
|
2
|
+
if (!$dom('.index.wrap')) {
|
3
|
+
return;
|
4
|
+
}
|
5
|
+
const io = new IntersectionObserver((entries) => {
|
6
|
+
entries.forEach((article) => {
|
7
|
+
if (article.target.hasClass('show')) {
|
8
|
+
io.unobserve(article.target);
|
9
|
+
}
|
10
|
+
else {
|
11
|
+
if (article.isIntersecting || article.intersectionRatio > 0) {
|
12
|
+
article.target.addClass('show');
|
13
|
+
io.unobserve(article.target);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
});
|
17
|
+
}, {
|
18
|
+
root: null,
|
19
|
+
threshold: [0.3]
|
20
|
+
});
|
21
|
+
$dom.each('.index.wrap article.item, .index.wrap section.item', (article) => {
|
22
|
+
io.observe(article);
|
23
|
+
});
|
24
|
+
$dom('.index.wrap .item:first-child').addClass('show');
|
25
|
+
$dom.each('.cards .item', (element) => {
|
26
|
+
['mouseenter', 'touchstart'].forEach((item) => {
|
27
|
+
element.addEventListener(item, () => {
|
28
|
+
if ($dom('.cards .item.active')) {
|
29
|
+
$dom('.cards .item.active').removeClass('active');
|
30
|
+
}
|
31
|
+
element.addClass('active');
|
32
|
+
}, { passive: true });
|
33
|
+
});
|
34
|
+
['mouseleave'].forEach((item) => {
|
35
|
+
element.addEventListener(item, () => {
|
36
|
+
element.removeClass('active');
|
37
|
+
}, { passive: true });
|
38
|
+
});
|
39
|
+
});
|
40
|
+
};
|
41
|
+
const registerExtURL = () => {
|
42
|
+
$dom.each('span.exturl', (element) => {
|
43
|
+
const link = document.createElement('a');
|
44
|
+
link.href = decodeURIComponent(window.atob(element.dataset.url).split('').map((c) => {
|
45
|
+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
46
|
+
}).join(''));
|
47
|
+
link.rel = 'noopener external nofollow noreferrer';
|
48
|
+
link.target = '_blank';
|
49
|
+
link.className = element.className;
|
50
|
+
link.title = element.title || element.innerText;
|
51
|
+
link.innerHTML = element.innerHTML;
|
52
|
+
if (element.dataset.backgroundImage) {
|
53
|
+
link.dataset.backgroundImage = element.dataset.backgroundImage;
|
54
|
+
}
|
55
|
+
element.parentNode.replaceChild(link, element);
|
56
|
+
});
|
57
|
+
};
|
@@ -0,0 +1,59 @@
|
|
1
|
+
const postFancybox = (p) => {
|
2
|
+
if ($dom(p + ' .md img')) {
|
3
|
+
vendorCss('fancybox');
|
4
|
+
vendorJs('fancybox', () => {
|
5
|
+
const q = jQuery.noConflict();
|
6
|
+
$dom.each(p + ' p.gallery', (element) => {
|
7
|
+
const box = document.createElement('div');
|
8
|
+
box.className = 'gallery';
|
9
|
+
box.attr('data-height', String(element.attr('data-height') || 220));
|
10
|
+
box.innerHTML = element.innerHTML.replace(/<br>/g, '');
|
11
|
+
element.parentNode.insertBefore(box, element);
|
12
|
+
element.remove();
|
13
|
+
});
|
14
|
+
$dom.each(p + ' .md img:not(.emoji):not(.vemoji)', (element) => {
|
15
|
+
const $image = q(element);
|
16
|
+
const imageLink = $image.attr('data-src') || $image.attr('src');
|
17
|
+
const $imageWrapLink = $image.wrap('<a class="fancybox" href="' + imageLink + '" itemscope itemtype="https://schema.org/ImageObject" itemprop="url"></a>').parent('a');
|
18
|
+
let info;
|
19
|
+
let captionClass = 'image-info';
|
20
|
+
if (!$image.is('a img')) {
|
21
|
+
$image.data('safe-src', imageLink);
|
22
|
+
if (!$image.is('.gallery img')) {
|
23
|
+
$imageWrapLink.attr('data-fancybox', 'default').attr('rel', 'default');
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
captionClass = 'jg-caption';
|
27
|
+
}
|
28
|
+
}
|
29
|
+
if ((info = element.attr('title'))) {
|
30
|
+
$imageWrapLink.attr('data-caption', info);
|
31
|
+
const para = document.createElement('span');
|
32
|
+
const txt = document.createTextNode(info);
|
33
|
+
para.appendChild(txt);
|
34
|
+
para.addClass(captionClass);
|
35
|
+
element.insertAfter(para);
|
36
|
+
}
|
37
|
+
});
|
38
|
+
$dom.each(p + ' div.gallery', (el, i) => {
|
39
|
+
q(el).justifiedGallery({
|
40
|
+
rowHeight: q(el).data('height') || 120,
|
41
|
+
rel: 'gallery-' + i
|
42
|
+
}).on('jg.complete', function () {
|
43
|
+
q(this).find('a').each((k, ele) => {
|
44
|
+
ele.attr('data-fancybox', 'gallery-' + i);
|
45
|
+
});
|
46
|
+
});
|
47
|
+
});
|
48
|
+
q.fancybox.defaults.hash = false;
|
49
|
+
q(p + ' .fancybox').fancybox({
|
50
|
+
loop: true,
|
51
|
+
helpers: {
|
52
|
+
overlay: {
|
53
|
+
locked: false
|
54
|
+
}
|
55
|
+
}
|
56
|
+
});
|
57
|
+
}, window.jQuery);
|
58
|
+
}
|
59
|
+
};
|
@@ -0,0 +1,232 @@
|
|
1
|
+
const postBeauty = () => {
|
2
|
+
loadComments();
|
3
|
+
if (!$dom('.md')) {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
postFancybox('.post.block');
|
7
|
+
$dom('.post.block').oncopy = async (event) => {
|
8
|
+
showtip(LOCAL.copyright);
|
9
|
+
if (LOCAL.nocopy) {
|
10
|
+
event.preventDefault();
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
const copyright = await $dom.asyncify('#copyright');
|
14
|
+
if (window.getSelection().toString().length > 30 && copyright) {
|
15
|
+
event.preventDefault();
|
16
|
+
const author = '# ' + copyright.child('.author').innerText;
|
17
|
+
const link = '# ' + copyright.child('.link').innerText;
|
18
|
+
const license = '# ' + copyright.child('.license').innerText;
|
19
|
+
const htmlData = author + '<br>' + link + '<br>' + license + '<br><br>' + window.getSelection().toString().replace(/\r\n/g, '<br>');
|
20
|
+
const textData = author + '\n' + link + '\n' + license + '\n\n' + window.getSelection().toString().replace(/\r\n/g, '\n');
|
21
|
+
if (event.clipboardData) {
|
22
|
+
event.clipboardData.setData('text/html', htmlData);
|
23
|
+
event.clipboardData.setData('text/plain', textData);
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
if (window.clipboardData) {
|
27
|
+
return window.clipboardData.setData('text', textData);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
};
|
32
|
+
$dom.each('li ruby', (element) => {
|
33
|
+
let parent = element.parentNode;
|
34
|
+
if (element.parentNode.tagName !== 'LI') {
|
35
|
+
parent = element.parentNode.parentNode;
|
36
|
+
}
|
37
|
+
parent.addClass('ruby');
|
38
|
+
});
|
39
|
+
$dom.each('ol[start]', (element) => {
|
40
|
+
element.style.counterReset = 'counter ' + parseInt(element.attr('start') - 1);
|
41
|
+
});
|
42
|
+
$dom.each('.md table', (element) => {
|
43
|
+
element.wrapObject({
|
44
|
+
className: 'table-container'
|
45
|
+
});
|
46
|
+
});
|
47
|
+
$dom.each('.highlight > .table-container', (element) => {
|
48
|
+
element.className = 'code-container';
|
49
|
+
});
|
50
|
+
$dom.each('figure.highlight', (element) => {
|
51
|
+
const code_container = element.child('.code-container');
|
52
|
+
const caption = element.child('figcaption');
|
53
|
+
element.insertAdjacentHTML('beforeend', '<div class="operation"><span class="breakline-btn"><i class="ic i-align-left"></i></span><span class="copy-btn"><i class="ic i-clipboard"></i></span><span class="fullscreen-btn"><i class="ic i-expand"></i></span></div>');
|
54
|
+
const copyBtn = element.child('.copy-btn');
|
55
|
+
if (LOCAL.nocopy) {
|
56
|
+
copyBtn.remove();
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
copyBtn.addEventListener('click', (event) => {
|
60
|
+
const target = event.currentTarget;
|
61
|
+
let comma = '';
|
62
|
+
let code = '';
|
63
|
+
code_container.find('pre').forEach((line) => {
|
64
|
+
code += comma + line.innerText;
|
65
|
+
comma = '\n';
|
66
|
+
});
|
67
|
+
clipBoard(code, (result) => {
|
68
|
+
target.child('.ic').className = result ? 'ic i-check' : 'ic i-times';
|
69
|
+
target.blur();
|
70
|
+
showtip(LOCAL.copyright);
|
71
|
+
});
|
72
|
+
}, { passive: true });
|
73
|
+
copyBtn.addEventListener('mouseleave', (event) => {
|
74
|
+
setTimeout(() => {
|
75
|
+
event.target.child('.ic').className = 'ic i-clipboard';
|
76
|
+
}, 1000);
|
77
|
+
});
|
78
|
+
}
|
79
|
+
const breakBtn = element.child('.breakline-btn');
|
80
|
+
breakBtn.addEventListener('click', (event) => {
|
81
|
+
const target = event.currentTarget;
|
82
|
+
if (element.hasClass('breakline')) {
|
83
|
+
element.removeClass('breakline');
|
84
|
+
target.child('.ic').className = 'ic i-align-left';
|
85
|
+
}
|
86
|
+
else {
|
87
|
+
element.addClass('breakline');
|
88
|
+
target.child('.ic').className = 'ic i-align-justify';
|
89
|
+
}
|
90
|
+
});
|
91
|
+
const fullscreenBtn = element.child('.fullscreen-btn');
|
92
|
+
const removeFullscreen = () => {
|
93
|
+
element.removeClass('fullscreen');
|
94
|
+
element.scrollTop = 0;
|
95
|
+
BODY.removeClass('fullscreen');
|
96
|
+
fullscreenBtn.child('.ic').className = 'ic i-expand';
|
97
|
+
};
|
98
|
+
const fullscreenHandle = () => {
|
99
|
+
if (element.hasClass('fullscreen')) {
|
100
|
+
removeFullscreen();
|
101
|
+
if (code_container && code_container.find('tr').length > 15) {
|
102
|
+
const showBtn = code_container.child('.show-btn');
|
103
|
+
code_container.style.maxHeight = '300px';
|
104
|
+
showBtn.removeClass('open');
|
105
|
+
}
|
106
|
+
pageScroll(element);
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
element.addClass('fullscreen');
|
110
|
+
BODY.addClass('fullscreen');
|
111
|
+
fullscreenBtn.child('.ic').className = 'ic i-compress';
|
112
|
+
if (code_container && code_container.find('tr').length > 15) {
|
113
|
+
const showBtn = code_container.child('.show-btn');
|
114
|
+
code_container.style.maxHeight = '';
|
115
|
+
showBtn.addClass('open');
|
116
|
+
}
|
117
|
+
}
|
118
|
+
};
|
119
|
+
fullscreenBtn.addEventListener('click', fullscreenHandle);
|
120
|
+
caption && caption.addEventListener('click', fullscreenHandle);
|
121
|
+
if (code_container && code_container.find('tr').length > 15) {
|
122
|
+
code_container.style.maxHeight = '300px';
|
123
|
+
code_container.insertAdjacentHTML('beforeend', '<div class="show-btn"><i class="ic i-angle-down"></i></div>');
|
124
|
+
const showBtn = code_container.child('.show-btn');
|
125
|
+
const hideCode = () => {
|
126
|
+
code_container.style.maxHeight = '300px';
|
127
|
+
showBtn.removeClass('open');
|
128
|
+
};
|
129
|
+
const showCode = () => {
|
130
|
+
code_container.style.maxHeight = '';
|
131
|
+
showBtn.addClass('open');
|
132
|
+
};
|
133
|
+
showBtn.addEventListener('click', () => {
|
134
|
+
if (showBtn.hasClass('open')) {
|
135
|
+
removeFullscreen();
|
136
|
+
hideCode();
|
137
|
+
pageScroll(code_container);
|
138
|
+
}
|
139
|
+
else {
|
140
|
+
showCode();
|
141
|
+
}
|
142
|
+
});
|
143
|
+
}
|
144
|
+
});
|
145
|
+
$dom.asyncifyEach('pre.mermaid > svg', (element) => {
|
146
|
+
const temp = element;
|
147
|
+
temp.style.maxWidth = '';
|
148
|
+
});
|
149
|
+
$dom.each('.reward button', (element) => {
|
150
|
+
element.addEventListener('click', (event) => {
|
151
|
+
event.preventDefault();
|
152
|
+
const qr = $dom('#qr');
|
153
|
+
if (qr.display() === 'inline-flex') {
|
154
|
+
transition(qr, 0);
|
155
|
+
}
|
156
|
+
else {
|
157
|
+
transition(qr, 1, () => {
|
158
|
+
qr.display('inline-flex');
|
159
|
+
});
|
160
|
+
}
|
161
|
+
});
|
162
|
+
});
|
163
|
+
$dom.asyncifyEach('.quiz > ul.options li', (element) => {
|
164
|
+
element.addEventListener('click', () => {
|
165
|
+
if (element.hasClass('correct')) {
|
166
|
+
element.toggleClass('right');
|
167
|
+
element.parentNode.parentNode.addClass('show');
|
168
|
+
}
|
169
|
+
else {
|
170
|
+
element.toggleClass('wrong');
|
171
|
+
}
|
172
|
+
});
|
173
|
+
});
|
174
|
+
$dom.asyncifyEach('.quiz > p', (element) => {
|
175
|
+
element.addEventListener('click', () => {
|
176
|
+
element.parentNode.toggleClass('show');
|
177
|
+
});
|
178
|
+
});
|
179
|
+
$dom.asyncifyEach('.quiz > p:first-child', (element) => {
|
180
|
+
const quiz = element.parentNode;
|
181
|
+
let type = 'choice';
|
182
|
+
if (quiz.hasClass('true') || quiz.hasClass('false')) {
|
183
|
+
type = 'true_false';
|
184
|
+
}
|
185
|
+
if (quiz.hasClass('multi')) {
|
186
|
+
type = 'multiple';
|
187
|
+
}
|
188
|
+
if (quiz.hasClass('fill')) {
|
189
|
+
type = 'gap_fill';
|
190
|
+
}
|
191
|
+
if (quiz.hasClass('essay')) {
|
192
|
+
type = 'essay';
|
193
|
+
}
|
194
|
+
element.attr('data-type', LOCAL.quiz[type]);
|
195
|
+
});
|
196
|
+
$dom.asyncifyEach('.quiz .mistake', (element) => {
|
197
|
+
element.attr('data-type', LOCAL.quiz.mistake);
|
198
|
+
});
|
199
|
+
$dom.each('div.tags a', (element) => {
|
200
|
+
element.className = ['primary', 'success', 'info', 'warning', 'danger'][Math.floor(Math.random() * 5)];
|
201
|
+
});
|
202
|
+
$dom.asyncifyEach('.md div.player', (element) => {
|
203
|
+
mediaPlayer(element, {
|
204
|
+
type: element.attr('data-type'),
|
205
|
+
mode: 'order',
|
206
|
+
btns: []
|
207
|
+
}).player.load(JSON.parse(element.attr('data-src'))).fetch();
|
208
|
+
});
|
209
|
+
const angleDown = document.querySelectorAll('.show-btn .i-angle-down');
|
210
|
+
if (angleDown.length) {
|
211
|
+
const io = new IntersectionObserver((entries) => {
|
212
|
+
entries.forEach(entry => {
|
213
|
+
if (entry.isIntersecting) {
|
214
|
+
angleDown.forEach(i => {
|
215
|
+
i.classList.remove('stop-animation');
|
216
|
+
});
|
217
|
+
}
|
218
|
+
else {
|
219
|
+
angleDown.forEach(i => {
|
220
|
+
i.classList.add('stop-animation');
|
221
|
+
});
|
222
|
+
}
|
223
|
+
});
|
224
|
+
}, {
|
225
|
+
root: null,
|
226
|
+
threshold: 0.5
|
227
|
+
});
|
228
|
+
angleDown.forEach(i => {
|
229
|
+
io.observe(i);
|
230
|
+
});
|
231
|
+
}
|
232
|
+
};
|