1
1
( function ( ) {
2
- function scrollToLint ( lintId ) {
3
- const target = document . getElementById ( lintId ) ;
4
- if ( ! target ) {
5
- return ;
6
- }
7
- target . scrollIntoView ( ) ;
8
- }
9
-
10
- function scrollToLintByURL ( $scope , $location ) {
11
- const removeListener = $scope . $on ( 'ngRepeatFinished' , function ( ngRepeatFinishedEvent ) {
12
- scrollToLint ( $location . path ( ) . substring ( 1 ) ) ;
13
- removeListener ( ) ;
14
- } ) ;
15
- }
16
-
17
2
function selectGroup ( $scope , selectedGroup ) {
18
3
const groups = $scope . groups ;
19
4
for ( const group in groups ) {
365
350
return $scope . applicabilities [ lint . applicability ] ;
366
351
} ;
367
352
368
- // Show details for one lint
369
- $scope . openLint = function ( lint ) {
370
- $scope . open [ lint . id ] = true ;
371
- $location . path ( lint . id ) ;
372
- } ;
373
-
374
353
$scope . toggleExpansion = function ( lints , isExpanded ) {
375
354
lints . forEach ( lint => {
376
355
$scope . open [ lint . id ] = isExpanded ;
377
356
} ) ;
378
357
}
379
358
380
- $scope . copyToClipboard = function ( lint ) {
381
- const clipboard = document . getElementById ( "clipboard-" + lint . id ) ;
382
- if ( clipboard ) {
383
- let resetClipboardTimeout = null ;
384
- const resetClipboardIcon = clipboard . innerHTML ;
385
-
386
- function resetClipboard ( ) {
387
- resetClipboardTimeout = null ;
388
- clipboard . innerHTML = resetClipboardIcon ;
389
- }
390
-
391
- navigator . clipboard . writeText ( "clippy::" + lint . id ) ;
392
-
393
- clipboard . innerHTML = "✓" ;
394
- if ( resetClipboardTimeout !== null ) {
395
- clearTimeout ( resetClipboardTimeout ) ;
396
- }
397
- resetClipboardTimeout = setTimeout ( resetClipboard , 1000 ) ;
398
- }
399
- }
400
-
401
359
// Get data
402
360
$scope . open = { } ;
403
361
$scope . loading = true ;
413
371
selectGroup ( $scope , selectedGroup . toLowerCase ( ) ) ;
414
372
}
415
373
416
- scrollToLintByURL ( $scope , $location ) ;
417
-
418
374
setTimeout ( function ( ) {
419
375
const el = document . getElementById ( 'filter-input' ) ;
420
376
if ( el ) { el . focus ( ) }
@@ -433,6 +389,65 @@ function getQueryVariable(variable) {
433
389
}
434
390
}
435
391
392
+ function storeValue ( settingName , value ) {
393
+ try {
394
+ localStorage . setItem ( `clippy-lint-list-${ settingName } ` , value ) ;
395
+ } catch ( e ) { }
396
+ }
397
+
398
+ function loadValue ( settingName ) {
399
+ return localStorage . getItem ( `clippy-lint-list-${ settingName } ` ) ;
400
+ }
401
+
402
+ function setTheme ( theme , store ) {
403
+ let enableHighlight = false ;
404
+ let enableNight = false ;
405
+ let enableAyu = false ;
406
+
407
+ switch ( theme ) {
408
+ case "ayu" :
409
+ enableAyu = true ;
410
+ break ;
411
+ case "coal" :
412
+ case "navy" :
413
+ enableNight = true ;
414
+ break ;
415
+ case "rust" :
416
+ enableHighlight = true ;
417
+ break ;
418
+ default :
419
+ enableHighlight = true ;
420
+ theme = "light" ;
421
+ break ;
422
+ }
423
+
424
+ document . getElementsByTagName ( "body" ) [ 0 ] . className = theme ;
425
+
426
+ document . getElementById ( "githubLightHighlight" ) . disabled = enableNight || ! enableHighlight ;
427
+ document . getElementById ( "githubDarkHighlight" ) . disabled = ! enableNight && ! enableAyu ;
428
+
429
+ document . getElementById ( "styleHighlight" ) . disabled = ! enableHighlight ;
430
+ document . getElementById ( "styleNight" ) . disabled = ! enableNight ;
431
+ document . getElementById ( "styleAyu" ) . disabled = ! enableAyu ;
432
+
433
+ if ( store ) {
434
+ storeValue ( "theme" , theme ) ;
435
+ } else {
436
+ document . getElementById ( `theme-choice` ) . value = theme ;
437
+ }
438
+ }
439
+
440
+ // loading the theme after the initial load
441
+ const prefersDark = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
442
+ const theme = loadValue ( 'theme' ) ;
443
+ if ( prefersDark . matches && ! theme ) {
444
+ setTheme ( "coal" , false ) ;
445
+ } else {
446
+ setTheme ( theme , false ) ;
447
+ }
448
+ let disableShortcuts = loadValue ( 'disable-shortcuts' ) === "true" ;
449
+ document . getElementById ( "disable-shortcuts" ) . checked = disableShortcuts ;
450
+
436
451
window . searchState = {
437
452
timeout : null ,
438
453
inputElem : document . getElementById ( "search-input" ) ,
@@ -486,6 +501,11 @@ window.searchState = {
486
501
lint . style . display = "none" ;
487
502
}
488
503
} ) ;
504
+ if ( searchStr . length > 0 ) {
505
+ window . location . hash = `/${ searchStr } ` ;
506
+ } else {
507
+ window . location . hash = '' ;
508
+ }
489
509
} ,
490
510
} ;
491
511
@@ -496,54 +516,6 @@ function handleInputChanged(event) {
496
516
searchState . resetInputTimeout ( ) ;
497
517
}
498
518
499
- function storeValue ( settingName , value ) {
500
- try {
501
- localStorage . setItem ( `clippy-lint-list-${ settingName } ` , value ) ;
502
- } catch ( e ) { }
503
- }
504
-
505
- function loadValue ( settingName ) {
506
- return localStorage . getItem ( `clippy-lint-list-${ settingName } ` ) ;
507
- }
508
-
509
- function setTheme ( theme , store ) {
510
- let enableHighlight = false ;
511
- let enableNight = false ;
512
- let enableAyu = false ;
513
-
514
- switch ( theme ) {
515
- case "ayu" :
516
- enableAyu = true ;
517
- break ;
518
- case "coal" :
519
- case "navy" :
520
- enableNight = true ;
521
- break ;
522
- case "rust" :
523
- enableHighlight = true ;
524
- break ;
525
- default :
526
- enableHighlight = true ;
527
- theme = "light" ;
528
- break ;
529
- }
530
-
531
- document . getElementsByTagName ( "body" ) [ 0 ] . className = theme ;
532
-
533
- document . getElementById ( "githubLightHighlight" ) . disabled = enableNight || ! enableHighlight ;
534
- document . getElementById ( "githubDarkHighlight" ) . disabled = ! enableNight && ! enableAyu ;
535
-
536
- document . getElementById ( "styleHighlight" ) . disabled = ! enableHighlight ;
537
- document . getElementById ( "styleNight" ) . disabled = ! enableNight ;
538
- document . getElementById ( "styleAyu" ) . disabled = ! enableAyu ;
539
-
540
- if ( store ) {
541
- storeValue ( "theme" , theme ) ;
542
- } else {
543
- document . getElementById ( `theme-choice` ) . value = theme ;
544
- }
545
- }
546
-
547
519
function handleShortcut ( ev ) {
548
520
if ( ev . ctrlKey || ev . altKey || ev . metaKey || disableShortcuts ) {
549
521
return ;
@@ -584,6 +556,52 @@ function onEachLazy(lazyArray, func) {
584
556
}
585
557
}
586
558
559
+ function expandLintId ( lintId ) {
560
+ searchState . inputElem . value = lintId ;
561
+ searchState . filterLints ( ) ;
562
+
563
+ // Expand the lint.
564
+ const lintElem = document . getElementById ( lintId ) ;
565
+ const isCollapsed = lintElem . classList . remove ( "collapsed" ) ;
566
+ lintElem . querySelector ( ".label-doc-folding" ) . innerText = "-" ;
567
+ }
568
+
569
+ // Show details for one lint
570
+ function openLint ( event ) {
571
+ event . preventDefault ( ) ;
572
+ event . stopPropagation ( ) ;
573
+ expandLintId ( event . target . getAttribute ( "href" ) . slice ( 1 ) ) ;
574
+ }
575
+
576
+ function expandLint ( lintId ) {
577
+ const lintElem = document . getElementById ( lintId ) ;
578
+ const isCollapsed = lintElem . classList . toggle ( "collapsed" ) ;
579
+ lintElem . querySelector ( ".label-doc-folding" ) . innerText = isCollapsed ? "+" : "-" ;
580
+ }
581
+
582
+ function copyToClipboard ( event ) {
583
+ event . preventDefault ( ) ;
584
+ event . stopPropagation ( ) ;
585
+
586
+ const clipboard = event . target ;
587
+
588
+ let resetClipboardTimeout = null ;
589
+ const resetClipboardIcon = clipboard . innerHTML ;
590
+
591
+ function resetClipboard ( ) {
592
+ resetClipboardTimeout = null ;
593
+ clipboard . innerHTML = resetClipboardIcon ;
594
+ }
595
+
596
+ navigator . clipboard . writeText ( "clippy::" + clipboard . parentElement . id . slice ( 5 ) ) ;
597
+
598
+ clipboard . innerHTML = "✓" ;
599
+ if ( resetClipboardTimeout !== null ) {
600
+ clearTimeout ( resetClipboardTimeout ) ;
601
+ }
602
+ resetClipboardTimeout = setTimeout ( resetClipboard , 1000 ) ;
603
+ }
604
+
587
605
function handleBlur ( event ) {
588
606
const parent = document . getElementById ( "settings-dropdown" ) ;
589
607
if ( ! parent . contains ( document . activeElement ) &&
@@ -617,15 +635,23 @@ function generateSearch() {
617
635
generateSettings ( ) ;
618
636
generateSearch ( ) ;
619
637
620
- // loading the theme after the initial load
621
- const prefersDark = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
622
- const theme = loadValue ( 'theme' ) ;
623
- if ( prefersDark . matches && ! theme ) {
624
- setTheme ( "coal" , false ) ;
625
- } else {
626
- setTheme ( theme , false ) ;
638
+ function scrollToLint ( lintId ) {
639
+ const target = document . getElementById ( lintId ) ;
640
+ if ( ! target ) {
641
+ return ;
642
+ }
643
+ target . scrollIntoView ( ) ;
644
+ expandLintId ( lintId ) ;
627
645
}
628
- let disableShortcuts = loadValue ( 'disable-shortcuts' ) === "true" ;
629
- document . getElementById ( "disable-shortcuts" ) . checked = disableShortcuts ;
630
646
631
- hljs . highlightAll ( ) ;
647
+ // If the page we arrive on has link to a given lint, we scroll to it.
648
+ function scrollToLintByURL ( ) {
649
+ const lintId = window . location . hash . substring ( 2 ) ;
650
+ if ( lintId . length > 0 ) {
651
+ scrollToLint ( lintId ) ;
652
+ }
653
+ }
654
+
655
+ scrollToLintByURL ( ) ;
656
+
657
+ onEachLazy ( document . querySelectorAll ( "pre > code.language-rust" ) , el => hljs . highlightElement ( el ) ) ;
0 commit comments