From fbf1396064d7bb739dd4513de6649b3e48d0205c Mon Sep 17 00:00:00 2001 From: Martijn van Dijk <61974936+Martijn-vanDijk@users.noreply.github.com> Date: Tue, 26 Mar 2024 14:12:04 +0000 Subject: [PATCH] Fix to solve issue of leaving page during upload of images --- module/Photo/view/photo/album-admin/add.phtml | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/module/Photo/view/photo/album-admin/add.phtml b/module/Photo/view/photo/album-admin/add.phtml index 00f5d95161..cef357a702 100644 --- a/module/Photo/view/photo/album-admin/add.phtml +++ b/module/Photo/view/photo/album-admin/add.phtml @@ -93,6 +93,27 @@ $this->breadcrumbs() document.addEventListener("DOMContentLoaded", function() { Dropzone.options.imageDropzone = { acceptedFiles: 'image/*', + init: function () { + let uploading = false; + + window.addEventListener("beforeunload", function (e) { + if (uploading) { + // Most modern browsers no longer support setting custom dialog messages + // for this dialog, but for backwards compatibility this could be nice. + const warning = "You are currently uploading files, are you sure you want to leave?"; + e.returnValue = warning; + return warning; + } + }); + + this.on("addedfile", function (file) { + uploading = true + }) + + this.on("queuecomplete", function (file) { + uploading = false + }); + } }; Dropzone.discover(); });