1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
<script>
// toggle theme
function toggleTheme() {
$('body').attr('data-theme', (index, attr) => {
if (attr === 'light') {
localStorage.setItem('fuji_theme', 'dark');
return 'dark';
} else {
localStorage.setItem('fuji_theme', 'light');
return 'light';
}
});
}
// update medium-zoom theme
// @params fujiTheme, mediumEvent
function updateMeidumTheme(fujiTheme, mediumEvent) {
if (fujiTheme && mediumEvent) {
mediumEvent.detach();
let mediumTheme;
if (fujiTheme === 'dark') {
mediumTheme = '#2f3136';
} else {
mediumTheme = '#fffffd';
}
mediumEvent = mediumZoom('.img-zoomable', {
background: mediumTheme
});
}
}
// update utterances theme
// @params fujiTheme, utterancesFrame
function updateUtterancesTheme(fujiTheme, utterancesFrame) {
if (fujiTheme && utterancesFrame) {
let ifMessage;
if (fujiTheme === 'dark') {
ifMessage = {
type: 'set-theme',
theme: 'photon-dark'
};
} else {
ifMessage = {
type: 'set-theme',
theme: 'github-light'
};
}
utterancesFrame.contentWindow.postMessage(ifMessage, 'https://utteranc.es');
}
}
</script>
<script>
// toc anchors & to-top button
$('.btn .btn-scroll-top').on('click', () => {
$('html, body').animate({
scrollTop: 0,
});
});
$('.sidebar-toc a').on('click', (event) => {
$('html, body').animate({
scrollTop: $($(event.currentTarget).attr('href')).offset().top
});
});
// init medium-zoom
var mediumTheme;
if ($('body').attr('data-theme') === 'dark') {
mediumTheme = '#2f3136';
} else {
mediumTheme = '#fffffd';
}
var mediumEvent = mediumZoom('.img-zoomable', {
background: mediumTheme
});
hljs.initHighlightingOnLoad();
// remove empty ul in toc if article only have ## and ###
if ($('.sidebar-toc ul ul').length > 0 && $('.sidebar-toc ul ul li').text() === '') {
$('.sidebar-toc ul ul').hide();
}
// init highlight.js
hljs.initHighlighting();
</script>
{{ if and (and (ne .Params.noComments true) (.IsPage)) (.Site.Params.utterancesRepo) }}
<script>
// utterances comment loading indicator
var commentStatus; // utterence status
var commentLoadingTime = 0; // loading time passed
var commentCheckInterval = self.setInterval(checkUtterances, 500);
function checkUtterances() {
commentStatus = $('.post-comment .utterances').attr('style');
if (commentStatus) {
clearInterval(commentCheckInterval);
updateUtterancesTheme($('body').attr('data-theme'), $('.post-comment iframe')[0])
$('.post-loading').hide();
} else {
if (++commentLoadingTime > 20) {
clearInterval(commentCheckInterval);
$('.post-comment').hide();
$('.post-loading p').text('{{ i18n "postCommentLoadingFailed" }}');
$('.post-loading i').attr('class', 'far fa-times-circle');
}
}
}
// theme switch button
$('.btn .btn-toggle-mode').on('click', () => {
// toggle theme
toggleTheme();
// update medium background
updateMeidumTheme($('body').attr('data-theme'), mediumEvent);
// update utterances theme if available
if (commentStatus) {
updateUtterancesTheme($('body').attr('data-theme'), $('.post-comment iframe')[0]);
}
});
</script>
{{ else if and (and (ne .Params.noComments true) (.IsPage)) (.Site.Params.disqusShortname) }}
<script>
// theme switch button
$('.btn .btn-toggle-mode').on('click', () => {
// toggle theme
toggleTheme();
// update medium background
updateMeidumTheme($('body').attr('data-theme'), mediumEvent);
// update disqus theme if available
if (DISQUS) {
DISQUS.reset({
reload: true
});
}
});
</script>
{{ else }}
<script>
// theme switch button
$('.btn .btn-toggle-mode').on('click', () => {
// toggle theme
toggleTheme();
// update medium background
updateMeidumTheme($('body').attr('data-theme'), mediumEvent);
});
</script>
{{ end }}
{{ with .Params.playerURL }}
<script>
// in-post aplayer
var aPlayer = new APlayer({
container: document.getElementById('post-aplayer'),
theme: '#8f82bc',
volume: 0.1,
audio: [{
name: '{{ $.Params.playerName }}',
artist: '{{ $.Params.playerArtist }}',
url: '{{ . }}',
cover: '{{ $.Params.playerCover }}'
}]
});
</script>
{{ end }}
|