File tree Expand file tree Collapse file tree 3 files changed +54
-2
lines changed
assets/stylesheets/components Expand file tree Collapse file tree 3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 290290 transform : translateY (-1px );
291291 text-decoration : none;
292292}
293+
294+ .help-outline-link {
295+ & .active {
296+ font-weight : bold;
297+ }
298+ }
Original file line number Diff line number Diff line change 1+ import { Controller } from "@hotwired/stimulus"
2+
3+ export default class extends Controller {
4+ static targets = [ "link" ]
5+
6+ connect ( ) {
7+ this . observer = new IntersectionObserver (
8+ this . onIntersect . bind ( this ) ,
9+ {
10+ rootMargin : "0px 0px -80% 0px" ,
11+ threshold : 0
12+ }
13+ )
14+
15+ this . headings ( ) . forEach ( heading => this . observer . observe ( heading ) )
16+ }
17+
18+ disconnect ( ) {
19+ this . observer . disconnect ( )
20+ }
21+
22+ onIntersect ( entries ) {
23+ entries . forEach ( entry => {
24+ if ( entry . isIntersecting ) {
25+ this . setActive ( entry . target . id )
26+ }
27+ } )
28+ }
29+
30+ setActive ( id ) {
31+ this . linkTargets . forEach ( link => {
32+ link . classList . toggle (
33+ "active" ,
34+ link . getAttribute ( "href" ) === `#${ id } `
35+ )
36+ } )
37+ }
38+
39+ headings ( ) {
40+ return Array . from (
41+ document . querySelectorAll ( ".help-content h1, .help-content h2, .help-content h3" )
42+ )
43+ }
44+ }
Original file line number Diff line number Diff line change 66 - if @outline .present?
77 .help-outline
88 .help-outline-header On this page
9- nav .help-outline-nav
9+ nav .help-outline-nav data-controller = " help-outline "
1010 - @outline .each do |heading |
11- = link_to " ##{ heading[:id ] } " , class : " help-outline-link level-#{ heading[:level ] } " do
11+ = link_to " ##{ heading[:id ] } " ,
12+ class : " help-outline-link level-#{ heading[:level ] } " ,
13+ data: { help_outline_target: " link" } do
1214 = heading[:title ]
1315
1416 nav .help-nav
You can’t perform that action at this time.
0 commit comments