Skip to content

Commit

Permalink
fix: minor code improvements for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdeus committed Oct 19, 2024
1 parent 7b63165 commit bab5ee3
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 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 @@ -54,30 +54,31 @@ $(() => {

$(document).on("click.zf.trigger", (event) => {
// Try to get the <a> directly or find the closest parent <a>
let $target = $(event.target);
if (!$target.is("a")) {
// Find the closest parent <a> if the click is not directly on an <a>
$target = $target.closest("a");
}
const $target = $(event.target).closest("a");

// 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").
attr("name", "redirect_url").
attr("value", redirectUrl).
appendTo(`${dialogTarget} form`);
if (!$target) {
return;
}


const dialogTarget = `#${$target.data("dialog-open")}`;
const redirectUrl = $target.data("redirectUrl");

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

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

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

$(document).on("closed.zf.reveal", (event) => {
Expand Down

0 comments on commit bab5ee3

Please sign in to comment.