app/packs/src/decidim/budgets/exit_handler.js in decidim-budgets-0.26.1 vs app/packs/src/decidim/budgets/exit_handler.js in decidim-budgets-0.26.2
- old
+ new
@@ -43,26 +43,16 @@
}
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
return;
}
@@ -77,20 +67,15 @@
$exitLink.attr("href", url);
$exitLink.html(exitLinkText);
$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"));
}
});
// Custom handling for the header sign out so that it won't trigger the
@@ -109,23 +94,7 @@
// text to the default text as this is not handled by the document click
// listener.
$("a[data-open='exit-notification']").on("click", () => {
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;
});
});