-
Notifications
You must be signed in to change notification settings - Fork 0
/
00_slideshow.html
118 lines (108 loc) · 2.4 KB
/
00_slideshow.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Slideshow</title>
<script>
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
var files = [
// List of files goes here
];
var index = 0;
var current = null;
var next = null;
var previous = null;
function nextIndex(i) {
++i;
if (i >= files.length) {
return 0;
}
return i;
}
function prevIndex(i) {
--i;
if (i == -1) {
return files.length - 1;
}
return i;
}
function createNode(filename) {
if (filename.endsWith(".mp4") || filename.endsWith(".webm")) {
var e = document.createElement("video");
e.src = filename;
e.load();
return e;
}
var e = document.createElement("img");
e.src = filename;
e.decode();
return e;
}
function showCurrent() {
document.body.replaceChild(current, document.body.firstChild);
if (current instanceof HTMLVideoElement) {
current.play();
}
}
function nextSlide() {
previous = current;
current = next;
index = nextIndex(index);
next = createNode(files[nextIndex(index)]);
showCurrent();
}
function prevSlide() {
next = current;
current = previous;
index = prevIndex(index);
previous = createNode(files[prevIndex(index)]);
showCurrent();
}
function boot() {
current = createNode(files[index]);
next = createNode(files[nextIndex(index)]);
previous = createNode(files[prevIndex(index)]);
showCurrent();
document.onkeydown = function (e) {
switch (e.key) {
case "Right":
case "ArrowRight":
case "Down":
case "ArrowDown":
case "Space":
case "PageDown":
nextSlide();
break;
case "Left":
case "ArrowLeft":
case "Up":
case "ArrowUp":
case "Backspace":
case "PageUp":
prevSlide();
break;
}
}
document.onmouseup = function (e) {
nextSlide();
}
}
</script>
<style>
* {
border: 0;
margin: 0;
padding: 0;
background-color: black;
object-fit: contain;
width: 100%;
height: 100%;
overflow: hidden;
}
</style>
</head>
<body onload="boot();">
</body>
</html>