Skip to content

Commit

Permalink
improve(NO-JIRA): Add clickable javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronware committed Jun 2, 2023
1 parent e8cdf9c commit d42ba96
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions assets/js/ash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Clickable elements
*/
document.getElementsByClassName('clickable').on( 'click', (event) => {
const tgt = event.target;
const href = tgt.getAttribute('href');

if ( href === null || href === undefined ) {

event.preventDefault();
event.stopPropagation();

const anchor = tgt.querySelector('a:first-of-type');
const btn = tgt.querySelector('button:first-of-type');
const uri = anchor ? anchor.getAttribute('href') : null;
const newWindow = tgt.classList.contains('external-link') || (anchor && anchor.classList.contains('external-link')) || (anchor && anchor.getAttribute( 'target' ) === '_blank') || event.metaKey || event.ctrlKey;

if ( btn ) {
event.stopImmediatePropagation();
btn.click();
return;
}

if ( ! btn && anchor ) {
if ( newWindow ) {
window.open( uri );
} else {
window.location = uri;
}
}

return false;
} else {
return;
}
});

0 comments on commit d42ba96

Please sign in to comment.