1
1
// Local js definitions:
2
- /* global addClass, getSettingValue, hasClass, searchState, updateLocalStorage */
2
+ /* global addClass, getSettingValue, hasClass, updateLocalStorage */
3
3
/* global onEachLazy, removeClass, getVar */
4
4
5
5
"use strict" ;
@@ -121,12 +121,9 @@ function getNakedUrl() {
121
121
* doesn't have a parent node.
122
122
*
123
123
* @param {HTMLElement } newNode
124
- * @param {HTMLElement } referenceNode
124
+ * @param {HTMLElement & { parentNode: HTMLElement } } referenceNode
125
125
*/
126
126
function insertAfter ( newNode , referenceNode ) {
127
- // You're not allowed to pass an element with no parent.
128
- // I dunno how to make TS's typechecker see that.
129
- // @ts -expect-error
130
127
referenceNode . parentNode . insertBefore ( newNode , referenceNode . nextSibling ) ;
131
128
}
132
129
@@ -305,11 +302,10 @@ function preLoadCss(cssUrl) {
305
302
window . searchState . timeout = null ;
306
303
}
307
304
} ,
308
- // @ts -expect-error
309
305
isDisplayed : ( ) => {
310
306
const outputElement = window . searchState . outputElement ( ) ;
311
- return outputElement &&
312
- outputElement . parentElement &&
307
+ return ! ! outputElement &&
308
+ ! ! outputElement . parentElement &&
313
309
outputElement . parentElement . id === ALTERNATIVE_DISPLAY_ID ;
314
310
} ,
315
311
// Sets the focus on the search bar at the top of the page
@@ -325,8 +321,6 @@ function preLoadCss(cssUrl) {
325
321
search = window . searchState . outputElement ( ) ;
326
322
}
327
323
switchDisplayedElement ( search ) ;
328
- // @ts -expect-error
329
- window . searchState . mouseMovedAfterSearch = false ;
330
324
document . title = window . searchState . title ;
331
325
} ,
332
326
removeQueryParameters : ( ) => {
@@ -503,43 +497,49 @@ function preLoadCss(cssUrl) {
503
497
handleHashes ( ev ) ;
504
498
}
505
499
506
- // @ts -expect-error
500
+ /**
501
+ * @param {HTMLElement|null } elem
502
+ */
507
503
function openParentDetails ( elem ) {
508
504
while ( elem ) {
509
505
if ( elem . tagName === "DETAILS" ) {
506
+ // @ts -expect-error
510
507
elem . open = true ;
511
508
}
512
- elem = elem . parentNode ;
509
+ elem = elem . parentElement ;
513
510
}
514
511
}
515
512
516
- // @ts -expect-error
513
+ /**
514
+ * @param {string } id
515
+ */
517
516
function expandSection ( id ) {
518
517
openParentDetails ( document . getElementById ( id ) ) ;
519
518
}
520
519
521
- // @ts -expect-error
520
+ /**
521
+ * @param {KeyboardEvent } ev
522
+ */
522
523
function handleEscape ( ev ) {
523
- // @ts -expect-error
524
- searchState . clearInputTimeout ( ) ;
525
- // @ts -expect-error
526
- searchState . hideResults ( ) ;
524
+ window . searchState . clearInputTimeout ( ) ;
525
+ window . searchState . hideResults ( ) ;
527
526
ev . preventDefault ( ) ;
528
- // @ts -expect-error
529
- searchState . defocus ( ) ;
527
+ window . searchState . defocus ( ) ;
530
528
window . hideAllModals ( true ) ; // true = reset focus for tooltips
531
529
}
532
530
533
- // @ts -expect-error
531
+ /**
532
+ * @param {KeyboardEvent } ev
533
+ */
534
534
function handleShortcut ( ev ) {
535
535
// Don't interfere with browser shortcuts
536
536
const disableShortcuts = getSettingValue ( "disable-shortcuts" ) === "true" ;
537
537
if ( ev . ctrlKey || ev . altKey || ev . metaKey || disableShortcuts ) {
538
538
return ;
539
539
}
540
540
541
- // @ts -expect-error
542
- if ( document . activeElement . tagName === "INPUT" &&
541
+ if ( document . activeElement &&
542
+ document . activeElement . tagName === "INPUT" &&
543
543
// @ts -expect-error
544
544
document . activeElement . type !== "checkbox" &&
545
545
// @ts -expect-error
@@ -559,8 +559,7 @@ function preLoadCss(cssUrl) {
559
559
case "S" :
560
560
case "/" :
561
561
ev . preventDefault ( ) ;
562
- // @ts -expect-error
563
- searchState . focus ( ) ;
562
+ window . searchState . focus ( ) ;
564
563
break ;
565
564
566
565
case "+" :
@@ -586,7 +585,6 @@ function preLoadCss(cssUrl) {
586
585
document . addEventListener ( "keydown" , handleShortcut ) ;
587
586
588
587
function addSidebarItems ( ) {
589
- // @ts -expect-error
590
588
if ( ! window . SIDEBAR_ITEMS ) {
591
589
return ;
592
590
}
@@ -675,7 +673,6 @@ function preLoadCss(cssUrl) {
675
673
}
676
674
677
675
// <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+trait.impl&type=code>
678
- // @ts -expect-error
679
676
window . register_implementors = imp => {
680
677
const implementors = document . getElementById ( "implementors-list" ) ;
681
678
const synthetic_implementors = document . getElementById ( "synthetic-implementors-list" ) ;
@@ -767,9 +764,7 @@ function preLoadCss(cssUrl) {
767
764
}
768
765
}
769
766
} ;
770
- // @ts -expect-error
771
767
if ( window . pending_implementors ) {
772
- // @ts -expect-error
773
768
window . register_implementors ( window . pending_implementors ) ;
774
769
}
775
770
@@ -802,16 +797,14 @@ function preLoadCss(cssUrl) {
802
797
*
803
798
* - After processing all of the impls, it sorts the sidebar items by name.
804
799
*
805
- * @param {{[cratename: string]: Array<Array<string|0>>} } imp
800
+ * @param {rustdoc.TypeImpls } imp
806
801
*/
807
- // @ts -expect-error
808
802
window . register_type_impls = imp => {
809
803
// @ts -expect-error
810
804
if ( ! imp || ! imp [ window . currentCrate ] ) {
811
805
return ;
812
806
}
813
- // @ts -expect-error
814
- window . pending_type_impls = null ;
807
+ window . pending_type_impls = undefined ;
815
808
const idMap = new Map ( ) ;
816
809
817
810
let implementations = document . getElementById ( "implementations-list" ) ;
@@ -997,9 +990,7 @@ function preLoadCss(cssUrl) {
997
990
list . replaceChildren ( ...newChildren ) ;
998
991
}
999
992
} ;
1000
- // @ts -expect-error
1001
993
if ( window . pending_type_impls ) {
1002
- // @ts -expect-error
1003
994
window . register_type_impls ( window . pending_type_impls ) ;
1004
995
}
1005
996
@@ -1695,8 +1686,7 @@ function preLoadCss(cssUrl) {
1695
1686
addSidebarCrates ( ) ;
1696
1687
onHashChange ( null ) ;
1697
1688
window . addEventListener ( "hashchange" , onHashChange ) ;
1698
- // @ts -expect-error
1699
- searchState . setup ( ) ;
1689
+ window . searchState . setup ( ) ;
1700
1690
} ( ) ) ;
1701
1691
1702
1692
// Hide, show, and resize the sidebar
0 commit comments