2022-07-23 01:44:03 +02:00
|
|
|
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
|
2024-04-14 12:38:48 +02:00
|
|
|
import "phoenix_html";
|
2022-07-23 01:44:03 +02:00
|
|
|
// Establish Phoenix Socket and LiveView configuration.
|
2024-04-14 12:38:48 +02:00
|
|
|
import { Socket, Presence } from "phoenix";
|
|
|
|
|
import { LiveSocket } from "phoenix_live_view";
|
|
|
|
|
import topbar from "../vendor/topbar";
|
|
|
|
|
import Alpine from "alpinejs";
|
|
|
|
|
import moment from "moment-timezone";
|
|
|
|
|
import AirDatepicker from "air-datepicker";
|
|
|
|
|
import airdatepickerLocaleEn from "air-datepicker/locale/en";
|
|
|
|
|
import airdatepickerLocaleFr from "air-datepicker/locale/fr";
|
|
|
|
|
import airdatepickerLocaleDe from "air-datepicker/locale/de";
|
|
|
|
|
import airdatepickerLocaleEs from "air-datepicker/locale/es";
|
2024-06-07 15:04:02 +02:00
|
|
|
import airdatepickerLocaleNl from "air-datepicker/locale/nl";
|
2024-04-14 12:38:48 +02:00
|
|
|
import "moment/locale/de";
|
|
|
|
|
import "moment/locale/fr";
|
|
|
|
|
import "moment/locale/es";
|
2024-06-07 15:04:02 +02:00
|
|
|
import "moment/locale/nl";
|
2024-04-14 12:38:48 +02:00
|
|
|
import QRCodeStyling from "qr-code-styling";
|
|
|
|
|
import { Presenter } from "./presenter";
|
|
|
|
|
import { Manager } from "./manager";
|
|
|
|
|
import Split from "split-grid";
|
|
|
|
|
import { TourGuideClient } from "@sjmc11/tourguidejs/src/Tour";
|
|
|
|
|
window.moment = moment;
|
|
|
|
|
|
2024-06-07 15:04:02 +02:00
|
|
|
const supportedLocales = ["en", "fr", "de", "es", "nl"];
|
2024-05-20 18:50:56 +02:00
|
|
|
|
|
|
|
|
var locale =
|
2024-04-14 12:38:48 +02:00
|
|
|
document.querySelector("html").getAttribute("lang") ||
|
|
|
|
|
navigator.language.split("-")[0];
|
2024-05-20 18:50:56 +02:00
|
|
|
|
|
|
|
|
if (!supportedLocales.includes(locale)) {
|
|
|
|
|
locale = "en";
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-14 12:38:48 +02:00
|
|
|
window.moment.locale("en");
|
|
|
|
|
window.moment.locale(locale);
|
|
|
|
|
window.Alpine = Alpine;
|
|
|
|
|
Alpine.start();
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2024-04-06 11:48:47 +02:00
|
|
|
let airdatepickerLocale = {
|
|
|
|
|
en: airdatepickerLocaleEn,
|
|
|
|
|
fr: airdatepickerLocaleFr,
|
2024-04-07 12:25:07 +02:00
|
|
|
de: airdatepickerLocaleDe,
|
2024-04-14 12:38:48 +02:00
|
|
|
es: airdatepickerLocaleEs,
|
2024-06-07 15:04:02 +02:00
|
|
|
nl: airdatepickerLocaleNl,
|
2024-04-14 12:38:48 +02:00
|
|
|
};
|
|
|
|
|
let csrfToken = document
|
|
|
|
|
.querySelector("meta[name='csrf-token']")
|
|
|
|
|
.getAttribute("content");
|
|
|
|
|
let Hooks = {};
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2024-04-06 11:48:47 +02:00
|
|
|
Hooks.EmbeddedBanner = {
|
|
|
|
|
mounted() {
|
|
|
|
|
if (window !== window.parent) {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.classList.remove("hidden");
|
2024-04-06 11:48:47 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
updated() {
|
|
|
|
|
if (window !== window.parent) {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.classList.remove("hidden");
|
2024-04-06 11:48:47 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
},
|
|
|
|
|
};
|
2024-04-06 11:48:47 +02:00
|
|
|
|
|
|
|
|
Hooks.TourGuide = {
|
|
|
|
|
mounted() {
|
|
|
|
|
this.tour = new TourGuideClient({
|
|
|
|
|
nextLabel: this.el.dataset.nextLabel,
|
|
|
|
|
prevLabel: this.el.dataset.prevLabel,
|
|
|
|
|
finishLabel: this.el.dataset.finishLabel,
|
|
|
|
|
completeOnFinish: true,
|
|
|
|
|
rememberStep: true,
|
2024-04-14 12:38:48 +02:00
|
|
|
});
|
2024-04-06 11:48:47 +02:00
|
|
|
|
|
|
|
|
if (!this.tour.isFinished(this.el.dataset.group)) {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.tour.start(this.el.dataset.group);
|
2024-04-06 11:48:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.tour.onBeforeExit(() => {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.tour.finishTour(true, this.el.dataset.group);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
2024-04-06 11:48:47 +02:00
|
|
|
|
|
|
|
|
Hooks.Split = {
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
const type = this.el.dataset.type;
|
2024-06-08 16:31:59 +02:00
|
|
|
const id = this.el.id;
|
2024-04-14 12:38:48 +02:00
|
|
|
const gutter = this.el.dataset.gutter;
|
2024-06-08 16:31:59 +02:00
|
|
|
const forceLayout = this.el.classList.contains("grid-cols-[1fr]");
|
2024-04-14 12:38:48 +02:00
|
|
|
const columnSlitValue =
|
2024-06-08 16:31:59 +02:00
|
|
|
localStorage.getItem(`column-split-${id}`) || "1fr 10px 1fr";
|
|
|
|
|
const rowSlitValue =
|
|
|
|
|
localStorage.getItem(`row-split-${id}`) || "1fr 10px 1fr";
|
2024-04-06 11:48:47 +02:00
|
|
|
|
|
|
|
|
if (type === "column") {
|
|
|
|
|
this.columnSplit = Split({
|
2024-04-14 12:38:48 +02:00
|
|
|
columnGutters: [
|
|
|
|
|
{
|
|
|
|
|
track: 1,
|
|
|
|
|
element: this.el.querySelector(gutter),
|
|
|
|
|
},
|
|
|
|
|
],
|
2024-04-06 11:48:47 +02:00
|
|
|
onDragEnd: () => {
|
2024-04-14 12:38:48 +02:00
|
|
|
const currentPosition = this.el.style["grid-template-columns"];
|
2024-06-08 16:31:59 +02:00
|
|
|
localStorage.setItem(`column-split-${id}`, currentPosition);
|
2024-04-06 11:48:47 +02:00
|
|
|
},
|
2024-04-14 12:38:48 +02:00
|
|
|
});
|
2024-06-08 16:31:59 +02:00
|
|
|
if (!forceLayout) {
|
|
|
|
|
this.el.style["grid-template-columns"] = columnSlitValue;
|
|
|
|
|
}
|
2024-04-06 11:48:47 +02:00
|
|
|
} else {
|
|
|
|
|
this.rowSplit = Split({
|
2024-04-14 12:38:48 +02:00
|
|
|
rowGutters: [
|
|
|
|
|
{
|
|
|
|
|
track: 1,
|
|
|
|
|
element: this.el.querySelector(gutter),
|
|
|
|
|
},
|
|
|
|
|
],
|
2024-04-06 11:48:47 +02:00
|
|
|
onDragEnd: () => {
|
2024-04-14 12:38:48 +02:00
|
|
|
const value = this.el.style["grid-template-rows"];
|
2024-06-08 16:31:59 +02:00
|
|
|
localStorage.setItem(`row-split-${id}`, value);
|
2024-04-06 11:48:47 +02:00
|
|
|
},
|
2024-04-14 12:38:48 +02:00
|
|
|
});
|
2024-06-08 16:31:59 +02:00
|
|
|
if (!forceLayout) {
|
|
|
|
|
this.el.style["grid-template-rows"] = rowSlitValue;
|
|
|
|
|
}
|
2024-04-06 11:48:47 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
updated() {
|
2024-06-08 16:31:59 +02:00
|
|
|
const id = this.el.id;
|
|
|
|
|
const forceLayout = this.el.classList.contains("grid-cols-[1fr]");
|
|
|
|
|
if (forceLayout) {
|
|
|
|
|
return;
|
2024-04-06 11:48:47 +02:00
|
|
|
}
|
2024-06-08 16:31:59 +02:00
|
|
|
|
|
|
|
|
this.mounted();
|
2024-04-06 11:48:47 +02:00
|
|
|
},
|
|
|
|
|
destroyed() {
|
|
|
|
|
if (this.columnSplit) {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.columnSplit.destroy();
|
2024-04-06 11:48:47 +02:00
|
|
|
}
|
|
|
|
|
if (this.rowSplit) {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.rowSplit.destroy();
|
2024-04-06 11:48:47 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
},
|
|
|
|
|
};
|
2024-04-06 11:48:47 +02:00
|
|
|
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.Scroll = {
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
if (this.el.dataset.postsNb > 4)
|
|
|
|
|
window.scrollTo({
|
|
|
|
|
top: document.querySelector(this.el.dataset.target).scrollHeight,
|
|
|
|
|
behavior: "smooth",
|
|
|
|
|
});
|
|
|
|
|
this.handleEvent("scroll", () => {});
|
2024-04-06 11:48:47 +02:00
|
|
|
},
|
|
|
|
|
updated() {
|
2024-04-14 12:38:48 +02:00
|
|
|
let t = document.querySelector(this.el.dataset.target);
|
|
|
|
|
if (
|
|
|
|
|
this.el.childElementCount > 4 &&
|
|
|
|
|
window.scrollY + window.innerHeight >= t.offsetHeight - 300
|
|
|
|
|
) {
|
|
|
|
|
window.scrollTo({ top: t.scrollHeight, behavior: "smooth" });
|
2024-04-06 11:48:47 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
Hooks.ScrollIntoDiv = {
|
|
|
|
|
mounted() {
|
2024-04-06 11:48:47 +02:00
|
|
|
this.scrollElement(true);
|
|
|
|
|
this.handleEvent("scroll", this.scrollElement.bind(this));
|
|
|
|
|
},
|
|
|
|
|
scrollElement(firstScroll) {
|
|
|
|
|
let t = this.el.parentElement;
|
2024-04-14 12:38:48 +02:00
|
|
|
if (
|
|
|
|
|
firstScroll === true ||
|
|
|
|
|
t.scrollHeight - t.scrollTop - t.clientHeight <= 100
|
|
|
|
|
) {
|
|
|
|
|
t.scrollTo({ top: t.scrollHeight, behavior: "smooth" });
|
2024-04-06 11:48:47 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2023-08-10 20:39:38 +02:00
|
|
|
Hooks.NicknamePicker = {
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
let currentNickname = localStorage.getItem("nickname") || "";
|
2023-08-10 20:39:38 +02:00
|
|
|
if (currentNickname.length > 0) {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.pushEvent("set-nickname", { nickname: currentNickname });
|
2023-08-10 20:39:38 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.addEventListener("click", (e) => this.clicked(e));
|
2023-08-10 20:39:38 +02:00
|
|
|
},
|
2024-04-06 11:48:47 +02:00
|
|
|
destroyed() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.removeEventListener("click", (e) => this.clicked(e));
|
2023-08-10 20:39:38 +02:00
|
|
|
},
|
|
|
|
|
clicked(e) {
|
2024-04-14 12:38:48 +02:00
|
|
|
let nickname = prompt(
|
|
|
|
|
this.el.dataset.prompt,
|
|
|
|
|
localStorage.getItem("nickname") || ""
|
|
|
|
|
);
|
2023-08-10 20:39:38 +02:00
|
|
|
|
|
|
|
|
if (nickname) {
|
2024-04-14 12:38:48 +02:00
|
|
|
localStorage.setItem("nickname", nickname);
|
|
|
|
|
this.pushEvent("set-nickname", { nickname: nickname });
|
2023-08-10 20:39:38 +02:00
|
|
|
}
|
|
|
|
|
},
|
2024-04-14 12:38:48 +02:00
|
|
|
};
|
2023-08-10 20:39:38 +02:00
|
|
|
|
|
|
|
|
Hooks.EmptyNickname = {
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.addEventListener("click", (e) => this.clicked(e));
|
2023-08-10 20:39:38 +02:00
|
|
|
},
|
2024-04-06 11:48:47 +02:00
|
|
|
destroyed() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.removeEventListener("click", (e) => this.clicked(e));
|
2023-08-10 20:39:38 +02:00
|
|
|
},
|
|
|
|
|
clicked(e) {
|
2024-04-14 12:38:48 +02:00
|
|
|
localStorage.removeItem("nickname");
|
2023-08-10 20:39:38 +02:00
|
|
|
},
|
2024-04-14 12:38:48 +02:00
|
|
|
};
|
2023-08-10 20:39:38 +02:00
|
|
|
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.PostForm = {
|
|
|
|
|
onPress(e, submitBtn, TA) {
|
|
|
|
|
if (e.key == "Enter" && !e.shiftKey) {
|
2024-04-14 12:38:48 +02:00
|
|
|
e.preventDefault();
|
|
|
|
|
submitBtn.click();
|
2022-07-23 01:44:03 +02:00
|
|
|
} else {
|
2023-09-17 19:18:03 +02:00
|
|
|
if (TA.value.length > 1 && TA.value.length < 256) {
|
2024-04-14 12:38:48 +02:00
|
|
|
submitBtn.classList.remove("opacity-50");
|
|
|
|
|
submitBtn.classList.add("opacity-100");
|
|
|
|
|
submitBtn.disabled = false;
|
2022-07-23 01:44:03 +02:00
|
|
|
} else {
|
2024-04-14 12:38:48 +02:00
|
|
|
submitBtn.classList.add("opacity-50");
|
|
|
|
|
submitBtn.classList.remove("opacity-100");
|
|
|
|
|
submitBtn.disabled = true;
|
2022-07-23 01:44:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onSubmit(e, TA) {
|
2024-04-14 12:38:48 +02:00
|
|
|
e.preventDefault();
|
|
|
|
|
document.getElementById("hiddenSubmit").click();
|
|
|
|
|
TA.value = "";
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
mounted() {
|
2023-08-10 20:39:38 +02:00
|
|
|
setTimeout(() => {
|
2024-04-14 12:38:48 +02:00
|
|
|
const submitBtn = document.getElementById("submitBtn");
|
|
|
|
|
const TA = document.getElementById("postFormTA");
|
2023-08-10 20:39:38 +02:00
|
|
|
if (submitBtn && TA) {
|
2024-04-14 12:38:48 +02:00
|
|
|
submitBtn.addEventListener("click", (e) => this.onSubmit(e, TA));
|
|
|
|
|
TA.addEventListener("keydown", (e) => this.onPress(e, submitBtn, TA));
|
2023-08-10 20:39:38 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
}, 500);
|
|
|
|
|
|
2023-08-10 20:39:38 +02:00
|
|
|
// set nickname if present
|
2024-04-14 12:38:48 +02:00
|
|
|
let nickname = this.el.dataset.nickname;
|
2023-08-10 20:39:38 +02:00
|
|
|
if (nickname) {
|
2024-04-14 12:38:48 +02:00
|
|
|
localStorage.setItem("nickname", nickname);
|
2023-04-21 12:46:43 +02:00
|
|
|
}
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
updated() {
|
2024-04-14 12:38:48 +02:00
|
|
|
const submitBtn = document.getElementById("submitBtn");
|
|
|
|
|
const TA = document.getElementById("postFormTA");
|
2023-09-17 19:18:03 +02:00
|
|
|
if (TA.value.length > 1 && TA.value.length < 256) {
|
2024-04-14 12:38:48 +02:00
|
|
|
submitBtn.classList.remove("opacity-50");
|
|
|
|
|
submitBtn.classList.add("opacity-100");
|
|
|
|
|
submitBtn.disabled = false;
|
2022-07-23 01:44:03 +02:00
|
|
|
} else {
|
2024-04-14 12:38:48 +02:00
|
|
|
submitBtn.classList.add("opacity-50");
|
|
|
|
|
submitBtn.classList.remove("opacity-100");
|
|
|
|
|
submitBtn.disabled = true;
|
2022-07-23 01:44:03 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
destroyed() {
|
2024-04-14 12:38:48 +02:00
|
|
|
const submitBtn = document.getElementById("submitBtn");
|
|
|
|
|
const TA = document.getElementById("postFormTA");
|
2023-04-21 12:46:43 +02:00
|
|
|
if (submitBtn && TA) {
|
2024-04-14 12:38:48 +02:00
|
|
|
TA.removeEventListener("keydown", (e) => this.onPress(e, submitBtn, TA));
|
|
|
|
|
submitBtn.removeEventListener("click", (e) => this.onSubmit(e, TA));
|
2023-04-21 12:46:43 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
Hooks.CalendarLocalDate = {
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.innerHTML = moment.utc(this.el.dataset.date).local().calendar();
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
updated() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.innerHTML = moment.utc(this.el.dataset.date).local().calendar();
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.Pickr = {
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
const localTime = this.el.querySelector("input[type=text]");
|
|
|
|
|
const utcTime = this.el.querySelector("input[type=hidden]");
|
|
|
|
|
localTime.value = moment
|
|
|
|
|
.utc(utcTime.value)
|
|
|
|
|
.local()
|
|
|
|
|
.format("DD-MM-YYYY HH:mm");
|
2024-04-06 11:48:47 +02:00
|
|
|
this.pickr = new AirDatepicker(localTime, {
|
|
|
|
|
dateFormat: "dd-MM-yyyy",
|
|
|
|
|
timepicker: true,
|
|
|
|
|
minutesStep: 5,
|
|
|
|
|
minDate: moment(),
|
|
|
|
|
timeFormat: "HH:mm",
|
|
|
|
|
selectedDates: [moment(localTime.value, "DD-MM-YYYY HH:mm").toDate()],
|
2024-04-14 12:38:48 +02:00
|
|
|
onSelect: ({ date }) => {
|
|
|
|
|
const utc = moment(date).utc().format("YYYY-MM-DDTHH:mm:ss");
|
|
|
|
|
utcTime.value = utc;
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
2024-04-14 12:38:48 +02:00
|
|
|
locale: airdatepickerLocale[locale],
|
|
|
|
|
});
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
2024-04-14 12:38:48 +02:00
|
|
|
updated() {},
|
2022-07-23 01:44:03 +02:00
|
|
|
destroyed() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.pickr.destroy();
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.Presenter = {
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.presenter = new Presenter(this);
|
|
|
|
|
this.presenter.init();
|
|
|
|
|
},
|
2024-06-08 16:31:59 +02:00
|
|
|
updated() {
|
|
|
|
|
this.presenter.update();
|
|
|
|
|
},
|
2024-04-14 12:38:48 +02:00
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.Manager = {
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.manager = new Manager(this);
|
|
|
|
|
this.manager.init();
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
updated() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.manager.update();
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.OpenPresenter = {
|
|
|
|
|
open(e) {
|
2024-04-14 12:38:48 +02:00
|
|
|
e.preventDefault();
|
|
|
|
|
window.open(
|
|
|
|
|
this.el.dataset.url,
|
|
|
|
|
"newwindow",
|
|
|
|
|
"width=" + window.screen.width + ",height=" + window.screen.height
|
|
|
|
|
);
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.addEventListener("click", (e) => this.open(e));
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
updated() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.removeEventListener("click", (e) => this.open(e));
|
|
|
|
|
this.el.addEventListener("click", (e) => this.open(e));
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
destroyed() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.removeEventListener("click", (e) => this.open(e));
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.GlobalReacts = {
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.handleEvent("global-react", (data) => {
|
2022-07-23 01:44:03 +02:00
|
|
|
var img = document.createElement("img");
|
2024-04-14 12:38:48 +02:00
|
|
|
img.src = "/images/icons/" + data.type + ".svg";
|
|
|
|
|
img.className =
|
|
|
|
|
"react-animation absolute transform opacity-0" + this.el.className;
|
|
|
|
|
this.el.appendChild(img);
|
|
|
|
|
});
|
|
|
|
|
this.handleEvent("reset-global-react", (data) => {
|
|
|
|
|
this.el.innerHTML = "";
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.JoinEvent = {
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
const loading = document.getElementById("loading");
|
|
|
|
|
const submit = document.getElementById("submit");
|
|
|
|
|
const input = document.getElementById("input");
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
submit.addEventListener("click", (e) => {
|
|
|
|
|
if (input.value.length > 0) {
|
2024-04-14 12:38:48 +02:00
|
|
|
submit.style.display = "none";
|
|
|
|
|
loading.style.display = "block";
|
2022-07-23 01:44:03 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
});
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
destroyed() {
|
2024-04-14 12:38:48 +02:00
|
|
|
const loading = document.getElementById("loading");
|
|
|
|
|
const submit = document.getElementById("submit");
|
|
|
|
|
const input = document.getElementById("input");
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
submit.removeEventListener("click", (e) => {
|
|
|
|
|
if (input.value.length > 0) {
|
2024-04-14 12:38:48 +02:00
|
|
|
submit.style.display = "none";
|
|
|
|
|
loading.style.display = "block";
|
2022-07-23 01:44:03 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.WelcomeEarly = {
|
|
|
|
|
mounted() {
|
|
|
|
|
if (localStorage.getItem("welcome-early") !== "false") {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.style.display = "block";
|
2022-07-23 01:44:03 +02:00
|
|
|
this.el.children[0].addEventListener("click", (e) => {
|
2024-04-14 12:38:48 +02:00
|
|
|
e.preventDefault();
|
|
|
|
|
localStorage.setItem("welcome-early", "false");
|
|
|
|
|
this.el.style.display = "none";
|
|
|
|
|
});
|
2022-07-23 01:44:03 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
destroyed() {
|
|
|
|
|
this.el.children[0].removeEventListener("click", (e) => {
|
2024-04-14 12:38:48 +02:00
|
|
|
e.preventDefault();
|
|
|
|
|
localStorage.setItem("welcome-early", "false");
|
|
|
|
|
this.el.style.display = "none";
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.ClickFeedback = {
|
|
|
|
|
clicked(e) {
|
|
|
|
|
this.el.className = "animate__animated animate__rubberBand animate__faster";
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
this.el.className = "";
|
2024-04-14 12:38:48 +02:00
|
|
|
}, 500);
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
mounted() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.addEventListener("click", (e) => this.clicked(e));
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
2024-04-06 11:48:47 +02:00
|
|
|
destroyed() {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.removeEventListener("click", (e) => this.clicked(e));
|
|
|
|
|
},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
Hooks.QRCode = {
|
|
|
|
|
draw() {
|
2024-04-14 12:38:48 +02:00
|
|
|
var url = this.el.dataset.code
|
|
|
|
|
? window.location.protocol +
|
|
|
|
|
"//" +
|
|
|
|
|
window.location.host +
|
|
|
|
|
"/e/" +
|
|
|
|
|
this.el.dataset.code
|
|
|
|
|
: window.location.href;
|
|
|
|
|
this.el.style.width = document.documentElement.clientWidth * 0.27 + "px";
|
|
|
|
|
this.el.style.height = document.documentElement.clientWidth * 0.27 + "px";
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
if (this.qrCode == null) {
|
|
|
|
|
this.qrCode = new QRCodeStyling({
|
2024-04-14 12:38:48 +02:00
|
|
|
width: this.el.dataset.dynamic
|
|
|
|
|
? document.documentElement.clientWidth * 0.25
|
|
|
|
|
: 240,
|
|
|
|
|
height: this.el.dataset.dynamic
|
|
|
|
|
? document.documentElement.clientWidth * 0.25
|
|
|
|
|
: 240,
|
2022-07-23 01:44:03 +02:00
|
|
|
margin: 0,
|
|
|
|
|
data: url,
|
|
|
|
|
cornersSquareOptions: {
|
2024-04-14 12:38:48 +02:00
|
|
|
type: "square",
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
dotsOptions: {
|
|
|
|
|
type: "square",
|
2023-09-09 12:08:23 +02:00
|
|
|
color: "#ffffff",
|
|
|
|
|
},
|
|
|
|
|
backgroundOptions: {
|
|
|
|
|
color: "#000000",
|
2022-07-23 01:44:03 +02:00
|
|
|
},
|
|
|
|
|
imageOptions: {
|
|
|
|
|
crossOrigin: "anonymous",
|
|
|
|
|
imageSize: 0.6,
|
2024-04-14 12:38:48 +02:00
|
|
|
margin: 10,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
this.qrCode.append(this.el);
|
2022-07-23 01:44:03 +02:00
|
|
|
} else {
|
|
|
|
|
this.qrCode.update({
|
2024-04-14 12:38:48 +02:00
|
|
|
width: this.el.dataset.dynamic
|
|
|
|
|
? document.documentElement.clientWidth * 0.25
|
|
|
|
|
: 240,
|
|
|
|
|
height: this.el.dataset.dynamic
|
|
|
|
|
? document.documentElement.clientWidth * 0.25
|
|
|
|
|
: 240,
|
|
|
|
|
});
|
2022-07-23 01:44:03 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
window.addEventListener("resize", this.draw.bind(this));
|
2024-04-14 12:38:48 +02:00
|
|
|
this.draw();
|
2022-07-23 01:44:03 +02:00
|
|
|
if (this.el.dataset.getUrl) {
|
|
|
|
|
setTimeout(() => {
|
2024-04-14 12:38:48 +02:00
|
|
|
var dataURL = this.qrCode._canvas.toDataURL();
|
|
|
|
|
document.getElementById("qr-url").value = dataURL;
|
|
|
|
|
}, 500);
|
2022-07-23 01:44:03 +02:00
|
|
|
}
|
|
|
|
|
},
|
2024-04-14 12:38:48 +02:00
|
|
|
updated() {},
|
|
|
|
|
destroyed() {},
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2024-04-06 11:48:47 +02:00
|
|
|
Hooks.Dropdown = {
|
|
|
|
|
mounted() {
|
|
|
|
|
this.el.addEventListener("click", (e) => {
|
2024-04-14 12:38:48 +02:00
|
|
|
this.el.classList.toggle("hidden");
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let Uploaders = {};
|
|
|
|
|
|
|
|
|
|
Uploaders.S3 = function (entries, onViewError) {
|
|
|
|
|
entries.forEach((entry) => {
|
|
|
|
|
let formData = new FormData();
|
|
|
|
|
let { url, fields } = entry.meta;
|
|
|
|
|
Object.entries(fields).forEach(([key, val]) => formData.append(key, val));
|
|
|
|
|
formData.append("file", entry.file);
|
|
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
|
onViewError(() => xhr.abort());
|
|
|
|
|
xhr.onload = () =>
|
|
|
|
|
xhr.status === 204 ? entry.progress(100) : entry.error();
|
|
|
|
|
xhr.onerror = () => entry.error();
|
2022-07-23 01:44:03 +02:00
|
|
|
xhr.upload.addEventListener("progress", (event) => {
|
2024-04-14 12:38:48 +02:00
|
|
|
if (event.lengthComputable) {
|
|
|
|
|
let percent = Math.round((event.loaded / event.total) * 100);
|
|
|
|
|
if (percent < 100) {
|
|
|
|
|
entry.progress(percent);
|
|
|
|
|
}
|
2022-07-23 01:44:03 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
});
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2024-04-14 12:38:48 +02:00
|
|
|
xhr.open("POST", url, true);
|
|
|
|
|
xhr.send(formData);
|
|
|
|
|
});
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
let liveSocket = new LiveSocket("/live", Socket, {
|
|
|
|
|
uploaders: Uploaders,
|
2024-04-14 12:38:48 +02:00
|
|
|
params: {
|
|
|
|
|
_csrf_token: csrfToken,
|
|
|
|
|
tz: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
|
|
|
host: window.location.host,
|
|
|
|
|
},
|
2022-07-23 01:44:03 +02:00
|
|
|
hooks: Hooks,
|
|
|
|
|
dom: {
|
2024-04-14 12:38:48 +02:00
|
|
|
onBeforeElUpdated(from, to) {
|
|
|
|
|
if (from._x_dataStack) {
|
|
|
|
|
window.Alpine.clone(from, to);
|
|
|
|
|
window.Alpine.initTree(to);
|
2022-07-23 01:44:03 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
// Show progress bar on live navigation and form submits
|
2024-04-14 12:38:48 +02:00
|
|
|
let topBarScheduled = undefined;
|
|
|
|
|
topbar.config({ barColors: { 0: "#fff" }, shadowColor: "rgba(0, 0, 0, .3)" });
|
|
|
|
|
window.addEventListener("phx:page-loading-start", (info) => {
|
|
|
|
|
if (!topBarScheduled) {
|
|
|
|
|
topBarScheduled = setTimeout(() => topbar.show(), 500);
|
2022-07-23 01:44:03 +02:00
|
|
|
}
|
2024-04-14 12:38:48 +02:00
|
|
|
});
|
|
|
|
|
window.addEventListener("phx:page-loading-stop", (info) => {
|
|
|
|
|
clearTimeout(topBarScheduled);
|
|
|
|
|
topBarScheduled = undefined;
|
|
|
|
|
topbar.hide();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const renderOnlineUsers = function (presences) {
|
|
|
|
|
let onlineUsers = Presence.list(
|
|
|
|
|
presences,
|
|
|
|
|
(_id, { metas: [user, ...rest] }) => {
|
|
|
|
|
return onlineUserTemplate(user);
|
|
|
|
|
}
|
|
|
|
|
).join("");
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
document.querySelector("body").innerHTML = onlineUsers;
|
2024-04-14 12:38:48 +02:00
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
|
2024-04-14 12:38:48 +02:00
|
|
|
const onlineUserTemplate = function (user) {
|
2022-07-23 01:44:03 +02:00
|
|
|
return `
|
|
|
|
|
<div id="online-user">
|
|
|
|
|
<strong class="text-secondary">aaa</strong>
|
|
|
|
|
</div>
|
2024-04-14 12:38:48 +02:00
|
|
|
`;
|
|
|
|
|
};
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
let presences = {};
|
2024-04-14 12:38:48 +02:00
|
|
|
liveSocket.on("presence_state", (state) => {
|
|
|
|
|
presences = Presence.syncState(presences, state);
|
|
|
|
|
renderOnlineUsers(presences);
|
|
|
|
|
});
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
// connect if there are any LiveViews on the page
|
2024-04-14 12:38:48 +02:00
|
|
|
liveSocket.connect();
|
2022-07-23 01:44:03 +02:00
|
|
|
|
|
|
|
|
// expose liveSocket on window for web console debug logs and latency simulation:
|
|
|
|
|
// >> liveSocket.enableDebug()
|
|
|
|
|
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
|
|
|
|
|
// >> liveSocket.disableLatencySim()
|
2024-04-14 12:38:48 +02:00
|
|
|
window.liveSocket = liveSocket;
|