diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-15 18:44:49 -0400 |
---|---|---|
committer | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2019-09-27 21:41:00 -0400 |
commit | 8db830b46887ee49f8be268d35eaaf155979fc56 (patch) | |
tree | 277765f2940187f4143c4fe46975b6bf1da1ea0f /ext | |
parent | 3ca84e3a85e02659ca818cc0d0506cd4f374eb8c (diff) |
Change how current entry is indicated
Diffstat (limited to 'ext')
-rw-r--r-- | ext/mixed/css/display.css | 4 | ||||
-rw-r--r-- | ext/mixed/js/display.js | 19 |
2 files changed, 20 insertions, 3 deletions
diff --git a/ext/mixed/css/display.css b/ext/mixed/css/display.css index eadb9dae..8a4cf4a7 100644 --- a/ext/mixed/css/display.css +++ b/ext/mixed/css/display.css @@ -230,3 +230,7 @@ div.glossary-item.compact-glossary { .info-output td { text-align: right; } + +.entry:not(.entry-current) .current { + display: none; +} 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; + } } |