hexo-theme-shokax 0.3.13 → 0.4.0-alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- package/_config.yml +16 -9
- package/layout/_mixin/comment.pug +4 -4
- package/layout/_partials/footer.pug +1 -1
- package/layout/_partials/head/head.pug +7 -1
- package/layout/_partials/header.pug +1 -1
- package/layout/_partials/layout.pug +0 -10
- package/layout/_partials/post/footer.pug +1 -2
- package/package.json +10 -5
- package/scripts/generaters/archive.js +1 -1
- package/scripts/generaters/script.js +64 -42
- package/scripts/helpers/asset.js +1 -1
- package/scripts/helpers/list_categories.js +0 -4
- package/scripts/plugin/lib/injects.js +1 -1
- package/source/js/_app/components/comments.ts +33 -0
- package/source/js/_app/components/sidebar.ts +239 -0
- package/source/js/_app/globals/globalVars.ts +99 -0
- package/source/js/_app/globals/handles.ts +123 -0
- package/source/js/_app/globals/themeColor.ts +64 -0
- package/source/js/_app/globals/thirdparty.ts +63 -0
- package/source/js/_app/globals/tools.ts +75 -0
- package/source/js/_app/library/anime.ts +110 -0
- package/source/js/_app/library/declare.d.ts +126 -0
- package/source/js/_app/library/dom.ts +26 -0
- package/source/js/_app/library/loadFile.ts +43 -0
- package/source/js/_app/library/proto.ts +141 -0
- package/source/js/_app/library/scriptPjax.ts +72 -0
- package/source/js/_app/library/storage.ts +12 -0
- package/source/js/_app/library/vue.ts +50 -0
- package/source/js/_app/page/common.ts +42 -0
- package/source/js/_app/page/fancybox.ts +71 -0
- package/source/js/_app/page/post.ts +266 -0
- package/source/js/_app/page/search.ts +135 -0
- package/source/js/_app/page/tab.ts +60 -0
- package/source/js/_app/pjax/domInit.ts +96 -0
- package/source/js/_app/pjax/refresh.ts +78 -0
- package/source/js/_app/pjax/siteInit.ts +72 -0
- package/source/js/_app/player.ts +799 -0
- package/source/assets/beian.webp +0 -0
- package/source/js/_app/components/sidebar.js +0 -209
- package/source/js/_app/fireworks.js +0 -10
- package/source/js/_app/globals/globalVars.js +0 -80
- package/source/js/_app/globals/handles.js +0 -98
- package/source/js/_app/globals/themeColor.js +0 -62
- package/source/js/_app/globals/thirdparty.js +0 -62
- package/source/js/_app/globals/tools.js +0 -66
- package/source/js/_app/library/anime.js +0 -106
- package/source/js/_app/library/dom.js +0 -34
- package/source/js/_app/library/loadFile.js +0 -36
- package/source/js/_app/library/proto.js +0 -163
- package/source/js/_app/library/scriptPjax.js +0 -70
- package/source/js/_app/library/storage.js +0 -12
- package/source/js/_app/library/vue.js +0 -53
- package/source/js/_app/page/comment.js +0 -23
- package/source/js/_app/page/common.js +0 -41
- package/source/js/_app/page/fancybox.js +0 -65
- package/source/js/_app/page/post.js +0 -244
- package/source/js/_app/page/search.js +0 -118
- package/source/js/_app/page/tab.js +0 -53
- package/source/js/_app/pjax/domInit.js +0 -76
- package/source/js/_app/pjax/refresh.js +0 -52
- package/source/js/_app/pjax/siteInit.js +0 -51
- package/source/js/_app/player.js +0 -771
@@ -0,0 +1,266 @@
|
|
1
|
+
import { $dom } from '../library/dom'
|
2
|
+
import { postFancybox } from './fancybox'
|
3
|
+
import { clipBoard, showtip } from '../globals/tools'
|
4
|
+
import { BODY } from '../globals/globalVars'
|
5
|
+
import { pageScroll, transition } from '../library/anime'
|
6
|
+
import { mediaPlayer } from '../player'
|
7
|
+
import { getDisplay, setDisplay, wrapObject } from '../library/proto'
|
8
|
+
|
9
|
+
export const postBeauty = () => {
|
10
|
+
if (!$dom('.md')) { return }
|
11
|
+
|
12
|
+
if (__shokax_fancybox__) {
|
13
|
+
postFancybox('.post.block')
|
14
|
+
}
|
15
|
+
|
16
|
+
$dom('.post.block').oncopy = (event) => {
|
17
|
+
showtip(LOCAL.copyright)
|
18
|
+
|
19
|
+
if (LOCAL.nocopy) {
|
20
|
+
event.preventDefault()
|
21
|
+
return
|
22
|
+
}
|
23
|
+
|
24
|
+
const copyright = $dom('#copyright')
|
25
|
+
if (window.getSelection().toString().length > 30 && copyright) {
|
26
|
+
event.preventDefault()
|
27
|
+
const author = '# ' + copyright.child('.author').innerText
|
28
|
+
const link = '# ' + copyright.child('.link').innerText
|
29
|
+
const license = '# ' + copyright.child('.license').innerText
|
30
|
+
const htmlData = author + '<br>' + link + '<br>' + license + '<br><br>' + window.getSelection().toString().replace(/\r\n/g, '<br>')
|
31
|
+
|
32
|
+
const textData = author + '\n' + link + '\n' + license + '\n\n' + window.getSelection().toString().replace(/\r\n/g, '\n')
|
33
|
+
if (event.clipboardData) {
|
34
|
+
event.clipboardData.setData('text/html', htmlData)
|
35
|
+
event.clipboardData.setData('text/plain', textData)
|
36
|
+
} else {
|
37
|
+
// @ts-ignore
|
38
|
+
if (window.clipboardData) {
|
39
|
+
// @ts-ignore
|
40
|
+
return window.clipboardData.setData('text', textData)
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
$dom.each('li ruby', (element) => {
|
47
|
+
let parent = element.parentNode
|
48
|
+
// @ts-ignore
|
49
|
+
if (element.parentNode.tagName !== 'LI') {
|
50
|
+
parent = element.parentNode.parentNode
|
51
|
+
}
|
52
|
+
parent.addClass('ruby')
|
53
|
+
})
|
54
|
+
|
55
|
+
$dom.each('ol[start]', (element) => {
|
56
|
+
// @ts-ignore
|
57
|
+
element.style.counterReset = 'counter ' + parseInt(element.getAttribute('start') - 1)
|
58
|
+
})
|
59
|
+
|
60
|
+
$dom.each('.md table', (element) => {
|
61
|
+
wrapObject(element, {
|
62
|
+
className: 'table-container'
|
63
|
+
})
|
64
|
+
})
|
65
|
+
|
66
|
+
$dom.each('.highlight > .table-container', (element) => {
|
67
|
+
element.className = 'code-container'
|
68
|
+
})
|
69
|
+
|
70
|
+
$dom.each('figure.highlight', (element) => {
|
71
|
+
const code_container = element.child('.code-container')
|
72
|
+
const caption = element.child('figcaption')
|
73
|
+
|
74
|
+
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>')
|
75
|
+
|
76
|
+
const copyBtn = element.child('.copy-btn')
|
77
|
+
if (LOCAL.nocopy) {
|
78
|
+
copyBtn.remove()
|
79
|
+
} else {
|
80
|
+
copyBtn.addEventListener('click', (event) => {
|
81
|
+
const target = <HTMLElement>event.currentTarget
|
82
|
+
let comma = ''; let code = ''
|
83
|
+
code_container.find('pre').forEach((line) => {
|
84
|
+
code += comma + line.innerText
|
85
|
+
comma = '\n'
|
86
|
+
})
|
87
|
+
|
88
|
+
clipBoard(code, (result) => {
|
89
|
+
target.child('.ic').className = result ? 'ic i-check' : 'ic i-times'
|
90
|
+
target.blur()
|
91
|
+
showtip(LOCAL.copyright)
|
92
|
+
})
|
93
|
+
}, { passive: true })
|
94
|
+
copyBtn.addEventListener('mouseleave', (event) => {
|
95
|
+
setTimeout(() => {
|
96
|
+
event.target.child('.ic').className = 'ic i-clipboard'
|
97
|
+
}, 1000)
|
98
|
+
})
|
99
|
+
}
|
100
|
+
|
101
|
+
const breakBtn = element.child('.breakline-btn')
|
102
|
+
breakBtn.addEventListener('click', (event) => {
|
103
|
+
const target = event.currentTarget
|
104
|
+
if (element.hasClass('breakline')) {
|
105
|
+
element.removeClass('breakline')
|
106
|
+
target.child('.ic').className = 'ic i-align-left'
|
107
|
+
} else {
|
108
|
+
element.addClass('breakline')
|
109
|
+
target.child('.ic').className = 'ic i-align-justify'
|
110
|
+
}
|
111
|
+
})
|
112
|
+
|
113
|
+
const fullscreenBtn = element.child('.fullscreen-btn')
|
114
|
+
const removeFullscreen = () => {
|
115
|
+
element.removeClass('fullscreen')
|
116
|
+
element.scrollTop = 0
|
117
|
+
BODY.removeClass('fullscreen')
|
118
|
+
fullscreenBtn.child('.ic').className = 'ic i-expand'
|
119
|
+
}
|
120
|
+
const fullscreenHandle = () => {
|
121
|
+
if (element.hasClass('fullscreen')) {
|
122
|
+
removeFullscreen()
|
123
|
+
if (code_container && code_container.find('tr').length > 15) {
|
124
|
+
const showBtn = code_container.child('.show-btn')
|
125
|
+
code_container.style.maxHeight = '300px'
|
126
|
+
showBtn.removeClass('open')
|
127
|
+
}
|
128
|
+
pageScroll(element)
|
129
|
+
} else {
|
130
|
+
element.addClass('fullscreen')
|
131
|
+
BODY.addClass('fullscreen')
|
132
|
+
fullscreenBtn.child('.ic').className = 'ic i-compress'
|
133
|
+
if (code_container && code_container.find('tr').length > 15) {
|
134
|
+
const showBtn = code_container.child('.show-btn')
|
135
|
+
code_container.style.maxHeight = ''
|
136
|
+
showBtn.addClass('open')
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
fullscreenBtn.addEventListener('click', fullscreenHandle)
|
141
|
+
caption && caption.addEventListener('click', fullscreenHandle)
|
142
|
+
|
143
|
+
if (code_container && code_container.find('tr').length > 15) {
|
144
|
+
code_container.style.maxHeight = '300px'
|
145
|
+
code_container.insertAdjacentHTML('beforeend', '<div class="show-btn"><i class="ic i-angle-down"></i></div>')
|
146
|
+
const showBtn = code_container.child('.show-btn')
|
147
|
+
|
148
|
+
const hideCode = () => {
|
149
|
+
code_container.style.maxHeight = '300px'
|
150
|
+
showBtn.removeClass('open')
|
151
|
+
}
|
152
|
+
const showCode = () => {
|
153
|
+
code_container.style.maxHeight = ''
|
154
|
+
showBtn.addClass('open')
|
155
|
+
}
|
156
|
+
|
157
|
+
showBtn.addEventListener('click', () => {
|
158
|
+
if (showBtn.hasClass('open')) {
|
159
|
+
removeFullscreen()
|
160
|
+
hideCode()
|
161
|
+
pageScroll(code_container)
|
162
|
+
} else {
|
163
|
+
showCode()
|
164
|
+
}
|
165
|
+
})
|
166
|
+
}
|
167
|
+
})
|
168
|
+
|
169
|
+
$dom.each('pre.mermaid > svg', (element) => {
|
170
|
+
const temp = <SVGAElement><unknown>element
|
171
|
+
temp.style.maxWidth = ''
|
172
|
+
})
|
173
|
+
|
174
|
+
$dom.each('.reward button', (element) => {
|
175
|
+
element.addEventListener('click', (event) => {
|
176
|
+
event.preventDefault()
|
177
|
+
const qr = $dom('#qr')
|
178
|
+
if (getDisplay(qr) === 'inline-flex') {
|
179
|
+
transition(qr, 0)
|
180
|
+
} else {
|
181
|
+
transition(qr, 1, () => {
|
182
|
+
setDisplay(qr, 'inline-flex')
|
183
|
+
}) // slideUpBigIn
|
184
|
+
}
|
185
|
+
})
|
186
|
+
})
|
187
|
+
|
188
|
+
// quiz
|
189
|
+
if (__shokax_quiz__) {
|
190
|
+
$dom.each('.quiz > ul.options li', (element) => {
|
191
|
+
element.addEventListener('click', () => {
|
192
|
+
if (element.hasClass('correct')) {
|
193
|
+
element.toggleClass('right')
|
194
|
+
element.parentNode.parentNode.addClass('show')
|
195
|
+
} else {
|
196
|
+
element.toggleClass('wrong')
|
197
|
+
}
|
198
|
+
})
|
199
|
+
})
|
200
|
+
|
201
|
+
$dom.each('.quiz > p', (element) => {
|
202
|
+
element.addEventListener('click', () => {
|
203
|
+
element.parentNode.toggleClass('show')
|
204
|
+
})
|
205
|
+
})
|
206
|
+
|
207
|
+
$dom.each('.quiz > p:first-child', (element) => {
|
208
|
+
const quiz = element.parentNode
|
209
|
+
let type = 'choice'
|
210
|
+
if (quiz.hasClass('true') || quiz.hasClass('false')) {
|
211
|
+
type = 'true_false'
|
212
|
+
}
|
213
|
+
if (quiz.hasClass('multi')) {
|
214
|
+
type = 'multiple'
|
215
|
+
}
|
216
|
+
if (quiz.hasClass('fill')) {
|
217
|
+
type = 'gap_fill'
|
218
|
+
}
|
219
|
+
if (quiz.hasClass('essay')) {
|
220
|
+
type = 'essay'
|
221
|
+
}
|
222
|
+
element.setAttribute('data-type', LOCAL.quiz[type])
|
223
|
+
})
|
224
|
+
|
225
|
+
$dom.each('.quiz .mistake', (element) => {
|
226
|
+
element.setAttribute('data-type', LOCAL.quiz.mistake)
|
227
|
+
})
|
228
|
+
}
|
229
|
+
|
230
|
+
$dom.each('div.tags a', (element) => {
|
231
|
+
element.className = ['primary', 'success', 'info', 'warning', 'danger'][Math.floor(Math.random() * 5)]
|
232
|
+
})
|
233
|
+
|
234
|
+
if (__shokax_player__) {
|
235
|
+
$dom.each('.md div.player', (element) => {
|
236
|
+
mediaPlayer(element, {
|
237
|
+
type: element.getAttribute('data-type'),
|
238
|
+
mode: 'order',
|
239
|
+
btns: []
|
240
|
+
}).player.load(JSON.parse(element.getAttribute('data-src'))).fetch()
|
241
|
+
})
|
242
|
+
}
|
243
|
+
|
244
|
+
const angleDown = document.querySelectorAll('.show-btn .i-angle-down')
|
245
|
+
if (angleDown.length) {
|
246
|
+
const io = new IntersectionObserver((entries) => {
|
247
|
+
entries.forEach(entry => {
|
248
|
+
if (entry.isIntersecting) {
|
249
|
+
angleDown.forEach(i => {
|
250
|
+
i.classList.remove('stop-animation')
|
251
|
+
})
|
252
|
+
} else {
|
253
|
+
angleDown.forEach(i => {
|
254
|
+
i.classList.add('stop-animation')
|
255
|
+
})
|
256
|
+
}
|
257
|
+
})
|
258
|
+
}, {
|
259
|
+
root: null,
|
260
|
+
threshold: 0.5
|
261
|
+
})
|
262
|
+
angleDown.forEach(i => {
|
263
|
+
io.observe(i)
|
264
|
+
})
|
265
|
+
}
|
266
|
+
}
|
@@ -0,0 +1,135 @@
|
|
1
|
+
import { BODY, CONFIG, setSiteSearch, siteSearch } from '../globals/globalVars'
|
2
|
+
import { transition } from '../library/anime'
|
3
|
+
import { $dom } from '../library/dom'
|
4
|
+
import { searchBox, configure, stats, hits, pagination } from 'instantsearch.js/es/widgets'
|
5
|
+
import type { HitHighlightResult } from 'instantsearch.js/es/types/results'
|
6
|
+
import instantsearch from 'instantsearch.js'
|
7
|
+
import algoliasearch from 'algoliasearch/lite'
|
8
|
+
import {createChild} from "../library/proto";
|
9
|
+
|
10
|
+
export function algoliaSearch (pjax) {
|
11
|
+
if (CONFIG.search === null) { return }
|
12
|
+
|
13
|
+
if (!siteSearch) {
|
14
|
+
setSiteSearch(createChild(BODY, 'div', {
|
15
|
+
id: 'search',
|
16
|
+
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>'
|
17
|
+
}))
|
18
|
+
}
|
19
|
+
|
20
|
+
const search = instantsearch({
|
21
|
+
indexName: CONFIG.search.indexName,
|
22
|
+
searchClient: algoliasearch(CONFIG.search.appID, CONFIG.search.apiKey),
|
23
|
+
// TODO 移除弃用函数
|
24
|
+
searchFunction (helper) {
|
25
|
+
const searchInput = $dom('.search-input') as HTMLInputElement
|
26
|
+
if (searchInput.value) {
|
27
|
+
helper.search()
|
28
|
+
}
|
29
|
+
}
|
30
|
+
})
|
31
|
+
|
32
|
+
search.on('render', () => {
|
33
|
+
pjax.refresh($dom('#search-hits'))
|
34
|
+
})
|
35
|
+
|
36
|
+
// Registering Widgets
|
37
|
+
search.addWidgets([
|
38
|
+
configure({
|
39
|
+
hitsPerPage: CONFIG.search.hits.per_page || 10
|
40
|
+
}),
|
41
|
+
|
42
|
+
searchBox({
|
43
|
+
container: '.search-input-container',
|
44
|
+
placeholder: LOCAL.search.placeholder,
|
45
|
+
// Hide default icons of algolia search
|
46
|
+
showReset: false,
|
47
|
+
showSubmit: false,
|
48
|
+
showLoadingIndicator: false,
|
49
|
+
cssClasses: {
|
50
|
+
input: 'search-input'
|
51
|
+
}
|
52
|
+
}),
|
53
|
+
|
54
|
+
stats({
|
55
|
+
container: '#search-stats',
|
56
|
+
templates: {
|
57
|
+
text (data) {
|
58
|
+
const stats = LOCAL.search.stats
|
59
|
+
.replace(/\$\{hits}/, data.nbHits.toString())
|
60
|
+
.replace(/\$\{time}/, data.processingTimeMS.toString())
|
61
|
+
return stats + '<span class="algolia-powered"></span><hr>'
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}),
|
65
|
+
|
66
|
+
hits({
|
67
|
+
container: '#search-hits',
|
68
|
+
templates: {
|
69
|
+
item (data) {
|
70
|
+
const cats = data.categories ? '<span>' + data.categories.join('<i class="ic i-angle-right"></i>') + '</span>' : ''
|
71
|
+
return '<a href="' + CONFIG.root + data.path + '">' + cats + (data._highlightResult.title as HitHighlightResult).value + '</a>'
|
72
|
+
},
|
73
|
+
empty (data) {
|
74
|
+
return '<div id="hits-empty">' +
|
75
|
+
LOCAL.search.empty.replace(/\$\{query}/, data.query) +
|
76
|
+
'</div>'
|
77
|
+
}
|
78
|
+
},
|
79
|
+
cssClasses: {
|
80
|
+
item: 'item'
|
81
|
+
}
|
82
|
+
}),
|
83
|
+
|
84
|
+
pagination({
|
85
|
+
container: '#search-pagination',
|
86
|
+
scrollTo: false,
|
87
|
+
showFirst: false,
|
88
|
+
showLast: false,
|
89
|
+
templates: {
|
90
|
+
first: '<i class="ic i-angle-double-left"></i>',
|
91
|
+
last: '<i class="ic i-angle-double-right"></i>',
|
92
|
+
previous: '<i class="ic i-angle-left"></i>',
|
93
|
+
next: '<i class="ic i-angle-right"></i>'
|
94
|
+
},
|
95
|
+
cssClasses: {
|
96
|
+
root: 'pagination',
|
97
|
+
item: 'pagination-item',
|
98
|
+
link: 'page-number',
|
99
|
+
selectedItem: 'current',
|
100
|
+
disabledItem: 'disabled-item'
|
101
|
+
}
|
102
|
+
})
|
103
|
+
])
|
104
|
+
|
105
|
+
search.start()
|
106
|
+
|
107
|
+
// Handle and trigger popup window
|
108
|
+
$dom.each('.search', (element) => {
|
109
|
+
element.addEventListener('click', () => {
|
110
|
+
document.body.style.overflow = 'hidden'
|
111
|
+
transition(siteSearch, 'shrinkIn', () => {
|
112
|
+
$dom('.search-input').focus()
|
113
|
+
}) // transition.shrinkIn
|
114
|
+
})
|
115
|
+
})
|
116
|
+
|
117
|
+
// Monitor main search box
|
118
|
+
const onPopupClose = () => {
|
119
|
+
document.body.style.overflow = ''
|
120
|
+
transition(siteSearch, 0) // "transition.shrinkOut"
|
121
|
+
}
|
122
|
+
|
123
|
+
siteSearch.addEventListener('click', (event) => {
|
124
|
+
if (event.target === siteSearch) {
|
125
|
+
onPopupClose()
|
126
|
+
}
|
127
|
+
})
|
128
|
+
$dom('.close-btn').addEventListener('click', onPopupClose)
|
129
|
+
window.addEventListener('pjax:success', onPopupClose)
|
130
|
+
window.addEventListener('keyup', (event) => {
|
131
|
+
if (event.key === 'Escape') {
|
132
|
+
onPopupClose()
|
133
|
+
}
|
134
|
+
})
|
135
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { pageScroll } from '../library/anime'
|
2
|
+
import { $dom } from '../library/dom'
|
3
|
+
import { createChild } from '../library/proto'
|
4
|
+
|
5
|
+
export const tabFormat = () => {
|
6
|
+
// tab
|
7
|
+
let first_tab:boolean
|
8
|
+
$dom.each('div.tab', (element) => {
|
9
|
+
if (element.getAttribute('data-ready')) { return }
|
10
|
+
|
11
|
+
const id = element.getAttribute('data-id')
|
12
|
+
const title = element.getAttribute('data-title')
|
13
|
+
let box = $dom('#' + id)
|
14
|
+
if (!box) {
|
15
|
+
box = document.createElement('div')
|
16
|
+
box.className = 'tabs'
|
17
|
+
box.id = id
|
18
|
+
box.innerHTML = '<div class="show-btn"></div>'
|
19
|
+
|
20
|
+
const showBtn = box.child('.show-btn')
|
21
|
+
showBtn.addEventListener('click', () => {
|
22
|
+
pageScroll(box)
|
23
|
+
})
|
24
|
+
|
25
|
+
element.parentNode.insertBefore(box, element)
|
26
|
+
first_tab = true
|
27
|
+
} else {
|
28
|
+
first_tab = false
|
29
|
+
}
|
30
|
+
|
31
|
+
let ul = box.child('.nav ul')
|
32
|
+
if (!ul) {
|
33
|
+
ul = createChild(box, 'div', {
|
34
|
+
className: 'nav',
|
35
|
+
innerHTML: '<ul></ul>'
|
36
|
+
}).child('ul')
|
37
|
+
}
|
38
|
+
|
39
|
+
const li = createChild(ul, 'li', {
|
40
|
+
innerHTML: title
|
41
|
+
})
|
42
|
+
|
43
|
+
if (first_tab) {
|
44
|
+
li.addClass('active')
|
45
|
+
element.addClass('active')
|
46
|
+
}
|
47
|
+
|
48
|
+
li.addEventListener('click', (event) => {
|
49
|
+
const target = event.currentTarget
|
50
|
+
box.find('.active').forEach((el) => {
|
51
|
+
el.removeClass('active')
|
52
|
+
})
|
53
|
+
element.addClass('active')
|
54
|
+
target.addClass('active')
|
55
|
+
})
|
56
|
+
|
57
|
+
box.appendChild(element)
|
58
|
+
element.setAttribute('data-ready', String(true))
|
59
|
+
})
|
60
|
+
}
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import { backToTopHandle, goToBottomHandle, goToCommentHandle, sideBarToggleHandle } from '../components/sidebar'
|
2
|
+
import {
|
3
|
+
backToTop,
|
4
|
+
goToComment,
|
5
|
+
loadCat,
|
6
|
+
menuToggle,
|
7
|
+
quickBtn, setBackToTop, setGoToComment, setShowContents, setToolBtn,
|
8
|
+
setToolPlayer,
|
9
|
+
showContents,
|
10
|
+
siteHeader,
|
11
|
+
siteNav,
|
12
|
+
toolBtn,
|
13
|
+
toolPlayer
|
14
|
+
} from '../globals/globalVars'
|
15
|
+
import { Loader } from '../globals/thirdparty'
|
16
|
+
import { $dom } from '../library/dom'
|
17
|
+
import { mediaPlayer } from '../player'
|
18
|
+
import { child, createChild } from '../library/proto'
|
19
|
+
|
20
|
+
export default function domInit () {
|
21
|
+
$dom.each('.overview .menu > .item', (el) => {
|
22
|
+
child(siteNav, '.menu').appendChild(el.cloneNode(true))
|
23
|
+
})
|
24
|
+
|
25
|
+
loadCat.addEventListener('click', Loader.vanish)
|
26
|
+
menuToggle.addEventListener('click', sideBarToggleHandle)
|
27
|
+
$dom('.dimmer').addEventListener('click', sideBarToggleHandle)
|
28
|
+
|
29
|
+
child(quickBtn, '.down').addEventListener('click', goToBottomHandle)
|
30
|
+
child(quickBtn, '.up').addEventListener('click', backToTopHandle)
|
31
|
+
|
32
|
+
if (!toolBtn) {
|
33
|
+
setToolBtn(createChild(siteHeader, 'div', {
|
34
|
+
id: 'tool',
|
35
|
+
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>'
|
36
|
+
}))
|
37
|
+
}
|
38
|
+
|
39
|
+
setToolPlayer(toolBtn.child('.player'))
|
40
|
+
setBackToTop(toolBtn.child('.back-to-top'))
|
41
|
+
setGoToComment(toolBtn.child('.chat'))
|
42
|
+
setShowContents(toolBtn.child('.contents'))
|
43
|
+
|
44
|
+
backToTop.addEventListener('click', backToTopHandle)
|
45
|
+
goToComment.addEventListener('click', goToCommentHandle)
|
46
|
+
showContents.addEventListener('click', sideBarToggleHandle)
|
47
|
+
|
48
|
+
if (__shokax_player__) {
|
49
|
+
mediaPlayer(toolPlayer)
|
50
|
+
|
51
|
+
$dom('main').addEventListener('click', () => {
|
52
|
+
toolPlayer.player.mini()
|
53
|
+
})
|
54
|
+
}
|
55
|
+
|
56
|
+
const createIntersectionObserver = () => {
|
57
|
+
// waves在视口外时停止动画
|
58
|
+
new IntersectionObserver(([entry]) => {
|
59
|
+
if (entry.isIntersecting) {
|
60
|
+
document.querySelectorAll('.parallax>use').forEach(i => {
|
61
|
+
i.classList.remove('stop-animation')
|
62
|
+
})
|
63
|
+
document.querySelectorAll('#imgs .item').forEach(i => {
|
64
|
+
i.classList.remove('stop-animation')
|
65
|
+
})
|
66
|
+
} else {
|
67
|
+
document.querySelectorAll('.parallax>use').forEach(i => {
|
68
|
+
i.classList.add('stop-animation')
|
69
|
+
})
|
70
|
+
// waves不可见时imgs也应该不可见了
|
71
|
+
document.querySelectorAll('#imgs .item').forEach(i => {
|
72
|
+
i.classList.add('stop-animation')
|
73
|
+
})
|
74
|
+
}
|
75
|
+
}, {
|
76
|
+
root: null,
|
77
|
+
threshold: 0.2
|
78
|
+
}).observe(document.getElementById('waves'))
|
79
|
+
// sakura在视口外时停止动画
|
80
|
+
new IntersectionObserver(([entry]) => {
|
81
|
+
if (entry.isIntersecting) {
|
82
|
+
document.querySelectorAll('.with-love>i').forEach(i => {
|
83
|
+
i.classList.remove('stop-animation')
|
84
|
+
})
|
85
|
+
} else {
|
86
|
+
document.querySelectorAll('.with-love>i').forEach(i => {
|
87
|
+
i.classList.add('stop-animation')
|
88
|
+
})
|
89
|
+
}
|
90
|
+
}, {
|
91
|
+
root: null,
|
92
|
+
threshold: 0.2
|
93
|
+
}).observe(document.querySelector('.with-love'))
|
94
|
+
}
|
95
|
+
createIntersectionObserver()
|
96
|
+
}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import { $dom } from '../library/dom'
|
2
|
+
import { cardActive } from '../page/common'
|
3
|
+
import { pageScroll, transition } from '../library/anime'
|
4
|
+
import { vendorCss, vendorJs } from '../library/loadFile'
|
5
|
+
import { pjaxScript } from '../library/scriptPjax'
|
6
|
+
import { resizeHandle } from '../globals/handles'
|
7
|
+
import {
|
8
|
+
CONFIG,
|
9
|
+
loadCat,
|
10
|
+
menuToggle,
|
11
|
+
setLocalHash, setLocalUrl, setOriginTitle,
|
12
|
+
sideBar,
|
13
|
+
toolPlayer
|
14
|
+
} from '../globals/globalVars'
|
15
|
+
import { pagePosition, positionInit } from '../globals/tools'
|
16
|
+
import { menuActive, sideBarTab, sidebarTOC } from '../components/sidebar'
|
17
|
+
import { Loader, isOutime } from '../globals/thirdparty'
|
18
|
+
import { tabFormat } from '../page/tab'
|
19
|
+
|
20
|
+
export const pjaxReload = () => {
|
21
|
+
pagePosition()
|
22
|
+
|
23
|
+
if (sideBar.hasClass('on')) {
|
24
|
+
transition(sideBar, 0, () => {
|
25
|
+
sideBar.removeClass('on')
|
26
|
+
menuToggle.removeClass('close')
|
27
|
+
}) // 'transition.slideRightOut'
|
28
|
+
}
|
29
|
+
const mainNode = $dom('#main')
|
30
|
+
mainNode.innerHTML = ''
|
31
|
+
mainNode.appendChild(loadCat.lastChild.cloneNode(true))
|
32
|
+
pageScroll(0)
|
33
|
+
}
|
34
|
+
|
35
|
+
export const siteRefresh = (reload) => {
|
36
|
+
setLocalHash(0)
|
37
|
+
setLocalUrl(window.location.href)
|
38
|
+
|
39
|
+
vendorCss('katex')
|
40
|
+
vendorJs('copy_tex')
|
41
|
+
vendorCss('mermaid')
|
42
|
+
|
43
|
+
if (reload !== 1) {
|
44
|
+
$dom.each('script[data-pjax]', pjaxScript)
|
45
|
+
}
|
46
|
+
|
47
|
+
setOriginTitle(document.title)
|
48
|
+
|
49
|
+
resizeHandle()
|
50
|
+
|
51
|
+
menuActive()
|
52
|
+
|
53
|
+
sideBarTab()
|
54
|
+
sidebarTOC()
|
55
|
+
|
56
|
+
import('../page/post').then(({ postBeauty }) => {
|
57
|
+
postBeauty()
|
58
|
+
})
|
59
|
+
|
60
|
+
if (__shokax_tabs__) {
|
61
|
+
tabFormat()
|
62
|
+
}
|
63
|
+
|
64
|
+
if (__shokax_player__) {
|
65
|
+
toolPlayer.player.load(LOCAL.audio || CONFIG.audio || {})
|
66
|
+
}
|
67
|
+
Loader.hide()
|
68
|
+
|
69
|
+
setTimeout(() => {
|
70
|
+
positionInit()
|
71
|
+
}, 500)
|
72
|
+
|
73
|
+
cardActive()
|
74
|
+
|
75
|
+
if (__shokax_outime__) {
|
76
|
+
isOutime()
|
77
|
+
}
|
78
|
+
}
|