Skip to content

Commit b87f876

Browse files
authored
feat: webui confirm on exit while uploading (#693)
1 parent 30b2979 commit b87f876

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

assets/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ let $logoutBtn;
106106
*/
107107
let $userName;
108108

109+
// manage unload event to prevent leaving with uploads in progress
110+
const beforeUnloadHandler = (event) => {
111+
if (Uploader.queues.length > 0 || Uploader.runnings > 0) {
112+
event.preventDefault();
113+
event.returnValue = '';
114+
return ''; // for some browsers
115+
}
116+
};
117+
109118
// Produce table when window loads
110119
window.addEventListener("DOMContentLoaded", async () => {
111120
const $indexData = document.getElementById('index-data');
@@ -131,6 +140,8 @@ async function ready() {
131140
$logoutBtn = document.querySelector(".logout-btn");
132141
$userName = document.querySelector(".user-name");
133142

143+
window.addEventListener('beforeunload', beforeUnloadHandler);
144+
134145
addBreadcrumb(DATA.href, DATA.uri_prefix);
135146

136147
if (DATA.kind === "Index") {

0 commit comments

Comments
 (0)