summaryrefslogtreecommitdiff
path: root/html/slideshow.js
diff options
context:
space:
mode:
authorpdp8 <pdp8@pdp8.info>2024-07-28 09:44:00 +0200
committerpdp8 <pdp8@pdp8.info>2024-07-28 09:44:00 +0200
commitd987641d7b68fcfa8431b1835411bb1095a37961 (patch)
tree3fbc5e18a16ea0003adace63b1bdb0ea7521f1e7 /html/slideshow.js
parentd13dc919f9fe0e14e8b58ec2e6ce727a6bbc1621 (diff)
image albums, flex layout
Diffstat (limited to 'html/slideshow.js')
-rw-r--r--html/slideshow.js80
1 files changed, 0 insertions, 80 deletions
diff --git a/html/slideshow.js b/html/slideshow.js
deleted file mode 100644
index 48a5395..0000000
--- a/html/slideshow.js
+++ /dev/null
@@ -1,80 +0,0 @@
-selection = []
-visited = []
-current = 0
-playing = 1
-
-document.addEventListener('keyup', function(event) {
- if(event.keyCode == 37) { prev() } // left
- else if(event.keyCode == 39) { next() } // right
- else if(event.keyCode == 32) {
- toggle_play()
- } // space
- else if(event.keyCode == 13) { new_selection() } // enter
-});
-
-function new_selection() {
- images = Object.keys(distances)
- start = images[Math.floor(Math.random()*images.length)]
- sortable = []
- for (file in distances[start]) {
- if (visited.indexOf(file) == -1) { // not in visited
- sortable.push([file,distances[start][file]]) // objects cannot be sorted in js, use array instead
- }
- }
- n = 6
- selection = []
- sorted = sortable.sort(function(a, b) { return a[1] - b[1]; }).slice(0,n); // sort by distance, get first n elements
- sorted.forEach(function(img,index) {
- selection.push(img[0])
- visited.push(img[0])
- })
- selection = selection.sort(() => Math.random() - 0.5); // shuffle
- current = 0
- update()
-}
-
-function src(id,path) { document.getElementById(id).src = path }
-function onclick(id,fun) { document.getElementById(id).onclick = fun }
-
-function hide_controls() {
- document.getElementById("prev").style.display = "none"
- document.getElementById("next").style.display = "none"
-}
-
-function show_controls() {
- document.getElementById("prev").style.display = "block"
- document.getElementById("next").style.display = "block"
-}
-
-function toggle_play() { playing == 1 ? stop() : play() }
-
-function play() {
- playing = 1
- interval = setInterval(function () { next() }, 3000);
- document.getElementById("play-indicator").title = "Pause slideshow"
- document.getElementById("play-indicator").className = "fa fa-inverse fa-pause"
- hide_controls()
-}
-
-function stop() {
- playing = 0
- clearInterval(interval)
- document.getElementById("play-indicator").title = "Play slideshow"
- document.getElementById("play-indicator").className = "fa fa-inverse fa-play"
- show_controls()
-}
-
-function prev() {
- current = (current-1+selection.length) % selection.length // js % cannot handle negative values
- update()
-}
-
-function next() {
- current = (current+1) % selection.length
- update()
-}
-
-function update() {
- src('image',"https://media.pdp8.info/pictures/"+selection[current])
-}
-