aboutsummaryrefslogtreecommitdiff
path: root/slides/vendor/slides.js
blob: a909352d9e8e2ae62e4c37d9e2bad0d290797d5e (plain)
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
window.addEventListener('load', function(evt) {

	let main = document.querySelector('main');
	let nav = document.querySelector('nav');
	let wrapper = document.querySelector('div.wrapper');
	let hash = window.location.hash.slice(1, window.location.hash.length);

	if (hash.length == 0) {
		main.innerHTML = '<h1>No presentation selected!</h1>';
	} else {

		fetch(`presentations/${hash}/default.pug`).then(function(response) {
			response.text().then(function(template) {
				if (response.status == 200) {
					main.innerHTML = jade.render(template, {});
					initSlideshow();
				} else {
					main.innerHTML = '<section><h3>Presentation does not exists!</h3></section>';
				}
			}).catch(function(error) {
				console.log(error);
			});
		});

		fetch(`presentations/${hash}/meta.json`).then(function(response) {
			response.json().then(function(data) {
				document.title = data.title;
			}).catch(function(error) {
				console.log(error);
			});
		});

	}

	function initSlideshow() {

		// mathjax formulas
		MathJax.Hub.Config({
			//displayAlign: 'left',
			extensions: ['tex2jax.js'],
			jax: ['input/TeX', 'output/SVG'],
			tex2jax: {
				skipTags: ['script', 'noscript', 'style', 'textarea', 'code'],
				inlineMath: [
					['$', '$'],
					["\\(", "\\)"]
				],
				displayMath: [
					['$$', '$$'],
					["\\[", "\\]"]
				],
			}
		});
		MathJax.Hub.Configured();

		// syntax highlighting
		Prism.highlightAll();

		// initializes slides
		function showSlide(slides, op) {
			let tmpIdx = currentIdx + op;
			if (tmpIdx >= 0 && tmpIdx < slides.length) {
				slides.forEach(function(slide) {
					slide.classList.add('hide');
				});
				slides[tmpIdx].classList.remove('hide');
				nav.innerHTML = `${tmpIdx+1} / ${slides.length}`;
				currentIdx = tmpIdx;
			}
		}

		let slides = document.querySelectorAll('section');
		let currentIdx = 0;
		showSlide(slides, currentIdx);

		document.addEventListener('keydown', function(evt) {
			switch (evt.code) {
				case 'ArrowRight':
					{
						showSlide(slides, 1);
						break;
					}
				case 'ArrowLeft':
					{
						showSlide(slides, -1);
						break;
					}
				case 'KeyF':
					{
						if (wrapper.requestFullscreen) {
							wrapper.requestFullscreen();
						} else if (wrapper.mozRequestFullScreen) {
							wrapper.mozRequestFullScreen();
						} else if (wrapper.webkitRequestFullscreen) {
							wrapper.webkitRequestFullscreen();
						} else if (wrapper.msRequestFullscreen) {
							wrapper.msRequestFullscreen();
						}
						break;
					}
			}
		}, false);


		//var elem = document.getElementById("myvideo");
		//if (elem.requestFullscreen) {
		//	elem.requestFullscreen();
		//}

	}

}, false);