aboutsummaryrefslogtreecommitdiff
path: root/profile/public/script.js
diff options
context:
space:
mode:
authorMarvin Borner2021-01-29 14:10:17 +0100
committerMarvin Borner2021-01-29 14:10:17 +0100
commit8637186a9f835972a5a0b96e4df1665d6d42557a (patch)
tree5716f4d7095f675f6dc6ebffd68aa9fe701c74d4 /profile/public/script.js
parente83901076f3d15f5d601d53237f886b7bc34f50b (diff)
idk
Diffstat (limited to 'profile/public/script.js')
-rw-r--r--profile/public/script.js60
1 files changed, 34 insertions, 26 deletions
diff --git a/profile/public/script.js b/profile/public/script.js
index 91b723e..db9a277 100644
--- a/profile/public/script.js
+++ b/profile/public/script.js
@@ -12,17 +12,18 @@ const controlButtons = document.querySelectorAll(".control-btns button");
let cropper = undefined;
const crop = () => {
- cropper = new Cropper(document.getElementById("popup-img"), { // Consider dataset id
- dragMode: "move",
+ cropper = new Cropper(document.getElementById("popup-img"), {
+ // Consider dataset id
+ //dragMode: "move",
aspectRatio: 10 / 13,
- autoCropArea: 0.65,
- restore: false,
- guides: false,
- center: false,
- highlight: false,
- cropBoxMovable: false,
- cropBoxResizable: false,
- toggleDragModeOnDblclick: false,
+ //autoCropArea: 0.65,
+ //restore: false,
+ //guides: false,
+ //center: false,
+ //highlight: false,
+ //cropBoxMovable: false,
+ //cropBoxResizable: false,
+ //toggleDragModeOnDblclick: false,
});
};
@@ -86,7 +87,7 @@ form.addEventListener("submit", async (evt) => {
const method = init ? "POST" : "PUT";
const inputs = form.querySelectorAll("input");
- const rawBody = {}
+ const rawBody = {};
for (const input of inputs) {
if (input.type !== "file") rawBody[input.name] = input.value;
}
@@ -94,25 +95,32 @@ form.addEventListener("submit", async (evt) => {
const resp = await fetch("api/answer", { method, body, headers: { "Content-Type": "application/json" } });
const res = await resp.json();
- if (!res.success) alert("AHHHH");
+ if (!res.success) alert("An error occurred");
else init = false;
});
saveBtn.addEventListener("click", (e) => {
- cropper.getCroppedCanvas()
- .toBlob(async (blob) => {
- const url = "api/answerImage";
- const method = imageInit ? "POST" : "PUT";
- const body = new FormData();
- if (imageID === -1) {
- return;
- }
- body.append(imageID, blob);
- const resp = await fetch(url, { method, body });
- const res = await resp.json();
- if (!res.success) alert("AHHH");
- else imageInit = false;
- }, "image/jpeg");
+ cropper.getCroppedCanvas().toBlob(async (blob) => {
+ const url = "api/answerImage";
+ const method = imageInit ? "POST" : "PUT";
+ const body = new FormData();
+ if (imageID === -1) {
+ return;
+ }
+ body.append(imageID, blob);
+ const resp = await fetch(url, { method, body });
+ const res = await resp.json();
+ if (!res.success) {
+ alert("An error occurred");
+ } else {
+ imageInit = false;
+ popup.style.display = "none";
+ cropper.destroy();
+ document.querySelectorAll("img").forEach((elem) => {
+ if (elem.src.startsWith("http")) elem.src += "#" + new Date().getTime();
+ });
+ }
+ }, "image/jpeg");
});
slider.addEventListener("input", (e) => {