Change how current entry is indicated

This commit is contained in:
toasted-nutbread 2019-09-15 18:44:49 -04:00
parent 3ca84e3a85
commit 8db830b468
2 changed files with 20 additions and 3 deletions

View File

@ -230,3 +230,7 @@ div.glossary-item.compact-glossary {
.info-output td {
text-align: right;
}
.entry:not(.entry-current) .current {
display: none;
}

View File

@ -412,16 +412,23 @@ class Display {
index = Math.min(index, this.definitions.length - 1);
index = Math.max(index, 0);
$('.current').hide().eq(index).show();
const entryPre = this.getEntry(this.index);
if (entryPre !== null) {
entryPre.classList.remove('entry-current');
}
const entry = this.getEntry(index);
if (entry !== null) {
entry.classList.add('entry-current');
}
this.windowScroll.stop();
const entry = $('.entry').eq(index);
let target;
if (scroll) {
target = scroll;
} else {
target = index === 0 ? 0 : entry.offset().top;
target = index === 0 || entry === null ? 0 : Display.getElementTop(entry);
}
if (smooth) {
@ -606,4 +613,10 @@ class Display {
addEventListeners(selector, ...args) {
this.container.querySelectorAll(selector).forEach((node) => node.addEventListener(...args));
}
static getElementTop(element) {
const elementRect = element.getBoundingClientRect();
const documentRect = document.documentElement.getBoundingClientRect();
return elementRect.top - documentRect.top;
}
}