Skip to content

Commit

Permalink
fix: improve JavaScript selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
laurelfulford committed Jun 30, 2021
1 parent 9909e97 commit 4675b36
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions newspack-theme/js/src/amp-fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

// Menu toggle variables.
const mobileToggle = document.getElementsByClassName( 'mobile-menu-toggle' ),
body = document.getElementsByTagName( 'body' )[ 0 ],
body = document.body,
mobileSidebar = document.getElementById( 'mobile-sidebar-fallback' ),
desktopToggle = document.getElementsByClassName( 'desktop-menu-toggle' ),
desktopSidebar = document.getElementById( 'desktop-sidebar-fallback' ),
Expand Down Expand Up @@ -92,8 +92,8 @@

// Mobile menu fallback.
for ( let i = 0; i < mobileToggle.length; i++ ) {
const mobileOpenButton = headerContain.getElementsByClassName( 'mobile-menu-toggle' )[ 0 ],
mobileCloseButton = mobileSidebar.getElementsByClassName( 'mobile-menu-toggle' )[ 0 ];
const mobileOpenButton = headerContain.querySelector( '.mobile-menu-toggle' ),
mobileCloseButton = mobileSidebar.querySelector( '.mobile-menu-toggle' );

mobileToggle[ i ].addEventListener(
'click',
Expand All @@ -110,8 +110,8 @@

// Desktop menu (AKA slide-out sidebar) fallback.
for ( let i = 0; i < desktopToggle.length; i++ ) {
const desktopOpenButton = headerContain.getElementsByClassName( 'desktop-menu-toggle' )[ 0 ],
desktopCloseButton = desktopSidebar.getElementsByClassName( 'desktop-menu-toggle' )[ 0 ];
const desktopOpenButton = headerContain.querySelector( '.desktop-menu-toggle' ),
desktopCloseButton = desktopSidebar.querySelector( '.desktop-menu-toggle' );

desktopToggle[ i ].addEventListener(
'click',
Expand All @@ -129,8 +129,8 @@
// 'Subpage' menu fallback.
if ( 0 < subpageToggle.length ) {
const subpageSidebar = document.getElementById( 'subpage-sidebar-fallback' ),
subpageOpenButton = headerContain.getElementsByClassName( 'subpage-toggle' )[ 0 ],
subpageCloseButton = subpageSidebar.getElementsByClassName( 'subpage-toggle' )[ 0 ];
subpageOpenButton = headerContain.querySelector( '.subpage-toggle' ),
subpageCloseButton = subpageSidebar.querySelector( '.subpage-toggle' );

for ( let i = 0; i < subpageToggle.length; i++ ) {
subpageToggle[ i ].addEventListener(
Expand Down

0 comments on commit 4675b36

Please sign in to comment.