Make WordPress Core

Changeset 50269


Ignore:
Timestamp:
02/09/2021 02:54:48 PM (6 years ago)
Author:
desrosj
Message:

Twenty Twenty-One: Prevent Dark Mode related JavaScript error.

This prevents an Uncaught TypeError in the block editor when scrolling caused by the absence of a #dark-mode-toggler element.

Props ocean90, mukesh27, justinahinon.
Fixes #52473.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwentyone/assets/js/dark-mode-toggler.js

    r49633 r50269  
    4545
    4646function darkModeRepositionTogglerOnScroll() {
    47         var prevScroll = window.scrollY || document.documentElement.scrollTop,
     47
     48        var toggler = document.getElementById( 'dark-mode-toggler' ),
     49                prevScroll = window.scrollY || document.documentElement.scrollTop,
    4850                currentScroll,
    4951
    … …  
    5456                                currentScroll < prevScroll
    5557                        ) {
    56                                 document.getElementById( 'dark-mode-toggler' ).classList.remove( 'hide' );
     58                                toggler.classList.remove( 'hide' );
    5759                        } else if ( currentScroll > prevScroll && 250 < currentScroll ) {
    58                                 document.getElementById( 'dark-mode-toggler' ).classList.add( 'hide' );
     60                                toggler.classList.add( 'hide' );
    5961                        }
    6062                        prevScroll = currentScroll;
    6163                };
    62         window.addEventListener( 'scroll', checkScroll );
     64
     65        if ( toggler ) {
     66                window.addEventListener( 'scroll', checkScroll );
     67        }
    6368}
    6469
Note: See TracChangeset for help on using the changeset viewer.