@@ -381,56 +381,9 @@ function hideThemeButtonState() {
381
381
}
382
382
}
383
383
384
- function highlightSourceLines ( match , ev ) {
385
- if ( typeof match === "undefined" ) {
386
- // If we're in mobile mode, we should hide the sidebar in any case.
387
- hideSidebar ( ) ;
388
- match = window . location . hash . match ( / ^ # ? ( \d + ) (?: - ( \d + ) ) ? $ / ) ;
389
- }
390
- if ( ! match ) {
391
- return ;
392
- }
393
- var from = parseInt ( match [ 1 ] , 10 ) ;
394
- var to = from ;
395
- if ( typeof match [ 2 ] !== "undefined" ) {
396
- to = parseInt ( match [ 2 ] , 10 ) ;
397
- }
398
- if ( to < from ) {
399
- var tmp = to ;
400
- to = from ;
401
- from = tmp ;
402
- }
403
- var elem = document . getElementById ( from ) ;
404
- if ( ! elem ) {
405
- return ;
406
- }
407
- if ( ! ev ) {
408
- var x = document . getElementById ( from ) ;
409
- if ( x ) {
410
- x . scrollIntoView ( ) ;
411
- }
412
- }
413
- onEachLazy ( document . getElementsByClassName ( "line-numbers" ) , function ( e ) {
414
- onEachLazy ( e . getElementsByTagName ( "span" ) , function ( i_e ) {
415
- removeClass ( i_e , "line-highlighted" ) ;
416
- } ) ;
417
- } ) ;
418
- for ( var i = from ; i <= to ; ++ i ) {
419
- elem = document . getElementById ( i ) ;
420
- if ( ! elem ) {
421
- break ;
422
- }
423
- addClass ( elem , "line-highlighted" ) ;
424
- }
425
- }
426
-
427
384
function onHashChange ( ev ) {
428
385
// If we're in mobile mode, we should hide the sidebar in any case.
429
386
hideSidebar ( ) ;
430
- var match = window . location . hash . match ( / ^ # ? ( \d + ) (?: - ( \d + ) ) ? $ / ) ;
431
- if ( match ) {
432
- return highlightSourceLines ( match , ev ) ;
433
- }
434
387
handleHashes ( ev ) ;
435
388
}
436
389
@@ -585,78 +538,9 @@ function hideThemeButtonState() {
585
538
}
586
539
}
587
540
588
- function findParentElement ( elem , tagName ) {
589
- do {
590
- if ( elem && elem . tagName === tagName ) {
591
- return elem ;
592
- }
593
- elem = elem . parentNode ;
594
- } while ( elem ) ;
595
- return null ;
596
- }
597
-
598
541
document . addEventListener ( "keypress" , handleShortcut ) ;
599
542
document . addEventListener ( "keydown" , handleShortcut ) ;
600
543
601
- var handleSourceHighlight = ( function ( ) {
602
- var prev_line_id = 0 ;
603
-
604
- var set_fragment = function ( name ) {
605
- var x = window . scrollX ,
606
- y = window . scrollY ;
607
- if ( searchState . browserSupportsHistoryApi ( ) ) {
608
- history . replaceState ( null , null , "#" + name ) ;
609
- highlightSourceLines ( ) ;
610
- } else {
611
- location . replace ( "#" + name ) ;
612
- }
613
- // Prevent jumps when selecting one or many lines
614
- window . scrollTo ( x , y ) ;
615
- } ;
616
-
617
- return function ( ev ) {
618
- var cur_line_id = parseInt ( ev . target . id , 10 ) ;
619
- ev . preventDefault ( ) ;
620
-
621
- if ( ev . shiftKey && prev_line_id ) {
622
- // Swap selection if needed
623
- if ( prev_line_id > cur_line_id ) {
624
- var tmp = prev_line_id ;
625
- prev_line_id = cur_line_id ;
626
- cur_line_id = tmp ;
627
- }
628
-
629
- set_fragment ( prev_line_id + "-" + cur_line_id ) ;
630
- } else {
631
- prev_line_id = cur_line_id ;
632
-
633
- set_fragment ( cur_line_id ) ;
634
- }
635
- } ;
636
- } ( ) ) ;
637
-
638
- document . addEventListener ( "click" , function ( ev ) {
639
- var helpElem = getHelpElement ( false ) ;
640
- if ( hasClass ( ev . target , "help-button" ) ) {
641
- displayHelp ( true , ev ) ;
642
- } else if ( ev . target . tagName === "SPAN" && hasClass ( ev . target . parentNode , "line-numbers" ) ) {
643
- handleSourceHighlight ( ev ) ;
644
- } else if ( helpElem && hasClass ( helpElem , "hidden" ) === false ) {
645
- var is_inside_help_popup = ev . target !== helpElem && helpElem . contains ( ev . target ) ;
646
- if ( is_inside_help_popup === false ) {
647
- addClass ( helpElem , "hidden" ) ;
648
- removeClass ( document . body , "blur" ) ;
649
- }
650
- } else {
651
- // Making a collapsed element visible on onhashchange seems
652
- // too late
653
- var a = findParentElement ( ev . target , "A" ) ;
654
- if ( a && a . hash ) {
655
- expandSection ( a . hash . replace ( / ^ # / , "" ) ) ;
656
- }
657
- }
658
- } ) ;
659
-
660
544
( function ( ) {
661
545
var x = document . getElementsByClassName ( "version-selector" ) ;
662
546
if ( x . length > 0 ) {
@@ -1121,6 +1005,27 @@ function hideThemeButtonState() {
1121
1005
} ) ;
1122
1006
} ( ) ) ;
1123
1007
1008
+ function handleClick ( id , f ) {
1009
+ var elem = document . getElementById ( id ) ;
1010
+ if ( elem ) {
1011
+ elem . addEventListener ( "click" , f ) ;
1012
+ }
1013
+ }
1014
+ handleClick ( "help-button" , function ( ev ) {
1015
+ displayHelp ( true , ev ) ;
1016
+ } ) ;
1017
+
1018
+ onEachLazy ( document . getElementsByTagName ( "a" ) , function ( el ) {
1019
+ // For clicks on internal links (<A> tags with a hash property), we expand the section we're
1020
+ // jumping to *before* jumping there. We can't do this in onHashChange, because it changes
1021
+ // the height of the document so we wind up scrolled to the wrong place.
1022
+ if ( el . hash ) {
1023
+ el . addEventListener ( "click" , function ( ) {
1024
+ expandSection ( el . hash . slice ( 1 ) ) ;
1025
+ } ) ;
1026
+ }
1027
+ } ) ;
1028
+
1124
1029
onEachLazy ( document . getElementsByClassName ( "notable-traits" ) , function ( e ) {
1125
1030
e . onclick = function ( ) {
1126
1031
this . getElementsByClassName ( 'notable-traits-tooltiptext' ) [ 0 ]
@@ -1165,6 +1070,13 @@ function hideThemeButtonState() {
1165
1070
addClass ( popup , "hidden" ) ;
1166
1071
popup . id = "help" ;
1167
1072
1073
+ popup . addEventListener ( "click" , function ( ev ) {
1074
+ if ( ev . target === popup ) {
1075
+ // Clicked the blurred zone outside the help popup; dismiss help.
1076
+ displayHelp ( false , ev ) ;
1077
+ }
1078
+ } ) ;
1079
+
1168
1080
var book_info = document . createElement ( "span" ) ;
1169
1081
book_info . innerHTML = "You can find more information in \
1170
1082
<a href=\"https://doc.rust-lang.org/rustdoc/\">the rustdoc book</a>." ;
@@ -1223,7 +1135,7 @@ function hideThemeButtonState() {
1223
1135
}
1224
1136
1225
1137
onHashChange ( null ) ;
1226
- window . onhashchange = onHashChange ;
1138
+ window . addEventListener ( "hashchange" , onHashChange ) ;
1227
1139
searchState . setup ( ) ;
1228
1140
} ( ) ) ;
1229
1141
0 commit comments