Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to solve issue of leaving page during upload of images #1803

Merged
merged 3 commits into from
May 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions module/Photo/view/photo/album-admin/add.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +101 to +105
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works great! However, I suggest adding

e.preventDefault();

at the top inside the if-statement. That is the new way of actually enabling this event. The other options, setting e.returnValue and returning warning, are deprecated (imho the return warning; can be removed as e.returnValue has been supported in most major browsers since 2017 or earlier).

}
});

this.on("addedfile", function (file) {
uploading = true
})

this.on("queuecomplete", function (file) {
uploading = false
});
}
};
Dropzone.discover();
});
Expand Down
Loading