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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prevent redirection issue when clicking text or icon within button #6

Closed
wants to merge 5 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,32 @@
return url;
}

$(document).on("click.zf.trigger", (event) => {

Check failure on line 55 in decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js

View workflow job for this annotation

GitHub Actions / Lint code (npm run lint)

'event' is defined but never used
const target = `#${$(event.target).data("dialogOpen")}`;
const redirectUrl = $(event.target).data("redirectUrl");

if (!target || !redirectUrl) {
return;
}

$("<input type='hidden' />").
attr("id", "redirect_url").
attr("name", "redirect_url").
attr("value", redirectUrl).
appendTo(`${target} form`);

$(`${target} a`).attr("href", (index, href) => {
const querystring = jQuery.param({ "redirect_url": redirectUrl });
return href + (href.match(/\?/) ? "&" : "?") + querystring;
$(document).on("click.zf.trigger", (event) => {

Check failure on line 56 in decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js

View workflow job for this annotation

GitHub Actions / Lint code (npm run lint)

'event' is already declared in the upper scope on line 55 column 39
// Try to get the <a> directly or find the closest parent <a>
let $target = $(event.target);
if (!$target.is('a')) {

Check failure on line 59 in decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js

View workflow job for this annotation

GitHub Actions / Lint code (npm run lint)

Strings must use doublequote
$target = $target.closest('a'); // Find the closest parent <a> if the click is not directly on an <a>

Check failure on line 60 in decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js

View workflow job for this annotation

GitHub Actions / Lint code (npm run lint)

Strings must use doublequote

Check failure on line 60 in decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js

View workflow job for this annotation

GitHub Actions / Lint code (npm run lint)

Expected comment to be above code

Check failure on line 60 in decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js

View workflow job for this annotation

GitHub Actions / Lint code (npm run lint)

Unexpected comment inline with code
}

// Check if an <a> was found
if ($target.length) {
const dialogTarget = `#${$target.data("dialog-open")}`;
const redirectUrl = $target.data("redirectUrl");

if (dialogTarget && redirectUrl) {
$("<input type='hidden' />")
.attr("id", "redirect_url")

Check failure on line 70 in decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js

View workflow job for this annotation

GitHub Actions / Lint code (npm run lint)

Expected dot to be on same line as object
.attr("name", "redirect_url")

Check failure on line 71 in decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js

View workflow job for this annotation

GitHub Actions / Lint code (npm run lint)

Expected dot to be on same line as object
.attr("value", redirectUrl)

Check failure on line 72 in decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js

View workflow job for this annotation

GitHub Actions / Lint code (npm run lint)

Expected dot to be on same line as object
.appendTo(`${dialogTarget} form`);

Check failure on line 73 in decidim-core/app/packs/src/decidim/append_redirect_url_to_modals.js

View workflow job for this annotation

GitHub Actions / Lint code (npm run lint)

Expected dot to be on same line as object

$(`${dialogTarget} a`).attr("href", (index, href) => {
const querystring = jQuery.param({"redirect_url": redirectUrl});
return href + (href.match(/\?/) ? "&" : "?") + querystring;
});
}
}
});
});

Expand Down
Loading