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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/* Print button */
presentationStyle.cssRules[presentationStyle.cssRules.length - 1]
.insertRule("article, body { border: none !important; margin: 0; max-width: none; padding: 0; }");
presentationStyle.cssRules[presentationStyle.cssRules.length - 1]
.insertRule("nav, #article-container > :not(.slide), #pagenav { display: none !important; }");
presentationStyle.cssRules[presentationStyle.cssRules.length - 1]
.insertRule(".slide { height: 210mm; width: 297mm; margin: 0; }");
const printBtn = document.getElementById('printBtn');
printBtn.addEventListener('click', function() {
window.print();
});
/* Next and previous buttons */
const prevSlideBtn = document.getElementById('prevSlideBtn');
const slideIndexShow = document.getElementById('slideIndex');
const nextSlideBtn = document.getElementById('nextSlideBtn');
const slides = document.getElementsByClassName('slide');
var presenting = false;
var slideIndex = parseInt(document.URL.substr(document.URL.indexOf("#slide") + 7));
if (isNaN(slideIndex)) slideIndex = 0;
slideIndexShow.innerText = slideIndex;
slideIndexShow.href = '#slide-' + slideIndex;
var liIncrement = [];
var liCurrent = 0;
function resetIncrementation() {
liCurrent = 0;
liIncrement.forEach((li, i) => li.classList.remove('invisible-present'));
liIncrement = [];
}
// Shows the "slideIndex + mod" numbered slide
function showSlide(mod) {
if (!presenting) return;
if (incrementationMode) {
if (mod > 0 && liIncrement.length > 0 && liCurrent < liIncrement.length) {
liIncrement[liCurrent++].classList.remove('invisible-present');
return;
}
else if (mod < 0) {
resetIncrementation();
}
}
slides[slideIndex].classList.remove('absolute-slide');
slideIndex = (slides.length + slideIndex + mod) % slides.length;
slides[slideIndex].classList.add('absolute-slide');
if (incrementationMode && mod > 0) {
liCurrent = 0;
liIncrement = slides[slideIndex].querySelectorAll('li, dt, dd');
liIncrement.forEach((li, i) => li.classList.add('invisible-present'));
}
slideIndexShow.innerText = slideIndex;
slideIndexShow.href = '#slide-' + slideIndex;
}
prevSlideBtn.addEventListener('click', function() {
showSlide(-1);
});
nextSlideBtn.addEventListener('click', function() {
showSlide(+1);
});
/* Incrementation button */
const incrementationBtn = document.getElementById('incrementationBtn');
var incrementationMode = false;
function updateIncrementationMode() {
incrementationMode = !incrementationMode;
if (incrementationMode)
incrementationBtn.innerText = '⋱';
else
incrementationBtn.innerText = '⋮';
resetIncrementation();
}
incrementationBtn.addEventListener('click', updateIncrementationMode);
/* Present button */
const presentCont = document.getElementById('presentCont');
const presentBtn = document.getElementById('presentBtn');
const articleBtn = document.getElementById('articleBtn');
var pageY = 0;
var pageX = 0;
function togglePresentMode() {
if (presentationStyle.disabled) return;
// Hide the whole page
document.body.classList.toggle('invisible');
document.body.classList.toggle('no-overflow');
// Fix background color
document.body.classList.toggle('body-bg-color');
// Show the slide controller
presentCont.classList.toggle('absolute-cont');
for (var i = presentCont.children.length - 1; i >= 0; i--) {
if (i == 5) continue; // presentBtn
presentCont.children[i].classList.toggle('nodisplay');
}
presentBtn.classList.toggle('setting-btn');
if (presentBtn.innerText[0] === 'P') {
presentBtn.innerText = presentBtn.innerText.substr(8);
} else {
presentBtn.innerText = 'Present ' + presentBtn.innerText;
}
// Show the first slide
slides[slideIndex].classList.toggle('absolute-slide');
// Alignment of presentation to screen
if (presenting) {
window.scrollTo(pageX, pageY);
}
else {
pageY = window.scrollY; pageX = window.scrollX;
window.scrollTo(0, 0);
}
presenting = !presenting;
fixAbsoluteSlideScale();
}
presentBtn.addEventListener('click', togglePresentMode);
function fixAbsoluteSlideScale() {
var height = (presenting) ? window.innerHeight : articleElem.offsetHeight;
var width = (presenting) ? window.innerWidth : articleElem.offsetWidth - 32;
var scale = Math.min(height / slides[0].offsetHeight, width / slides[0].offsetWidth);
// Update .slide
presentationStyle.cssRules[0].style.transform = 'scale(' + scale + ')';
presentationStyle.cssRules[0].style.marginBottom = 'calc(1em - ' + slides[0].offsetHeight + 'px * ' + (1 - scale) + ')';
// Update .absolute-slide
presentationStyle.cssRules[1].style.transform = 'translate(-50%, -50%) scale(' + scale + ')';
// Update .clicked-image
presentationStyle.cssRules[2].style.transform = 'translate(-50%, -50%) scale(' + (1/scale) + ')';
}
function resizeCallback() {
let article = document.getElementsByTagName('article')[0];
if (article)
new ResizeObserver(fixAbsoluteSlideScale).observe(article);
else
setTimeout(resizeCallback, 0.1);
}
resizeCallback();
/* Show as article button */
function togglePresentationController() {
printBtn.classList.toggle('nodisplay');
presentBtn.classList.toggle('nodisplay');
// Fix message
if (articleBtn.innerText[3] === 'a')
articleBtn.innerText = 'As slides ☲';
else
articleBtn.innerText = 'As article ☲';
}
function toggleArticleMode() {
// Toggle presentation.css
presentationStyle.disabled = !presentationStyle.disabled;
// Add or remove "a" to url when in or not in article mode
var href = window.location.href;
var indqa = href.indexOf('?a');
if (presentationStyle.disabled && indqa == -1) {
var indquery = href.indexOf('?');
if (indquery < 0) {
var indend = Math.max(href.lastIndexOf('/'), href.indexOf('.html') + 4);
href = href.slice(0, indend + 1) + '?a' + href.slice(indend + 1);
}
else {
href = href.slice(0, indquery + 1) + 'a' + href.slice(indquery + 1);
}
}
else if (!presentationStyle.disabled && indqa > -1) {
href = href.slice(0, indqa) + href.slice(indqa + 2);
}
window.history.replaceState(history.state, document.title, href);
togglePresentationController();
fixAbsoluteSlideScale();
}
articleBtn.addEventListener('click', toggleArticleMode);
if (presentationStyle.disabled)
togglePresentationController();
|