Files
Claper/assets/js/presenter.js
Alex Lion dd5dd82daa Squashed commit of the following:
commit 7db48f592f
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri Jun 5 10:16:10 2026 +0200

    Update changelog

commit 3039b70edc
Author: Peter Rundqvist <47314226+pete1854@users.noreply.github.com>
Date:   Fri Jun 5 10:11:07 2026 +0200

    Add swedish translation (#228)

    * Initial translation

    * Initial error msg translation

    * Fixes suggested by Copilot.

    * Fixed spacing before ! and ?

    * Added missing provider translation.

    * Upddated translation for "Unpin"

    * Added missing Content-Type header.

commit d18e5d7c32
Author: fgallarday <fgallarday@users.noreply.github.com>
Date:   Fri Jun 5 03:07:25 2026 -0500

    Add PageUp and PageDown slide navigation support (#227)

commit 24e18c2764
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri Jun 5 10:06:54 2026 +0200

    Bump version to 2.5.2

commit d5df9a73f8
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri May 8 22:42:04 2026 +0200

    Fix form submissions losing values when field names contain spaces or non-word characters

commit 57596952d4
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri May 8 14:50:33 2026 +0200

    Update package-lock.json: add asset name, upgrade dependencies, and remove unused packages

commit e246530c23
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri May 8 14:34:53 2026 +0200

    Bump version to 2.5.1

commit 534d915782
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri May 8 10:55:38 2026 +0200

    Handle Ecto.NoResultsError in event retrieval and redirect with error message

commit b762e21325
Author: Alex Lion <dev@alexandrelion.com>
Date:   Fri May 8 10:47:01 2026 +0200

    Fix crash on event manager pages when an event has multiple activity leaders

commit 153cadb42b
Author: alxlion <dev@alexandrelion.com>
Date:   Wed Apr 29 13:42:05 2026 +0000

    Fix presentation views without slide count

commit 3cfb3cab7f
Author: alxlion <dev@alexandrelion.com>
Date:   Wed Apr 29 13:16:48 2026 +0000

    Fix event code normalization validation
2026-06-05 10:24:46 +02:00

198 lines
5.7 KiB
JavaScript

import { tns } from "tiny-slider";
export class Presenter {
constructor(context) {
this.context = context;
this.currentPage = parseInt(context.el.dataset.currentPage);
this.maxPage = parseInt(context.el.dataset.maxPage);
this.hash = context.el.dataset.hash;
}
init(refresh = false) {
this.slider = tns({
container: "#slider",
items: 1,
mode: "gallery",
slideBy: "page",
center: true,
autoplay: false,
controls: false,
swipeAngle: false,
startIndex: this.currentPage,
speed: 0,
loop: false,
nav: false,
});
if (refresh) {
return;
}
this.context.handleEvent("page", (data) => {
//set current page
if (this.currentPage == data.current_page) {
return;
}
this.currentPage = parseInt(data.current_page);
this.slider.goTo(data.current_page);
});
this.context.handleEvent("chat-visible", (data) => {
if (data.value) {
document
.getElementById("post-list")
.classList.remove("animate__animated", "animate__fadeOutLeft");
document
.getElementById("post-list")
.classList.add("animate__animated", "animate__fadeInLeft");
document
.getElementById("pinned-post-list")
.classList.remove("animate__animated", "animate__fadeOutLeft");
document
.getElementById("pinned-post-list")
.classList.add("animate__animated", "animate__fadeInLeft");
} else {
document
.getElementById("post-list")
.classList.remove("animate__animated", "animate__fadeInLeft");
document
.getElementById("post-list")
.classList.add("animate__animated", "animate__fadeOutLeft");
document
.getElementById("pinned-post-list")
.classList.remove("animate__animated", "animate__fadeInLeft");
document
.getElementById("pinned-post-list")
.classList.add("animate__animated", "animate__fadeOutLeft");
}
});
this.context.handleEvent("poll-visible", (data) => {
if (data.value) {
document
.getElementById("poll")
.classList.remove("animate__animated", "animate__fadeOut");
document
.getElementById("poll")
.classList.add("animate__animated", "animate__fadeIn");
} else {
document
.getElementById("poll")
.classList.remove("animate__animated", "animate__fadeIn");
document
.getElementById("poll")
.classList.add("animate__animated", "animate__fadeOut");
}
});
this.context.handleEvent("join-screen-visible", (data) => {
if (data.value) {
document
.getElementById("joinScreen")
.classList.remove("animate__animated", "animate__fadeOut");
document
.getElementById("joinScreen")
.classList.add("animate__animated", "animate__fadeIn");
} else {
document
.getElementById("joinScreen")
.classList.remove("animate__animated", "animate__fadeIn");
document
.getElementById("joinScreen")
.classList.add("animate__animated", "animate__fadeOut");
}
});
window.addEventListener("keyup", (e) => {
if (e.target.tagName.toLowerCase() != "input") {
switch (e.key) {
case "f": // F
e.preventDefault();
this.fullscreen();
break;
case "ArrowLeft":
case "PageUp":
e.preventDefault();
window.opener.dispatchEvent(
new KeyboardEvent("keydown", { key: "ArrowLeft" })
);
break;
case "ArrowRight":
case "PageDown":
e.preventDefault();
window.opener.dispatchEvent(
new KeyboardEvent("keydown", { key: "ArrowRight" })
);
break;
}
}
});
window.addEventListener("storage", (e) => {
console.log(e)
if (e.key == "slide-position") {
console.log("settings new value " + Date.now())
this.currentPage = parseInt(e.newValue);
this.slider.goTo(e.newValue);
}
})
}
update() {
const newHash = this.context.el.dataset.hash;
const newMaxPage = parseInt(this.context.el.dataset.maxPage);
const newPage = parseInt(this.context.el.dataset.currentPage);
const embedActive = this.context.el.dataset.embedActive === "true";
// Toggle slider visibility for embeds (phx-update="ignore" prevents LiveView from doing it)
const sliderEl = document.getElementById("slider");
if (sliderEl) {
if (embedActive) {
sliderEl.classList.add("hidden");
} else {
sliderEl.classList.remove("hidden");
}
}
if (newHash !== this.hash || newMaxPage !== this.maxPage) {
// Presentation file changed — full re-init needed
this.hash = newHash;
this.maxPage = newMaxPage;
this.currentPage = newPage;
this.init(true);
} else if (newPage !== this.currentPage) {
// Just a page change — navigate without re-init
this.currentPage = newPage;
this.slider.goTo(newPage);
}
// Otherwise: unrelated DOM update (e.g. transcription text) — do nothing
}
fullscreen() {
var docEl = document.getElementById("presenter");
try {
docEl
.webkitRequestFullscreen()
.then(function () {})
.catch(function (error) {});
} catch (e) {
docEl
.requestFullscreen()
.then(function () {})
.catch(function (error) {});
docEl
.mozRequestFullScreen()
.then(function () {})
.catch(function (error) {});
}
}
}