Skip to content

Commit

Permalink
check for the closest anchor when trying to open a link
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Oct 31, 2024
1 parent 65e5edd commit e268e1c
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 e268e1c

Please sign in to comment.