@@ -78,8 +78,6 @@ var prototype = {
78
78
if ( ! titles . length ) {
79
79
this . parentNode . removeChild ( this ) ;
80
80
return ;
81
- } else {
82
- this . parentNode . style . display = 'block' ;
83
81
}
84
82
85
83
// Append our template
@@ -112,6 +110,16 @@ var prototype = {
112
110
return ( typeof depth === "number" ? Math . min ( depth , 6 ) : 1 ) ;
113
111
}
114
112
} ,
113
+ get outlineScrollElement ( ) {
114
+ if ( this . scrollSelector === "true" || this . scrollSelector === "" ) {
115
+ return this ;
116
+ } else if ( this . scrollSelector ) {
117
+ return document . querySelector ( this . scroll ) ;
118
+ }
119
+ else {
120
+ return ;
121
+ }
122
+ } ,
115
123
get containerSelector ( ) {
116
124
return this . headingsContainerSelector || "article" ;
117
125
} ,
@@ -131,7 +139,7 @@ var prototype = {
131
139
setupHighlighting : function ( ) {
132
140
this . article = document . querySelector ( this . containerSelector ) ;
133
141
if ( this . article ) {
134
- var highlight = debounce ( this . highlight . bind ( this ) , 50 ) ;
142
+ var highlight = debounce ( this . highlight . bind ( this ) , 1 ) ;
135
143
this . article . addEventListener ( "scroll" , highlight ) ;
136
144
this . teardowns . push ( function ( ) {
137
145
this . article . removeEventListener ( "scroll" , highlight ) ;
@@ -188,6 +196,13 @@ var prototype = {
188
196
position . button . classList . add ( "active" ) ;
189
197
}
190
198
} ) ;
199
+ var elementToScroll = this . outlineScrollElement ;
200
+
201
+ if ( elementToScroll ) {
202
+ // find out where the midpoint is
203
+ var distance = ( this . article . scrollTop + this . article . offsetHeight / 2 ) / this . article . scrollHeight ;
204
+ elementToScroll . scrollTop = ( elementToScroll . scrollHeight * distance ) - ( elementToScroll . offsetHeight / 2 ) ;
205
+ }
191
206
} ,
192
207
disconnectedCallback : function ( ) {
193
208
this . teardowns . forEach ( function ( teardown ) {
0 commit comments