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:
parent
d0c1e2b97b
commit
34987fe903
|
@ -44,7 +44,9 @@ function darkModeInitialLoad() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function darkModeRepositionTogglerOnScroll() {
|
function darkModeRepositionTogglerOnScroll() {
|
||||||
var prevScroll = window.scrollY || document.documentElement.scrollTop,
|
|
||||||
|
var toggler = document.getElementById( 'dark-mode-toggler' ),
|
||||||
|
prevScroll = window.scrollY || document.documentElement.scrollTop,
|
||||||
currentScroll,
|
currentScroll,
|
||||||
|
|
||||||
checkScroll = function() {
|
checkScroll = function() {
|
||||||
|
@ -53,13 +55,16 @@ function darkModeRepositionTogglerOnScroll() {
|
||||||
currentScroll + ( window.innerHeight * 1.5 ) > document.body.clientHeight ||
|
currentScroll + ( window.innerHeight * 1.5 ) > document.body.clientHeight ||
|
||||||
currentScroll < prevScroll
|
currentScroll < prevScroll
|
||||||
) {
|
) {
|
||||||
document.getElementById( 'dark-mode-toggler' ).classList.remove( 'hide' );
|
toggler.classList.remove( 'hide' );
|
||||||
} else if ( currentScroll > prevScroll && 250 < currentScroll ) {
|
} else if ( currentScroll > prevScroll && 250 < currentScroll ) {
|
||||||
document.getElementById( 'dark-mode-toggler' ).classList.add( 'hide' );
|
toggler.classList.add( 'hide' );
|
||||||
}
|
}
|
||||||
prevScroll = currentScroll;
|
prevScroll = currentScroll;
|
||||||
};
|
};
|
||||||
window.addEventListener( 'scroll', checkScroll );
|
|
||||||
|
if ( toggler ) {
|
||||||
|
window.addEventListener( 'scroll', checkScroll );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
darkModeInitialLoad();
|
darkModeInitialLoad();
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue