1
1
/* eslint-env es6 */
2
2
/* eslint no-var: "error" */
3
3
/* eslint prefer-const: "error" */
4
+ /* eslint prefer-arrow-callback: "error" */
4
5
// Local js definitions:
5
6
/* global addClass, getSettingValue, hasClass, searchState */
6
7
/* global onEach, onEachLazy, removeClass */
@@ -152,7 +153,7 @@ function hideThemeButtonState() {
152
153
themePicker . style . borderBottomLeftRadius = "3px" ;
153
154
}
154
155
155
- window . hideSettings = function ( ) {
156
+ window . hideSettings = ( ) => {
156
157
// Does nothing by default.
157
158
} ;
158
159
@@ -190,10 +191,10 @@ window.hideSettings = function() {
190
191
191
192
themePicker . onclick = switchThemeButtonState ;
192
193
themePicker . onblur = handleThemeButtonsBlur ;
193
- availableThemes . forEach ( function ( item ) {
194
+ availableThemes . forEach ( item => {
194
195
const but = document . createElement ( "button" ) ;
195
196
but . textContent = item ;
196
- but . onclick = function ( ) {
197
+ but . onclick = ( ) => {
197
198
switchTheme ( window . currentTheme , window . mainTheme , item , true ) ;
198
199
useSystemTheme ( false ) ;
199
200
} ;
@@ -300,15 +301,15 @@ function loadCss(cssFileName) {
300
301
}
301
302
302
303
303
- getSettingsButton ( ) . onclick = function ( event ) {
304
+ getSettingsButton ( ) . onclick = event => {
304
305
event . preventDefault ( ) ;
305
306
loadScript ( window . settingsJS ) ;
306
307
} ;
307
308
308
309
window . searchState = {
309
310
loadingText : "Loading search results..." ,
310
311
input : document . getElementsByClassName ( "search-input" ) [ 0 ] ,
311
- outputElement : function ( ) {
312
+ outputElement : ( ) => {
312
313
let el = document . getElementById ( "search" ) ;
313
314
if ( ! el ) {
314
315
el = document . createElement ( "section" ) ;
@@ -328,32 +329,30 @@ function loadCss(cssFileName) {
328
329
currentTab : 0 ,
329
330
// tab and back preserves the element that was focused.
330
331
focusedByTab : [ null , null , null ] ,
331
- clearInputTimeout : function ( ) {
332
+ clearInputTimeout : ( ) => {
332
333
if ( searchState . timeout !== null ) {
333
334
clearTimeout ( searchState . timeout ) ;
334
335
searchState . timeout = null ;
335
336
}
336
337
} ,
337
- isDisplayed : function ( ) {
338
- return searchState . outputElement ( ) . parentElement . id === ALTERNATIVE_DISPLAY_ID ;
339
- } ,
338
+ isDisplayed : ( ) => searchState . outputElement ( ) . parentElement . id === ALTERNATIVE_DISPLAY_ID ,
340
339
// Sets the focus on the search bar at the top of the page
341
- focus : function ( ) {
340
+ focus : ( ) => {
342
341
searchState . input . focus ( ) ;
343
342
} ,
344
343
// Removes the focus from the search bar.
345
- defocus : function ( ) {
344
+ defocus : ( ) => {
346
345
searchState . input . blur ( ) ;
347
346
} ,
348
- showResults : function ( search ) {
347
+ showResults : search => {
349
348
if ( search === null || typeof search === 'undefined' ) {
350
349
search = searchState . outputElement ( ) ;
351
350
}
352
351
switchDisplayedElement ( search ) ;
353
352
searchState . mouseMovedAfterSearch = false ;
354
353
document . title = searchState . title ;
355
354
} ,
356
- hideResults : function ( ) {
355
+ hideResults : ( ) => {
357
356
switchDisplayedElement ( null ) ;
358
357
document . title = searchState . titleBeforeSearch ;
359
358
// We also remove the query parameter from the URL.
@@ -362,17 +361,17 @@ function loadCss(cssFileName) {
362
361
getNakedUrl ( ) + window . location . hash ) ;
363
362
}
364
363
} ,
365
- getQueryStringParams : function ( ) {
364
+ getQueryStringParams : ( ) => {
366
365
const params = { } ;
367
366
window . location . search . substring ( 1 ) . split ( "&" ) .
368
- map ( function ( s ) {
367
+ map ( s => {
369
368
const pair = s . split ( "=" ) ;
370
369
params [ decodeURIComponent ( pair [ 0 ] ) ] =
371
370
typeof pair [ 1 ] === "undefined" ? null : decodeURIComponent ( pair [ 1 ] ) ;
372
371
} ) ;
373
372
return params ;
374
373
} ,
375
- setup : function ( ) {
374
+ setup : ( ) => {
376
375
const search_input = searchState . input ;
377
376
if ( ! searchState . input ) {
378
377
return ;
@@ -386,13 +385,13 @@ function loadCss(cssFileName) {
386
385
}
387
386
}
388
387
389
- search_input . addEventListener ( "focus" , function ( ) {
388
+ search_input . addEventListener ( "focus" , ( ) => {
390
389
search_input . origPlaceholder = search_input . placeholder ;
391
390
search_input . placeholder = "Type your search here." ;
392
391
loadSearch ( ) ;
393
392
} ) ;
394
393
395
- if ( search_input . value != '' ) {
394
+ if ( search_input . value !== '' ) {
396
395
loadSearch ( ) ;
397
396
}
398
397
@@ -620,7 +619,7 @@ function loadCss(cssFileName) {
620
619
document . addEventListener ( "keydown" , handleShortcut ) ;
621
620
622
621
// delayed sidebar rendering.
623
- window . initSidebarItems = function ( items ) {
622
+ window . initSidebarItems = items => {
624
623
const sidebar = document . getElementsByClassName ( "sidebar-elems" ) [ 0 ] ;
625
624
let others ;
626
625
const current = window . sidebarCurrent ;
@@ -731,7 +730,7 @@ function loadCss(cssFileName) {
731
730
}
732
731
} ;
733
732
734
- window . register_implementors = function ( imp ) {
733
+ window . register_implementors = imp => {
735
734
const implementors = document . getElementById ( "implementors-list" ) ;
736
735
const synthetic_implementors = document . getElementById ( "synthetic-implementors-list" ) ;
737
736
const inlined_types = new Set ( ) ;
@@ -742,12 +741,12 @@ function loadCss(cssFileName) {
742
741
//
743
742
// By the way, this is only used by and useful for traits implemented automatically
744
743
// (like "Send" and "Sync").
745
- onEachLazy ( synthetic_implementors . getElementsByClassName ( "impl" ) , function ( el ) {
744
+ onEachLazy ( synthetic_implementors . getElementsByClassName ( "impl" ) , el => {
746
745
const aliases = el . getAttribute ( "data-aliases" ) ;
747
746
if ( ! aliases ) {
748
747
return ;
749
748
}
750
- aliases . split ( "," ) . forEach ( function ( alias ) {
749
+ aliases . split ( "," ) . forEach ( alias => {
751
750
inlined_types . add ( alias ) ;
752
751
} ) ;
753
752
} ) ;
@@ -781,7 +780,7 @@ function loadCss(cssFileName) {
781
780
addClass ( code , "code-header" ) ;
782
781
addClass ( code , "in-band" ) ;
783
782
784
- onEachLazy ( code . getElementsByTagName ( "a" ) , function ( elem ) {
783
+ onEachLazy ( code . getElementsByTagName ( "a" ) , elem => {
785
784
const href = elem . getAttribute ( "href" ) ;
786
785
787
786
if ( href && href . indexOf ( "http" ) !== 0 ) {
@@ -826,15 +825,15 @@ function loadCss(cssFileName) {
826
825
let sectionIsCollapsed = false ;
827
826
if ( hasClass ( innerToggle , "will-expand" ) ) {
828
827
removeClass ( innerToggle , "will-expand" ) ;
829
- onEachLazy ( document . getElementsByClassName ( "rustdoc-toggle" ) , function ( e ) {
828
+ onEachLazy ( document . getElementsByClassName ( "rustdoc-toggle" ) , e => {
830
829
if ( ! hasClass ( e , "type-contents-toggle" ) ) {
831
830
e . open = true ;
832
831
}
833
832
} ) ;
834
833
innerToggle . title = "collapse all docs" ;
835
834
} else {
836
835
addClass ( innerToggle , "will-expand" ) ;
837
- onEachLazy ( document . getElementsByClassName ( "rustdoc-toggle" ) , function ( e ) {
836
+ onEachLazy ( document . getElementsByClassName ( "rustdoc-toggle" ) , e => {
838
837
if ( e . parentNode . id !== "implementations-list" ||
839
838
( ! hasClass ( e , "implementors-toggle" ) &&
840
839
! hasClass ( e , "type-contents-toggle" ) ) )
@@ -861,7 +860,7 @@ function loadCss(cssFileName) {
861
860
function setImplementorsTogglesOpen ( id , open ) {
862
861
const list = document . getElementById ( id ) ;
863
862
if ( list !== null ) {
864
- onEachLazy ( list . getElementsByClassName ( "implementors-toggle" ) , function ( e ) {
863
+ onEachLazy ( list . getElementsByClassName ( "implementors-toggle" ) , e => {
865
864
e . open = open ;
866
865
} ) ;
867
866
}
@@ -872,7 +871,7 @@ function loadCss(cssFileName) {
872
871
setImplementorsTogglesOpen ( "blanket-implementations-list" , false ) ;
873
872
}
874
873
875
- onEachLazy ( document . getElementsByClassName ( "rustdoc-toggle" ) , function ( e ) {
874
+ onEachLazy ( document . getElementsByClassName ( "rustdoc-toggle" ) , e => {
876
875
if ( ! hideLargeItemContents && hasClass ( e , "type-contents-toggle" ) ) {
877
876
e . open = true ;
878
877
}
@@ -890,9 +889,9 @@ function loadCss(cssFileName) {
890
889
891
890
( function ( ) {
892
891
// To avoid checking on "rustdoc-line-numbers" value on every loop...
893
- let lineNumbersFunc = function ( ) { } ;
892
+ let lineNumbersFunc = ( ) => { } ;
894
893
if ( getSettingValue ( "line-numbers" ) === "true" ) {
895
- lineNumbersFunc = function ( x ) {
894
+ lineNumbersFunc = x => {
896
895
const count = x . textContent . split ( "\n" ) . length ;
897
896
const elems = [ ] ;
898
897
for ( let i = 0 ; i < count ; ++ i ) {
@@ -904,7 +903,7 @@ function loadCss(cssFileName) {
904
903
x . parentNode . insertBefore ( node , x ) ;
905
904
} ;
906
905
}
907
- onEachLazy ( document . getElementsByClassName ( "rust-example-rendered" ) , function ( e ) {
906
+ onEachLazy ( document . getElementsByClassName ( "rust-example-rendered" ) , e => {
908
907
if ( hasClass ( e , "compile_fail" ) ) {
909
908
e . addEventListener ( "mouseover" , function ( ) {
910
909
this . parentElement . previousElementSibling . childNodes [ 0 ] . style . color = "#f00" ;
@@ -935,34 +934,34 @@ function loadCss(cssFileName) {
935
934
elem . addEventListener ( "click" , f ) ;
936
935
}
937
936
}
938
- handleClick ( "help-button" , function ( ev ) {
937
+ handleClick ( "help-button" , ev => {
939
938
displayHelp ( true , ev ) ;
940
939
} ) ;
941
- handleClick ( MAIN_ID , function ( ) {
940
+ handleClick ( MAIN_ID , ( ) => {
942
941
hideSidebar ( ) ;
943
942
} ) ;
944
943
945
- onEachLazy ( document . getElementsByTagName ( "a" ) , function ( el ) {
944
+ onEachLazy ( document . getElementsByTagName ( "a" ) , el => {
946
945
// For clicks on internal links (<A> tags with a hash property), we expand the section we're
947
946
// jumping to *before* jumping there. We can't do this in onHashChange, because it changes
948
947
// the height of the document so we wind up scrolled to the wrong place.
949
948
if ( el . hash ) {
950
- el . addEventListener ( "click" , function ( ) {
949
+ el . addEventListener ( "click" , ( ) => {
951
950
expandSection ( el . hash . slice ( 1 ) ) ;
952
951
hideSidebar ( ) ;
953
952
} ) ;
954
953
}
955
954
} ) ;
956
955
957
- onEachLazy ( document . querySelectorAll ( ".rustdoc-toggle > summary:not(.hideme)" ) , function ( el ) {
958
- el . addEventListener ( "click" , function ( e ) {
959
- if ( e . target . tagName != "SUMMARY" && e . target . tagName != "A" ) {
956
+ onEachLazy ( document . querySelectorAll ( ".rustdoc-toggle > summary:not(.hideme)" ) , el => {
957
+ el . addEventListener ( "click" , e => {
958
+ if ( e . target . tagName !== "SUMMARY" && e . target . tagName != = "A" ) {
960
959
e . preventDefault ( ) ;
961
960
}
962
961
} ) ;
963
962
} ) ;
964
963
965
- onEachLazy ( document . getElementsByClassName ( "notable-traits" ) , function ( e ) {
964
+ onEachLazy ( document . getElementsByClassName ( "notable-traits" ) , e => {
966
965
e . onclick = function ( ) {
967
966
this . getElementsByClassName ( 'notable-traits-tooltiptext' ) [ 0 ]
968
967
. classList . toggle ( "force-tooltip" ) ;
@@ -971,7 +970,7 @@ function loadCss(cssFileName) {
971
970
972
971
const sidebar_menu_toggle = document . getElementsByClassName ( "sidebar-menu-toggle" ) [ 0 ] ;
973
972
if ( sidebar_menu_toggle ) {
974
- sidebar_menu_toggle . addEventListener ( "click" , function ( ) {
973
+ sidebar_menu_toggle . addEventListener ( "click" , ( ) => {
975
974
const sidebar = document . getElementsByClassName ( "sidebar" ) [ 0 ] ;
976
975
if ( ! hasClass ( sidebar , "shown" ) ) {
977
976
addClass ( sidebar , "shown" ) ;
@@ -981,12 +980,12 @@ function loadCss(cssFileName) {
981
980
} ) ;
982
981
}
983
982
984
- let buildHelperPopup = function ( ) {
983
+ let buildHelperPopup = ( ) => {
985
984
const popup = document . createElement ( "aside" ) ;
986
985
addClass ( popup , "hidden" ) ;
987
986
popup . id = "help" ;
988
987
989
- popup . addEventListener ( "click" , function ( ev ) {
988
+ popup . addEventListener ( "click" , ev => {
990
989
if ( ev . target === popup ) {
991
990
// Clicked the blurred zone outside the help popup; dismiss help.
992
991
displayHelp ( false , ev ) ;
@@ -1009,14 +1008,10 @@ function loadCss(cssFileName) {
1009
1008
[ "⏎" , "Go to active search result" ] ,
1010
1009
[ "+" , "Expand all sections" ] ,
1011
1010
[ "-" , "Collapse all sections" ] ,
1012
- ] . map ( function ( x ) {
1013
- return "<dt>" +
1014
- x [ 0 ] . split ( " " )
1015
- . map ( function ( y , index ) {
1016
- return ( index & 1 ) === 0 ? "<kbd>" + y + "</kbd>" : " " + y + " " ;
1017
- } )
1018
- . join ( "" ) + "</dt><dd>" + x [ 1 ] + "</dd>" ;
1019
- } ) . join ( "" ) ;
1011
+ ] . map ( x => "<dt>" +
1012
+ x [ 0 ] . split ( " " )
1013
+ . map ( ( y , index ) => ( index & 1 ) === 0 ? "<kbd>" + y + "</kbd>" : " " + y + " " )
1014
+ . join ( "" ) + "</dt><dd>" + x [ 1 ] + "</dd>" ) . join ( "" ) ;
1020
1015
const div_shortcuts = document . createElement ( "div" ) ;
1021
1016
addClass ( div_shortcuts , "shortcuts" ) ;
1022
1017
div_shortcuts . innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>" ;
@@ -1034,9 +1029,7 @@ function loadCss(cssFileName) {
1034
1029
"You can look for items with an exact name by putting double quotes around \
1035
1030
your request: <code>\"string\"</code>" ,
1036
1031
"Look for items inside another one by searching for a path: <code>vec::Vec</code>" ,
1037
- ] . map ( function ( x ) {
1038
- return "<p>" + x + "</p>" ;
1039
- } ) . join ( "" ) ;
1032
+ ] . map ( x => "<p>" + x + "</p>" ) . join ( "" ) ;
1040
1033
const div_infos = document . createElement ( "div" ) ;
1041
1034
addClass ( div_infos , "infos" ) ;
1042
1035
div_infos . innerHTML = "<h2>Search Tricks</h2>" + infos ;
@@ -1056,7 +1049,7 @@ function loadCss(cssFileName) {
1056
1049
popup . appendChild ( container ) ;
1057
1050
insertAfter ( popup , document . querySelector ( "main" ) ) ;
1058
1051
// So that it's only built once and then it'll do nothing when called!
1059
- buildHelperPopup = function ( ) { } ;
1052
+ buildHelperPopup = ( ) => { } ;
1060
1053
} ;
1061
1054
1062
1055
onHashChange ( null ) ;
@@ -1067,11 +1060,11 @@ function loadCss(cssFileName) {
1067
1060
( function ( ) {
1068
1061
let reset_button_timeout = null ;
1069
1062
1070
- window . copy_path = function ( but ) {
1063
+ window . copy_path = but => {
1071
1064
const parent = but . parentElement ;
1072
1065
const path = [ ] ;
1073
1066
1074
- onEach ( parent . childNodes , function ( child ) {
1067
+ onEach ( parent . childNodes , child => {
1075
1068
if ( child . tagName === 'A' ) {
1076
1069
path . push ( child . textContent ) ;
1077
1070
}
@@ -1097,7 +1090,7 @@ function loadCss(cssFileName) {
1097
1090
tmp = document . createTextNode ( '✓' ) ;
1098
1091
but . appendChild ( tmp ) ;
1099
1092
} else {
1100
- onEachLazy ( but . childNodes , function ( e ) {
1093
+ onEachLazy ( but . childNodes , e => {
1101
1094
if ( e . nodeType === Node . TEXT_NODE ) {
1102
1095
tmp = e ;
1103
1096
return true ;
0 commit comments