Skip to content

Commit

Permalink
fix: prevent white screen and errors on Widget Screen (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurelfulford authored Jun 30, 2021
1 parent 046375c commit 5731581
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
7 changes: 7 additions & 0 deletions newspack-theme/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ function newspack_enqueue_scripts() {
$languages_path = get_parent_theme_file_path( '/languages' );
$theme_version = wp_get_theme()->get( 'Version' );
$post_type = get_post_type();
$current_screen = get_current_screen();

// Add check to see if currently on the widgets screen; none of these files are needed there, but are loaded as of WP 5.8.
// See: https://github.com/WordPress/gutenberg/issues/28538.
if ( 'widgets' === $current_screen->id ) {
return;
}

// Featured Image options.
wp_register_script(
Expand Down
16 changes: 9 additions & 7 deletions newspack-theme/js/src/amp-fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@

// Menu toggle variables.
const mobileToggle = document.getElementsByClassName( 'mobile-menu-toggle' ),
body = document.getElementsByTagName( 'body' )[ 0 ],
body = document.body,
mobileSidebar = document.getElementById( 'mobile-sidebar-fallback' ),
mobileOpenButton = headerContain.getElementsByClassName( 'mobile-menu-toggle' )[ 0 ],
mobileCloseButton = mobileSidebar.getElementsByClassName( 'mobile-menu-toggle' )[ 0 ],
desktopToggle = document.getElementsByClassName( 'desktop-menu-toggle' ),
desktopSidebar = document.getElementById( 'desktop-sidebar-fallback' ),
desktopOpenButton = headerContain.getElementsByClassName( 'desktop-menu-toggle' )[ 0 ],
desktopCloseButton = desktopSidebar.getElementsByClassName( 'desktop-menu-toggle' )[ 0 ],
subpageToggle = document.getElementsByClassName( 'subpage-toggle' );

/**
Expand Down Expand Up @@ -96,6 +92,9 @@

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

mobileToggle[ i ].addEventListener(
'click',
function() {
Expand All @@ -111,6 +110,9 @@

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

desktopToggle[ i ].addEventListener(
'click',
function() {
Expand All @@ -127,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 5731581

Please sign in to comment.