Bundled Themes: Fixes JS TypeError in Twenty Twenty.

On mobile devices using a webkit browser, the menu and search modals could not be opened due to a `TypeError: document.body is null`. This commit fixes that issue by adding a `touch-enabled` class to the body for browsers that do not support media queries.

Props quicoto, poena, Boga86, acosmin, macmanx.
Fixes #48601.
Built from https://develop.svn.wordpress.org/trunk@46786


git-svn-id: http://core.svn.wordpress.org/trunk@46586 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ianbelanger 2019-11-26 18:21:03 +00:00
parent 5af0c2989b
commit c74c8cf5f1
2 changed files with 15 additions and 11 deletions

View File

@ -71,7 +71,9 @@ if ( ! Element.prototype.matches ) {
// Add a class to the body for when touch is enabled for browsers that don't support media queries // Add a class to the body for when touch is enabled for browsers that don't support media queries
// for interaction media features. Adapted from <https://codepen.io/Ferie/pen/vQOMmO> // for interaction media features. Adapted from <https://codepen.io/Ferie/pen/vQOMmO>
( function() { twentytwenty.touchEnabled = {
init: function() {
var matchMedia = function() { var matchMedia = function() {
// Include the 'heartz' as a way to have a non matching MQ to help terminate the join. See <https://git.io/vznFH>. // Include the 'heartz' as a way to have a non matching MQ to help terminate the join. See <https://git.io/vznFH>.
var prefixes = [ '-webkit-', '-moz-', '-o-', '-ms-' ]; var prefixes = [ '-webkit-', '-moz-', '-o-', '-ms-' ];
@ -82,7 +84,8 @@ if ( ! Element.prototype.matches ) {
if ( ( 'ontouchstart' in window ) || ( window.DocumentTouch && document instanceof window.DocumentTouch ) || matchMedia() ) { if ( ( 'ontouchstart' in window ) || ( window.DocumentTouch && document instanceof window.DocumentTouch ) || matchMedia() ) {
document.body.classList.add( 'touch-enabled' ); document.body.classList.add( 'touch-enabled' );
} }
}() ); }
}; // twentytwenty.touchEnabled
/* ----------------------------------------------------------------------------------------------- /* -----------------------------------------------------------------------------------------------
Cover Modals Cover Modals
@ -745,6 +748,7 @@ twentytwentyDomReady( function() {
twentytwenty.smoothScroll.init(); // Smooth scroll to anchor link or a specific element twentytwenty.smoothScroll.init(); // Smooth scroll to anchor link or a specific element
twentytwenty.modalMenu.init(); // Modal Menu twentytwenty.modalMenu.init(); // Modal Menu
twentytwenty.primaryMenu.init(); // Primary Menu twentytwenty.primaryMenu.init(); // Primary Menu
twentytwenty.touchEnabled.init(); // Add class to body if device is touch-enabled
} ); } );
/* ----------------------------------------------------------------------------------------------- /* -----------------------------------------------------------------------------------------------

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.4-alpha-46785'; $wp_version = '5.4-alpha-46786';
/** /**
* 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.