Skip to content

Commit

Permalink
Remove beforeunload confirmation panel (#9224) (#9266)
Browse files Browse the repository at this point in the history
Co-authored-by: Eero Lahdenperä <eero.lahdenpera@mainiotech.fi>
  • Loading branch information
andreslucena and Eero Lahdenperä committed May 10, 2022
1 parent b7d97a1 commit 0e70f28
Showing 1 changed file with 1 addition and 32 deletions.
33 changes: 1 addition & 32 deletions decidim-budgets/app/packs/src/decidim/budgets/exit_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,12 @@ const allowExitFrom = ($el) => {
return false;
}

// Don't show browser's default confirmation panel when visit current_path is called in tests.
const testReload = (initialLocation) => {
if (navigator && navigator.webdriver && initialLocation === location.href) {
return true;
}

return false;
}

$(() => {
const $exitNotification = $("#exit-notification");
const $exitLink = $("#exit-notification-link");
const defaultExitUrl = $exitLink.attr("href");
const defaultExitLinkText = $exitLink.text();
let exitLinkText = defaultExitLinkText;
const initialLocation = location.href;

if ($exitNotification.length < 1) {
// Do not apply when not inside the voting pipeline
Expand All @@ -79,16 +69,11 @@ $(() => {
$exitNotification.foundation("open");
};

// Handle "beforeunload"
window.allowExit = false;
$(document).on("click", "a", (event) => {
exitLinkText = defaultExitLinkText;
window.allowExit = false;

const $link = $(event.currentTarget);
if (allowExitFrom($link)) {
window.allowExit = true;
} else {
if (!allowExitFrom($link)) {
event.preventDefault();
openExitNotification($link.attr("href"), $link.data("method"));
}
Expand All @@ -112,20 +97,4 @@ $(() => {
exitLinkText = defaultExitLinkText;
openExitNotification(defaultExitUrl);
});
// Allow all form submits on the page, including language change and sign
// out form (when triggered by the exit link click).
$(document).on("submit", "form", () => {
window.allowExit = true;
});

window.addEventListener("beforeunload", (event) => {
const allowExit = window.allowExit;
window.allowExit = false;

if (allowExit || testReload(initialLocation)) {
return;
}

event.returnValue = true;
});
});

0 comments on commit 0e70f28

Please sign in to comment.