mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@50269 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user