File tree Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Expand file tree Collapse file tree 2 files changed +17
-11
lines changed Original file line number Diff line number Diff line change 11import { el , getCurrentPageSidebarType , qs , qsAll } from '../helpers'
22import { getSidebarNodes } from '../globals'
33
4+ // Sidebar list is only rendered when needed.
5+ // Mobile users may never see the sidebar.
46let init = false
57export function initialize ( ) {
68 if ( init ) return
@@ -88,15 +90,15 @@ export function initialize () {
8890 } ) )
8991 } )
9092
91- window . addEventListener ( 'hashchange' , markCurrentHashInSidebar )
92-
93- // We listen to swup:page:view event because we need to trigger
94- // markCurrentHashInSidebar() before scollNodeListToCurrentCategory.
95- window . addEventListener ( 'swup:page:view' , markCurrentHashInSidebar )
93+ // Update new sidebar list with current hash.
9694 markCurrentHashInSidebar ( )
9795
9896 // Triggers layout, defer.
9997 requestAnimationFrame ( scrollNodeListToCurrentCategory )
98+
99+ // Keep updated with future changes.
100+ window . addEventListener ( 'hashchange' , markCurrentHashInSidebar )
101+ window . addEventListener ( 'exdoc:loaded' , markCurrentHashInSidebar )
100102}
101103
102104/**
Original file line number Diff line number Diff line change @@ -3,9 +3,14 @@ import SwupA11yPlugin from '@swup/a11y-plugin'
33import SwupProgressPlugin from '@swup/progress-plugin'
44import { isEmbedded } from './globals'
55
6- window . addEventListener ( 'DOMContentLoaded' , ( ) => {
6+ // Emit exdoc:loaded each time content loads:
7+ // - on initial page load (DOMContentLoaded)
8+ // - on subsequent SWUP page loads (page:view)
9+ const emitExdocLoaded = ( ) => {
710 window . dispatchEvent ( new Event ( 'exdoc:loaded' ) )
8- } )
11+ }
12+
13+ window . addEventListener ( 'DOMContentLoaded' , emitExdocLoaded )
914
1015if ( ! isEmbedded && window . location . protocol !== 'file:' ) {
1116 new Swup ( {
@@ -17,10 +22,9 @@ if (!isEmbedded && window.location.protocol !== 'file:') {
1722 path === window . location . pathname + '.html'
1823 } ,
1924 linkSelector : 'a[href]:not([href^="/"]):not([href^="http"])' ,
25+ hooks : {
26+ 'page:view' : emitExdocLoaded
27+ } ,
2028 plugins : [ new SwupA11yPlugin ( ) , new SwupProgressPlugin ( { delay : 500 } ) ]
2129 } )
22-
23- window . addEventListener ( 'swup:page:view' , ( ) => {
24- window . dispatchEvent ( new Event ( 'exdoc:loaded' ) )
25- } )
2630}
You can’t perform that action at this time.
0 commit comments