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 issue #142: inform user when he/she is navigation away from file upload #143

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions assets/js/form_upload_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function (rootEl) {
);
let form = input.closest("form");
let csrfToken = document.querySelector("meta[name=csrf-token]").content;
let nUploadsBusy = 0

files.forEach((file, i) => {
let tmpl = document
Expand Down Expand Up @@ -84,6 +85,22 @@ export default function (rootEl) {

let req = new XMLHttpRequest();

req.addEventListener(
"loadstart", () => {
nUploadsBusy++;
// duplicate listeners are ignored
window.addEventListener("beforeunload", beforeUnloadHandler)
}
)
req.addEventListener(
"loadend", () => {
nUploadsBusy--;
if (nUploadsBusy <= 0) {
window.removeEventListener("beforeunload", beforeUnloadHandler)
}
}
)

req.addEventListener(
"abort",
(e) => {
Expand Down Expand Up @@ -185,3 +202,10 @@ function friendlyBytes(n) {
}
return val.toFixed(0) + " " + unit;
}

function beforeUnloadHandler(evt){
// Recommended
evt.preventDefault();
// Included for legacy support, e.g. Chrome/Edge < 119
evt.returnValue = true;
}
2 changes: 1 addition & 1 deletion static/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/js/app.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/js/app.js": "/js/app.js?id=528e3e99b04cecd259db3e4d8d9fb445",
"/js/app.js": "/js/app.js?id=9cf7e11ce6bd42b18a8bdee006984c5d",
"/css/app.css": "/css/app.css?id=36d98b9870456847d5142cee3bbfcbdf",
"/images/ghent-university-library-logo.svg": "/images/ghent-university-library-logo.svg?id=729f32c469a1aaa6f22f913591cd6fa1",
"/images/ghent-university-library-mark.svg": "/images/ghent-university-library-mark.svg?id=ddfeba39843a5fa6ab3c7adae01c858c",
Expand Down
Loading