Skip to content

Commit

Permalink
check for the closest anchor when trying to open a link (#3923)
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom authored Nov 5, 2024
1 parent 83e93fb commit 5ec1821
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions apps/dashboard/app/javascript/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,17 @@ export function bindFullPageSpinnerEvent() {
// open links in javascript and display an alert
export function openLinkInJs(event) {
event.preventDefault();
const href = event.target.href;
let href = event.target.href;

// do nothing if there's no href.
if(href == null){
return;
// event.target could be a child of the anchor, so try that.
if(href == null) {
const closestAnchor = event.target.closest('a');
if(closestAnchor.hasChildNodes(event.target)) {
href = closestAnchor.href;
} else {
// event.target is not a child of an anhcor, so there's nothing to do.
return;
}
}

if(window.open(href) == null) {
Expand Down

0 comments on commit 5ec1821

Please sign in to comment.