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.
Built from https://develop.svn.wordpress.org/trunk@50269


git-svn-id: http://core.svn.wordpress.org/trunk@49914 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
desrosj 2021-02-09 14:56:04 +00:00
parent d0c1e2b97b
commit 34987fe903
2 changed files with 10 additions and 5 deletions

View File

@ -44,7 +44,9 @@ function darkModeInitialLoad() {
}
function darkModeRepositionTogglerOnScroll() {
var prevScroll = window.scrollY || document.documentElement.scrollTop,
var toggler = document.getElementById( 'dark-mode-toggler' ),
prevScroll = window.scrollY || document.documentElement.scrollTop,
currentScroll,
checkScroll = function() {
@ -53,13 +55,16 @@ function darkModeRepositionTogglerOnScroll() {
currentScroll + ( window.innerHeight * 1.5 ) > document.body.clientHeight ||
currentScroll < prevScroll
) {
document.getElementById( 'dark-mode-toggler' ).classList.remove( 'hide' );
toggler.classList.remove( 'hide' );
} else if ( currentScroll > prevScroll && 250 < currentScroll ) {
document.getElementById( 'dark-mode-toggler' ).classList.add( 'hide' );
toggler.classList.add( 'hide' );
}
prevScroll = currentScroll;
};
window.addEventListener( 'scroll', checkScroll );
if ( toggler ) {
window.addEventListener( 'scroll', checkScroll );
}
}
darkModeInitialLoad();

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.7-beta1-50268';
$wp_version = '5.7-beta1-50269';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.