Load mini cart scripts by default on touch-enabled (mobile) devices (#48769)
This commit is contained in:
parent
b5de9d101f
commit
06c98dee1b
|
@ -28,6 +28,12 @@ updateTotals( getMiniCartTotalsFromLocalStorage() );
|
||||||
getMiniCartTotalsFromServer().then( updateTotals );
|
getMiniCartTotalsFromServer().then( updateTotals );
|
||||||
setStyles();
|
setStyles();
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
wcBlocksMiniCartFrontendDependencies: Record< string, dependencyData >;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
window.addEventListener( 'load', () => {
|
window.addEventListener( 'load', () => {
|
||||||
const miniCartBlocks = document.querySelectorAll( '.wc-block-mini-cart' );
|
const miniCartBlocks = document.querySelectorAll( '.wc-block-mini-cart' );
|
||||||
let wasLoadScriptsCalled = false;
|
let wasLoadScriptsCalled = false;
|
||||||
|
@ -36,10 +42,7 @@ window.addEventListener( 'load', () => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dependencies = window.wcBlocksMiniCartFrontendDependencies as Record<
|
const dependencies = window.wcBlocksMiniCartFrontendDependencies;
|
||||||
string,
|
|
||||||
dependencyData
|
|
||||||
>;
|
|
||||||
|
|
||||||
// Preload scripts
|
// Preload scripts
|
||||||
for ( const dependencyHandle in dependencies ) {
|
for ( const dependencyHandle in dependencies ) {
|
||||||
|
@ -158,8 +161,19 @@ window.addEventListener( 'load', () => {
|
||||||
loadContents();
|
loadContents();
|
||||||
};
|
};
|
||||||
|
|
||||||
miniCartButton.addEventListener( 'mouseover', loadScripts );
|
// Load the scripts if a device is touch-enabled. We don't get the mouseover or focus events on touch devices,
|
||||||
miniCartButton.addEventListener( 'focus', loadScripts );
|
// so the event listeners below won't work.
|
||||||
|
if (
|
||||||
|
'ontouchstart' in window ||
|
||||||
|
navigator.maxTouchPoints > 0 ||
|
||||||
|
window.matchMedia( '(pointer:coarse)' ).matches
|
||||||
|
) {
|
||||||
|
loadScripts();
|
||||||
|
} else {
|
||||||
|
miniCartButton.addEventListener( 'mouseover', loadScripts );
|
||||||
|
miniCartButton.addEventListener( 'focus', loadScripts );
|
||||||
|
}
|
||||||
|
|
||||||
miniCartButton.addEventListener( 'click', openDrawer );
|
miniCartButton.addEventListener( 'click', openDrawer );
|
||||||
|
|
||||||
const funcOnAddToCart =
|
const funcOnAddToCart =
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: fix
|
||||||
|
|
||||||
|
Fixed a bug where the close button is not visible on the mini cart when viewed on a mobile device
|
Loading…
Reference in New Issue