Skip to content

Commit

Permalink
refactor: clearer var names
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnaceMaes committed Feb 22, 2024
1 parent 18734e0 commit bfdf974
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions addon/modifiers/highlight-active-title.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { modifier } from 'ember-modifier';

export default modifier(function highlightActiveTitle(element, [toc]) {
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
const id = entry.target.getAttribute('aria-labelledby');
if (entry.intersectionRatio > 0) {
element
.querySelector(`a[href="#${id}"]`)
?.parentElement.classList.add('in-viewport');
const observer = new IntersectionObserver((tocSections) => {
tocSections.forEach((tocSection) => {
const tocId = tocSection.target.getAttribute('aria-labelledby');
const tocHeader = element.querySelector(`a[href="#${tocId}"]`);
if (tocSection.intersectionRatio > 0) {
tocHeader?.parentElement.classList.add('in-viewport');
} else {
element
.querySelector(`a[href="#${id}"]`)
?.parentElement.classList.remove('in-viewport');
tocHeader?.parentElement.classList.remove('in-viewport');
}
});
});
Expand Down

0 comments on commit bfdf974

Please sign in to comment.