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
|
/* Add stylesheet to page */
var presStyle = document.createElement('link');
presStyle.type = 'text/css';
presStyle.rel = 'stylesheet';
presStyle.href = '/presentation.css';
document.head.appendChild(presStyle);
/* Print button */
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;
// Shows the "slideIndex + mod" numbered slide
function showSlide(mod) {
if (!presenting) return;
slides[slideIndex].classList.remove('absolute-slide');
slideIndex = (slides.length + slideIndex + mod) % slides.length;
slides[slideIndex].classList.add('absolute-slide');
slideIndexShow.innerText = slideIndex;
slideIndexShow.href = '#slide-' + slideIndex;
}
prevSlideBtn.addEventListener('click', function() {
showSlide(-1);
});
nextSlideBtn.addEventListener('click', function() {
showSlide(+1);
});
/* Present button */
const presentCont = document.getElementById('presentCont');
const presentBtn = document.getElementById('presentBtn');
const articleBtn = document.getElementById('articleBtn');
var pageY = 0;
var pageX = 0;
presentBtn.addEventListener('click', function() {
// 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');
prevSlideBtn.classList.toggle('nodisplay');
slideIndexShow.classList.toggle('nodisplay');
nextSlideBtn.classList.toggle('nodisplay');
articleBtn.classList.toggle('nodisplay');
printBtn.classList.toggle('nodisplay');
// 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();
});
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
document.styleSheets.item(3).cssRules[0].style.transform = 'scale(' + scale + ')';
document.styleSheets.item(3).cssRules[0].style.marginBottom = 'calc(1em - ' + slides[0].offsetHeight + 'px * ' + (1 - scale) + ')';
// Update .absolute-slide
document.styleSheets.item(3).cssRules[1].style.transform = 'translate(-50%, -50%) scale(' + scale + ')';
// Update .clicked-image
document.styleSheets.item(3).cssRules[2].style.transform = 'translate(-50%, -50%) scale(' + (1/scale) + ')';
}
window.addEventListener('resize', fixAbsoluteSlideScale);
window.addEventListener('load', fixAbsoluteSlideScale);
/* Show as article button */
articleBtn.addEventListener('click', function() {
printBtn.classList.toggle('nodisplay');
presentBtn.classList.toggle('nodisplay');
// Toggle presentation.css
document.styleSheets.item(3).disabled = !document.styleSheets.item(3).disabled;
});
|