You've already forked 98.css
mirror of
https://github.com/jdan/98.css.git
synced 2026-05-05 06:01:22 +09:00
Merge pull request #177 from jdan/fix-172-tableview-event-path-access
fix exception on table element click
This commit is contained in:
@@ -965,9 +965,16 @@
|
|||||||
<script>
|
<script>
|
||||||
document.querySelectorAll('table.interactive').forEach(element => {
|
document.querySelectorAll('table.interactive').forEach(element => {
|
||||||
element.addEventListener('click', (event) => {
|
element.addEventListener('click', (event) => {
|
||||||
const row = event.path.find(element => element.tagName === 'TR' && element.parentElement.tagName === 'TBODY');
|
const highlightedClass = 'highlighted';
|
||||||
if (row) {
|
const isRow = element => element.tagName === 'TR' && element.parentElement.tagName === 'TBODY';
|
||||||
row.classList.toggle('highlighted');
|
const newlySelectedRow = event.composedPath().find(isRow);
|
||||||
|
const previouslySelectedRow = Array.from(newlySelectedRow.parentElement.children).filter(isRow).find(element => element.classList.contains(highlightedClass));
|
||||||
|
if(previouslySelectedRow){
|
||||||
|
previouslySelectedRow.classList.toggle(highlightedClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newlySelectedRow) {
|
||||||
|
newlySelectedRow.classList.toggle(highlightedClass);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user