hexo-theme-shokax 0.3.0 → 0.3.2
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.
- package/.eslintrc.cjs +5 -3
- package/README.md +11 -2
- package/_config.yml +12 -12
- package/layout/_mixin/comment.pug +1 -2
- package/layout/_mixin/widgets.pug +1 -1
- package/layout/_partials/layout.pug +23 -23
- package/package.json +27 -19
- package/scripts/generaters/script.js +17 -50
- package/scripts/helpers/asset.js +5 -2
- package/scripts/helpers/summary_ai.js +0 -1
- package/scripts/plugin/index.js +2 -2
- package/source/css/_common/scaffolding/normalize.styl +165 -180
- package/source/js/_app/components/sidebar.js +49 -35
- package/source/js/_app/fireworks.js +32 -19
- package/source/js/_app/globals/globalVars.js +91 -26
- package/source/js/_app/globals/handles.js +54 -42
- package/source/js/_app/globals/themeColor.js +22 -12
- package/source/js/_app/globals/thirdparty.js +17 -7
- package/source/js/_app/globals/tools.js +25 -14
- package/source/js/_app/library/anime.js +13 -3
- package/source/js/_app/library/dom.js +5 -0
- package/source/js/_app/library/loadFile.js +7 -1
- package/source/js/_app/library/proto.js +108 -102
- package/source/js/_app/library/scriptPjax.js +18 -10
- package/source/js/_app/library/storage.js +4 -1
- package/source/js/_app/library/vue.js +16 -9
- package/source/js/_app/page/comment.js +14 -7
- package/source/js/_app/page/common.js +13 -7
- package/source/js/_app/page/fancybox.js +12 -6
- package/source/js/_app/page/post.js +43 -29
- package/source/js/_app/page/search.js +21 -14
- package/source/js/_app/page/tab.js +9 -3
- package/source/js/_app/pjax/domInit.js +36 -23
- package/source/js/_app/pjax/refresh.js +48 -30
- package/source/js/_app/pjax/siteInit.js +30 -13
- package/source/js/_app/player.js +29 -16
- package/test/dom.test.js +86 -0
@@ -1,25 +1,31 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.algoliaSearch = void 0;
|
4
|
+
const globalVars_1 = require("../globals/globalVars");
|
5
|
+
const anime_1 = require("../library/anime");
|
6
|
+
const dom_1 = require("../library/dom");
|
7
|
+
function algoliaSearch(pjax) {
|
2
8
|
if (CONFIG.search === null) {
|
3
9
|
return;
|
4
10
|
}
|
5
|
-
if (!siteSearch) {
|
6
|
-
|
11
|
+
if (!globalVars_1.siteSearch) {
|
12
|
+
(0, globalVars_1.setSiteSearch)(globalVars_1.BODY.createChild('div', {
|
7
13
|
id: 'search',
|
8
14
|
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
|
-
});
|
15
|
+
}));
|
10
16
|
}
|
11
17
|
const search = instantsearch({
|
12
18
|
indexName: CONFIG.search.indexName,
|
13
19
|
searchClient: algoliasearch(CONFIG.search.appID, CONFIG.search.apiKey),
|
14
20
|
searchFunction(helper) {
|
15
|
-
const searchInput =
|
21
|
+
const searchInput = (0, dom_1.$dom)('.search-input');
|
16
22
|
if (searchInput.value) {
|
17
23
|
helper.search();
|
18
24
|
}
|
19
25
|
}
|
20
26
|
});
|
21
27
|
search.on('render', () => {
|
22
|
-
pjax.refresh(
|
28
|
+
pjax.refresh((0, dom_1.$dom)('#search-hits'));
|
23
29
|
});
|
24
30
|
search.addWidgets([
|
25
31
|
instantsearch.widgets.configure({
|
@@ -84,28 +90,29 @@ const algoliaSearch = (pjax) => {
|
|
84
90
|
})
|
85
91
|
]);
|
86
92
|
search.start();
|
87
|
-
|
93
|
+
dom_1.$dom.each('.search', (element) => {
|
88
94
|
element.addEventListener('click', () => {
|
89
95
|
document.body.style.overflow = 'hidden';
|
90
|
-
transition(siteSearch, 'shrinkIn', () => {
|
91
|
-
|
96
|
+
(0, anime_1.transition)(globalVars_1.siteSearch, 'shrinkIn', () => {
|
97
|
+
(0, dom_1.$dom)('.search-input').focus();
|
92
98
|
});
|
93
99
|
});
|
94
100
|
});
|
95
101
|
const onPopupClose = () => {
|
96
102
|
document.body.style.overflow = '';
|
97
|
-
transition(siteSearch, 0);
|
103
|
+
(0, anime_1.transition)(globalVars_1.siteSearch, 0);
|
98
104
|
};
|
99
|
-
siteSearch.addEventListener('click', (event) => {
|
100
|
-
if (event.target === siteSearch) {
|
105
|
+
globalVars_1.siteSearch.addEventListener('click', (event) => {
|
106
|
+
if (event.target === globalVars_1.siteSearch) {
|
101
107
|
onPopupClose();
|
102
108
|
}
|
103
109
|
});
|
104
|
-
|
110
|
+
(0, dom_1.$dom)('.close-btn').addEventListener('click', onPopupClose);
|
105
111
|
window.addEventListener('pjax:success', onPopupClose);
|
106
112
|
window.addEventListener('keyup', (event) => {
|
107
113
|
if (event.key === 'Escape') {
|
108
114
|
onPopupClose();
|
109
115
|
}
|
110
116
|
});
|
111
|
-
}
|
117
|
+
}
|
118
|
+
exports.algoliaSearch = algoliaSearch;
|
@@ -1,12 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.tabFormat = void 0;
|
4
|
+
const anime_1 = require("../library/anime");
|
5
|
+
const dom_1 = require("../library/dom");
|
1
6
|
const tabFormat = () => {
|
2
7
|
let first_tab;
|
3
|
-
|
8
|
+
dom_1.$dom.each('div.tab', (element) => {
|
4
9
|
if (element.attr('data-ready')) {
|
5
10
|
return;
|
6
11
|
}
|
7
12
|
const id = element.attr('data-id');
|
8
13
|
const title = element.attr('data-title');
|
9
|
-
let box =
|
14
|
+
let box = (0, dom_1.$dom)('#' + id);
|
10
15
|
if (!box) {
|
11
16
|
box = document.createElement('div');
|
12
17
|
box.className = 'tabs';
|
@@ -14,7 +19,7 @@ const tabFormat = () => {
|
|
14
19
|
box.innerHTML = '<div class="show-btn"></div>';
|
15
20
|
const showBtn = box.child('.show-btn');
|
16
21
|
showBtn.addEventListener('click', () => {
|
17
|
-
pageScroll(box);
|
22
|
+
(0, anime_1.pageScroll)(box);
|
18
23
|
});
|
19
24
|
element.parentNode.insertBefore(box, element);
|
20
25
|
first_tab = true;
|
@@ -48,3 +53,4 @@ const tabFormat = () => {
|
|
48
53
|
element.attr('data-ready', String(true));
|
49
54
|
});
|
50
55
|
};
|
56
|
+
exports.tabFormat = tabFormat;
|
@@ -1,29 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const sidebar_1 = require("../components/sidebar");
|
7
|
+
const globalVars_1 = require("../globals/globalVars");
|
8
|
+
const thirdparty_1 = require("../globals/thirdparty");
|
9
|
+
const dom_1 = require("../library/dom");
|
10
|
+
const player_1 = require("../player");
|
11
|
+
const proto_1 = __importDefault(require("../library/proto"));
|
12
|
+
function domInit() {
|
13
|
+
(0, proto_1.default)();
|
14
|
+
dom_1.$dom.each('.overview .menu > .item', (el) => {
|
15
|
+
globalVars_1.siteNav.child('.menu').appendChild(el.cloneNode(true));
|
4
16
|
});
|
5
|
-
loadCat.addEventListener('click', Loader.vanish);
|
6
|
-
menuToggle.addEventListener('click', sideBarToggleHandle);
|
7
|
-
|
8
|
-
quickBtn.child('.down').addEventListener('click', goToBottomHandle);
|
9
|
-
quickBtn.child('.up').addEventListener('click', backToTopHandle);
|
10
|
-
if (!toolBtn) {
|
11
|
-
|
17
|
+
globalVars_1.loadCat.addEventListener('click', thirdparty_1.Loader.vanish);
|
18
|
+
globalVars_1.menuToggle.addEventListener('click', sidebar_1.sideBarToggleHandle);
|
19
|
+
(0, dom_1.$dom)('.dimmer').addEventListener('click', sidebar_1.sideBarToggleHandle);
|
20
|
+
globalVars_1.quickBtn.child('.down').addEventListener('click', sidebar_1.goToBottomHandle);
|
21
|
+
globalVars_1.quickBtn.child('.up').addEventListener('click', sidebar_1.backToTopHandle);
|
22
|
+
if (!globalVars_1.toolBtn) {
|
23
|
+
(0, globalVars_1.setToolBtn)(globalVars_1.siteHeader.createChild('div', {
|
12
24
|
id: 'tool',
|
13
25
|
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
|
-
});
|
26
|
+
}));
|
15
27
|
}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
backToTop.addEventListener('click', backToTopHandle);
|
21
|
-
goToComment.addEventListener('click', goToCommentHandle);
|
22
|
-
showContents.addEventListener('click', sideBarToggleHandle);
|
23
|
-
if (typeof mediaPlayer !== 'undefined') {
|
24
|
-
mediaPlayer(toolPlayer);
|
25
|
-
|
26
|
-
toolPlayer.player.mini();
|
28
|
+
(0, globalVars_1.setToolPlayer)(globalVars_1.toolBtn.child('.player'));
|
29
|
+
(0, globalVars_1.setBackToTop)(globalVars_1.toolBtn.child('.back-to-top'));
|
30
|
+
(0, globalVars_1.setGoToComment)(globalVars_1.toolBtn.child('.chat'));
|
31
|
+
(0, globalVars_1.setShowContents)(globalVars_1.toolBtn.child('.contents'));
|
32
|
+
globalVars_1.backToTop.addEventListener('click', sidebar_1.backToTopHandle);
|
33
|
+
globalVars_1.goToComment.addEventListener('click', sidebar_1.goToCommentHandle);
|
34
|
+
globalVars_1.showContents.addEventListener('click', sidebar_1.sideBarToggleHandle);
|
35
|
+
if (typeof player_1.mediaPlayer !== 'undefined') {
|
36
|
+
(0, player_1.mediaPlayer)(globalVars_1.toolPlayer);
|
37
|
+
(0, dom_1.$dom)('main').addEventListener('click', () => {
|
38
|
+
globalVars_1.toolPlayer.player.mini();
|
27
39
|
});
|
28
40
|
}
|
29
41
|
const createIntersectionObserver = () => {
|
@@ -65,4 +77,5 @@ const domInit = () => {
|
|
65
77
|
}).observe(document.querySelector('.with-love'));
|
66
78
|
};
|
67
79
|
createIntersectionObserver();
|
68
|
-
}
|
80
|
+
}
|
81
|
+
exports.default = domInit;
|
@@ -1,42 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.siteRefresh = exports.pjaxReload = void 0;
|
4
|
+
const dom_1 = require("../library/dom");
|
5
|
+
const common_1 = require("../page/common");
|
6
|
+
const post_1 = require("../page/post");
|
7
|
+
const anime_1 = require("../library/anime");
|
8
|
+
const loadFile_1 = require("../library/loadFile");
|
9
|
+
const scriptPjax_1 = require("../library/scriptPjax");
|
10
|
+
const handles_1 = require("../globals/handles");
|
11
|
+
const globalVars_1 = require("../globals/globalVars");
|
12
|
+
const player_1 = require("../player");
|
13
|
+
const tools_1 = require("../globals/tools");
|
14
|
+
const sidebar_1 = require("../components/sidebar");
|
15
|
+
const thirdparty_1 = require("../globals/thirdparty");
|
16
|
+
const tab_1 = require("../page/tab");
|
1
17
|
const pjaxReload = () => {
|
2
|
-
pagePosition();
|
3
|
-
if (sideBar.hasClass('on')) {
|
4
|
-
transition(sideBar, 0, () => {
|
5
|
-
sideBar.removeClass('on');
|
6
|
-
menuToggle.removeClass('close');
|
18
|
+
(0, tools_1.pagePosition)();
|
19
|
+
if (globalVars_1.sideBar.hasClass('on')) {
|
20
|
+
(0, anime_1.transition)(globalVars_1.sideBar, 0, () => {
|
21
|
+
globalVars_1.sideBar.removeClass('on');
|
22
|
+
globalVars_1.menuToggle.removeClass('close');
|
7
23
|
});
|
8
24
|
}
|
9
|
-
const mainNode =
|
25
|
+
const mainNode = (0, dom_1.$dom)('#main');
|
10
26
|
mainNode.innerHTML = '';
|
11
|
-
mainNode.appendChild(loadCat.lastChild.cloneNode(true));
|
12
|
-
pageScroll(0);
|
27
|
+
mainNode.appendChild(globalVars_1.loadCat.lastChild.cloneNode(true));
|
28
|
+
(0, anime_1.pageScroll)(0);
|
13
29
|
};
|
30
|
+
exports.pjaxReload = pjaxReload;
|
14
31
|
const siteRefresh = (reload) => {
|
15
|
-
|
16
|
-
|
17
|
-
vendorCss('katex');
|
18
|
-
vendorJs('copy_tex');
|
19
|
-
vendorCss('mermaid');
|
20
|
-
vendorJs('chart');
|
32
|
+
(0, globalVars_1.setLocalHash)(0);
|
33
|
+
(0, globalVars_1.setLocalUrl)(window.location.href);
|
34
|
+
(0, loadFile_1.vendorCss)('katex');
|
35
|
+
(0, loadFile_1.vendorJs)('copy_tex');
|
36
|
+
(0, loadFile_1.vendorCss)('mermaid');
|
37
|
+
(0, loadFile_1.vendorJs)('chart');
|
21
38
|
if (reload !== 1) {
|
22
|
-
|
39
|
+
dom_1.$dom.each('script[data-pjax]', scriptPjax_1.pjaxScript);
|
23
40
|
}
|
24
|
-
|
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 || {});
|
41
|
+
(0, globalVars_1.setOriginTitle)(document.title);
|
42
|
+
(0, handles_1.resizeHandle)();
|
43
|
+
(0, sidebar_1.menuActive)();
|
44
|
+
(0, sidebar_1.sideBarTab)();
|
45
|
+
(0, sidebar_1.sidebarTOC)();
|
46
|
+
(0, common_1.registerExtURL)();
|
47
|
+
(0, post_1.postBeauty)();
|
48
|
+
(0, tab_1.tabFormat)();
|
49
|
+
if (typeof player_1.mediaPlayer !== 'undefined') {
|
50
|
+
globalVars_1.toolPlayer.player.load(LOCAL.audio || CONFIG.audio || {});
|
34
51
|
}
|
35
|
-
Loader.hide();
|
52
|
+
thirdparty_1.Loader.hide();
|
36
53
|
setTimeout(() => {
|
37
|
-
positionInit();
|
54
|
+
(0, tools_1.positionInit)();
|
38
55
|
}, 500);
|
39
|
-
cardActive();
|
40
|
-
lazyload.observe();
|
41
|
-
isOutime();
|
56
|
+
(0, common_1.cardActive)();
|
57
|
+
thirdparty_1.lazyload.observe();
|
58
|
+
(0, thirdparty_1.isOutime)();
|
42
59
|
};
|
60
|
+
exports.siteRefresh = siteRefresh;
|
@@ -1,6 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const domInit_1 = __importDefault(require("./domInit"));
|
7
|
+
const refresh_1 = require("./refresh");
|
8
|
+
const scriptPjax_1 = require("../library/scriptPjax");
|
9
|
+
const search_1 = require("../page/search");
|
10
|
+
const globalVars_1 = require("../globals/globalVars");
|
11
|
+
const themeColor_1 = require("../globals/themeColor");
|
12
|
+
const handles_1 = require("../globals/handles");
|
13
|
+
const tools_1 = require("../globals/tools");
|
14
|
+
const fireworks_1 = require("../fireworks");
|
15
|
+
const theme_shokax_pjax_1 = __importDefault(require("theme-shokax-pjax"));
|
1
16
|
const siteInit = () => {
|
2
|
-
|
3
|
-
|
17
|
+
(0, scriptPjax_1.cloudflareInit)();
|
18
|
+
(0, domInit_1.default)();
|
19
|
+
(0, globalVars_1.setPjax)(new theme_shokax_pjax_1.default({
|
4
20
|
selectors: [
|
5
21
|
'head title',
|
6
22
|
'.languages',
|
@@ -10,23 +26,24 @@ const siteInit = () => {
|
|
10
26
|
'script[data-config]'
|
11
27
|
],
|
12
28
|
cacheBust: false
|
13
|
-
});
|
29
|
+
}));
|
14
30
|
CONFIG.quicklink.ignores = LOCAL.ignores;
|
15
31
|
quicklink.listen(CONFIG.quicklink);
|
16
|
-
autoDarkmode();
|
32
|
+
(0, themeColor_1.autoDarkmode)();
|
17
33
|
if (!CONFIG.disableVL) {
|
18
|
-
visibilityListener();
|
34
|
+
(0, handles_1.visibilityListener)();
|
19
35
|
}
|
20
|
-
themeColorListener();
|
21
|
-
algoliaSearch(pjax);
|
22
|
-
|
23
|
-
window.addEventListener('
|
24
|
-
window.addEventListener('
|
25
|
-
window.addEventListener('pjax:
|
36
|
+
(0, themeColor_1.themeColorListener)();
|
37
|
+
(0, search_1.algoliaSearch)(globalVars_1.pjax);
|
38
|
+
(0, fireworks_1.initFireworks)();
|
39
|
+
window.addEventListener('scroll', handles_1.scrollHandle);
|
40
|
+
window.addEventListener('resize', handles_1.resizeHandle);
|
41
|
+
window.addEventListener('pjax:send', refresh_1.pjaxReload);
|
42
|
+
window.addEventListener('pjax:success', refresh_1.siteRefresh);
|
26
43
|
window.addEventListener('beforeunload', () => {
|
27
|
-
pagePosition();
|
44
|
+
(0, tools_1.pagePosition)();
|
28
45
|
});
|
29
|
-
siteRefresh(1);
|
46
|
+
(0, refresh_1.siteRefresh)(1);
|
30
47
|
};
|
31
48
|
window.addEventListener('DOMContentLoaded', siteInit, {
|
32
49
|
passive: true
|
package/source/js/_app/player.js
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.mediaPlayer = void 0;
|
4
|
+
const globalVars_1 = require("./globals/globalVars");
|
5
|
+
const tools_1 = require("./globals/tools");
|
6
|
+
const anime_1 = require("./library/anime");
|
7
|
+
const dom_1 = require("./library/dom");
|
8
|
+
const storage_1 = require("./library/storage");
|
9
|
+
const tab_1 = require("./page/tab");
|
1
10
|
let NOWPLAYING = null;
|
2
11
|
const isMobile = /mobile/i.test(window.navigator.userAgent);
|
3
12
|
const mediaPlayer = (t, config) => {
|
13
|
+
if (CONFIG.noPlayer) {
|
14
|
+
return;
|
15
|
+
}
|
4
16
|
const buttons = {
|
5
17
|
el: {},
|
6
18
|
create() {
|
@@ -75,7 +87,7 @@ const mediaPlayer = (t, config) => {
|
|
75
87
|
t.player.options.mode = 'loop';
|
76
88
|
}
|
77
89
|
controller.btns.mode.className = 'mode ' + t.player.options.mode + ' btn';
|
78
|
-
|
90
|
+
storage_1.$storage.set('_PlayerMode', t.player.options.mode);
|
79
91
|
},
|
80
92
|
volume(e) {
|
81
93
|
e.preventDefault();
|
@@ -234,7 +246,7 @@ const mediaPlayer = (t, config) => {
|
|
234
246
|
return null;
|
235
247
|
}
|
236
248
|
const id = 'list-' + t.player._id + '-' + item.group;
|
237
|
-
let tab =
|
249
|
+
let tab = (0, dom_1.$dom)('#' + id);
|
238
250
|
if (!tab) {
|
239
251
|
tab = el.createChild('div', {
|
240
252
|
id,
|
@@ -266,7 +278,7 @@ const mediaPlayer = (t, config) => {
|
|
266
278
|
});
|
267
279
|
return item;
|
268
280
|
});
|
269
|
-
tabFormat();
|
281
|
+
(0, tab_1.tabFormat)();
|
270
282
|
},
|
271
283
|
current() {
|
272
284
|
return this.data[this.index];
|
@@ -281,7 +293,7 @@ const mediaPlayer = (t, config) => {
|
|
281
293
|
li && li.addClass('active');
|
282
294
|
tab = this.el.find('.tab')[item.group];
|
283
295
|
tab && tab.addClass('active');
|
284
|
-
pageScroll(item.el, item.el.offsetTop);
|
296
|
+
(0, anime_1.pageScroll)(item.el, item.el.offsetTop);
|
285
297
|
return this;
|
286
298
|
},
|
287
299
|
title() {
|
@@ -289,7 +301,7 @@ const mediaPlayer = (t, config) => {
|
|
289
301
|
return;
|
290
302
|
}
|
291
303
|
const current = this.current();
|
292
|
-
document.title = 'Now Playing...' + current.name + ' - ' + current.artist + ' | ' + originTitle;
|
304
|
+
document.title = 'Now Playing...' + current.name + ' - ' + current.artist + ' | ' + globalVars_1.originTitle;
|
293
305
|
},
|
294
306
|
error() {
|
295
307
|
const current = this.current();
|
@@ -382,7 +394,7 @@ const mediaPlayer = (t, config) => {
|
|
382
394
|
const meta = utils.parse(raw);
|
383
395
|
if (meta[0]) {
|
384
396
|
const skey = JSON.stringify(meta);
|
385
|
-
const playlist =
|
397
|
+
const playlist = storage_1.$storage.get(skey);
|
386
398
|
if (playlist) {
|
387
399
|
list.push(...JSON.parse(playlist));
|
388
400
|
resolve(list);
|
@@ -392,7 +404,7 @@ const mediaPlayer = (t, config) => {
|
|
392
404
|
.then((response) => {
|
393
405
|
return response.json();
|
394
406
|
}).then((json) => {
|
395
|
-
|
407
|
+
storage_1.$storage.set(skey, JSON.stringify(json));
|
396
408
|
list.push(...json);
|
397
409
|
resolve(list);
|
398
410
|
}).catch((ex) => {
|
@@ -545,8 +557,8 @@ const mediaPlayer = (t, config) => {
|
|
545
557
|
}
|
546
558
|
source.attr('src', item.url);
|
547
559
|
source.attr('title', item.name + ' - ' + item.artist);
|
548
|
-
this.volume(
|
549
|
-
this.muted(
|
560
|
+
this.volume(storage_1.$storage.get('_PlayerVolume') || '0.7');
|
561
|
+
this.muted(storage_1.$storage.get('_PlayerMuted'));
|
550
562
|
progress.create();
|
551
563
|
if (this.options.type === 'audio') {
|
552
564
|
preview.create();
|
@@ -568,12 +580,12 @@ const mediaPlayer = (t, config) => {
|
|
568
580
|
},
|
569
581
|
pause() {
|
570
582
|
source.pause();
|
571
|
-
document.title = originTitle;
|
583
|
+
document.title = globalVars_1.originTitle;
|
572
584
|
},
|
573
585
|
stop() {
|
574
586
|
source.pause();
|
575
587
|
source.currentTime = 0;
|
576
|
-
document.title = originTitle;
|
588
|
+
document.title = globalVars_1.originTitle;
|
577
589
|
},
|
578
590
|
seek(time) {
|
579
591
|
time = Math.max(time, 0);
|
@@ -584,11 +596,11 @@ const mediaPlayer = (t, config) => {
|
|
584
596
|
muted(status) {
|
585
597
|
if (status === 'muted') {
|
586
598
|
source.muted = status;
|
587
|
-
|
599
|
+
storage_1.$storage.set('_PlayerMuted', status);
|
588
600
|
controller.update(0);
|
589
601
|
}
|
590
602
|
else {
|
591
|
-
|
603
|
+
storage_1.$storage.del('_PlayerMuted');
|
592
604
|
source.muted = false;
|
593
605
|
controller.update(source.volume);
|
594
606
|
}
|
@@ -596,7 +608,7 @@ const mediaPlayer = (t, config) => {
|
|
596
608
|
volume(percentage) {
|
597
609
|
if (!isNaN(percentage)) {
|
598
610
|
controller.update(percentage);
|
599
|
-
|
611
|
+
storage_1.$storage.set('_PlayerVolume', percentage);
|
600
612
|
source.volume = percentage;
|
601
613
|
}
|
602
614
|
},
|
@@ -709,7 +721,7 @@ const mediaPlayer = (t, config) => {
|
|
709
721
|
},
|
710
722
|
onplay() {
|
711
723
|
t.parentNode.addClass('playing');
|
712
|
-
showtip(this.attr('title'));
|
724
|
+
(0, tools_1.showtip)(this.attr('title'));
|
713
725
|
NOWPLAYING = t;
|
714
726
|
},
|
715
727
|
onpause() {
|
@@ -732,7 +744,7 @@ const mediaPlayer = (t, config) => {
|
|
732
744
|
return;
|
733
745
|
}
|
734
746
|
t.player.options = Object.assign(option, config);
|
735
|
-
t.player.options.mode =
|
747
|
+
t.player.options.mode = storage_1.$storage.get('_PlayerMode') || t.player.options.mode;
|
736
748
|
buttons.create();
|
737
749
|
source = t.createChild(t.player.options.type, events);
|
738
750
|
info.create();
|
@@ -742,3 +754,4 @@ const mediaPlayer = (t, config) => {
|
|
742
754
|
init(config);
|
743
755
|
return t;
|
744
756
|
};
|
757
|
+
exports.mediaPlayer = mediaPlayer;
|
package/test/dom.test.js
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
const { describe, beforeEach, afterEach, it } = require('mocha')
|
2
|
+
const jsdom = require('jsdom')
|
3
|
+
const { $dom } = require('../source/js/_app/library/dom')
|
4
|
+
const { expect } = require('chai')
|
5
|
+
|
6
|
+
describe('$dom', function () {
|
7
|
+
// 在每个测试用例之前创建一个虚拟文档
|
8
|
+
beforeEach(function () {
|
9
|
+
const html = `
|
10
|
+
<html lang="zh-cn">
|
11
|
+
<head><title>Test Page</title></head>
|
12
|
+
<body>
|
13
|
+
<div id="container">
|
14
|
+
<p class="text">Hello</p>
|
15
|
+
<p class="text">World</p>
|
16
|
+
</div>
|
17
|
+
</body>
|
18
|
+
</html>
|
19
|
+
`
|
20
|
+
const dom = new jsdom.JSDOM(html)
|
21
|
+
global.document = dom.window.document
|
22
|
+
global.HTMLElement = dom.window.HTMLElement
|
23
|
+
})
|
24
|
+
|
25
|
+
// 在每个测试用例之后清除虚拟文档
|
26
|
+
afterEach(function () {
|
27
|
+
global.document = null
|
28
|
+
})
|
29
|
+
|
30
|
+
it('should return the element with the given id selector', function () {
|
31
|
+
const element = $dom('#container')
|
32
|
+
expect(element).to.exist
|
33
|
+
expect(element).to.be.instanceOf(HTMLElement)
|
34
|
+
expect(element.id).to.equal('container')
|
35
|
+
})
|
36
|
+
|
37
|
+
it('should return the first element that matches the given selector', function () {
|
38
|
+
const element = $dom('.text')
|
39
|
+
expect(element).to.exist
|
40
|
+
expect(element).to.be.instanceOf(HTMLElement)
|
41
|
+
expect(element.textContent).to.equal('Hello')
|
42
|
+
})
|
43
|
+
|
44
|
+
it('should return null if no element matches the given selector', function () {
|
45
|
+
const element = $dom('.foo')
|
46
|
+
expect(element).to.be.null
|
47
|
+
})
|
48
|
+
})
|
49
|
+
|
50
|
+
describe('$dom.all & $dom.each', function () {
|
51
|
+
beforeEach(function () {
|
52
|
+
const html = `
|
53
|
+
<html lang="zh-cn">
|
54
|
+
<head><title>Test Page</title></head>
|
55
|
+
<body>
|
56
|
+
<div id="container">
|
57
|
+
<p class="text">Hello</p>
|
58
|
+
<p class="text">World</p>
|
59
|
+
</div>
|
60
|
+
</body>
|
61
|
+
</html>
|
62
|
+
`
|
63
|
+
const dom = new jsdom.JSDOM(html)
|
64
|
+
global.document = dom.window.document
|
65
|
+
global.HTMLElement = dom.window.HTMLElement
|
66
|
+
})
|
67
|
+
|
68
|
+
afterEach(function () {
|
69
|
+
global.document = null
|
70
|
+
})
|
71
|
+
|
72
|
+
it('should return all elements with the given selector', () => {
|
73
|
+
const elements = $dom.all('p')
|
74
|
+
expect(elements).to.be.exist
|
75
|
+
expect(elements).length(2)
|
76
|
+
})
|
77
|
+
|
78
|
+
it('should run callback with the given selector', () => {
|
79
|
+
$dom.each('p', function (value){
|
80
|
+
value.innerText = 'test'
|
81
|
+
})
|
82
|
+
const elements = $dom.all('p')
|
83
|
+
expect(elements[0].innerText).equal('test')
|
84
|
+
expect(elements[1].innerText).equal('test')
|
85
|
+
})
|
86
|
+
})
|