Check if button element exists when triggering added_to_cart (#51449)
This commit is contained in:
parent
cf7fd8303c
commit
2e3013555e
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Fix bug where manually triggering `added_to_cart` event without a button element caused an Exception.
|
|
@ -173,6 +173,8 @@ jQuery( function( $ ) {
|
|||
* Update cart page elements after add to cart events.
|
||||
*/
|
||||
AddToCartHandler.prototype.updateButton = function( e, fragments, cart_hash, $button ) {
|
||||
// Some themes and plugins manually trigger added_to_cart without passing a button element, which in turn calls this function.
|
||||
// If there is no button we don't want to crash.
|
||||
$button = typeof $button === 'undefined' ? false : $button;
|
||||
|
||||
if ( $button ) {
|
||||
|
@ -222,19 +224,25 @@ jQuery( function( $ ) {
|
|||
* Update cart live region message after add/remove cart events.
|
||||
*/
|
||||
AddToCartHandler.prototype.alertCartUpdated = function( e, fragments, cart_hash, $button ) {
|
||||
var message = $button.data( 'success_message' );
|
||||
// Some themes and plugins manually trigger added_to_cart without passing a button element, which in turn calls this function.
|
||||
// If there is no button we don't want to crash.
|
||||
$button = typeof $button === 'undefined' ? false : $button;
|
||||
|
||||
if ( !message ) {
|
||||
return;
|
||||
}
|
||||
if ( $button ) {
|
||||
var message = $button.data( 'success_message' );
|
||||
|
||||
if ( !message ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the response after adding/removing an item to/from the cart is really fast,
|
||||
// screen readers may not have time to identify the changes in the live region element.
|
||||
// So, we add a delay to ensure an interval between messages.
|
||||
e.data.addToCartHandler.$liveRegion
|
||||
.delay(1000)
|
||||
.text( message )
|
||||
.attr( 'aria-relevant', 'all' );
|
||||
// If the response after adding/removing an item to/from the cart is really fast,
|
||||
// screen readers may not have time to identify the changes in the live region element.
|
||||
// So, we add a delay to ensure an interval between messages.
|
||||
e.data.addToCartHandler.$liveRegion
|
||||
.delay(1000)
|
||||
.text( message )
|
||||
.attr( 'aria-relevant', 'all' );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue