File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change 1
1
import { modifier } from 'ember-modifier' ;
2
2
3
3
export default modifier ( function highlightActiveTitle ( element , [ toc ] ) {
4
- const observer = new IntersectionObserver ( ( entries ) => {
5
- entries . forEach ( ( entry ) => {
6
- const id = entry . target . getAttribute ( 'aria-labelledby' ) ;
7
- if ( entry . intersectionRatio > 0 ) {
8
- element
9
- . querySelector ( `a[href="#${ id } "]` )
10
- ?. parentElement . classList . add ( 'in-viewport' ) ;
4
+ const observer = new IntersectionObserver ( ( tocSections ) => {
5
+ tocSections . forEach ( ( tocSection ) => {
6
+ const tocId = tocSection . target . getAttribute ( 'aria-labelledby' ) ;
7
+ const tocHeader = element . querySelector ( `a[href="#${ tocId } "]` ) ;
8
+ if ( tocSection . intersectionRatio > 0 ) {
9
+ tocHeader ?. parentElement . classList . add ( 'in-viewport' ) ;
11
10
} else {
12
- element
13
- . querySelector ( `a[href="#${ id } "]` )
14
- ?. parentElement . classList . remove ( 'in-viewport' ) ;
11
+ tocHeader ?. parentElement . classList . remove ( 'in-viewport' ) ;
15
12
}
16
13
} ) ;
17
14
} ) ;
You can’t perform that action at this time.
0 commit comments