2023-09-18 13:50:03 +01:00
|
|
|
function load() {
|
2023-09-21 15:38:02 +01:00
|
|
|
for (const elm of document.querySelectorAll("form > button")) {
|
|
|
|
elm.addEventListener('click', (e) => {
|
|
|
|
e.target.parentElement.classList.add("submitted");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
for (const elm of document.querySelectorAll("button.icon")) {
|
|
|
|
elm.addEventListener('click', (e) => {
|
|
|
|
e.preventDefault()
|
|
|
|
const input = document.querySelectorAll('form .file-upload input[type="file"]')[0];
|
|
|
|
if (input) {
|
|
|
|
input.click();
|
|
|
|
input.addEventListener('change', (e) => {
|
|
|
|
const file = input.files[0];
|
|
|
|
if (!file) return;
|
|
|
|
elm.setAttribute("disabled", "true");
|
|
|
|
|
|
|
|
const spanToReplace = document.querySelector('.file-upload .icon span');
|
|
|
|
const imgToReplace = document.querySelector('.file-upload .icon img');
|
|
|
|
if (!imgToReplace || !spanToReplace) return;
|
|
|
|
|
|
|
|
if (imgToReplace.getAttribute("replace")) {
|
|
|
|
const fileReader = new FileReader();
|
|
|
|
fileReader.onloadend = () => {
|
|
|
|
imgToReplace.setAttribute("src", fileReader.result)
|
|
|
|
elm.classList.add("adapt");
|
|
|
|
}
|
|
|
|
fileReader.readAsDataURL(file)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spanToReplace.getAttribute("replace")) {
|
|
|
|
spanToReplace.innerHTML = spanToReplace.getAttribute("replace")
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2023-09-18 13:50:03 +01:00
|
|
|
}
|
|
|
|
window.onload = load;
|
|
|
|
htmx.on('htmx:afterSwap', load);
|
2023-09-19 13:39:59 +01:00
|
|
|
htmx.on('htmx:beforeSwap', (env) => {
|
|
|
|
if (env.detail.xhr.status === 401) {
|
|
|
|
window.location = "/login"
|
2023-09-21 15:38:02 +01:00
|
|
|
} else
|
|
|
|
// 309 is the code I selected for html to htmlfull change
|
|
|
|
if (env.detail.xhr.status === 309) {
|
|
|
|
env.detail.target = htmx.find(".app")
|
|
|
|
}
|
2023-09-19 13:39:59 +01:00
|
|
|
});
|