mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
require confirmation for navigation away from image upload form (derpibooru/philomena#164)
This commit is contained in:
parent
02bbf5e2f1
commit
1e6cef6092
1 changed files with 20 additions and 0 deletions
|
@ -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 };
|
||||
|
|
Loading…
Reference in a new issue