@@ -163,59 +163,71 @@ function getSearchElement() {
163
163
164
164
var main = document . getElementById ( "main" ) ;
165
165
166
- function highlightSourceLines ( ev ) {
167
- // If we're in mobile mode, we should add the sidebar in any case.
166
+ function onHashChange ( ev ) {
167
+ // If we're in mobile mode, we should hide the sidebar in any case.
168
168
hideSidebar ( ) ;
169
- var elem ;
170
- var search = getSearchElement ( ) ;
171
- var i , from , to , match = window . location . hash . match ( / ^ # ? ( \d + ) (?: - ( \d + ) ) ? $ / ) ;
169
+ var match = window . location . hash . match ( / ^ # ? ( \d + ) (?: - ( \d + ) ) ? $ / ) ;
172
170
if ( match ) {
173
- from = parseInt ( match [ 1 ] , 10 ) ;
174
- to = from ;
175
- if ( typeof match [ 2 ] !== "undefined" ) {
176
- to = parseInt ( match [ 2 ] , 10 ) ;
177
- }
178
- if ( to < from ) {
179
- var tmp = to ;
180
- to = from ;
181
- from = tmp ;
182
- }
183
- elem = document . getElementById ( from ) ;
184
- if ( ! elem ) {
185
- return ;
186
- }
187
- if ( ev === null ) {
188
- var x = document . getElementById ( from ) ;
189
- if ( x ) {
190
- x . scrollIntoView ( ) ;
191
- }
192
- }
193
- onEachLazy ( document . getElementsByClassName ( "line-numbers" ) , function ( e ) {
194
- onEachLazy ( e . getElementsByTagName ( "span" ) , function ( i_e ) {
195
- removeClass ( i_e , "line-highlighted" ) ;
196
- } ) ;
197
- } ) ;
198
- for ( i = from ; i <= to ; ++ i ) {
199
- elem = document . getElementById ( i ) ;
200
- if ( ! elem ) {
201
- break ;
202
- }
203
- addClass ( elem , "line-highlighted" ) ;
204
- }
205
- } else if ( ev !== null && search && ! hasClass ( search , "hidden" ) && ev . newURL ) {
171
+ return highlightSourceLines ( match , ev ) ;
172
+ }
173
+ var search = getSearchElement ( ) ;
174
+ if ( ev !== null && search && ! hasClass ( search , "hidden" ) && ev . newURL ) {
206
175
addClass ( search , "hidden" ) ;
207
176
removeClass ( main , "hidden" ) ;
208
177
var hash = ev . newURL . slice ( ev . newURL . indexOf ( "#" ) + 1 ) ;
209
178
if ( browserSupportsHistoryApi ( ) ) {
210
179
history . replaceState ( hash , "" , "?search=#" + hash ) ;
211
180
}
212
- elem = document . getElementById ( hash ) ;
181
+ var elem = document . getElementById ( hash ) ;
213
182
if ( elem ) {
214
183
elem . scrollIntoView ( ) ;
215
184
}
216
185
}
217
186
}
218
187
188
+ function highlightSourceLines ( match , ev ) {
189
+ if ( typeof match === "undefined" ) {
190
+ // If we're in mobile mode, we should hide the sidebar in any case.
191
+ hideSidebar ( ) ;
192
+ match = window . location . hash . match ( / ^ # ? ( \d + ) (?: - ( \d + ) ) ? $ / ) ;
193
+ }
194
+ if ( ! match ) {
195
+ return ;
196
+ }
197
+ var from = parseInt ( match [ 1 ] , 10 ) ;
198
+ var to = from ;
199
+ if ( typeof match [ 2 ] !== "undefined" ) {
200
+ to = parseInt ( match [ 2 ] , 10 ) ;
201
+ }
202
+ if ( to < from ) {
203
+ var tmp = to ;
204
+ to = from ;
205
+ from = tmp ;
206
+ }
207
+ var elem = document . getElementById ( from ) ;
208
+ if ( ! elem ) {
209
+ return ;
210
+ }
211
+ if ( ! ev ) {
212
+ var x = document . getElementById ( from ) ;
213
+ if ( x ) {
214
+ x . scrollIntoView ( ) ;
215
+ }
216
+ }
217
+ onEachLazy ( document . getElementsByClassName ( "line-numbers" ) , function ( e ) {
218
+ onEachLazy ( e . getElementsByTagName ( "span" ) , function ( i_e ) {
219
+ removeClass ( i_e , "line-highlighted" ) ;
220
+ } ) ;
221
+ } ) ;
222
+ for ( var i = from ; i <= to ; ++ i ) {
223
+ elem = document . getElementById ( i ) ;
224
+ if ( ! elem ) {
225
+ break ;
226
+ }
227
+ addClass ( elem , "line-highlighted" ) ;
228
+ }
229
+ }
230
+
219
231
function expandSection ( id ) {
220
232
var elem = document . getElementById ( id ) ;
221
233
if ( elem && isHidden ( elem ) ) {
@@ -234,8 +246,8 @@ function getSearchElement() {
234
246
}
235
247
}
236
248
237
- highlightSourceLines ( null ) ;
238
- window . onhashchange = highlightSourceLines ;
249
+ highlightSourceLines ( ) ;
250
+ window . onhashchange = onHashChange ;
239
251
240
252
// Gets the human-readable string for the virtual-key code of the
241
253
// given KeyboardEvent, ev.
@@ -358,7 +370,7 @@ function getSearchElement() {
358
370
var set_fragment = function ( name ) {
359
371
if ( browserSupportsHistoryApi ( ) ) {
360
372
history . replaceState ( null , null , "#" + name ) ;
361
- highlightSourceLines ( null ) ;
373
+ highlightSourceLines ( ) ;
362
374
} else {
363
375
location . replace ( "#" + name ) ;
364
376
}
0 commit comments