@@ -979,121 +979,6 @@ function hideThemeButtonState() {
979979 onHashChange ( null ) ;
980980 window . addEventListener ( "hashchange" , onHashChange ) ;
981981 searchState . setup ( ) ;
982-
983- /////// --scrape-examples interactions
984-
985- // Scroll code block to put the given code location in the middle of the viewer
986- function scrollToLoc ( elt , loc ) {
987- var wrapper = elt . querySelector ( ".code-wrapper" ) ;
988- var halfHeight = wrapper . offsetHeight / 2 ;
989- var lines = elt . querySelector ( '.line-numbers' ) ;
990- var offsetMid = ( lines . children [ loc [ 0 ] ] . offsetTop
991- + lines . children [ loc [ 1 ] ] . offsetTop ) / 2 ;
992- var scrollOffset = offsetMid - halfHeight ;
993- lines . scrollTo ( 0 , scrollOffset ) ;
994- elt . querySelector ( ".rust" ) . scrollTo ( 0 , scrollOffset ) ;
995- }
996-
997- function updateScrapedExample ( example ) {
998- var locs = JSON . parse ( example . attributes . getNamedItem ( "data-locs" ) . textContent ) ;
999- var offset = parseInt ( example . attributes . getNamedItem ( "data-offset" ) . textContent ) ;
1000-
1001- var locIndex = 0 ;
1002- var highlights = example . querySelectorAll ( '.highlight' ) ;
1003- var link = example . querySelector ( '.scraped-example-title a' ) ;
1004- addClass ( highlights [ 0 ] , 'focus' ) ;
1005- if ( locs . length > 1 ) {
1006- // Toggle through list of examples in a given file
1007- var onChangeLoc = function ( f ) {
1008- removeClass ( highlights [ locIndex ] , 'focus' ) ;
1009- f ( ) ;
1010- scrollToLoc ( example , locs [ locIndex ] ) ;
1011- addClass ( highlights [ locIndex ] , 'focus' ) ;
1012-
1013- var curLoc = locs [ locIndex ] ;
1014- var minLine = curLoc [ 0 ] + offset + 1 ;
1015- var maxLine = curLoc [ 1 ] + offset + 1 ;
1016-
1017- var text ;
1018- var anchor ;
1019- if ( minLine == maxLine ) {
1020- text = 'line ' + minLine . toString ( ) ;
1021- anchor = minLine . toString ( ) ;
1022- } else {
1023- var range = minLine . toString ( ) + '-' + maxLine . toString ( ) ;
1024- text = 'lines ' + range ;
1025- anchor = range ;
1026- }
1027-
1028- var url = new URL ( link . href ) ;
1029- url . hash = anchor ;
1030-
1031- link . href = url . toString ( ) ;
1032- link . innerHTML = text ;
1033- } ;
1034-
1035- example . querySelector ( '.prev' )
1036- . addEventListener ( 'click' , function ( ) {
1037- onChangeLoc ( function ( ) {
1038- locIndex = ( locIndex - 1 + locs . length ) % locs . length ;
1039- } ) ;
1040- } ) ;
1041-
1042- example . querySelector ( '.next' )
1043- . addEventListener ( 'click' , function ( ) {
1044- onChangeLoc ( function ( ) { locIndex = ( locIndex + 1 ) % locs . length ; } ) ;
1045- } ) ;
1046- } else {
1047- // Remove buttons if there's only one example in the file
1048- example . querySelector ( '.prev' ) . remove ( ) ;
1049- example . querySelector ( '.next' ) . remove ( ) ;
1050- }
1051-
1052- var codeEl = example . querySelector ( '.rust' ) ;
1053- var codeOverflows = codeEl . scrollHeight > codeEl . clientHeight ;
1054- var expandButton = example . querySelector ( '.expand' ) ;
1055- if ( codeOverflows ) {
1056- // If file is larger than default height, give option to expand the viewer
1057- expandButton . addEventListener ( 'click' , function ( ) {
1058- if ( hasClass ( example , "expanded" ) ) {
1059- removeClass ( example , "expanded" ) ;
1060- scrollToLoc ( example , locs [ 0 ] ) ;
1061- } else {
1062- addClass ( example , "expanded" ) ;
1063- }
1064- } ) ;
1065- } else {
1066- // Otherwise remove expansion buttons
1067- addClass ( example , 'expanded' ) ;
1068- expandButton . remove ( ) ;
1069- }
1070-
1071- // Start with the first example in view
1072- scrollToLoc ( example , locs [ 0 ] ) ;
1073- }
1074-
1075- function updateScrapedExamples ( ) {
1076- var firstExamples = document . querySelectorAll ( '.scraped-example-list > .scraped-example' ) ;
1077- onEach ( firstExamples , updateScrapedExample ) ;
1078- onEach ( document . querySelectorAll ( '.more-examples-toggle' ) , function ( toggle ) {
1079- // Allow users to click the left border of the <details> section to close it,
1080- // since the section can be large and finding the [+] button is annoying.
1081- toggle . querySelector ( '.toggle-line' ) . addEventListener ( 'click' , function ( ) {
1082- toggle . open = false ;
1083- } ) ;
1084-
1085- var moreExamples = toggle . querySelectorAll ( '.scraped-example' ) ;
1086- toggle . querySelector ( 'summary' ) . addEventListener ( 'click' , function ( ) {
1087- // Wrapping in setTimeout ensures the update happens after the elements are actually
1088- // visible. This is necessary since updateScrapedExample calls scrollToLoc which
1089- // depends on offsetHeight, a property that requires an element to be visible to
1090- // compute correctly.
1091- setTimeout ( function ( ) { onEach ( moreExamples , updateScrapedExample ) ; } ) ;
1092- } , { once : true } ) ;
1093- } ) ;
1094- }
1095-
1096- updateScrapedExamples ( ) ;
1097982} ( ) ) ;
1098983
1099984( function ( ) {
0 commit comments