aboutsummaryrefslogtreecommitdiff
path: root/ext/mixed/js/display.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-15 18:44:49 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-09-27 21:41:00 -0400
commit8db830b46887ee49f8be268d35eaaf155979fc56 (patch)
tree277765f2940187f4143c4fe46975b6bf1da1ea0f /ext/mixed/js/display.js
parent3ca84e3a85e02659ca818cc0d0506cd4f374eb8c (diff)
Change how current entry is indicated
Diffstat (limited to 'ext/mixed/js/display.js')
-rw-r--r--ext/mixed/js/display.js19
1 files changed, 16 insertions, 3 deletions
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index b11e8f99..2f7a694e 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -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;
+ }
}