30 lines
748 B
JavaScript
30 lines
748 B
JavaScript
|
|
/**
|
||
|
|
* Shared clickable-row behaviour for helpdesk tables.
|
||
|
|
* Navigates to `data-href` on click or Enter/Space key.
|
||
|
|
*/
|
||
|
|
export function initClickableRows() {
|
||
|
|
const rows = document.querySelectorAll('.app-clickable-row[data-href]');
|
||
|
|
|
||
|
|
rows.forEach((row) => {
|
||
|
|
row.addEventListener('click', (event) => {
|
||
|
|
if (event.target.closest('a')) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const href = row.dataset.href;
|
||
|
|
if (href) {
|
||
|
|
window.location.href = href;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
row.addEventListener('keydown', (event) => {
|
||
|
|
if (event.key === 'Enter' || event.key === ' ') {
|
||
|
|
event.preventDefault();
|
||
|
|
const href = row.dataset.href;
|
||
|
|
if (href) {
|
||
|
|
window.location.href = href;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|