require confirmation for navigation away from image upload form (derpibooru/philomena#164)

This commit is contained in:
byte[] 2020-08-11 01:43:19 -04:00
parent 02bbf5e2f1
commit 1e6cef6092

View file

@ -124,6 +124,26 @@ function setupImageUpload() {
else {
disableFetch();
}
// Catch unintentional navigation away from the page
function beforeUnload(event) {
// Chrome requires returnValue to be set
event.preventDefault();
event.returnValue = '';
}
function registerBeforeUnload() {
window.addEventListener('beforeunload', beforeUnload);
}
function unregisterBeforeUnload() {
window.removeEventListener('beforeunload', beforeUnload);
}
fileField.addEventListener('change', registerBeforeUnload);
fetchButton.addEventListener('click', registerBeforeUnload);
form.addEventListener('submit', unregisterBeforeUnload);
}
export { setupImageUpload };