@@ -465,8 +465,8 @@ $(document).ready(function () {
465
465
offcanvasElement . querySelectorAll ( "input, button, a" ) ;
466
466
const backdropElement = document . getElementById ( "navbar__backdrop" ) ;
467
467
468
- const documentWidth = document . documentElement . clientWidth
469
- const scrollbarWidth = Math . abs ( window . innerWidth - documentWidth )
468
+ const documentWidth = document . documentElement . clientWidth ;
469
+ const scrollbarWidth = Math . abs ( window . innerWidth - documentWidth ) ;
470
470
471
471
const offcanvasFocusTrapHandler = ( event ) => {
472
472
if ( event . key != "Tab" ) {
@@ -499,8 +499,8 @@ $(document).ready(function () {
499
499
// nav from being pushed off screen when the page has horizontal scroll,
500
500
// like downloads.php has.
501
501
document . documentElement . style . overflow = "hidden" ;
502
- document . body . style . paddingRight = `${ scrollbarWidth } px`
503
- offcanvasSelectables [ 0 ] . focus ( ) ;
502
+ document . body . style . paddingRight = `${ scrollbarWidth } px` ;
503
+ offcanvasElement . querySelector ( ".navbar__link" ) . focus ( ) ;
504
504
document . addEventListener ( "keydown" , offcanvasFocusTrapHandler ) ;
505
505
} ;
506
506
@@ -515,35 +515,30 @@ $(document).ready(function () {
515
515
( ) => {
516
516
document . body . style . overflow = "auto" ;
517
517
document . documentElement . style . overflow = "auto" ;
518
- document . body . style . paddingRight = ' 0px'
518
+ document . body . style . paddingRight = " 0px" ;
519
519
offcanvasElement . style . removeProperty ( "visibility" ) ;
520
520
} ,
521
521
{ once : true } ,
522
522
) ;
523
523
} ;
524
524
525
525
const closeOffCanvasByClickOutside = ( event ) => {
526
- if (
527
- ! offcanvasElement . contains ( event . target ) &&
528
- ! menuButton . contains ( event . target )
529
- ) {
530
- closeOffcanvasNav ( )
526
+ if ( event . target === backdropElement ) {
527
+ closeOffcanvasNav ( ) ;
531
528
}
532
529
} ;
533
530
534
- document
535
- . getElementById ( "navbar__menu-link" )
536
- . setAttribute ( "hidden" , "true" ) ;
531
+ document . getElementById ( "navbar__menu-link" ) . setAttribute ( "hidden" , "true" ) ;
537
532
538
- const menuButton = document . getElementById ( "navbar__menu-button" )
533
+ const menuButton = document . getElementById ( "navbar__menu-button" ) ;
539
534
menuButton . removeAttribute ( "hidden" ) ;
540
535
menuButton . addEventListener ( "click" , openOffcanvasNav ) ;
541
536
542
537
document
543
538
. getElementById ( "navbar__close-button" )
544
539
. addEventListener ( "click" , closeOffcanvasNav ) ;
545
540
546
- document . addEventListener ( ' click' , closeOffCanvasByClickOutside ) ;
541
+ backdropElement . addEventListener ( " click" , closeOffCanvasByClickOutside ) ;
547
542
548
543
/*}}}*/
549
544
0 commit comments