Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove beforeunload confirmation panel from the budgets voting #9224

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
});
});