plugin updates

This commit is contained in:
Tony Volpe
2024-11-15 13:53:04 -05:00
parent 1293d604ca
commit 0238f0c4ca
2009 changed files with 163492 additions and 89543 deletions

View File

@@ -104,7 +104,7 @@ jQuery( function ( $ ) {
// Remove errors
if ( ! preserve_notices ) {
$(
'.woocommerce-error, .woocommerce-message, .woocommerce-info, .is-error, .is-info, .is-success'
'.woocommerce-error, .woocommerce-message, .woocommerce-info, .is-error, .is-info, .is-success, .coupon-error-notice'
).remove();
}
@@ -135,12 +135,30 @@ jQuery( function ( $ ) {
if ( $( '.woocommerce-checkout' ).length ) {
$( document.body ).trigger( 'update_checkout' );
}
// Store the old coupon error message and value before the
// .woocommerce-cart-form is replaced with the new form.
var $old_coupon_field_val = $( '#coupon_code' ).val();
var $old_coupon_error_msg = $( '#coupon_code' )
.closest( '.coupon' )
.find( '.coupon-error-notice' );
$( '.woocommerce-cart-form' ).replaceWith( $new_form );
$( '.woocommerce-cart-form' )
.find( ':input[name="update_cart"]' )
.prop( 'disabled', true );
if ( preserve_notices && $old_coupon_error_msg.length > 0 ) {
var $new_coupon_field = $( '.woocommerce-cart-form' ).find( '#coupon_code' );
var $new_coupon_field_wrapper = $new_coupon_field.closest( '.coupon' );
$new_coupon_field.val( $old_coupon_field_val );
// The coupon input with error needs to be focused before adding the live region
// with the error message, otherwise the screen reader won't read it.
$new_coupon_field.focus();
show_coupon_error( $old_coupon_error_msg, $new_coupon_field_wrapper, true );
}
if ( $notices.length > 0 ) {
show_notice( $notices );
}
@@ -176,6 +194,43 @@ jQuery( function ( $ ) {
$target.prepend( html_element );
};
/**
* Shows coupon form errors.
*
* @param {string|object} html_element The HTML string response after applying an invalid coupon or a jQuery element.
* @param {Object} $target Coupon field wrapper jQuery element.
* @param {boolean} is_live_region Whether role="alert" should be added or not.
*/
var show_coupon_error = function ( html_element, $target, is_live_region ) {
if ( $target.length === 0 ) {
return;
}
var $coupon_error_el = '';
if ( typeof html_element === 'string' ) {
var msg = $( $.parseHTML( html_element ) ).text().trim();
if ( msg === '' ) {
return;
}
$coupon_error_el = $( '<p class="coupon-error-notice" id="coupon-error-notice">' + msg + '</p>' );
} else {
$coupon_error_el = html_element;
}
if ( is_live_region ) {
$coupon_error_el.attr( 'role', 'alert' );
}
$target.find( '#coupon_code' )
.addClass( 'has-error' )
.attr( 'aria-invalid', 'true' )
.attr( 'aria-describedby', 'coupon-error-notice' );
$target.append( $coupon_error_el );
};
/**
* Object to handle AJAX calls for cart shipping changes.
*/
@@ -315,6 +370,7 @@ jQuery( function ( $ ) {
this.apply_coupon = this.apply_coupon.bind( this );
this.remove_coupon_clicked =
this.remove_coupon_clicked.bind( this );
this.remove_coupon_error = this.remove_coupon_error.bind( this );
this.quantity_update = this.quantity_update.bind( this );
this.item_remove_clicked = this.item_remove_clicked.bind( this );
this.item_restore_clicked = this.item_restore_clicked.bind( this );
@@ -358,6 +414,11 @@ jQuery( function ( $ ) {
'.woocommerce-cart-form .cart_item :input',
this.input_changed
);
$( document ).on(
'blur change input',
'#coupon_code',
this.remove_coupon_error
);
$( '.woocommerce-cart-form :input[name="update_cart"]' ).prop(
'disabled',
@@ -525,16 +586,28 @@ jQuery( function ( $ ) {
dataType: 'html',
success: function ( response ) {
$(
'.woocommerce-error, .woocommerce-message, .woocommerce-info, .is-error, .is-info, .is-success'
'.woocommerce-error, .woocommerce-message, .woocommerce-info, ' +
'.is-error, .is-info, .is-success, .coupon-error-notice'
).remove();
show_notice( response );
// We only want to show coupon notices if they are not errors.
// Coupon errors are shown under the input.
if ( response.indexOf( 'woocommerce-error' ) === -1 && response.indexOf( 'is-error' ) === -1 ) {
show_notice( response );
} else {
var $coupon_wrapper = $text_field.closest( '.coupon' );
if ( $coupon_wrapper.length > 0 ) {
show_coupon_error( response, $coupon_wrapper, false );
}
}
$( document.body ).trigger( 'applied_coupon', [
coupon_code,
] );
},
complete: function () {
unblock( $form );
$text_field.val( '' );
cart.update_cart( true );
},
} );
@@ -578,6 +651,21 @@ jQuery( function ( $ ) {
} );
},
/**
* Handle when the coupon input loses focus.
*
* @param {Object} evt The JQuery event
*/
remove_coupon_error: function ( evt ) {
$( evt.currentTarget )
.removeClass( 'has-error' )
.removeAttr( 'aria-invalid' )
.removeAttr( 'aria-describedby' )
.closest( '.coupon' )
.find( '.coupon-error-notice' )
.remove();
},
/**
* Handle a cart Quantity Update
*

File diff suppressed because one or more lines are too long

View File

@@ -535,7 +535,8 @@ jQuery( function( $ ) {
wc_checkout_form.detachUnloadEventsOnSubmit();
try {
if ( 'success' === result.result && $form.triggerHandler( 'checkout_place_order_success', [ result, wc_checkout_form ] ) !== false ) {
if ( 'success' === result.result &&
$form.triggerHandler( 'checkout_place_order_success', [ result, wc_checkout_form ] ) !== false ) {
if ( -1 === result.redirect.indexOf( 'https://' ) || -1 === result.redirect.indexOf( 'http://' ) ) {
window.location = result.redirect;
} else {
@@ -614,7 +615,8 @@ jQuery( function( $ ) {
init: function() {
$( document.body ).on( 'click', 'a.showcoupon', this.show_coupon_form );
$( document.body ).on( 'click', '.woocommerce-remove-coupon', this.remove_coupon );
$( 'form.checkout_coupon' ).hide().on( 'submit', this.submit );
$( document.body ).on( 'blur change input', '#coupon_code', this.remove_coupon_error );
$( 'form.checkout_coupon' ).hide().on( 'submit', this.submit.bind( this ) );
},
show_coupon_form: function() {
$( '.checkout_coupon' ).slideToggle( 400, function() {
@@ -622,8 +624,36 @@ jQuery( function( $ ) {
});
return false;
},
submit: function() {
var $form = $( this );
show_coupon_error: function( html_element, $target ) {
if ( $target.length === 0 ) {
return;
}
var msg = $( $.parseHTML( html_element ) ).text().trim();
if ( msg === '' ) {
return;
}
$target.find( '#coupon_code' )
.focus()
.addClass( 'has-error' )
.attr( 'aria-invalid', 'true' )
.attr( 'aria-describedby', 'coupon-error-notice' );
$target.append( '<span class="coupon-error-notice" id="coupon-error-notice" role="alert">' + msg + '</span>' );
},
remove_coupon_error: function( evt ) {
$( evt.currentTarget )
.removeClass( 'has-error' )
.removeAttr( 'aria-invalid' )
.removeAttr( 'aria-describedby' )
.next( '.coupon-error-notice' )
.remove();
},
submit: function( evt ) {
var $form = $( evt.currentTarget );
var $coupon_field = $form.find( '#coupon_code' );
var self = this;
if ( $form.is( '.processing' ) ) {
return false;
@@ -647,13 +677,20 @@ jQuery( function( $ ) {
type: 'POST',
url: wc_checkout_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'apply_coupon' ),
data: data,
success: function( code ) {
success: function( response ) {
$( '.woocommerce-error, .woocommerce-message, .is-error, .is-success' ).remove();
$form.removeClass( 'processing' ).unblock();
if ( code ) {
$form.before( code );
$form.slideUp();
if ( response ) {
// We only want to show coupon notices if they are no errors.
// Coupon errors are shown under the input.
if ( response.indexOf( 'woocommerce-error' ) === -1 && response.indexOf( 'is-error' ) === -1 ) {
$form.slideUp( 400, function() {
$form.before( response );
} );
} else {
self.show_coupon_error( response, $coupon_field.parent() );
}
$( document.body ).trigger( 'applied_coupon_in_checkout', [ data.coupon_code ] );
$( document.body ).trigger( 'update_checkout', { update_shipping_method: false } );
@@ -699,6 +736,7 @@ jQuery( function( $ ) {
// Remove coupon code from coupon field
$( 'form.checkout_coupon' ).find( 'input[name="coupon_code"]' ).val( '' );
$( 'form.checkout_coupon' ).slideUp();
}
},
error: function ( jqXHR ) {

File diff suppressed because one or more lines are too long

View File

@@ -57,7 +57,7 @@
}
/**
* Determin whether sourcebuster.js is available.
* Determine whether sourcebuster.js is available.
*
* @returns {boolean} Whether sourcebuster.js is available.
*/

View File

@@ -127,6 +127,8 @@ jQuery( function( $ ) {
this.onResetSlidePosition = this.onResetSlidePosition.bind( this );
this.getGalleryItems = this.getGalleryItems.bind( this );
this.openPhotoswipe = this.openPhotoswipe.bind( this );
this.trapFocusPhotoswipe = this.trapFocusPhotoswipe.bind( this );
this.handlePswpTrapFocus = this.handlePswpTrapFocus.bind( this );
if ( this.flexslider_enabled ) {
this.initFlexslider( args.flexslider );
@@ -307,8 +309,10 @@ jQuery( function( $ ) {
e.preventDefault();
var pswpElement = $( '.pswp' )[0],
items = this.getGalleryItems(),
eventTarget = $( e.target ),
items = this.getGalleryItems(),
eventTarget = $( e.target ),
currentTarget = e.currentTarget,
self = this,
clicked;
if ( 0 < eventTarget.closest( '.woocommerce-product-gallery__trigger' ).length ) {
@@ -326,14 +330,73 @@ jQuery( function( $ ) {
}
captionEl.children[0].textContent = item.title;
return true;
}
},
timeToIdle: 0, // Ensure the gallery controls are always visible to avoid keyboard navigation issues.
}, wc_single_product_params.photoswipe_options );
// Initializes and opens PhotoSwipe.
var photoswipe = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options );
photoswipe.listen( 'afterInit', function() {
self.trapFocusPhotoswipe( true );
});
photoswipe.listen( 'close', function() {
self.trapFocusPhotoswipe( false );
currentTarget.focus();
});
photoswipe.init();
};
/**
* Control focus in photoswipe modal.
*
* @param {boolean} trapFocus - Whether to trap focus or not.
*/
ProductGallery.prototype.trapFocusPhotoswipe = function( trapFocus ) {
var pswp = document.querySelector( '.pswp' );
if ( ! pswp ) {
return;
}
if ( trapFocus ) {
pswp.addEventListener( 'keydown', this.handlePswpTrapFocus );
} else {
pswp.removeEventListener( 'keydown', this.handlePswpTrapFocus );
}
};
/**
* Handle keydown event in photoswipe modal.
*/
ProductGallery.prototype.handlePswpTrapFocus = function( e ) {
var allFocusablesEls = e.currentTarget.querySelectorAll( 'button:not([disabled])' );
var filteredFocusablesEls = Array.from( allFocusablesEls ).filter( function( btn ) {
return btn.style.display !== 'none' && window.getComputedStyle( btn ).display !== 'none';
} );
if ( 1 >= filteredFocusablesEls.length ) {
return;
}
var firstTabStop = filteredFocusablesEls[0];
var lastTabStop = filteredFocusablesEls[filteredFocusablesEls.length - 1];
if ( e.key === 'Tab' ) {
if ( e.shiftKey ) {
if ( document.activeElement === firstTabStop ) {
e.preventDefault();
lastTabStop.focus();
}
} else if ( document.activeElement === lastTabStop ) {
e.preventDefault();
firstTabStop.focus();
}
}
};
/**
* Function to call wc_product_gallery on jquery selector.
*/

File diff suppressed because one or more lines are too long

View File

@@ -148,7 +148,14 @@ jQuery( function ( $ ) {
} );
});
document.addEventListener( 'DOMContentLoaded' , function() {
/**
* Focus on the first notice element on the page.
*
* Populated live regions don't always are announced by screen readers.
* This function focus on the first notice message with the role="alert"
* attribute to make sure it's announced.
*/
function focus_populate_live_region() {
var noticeClasses = [ 'woocommerce-message', 'woocommerce-error', 'wc-block-components-notice-banner' ];
var noticeSelectors = noticeClasses.map( function( className ) {
return '.' + className + '[role="alert"]';
@@ -168,4 +175,28 @@ document.addEventListener( 'DOMContentLoaded' , function() {
firstNotice.focus();
clearTimeout( delayFocusNoticeId );
}, 500 );
} );
}
/**
* Refresh the sorted by live region.
*/
function refresh_sorted_by_live_region () {
var sorted_by_live_region = document.querySelector( '.woocommerce-result-count[data-is-sorted-by="true"]' );
if ( sorted_by_live_region ) {
var text = sorted_by_live_region.innerHTML;
var sorted_by_live_region_id = setTimeout( function() {
sorted_by_live_region.innerHTML = '';
sorted_by_live_region.innerHTML = text;
clearTimeout( sorted_by_live_region_id );
}, 1000 );
}
}
function on_document_ready() {
focus_populate_live_region();
refresh_sorted_by_live_region();
}
document.addEventListener( 'DOMContentLoaded' , on_document_ready );

View File

@@ -1 +1 @@
jQuery(function(o){o(".woocommerce-ordering").on("change","select.orderby",function(){o(this).closest("form").trigger("submit")}),o("input.qty:not(.product-quantity input.qty)").each(function(){var e=parseFloat(o(this).attr("min"));e>=0&&parseFloat(o(this).val())<e&&o(this).val(e)});var e="store_notice"+(o(".woocommerce-store-notice").data("noticeId")||"");"hidden"===Cookies.get(e)?o(".woocommerce-store-notice").hide():o(".woocommerce-store-notice").show(),o(".woocommerce-store-notice__dismiss-link").on("click",function(t){Cookies.set(e,"hidden",{path:"/"}),o(".woocommerce-store-notice").hide(),t.preventDefault()}),o(".woocommerce-input-wrapper span.description").length&&o(document.body).on("click",function(){o(".woocommerce-input-wrapper span.description:visible").prop("aria-hidden",!0).slideUp(250)}),o(".woocommerce-input-wrapper").on("click",function(o){o.stopPropagation()}),o(".woocommerce-input-wrapper :input").on("keydown",function(e){var t=o(this).parent().find("span.description");if(27===e.which&&t.length&&t.is(":visible"))return t.prop("aria-hidden",!0).slideUp(250),e.preventDefault(),!1}).on("click focus",function(){var e=o(this).parent(),t=e.find("span.description");e.addClass("currentTarget"),o(".woocommerce-input-wrapper:not(.currentTarget) span.description:visible").prop("aria-hidden",!0).slideUp(250),t.length&&t.is(":hidden")&&t.prop("aria-hidden",!1).slideDown(250),e.removeClass("currentTarget")}),o.scroll_to_notices=function(e){e.length&&o("html, body").animate({scrollTop:e.offset().top-100},1e3)},o('.woocommerce form .woocommerce-Input[type="password"]').wrap('<span class="password-input"></span>'),o(".woocommerce form input").filter(":password").parent("span").addClass("password-input"),o(".password-input").append('<span class="show-password-input"></span>'),o(".show-password-input").on("click",function(){o(this).hasClass("display-password")?o(this).removeClass("display-password"):o(this).addClass("display-password"),o(this).hasClass("display-password")?o(this).siblings(['input[type="password"]']).prop("type","text"):o(this).siblings('input[type="text"]').prop("type","password")}),o("a.coming-soon-footer-banner-dismiss").on("click",function(e){var t=o(e.target);o.ajax({type:"post",url:t.data("rest-url"),data:{woocommerce_meta:{coming_soon_banner_dismissed:"yes"}},beforeSend:function(o){o.setRequestHeader("X-WP-Nonce",t.data("rest-nonce"))},complete:function(){o("#coming-soon-footer-banner").hide()}})})}),document.addEventListener("DOMContentLoaded",function(){var o=["woocommerce-message","woocommerce-error","wc-block-components-notice-banner"].map(function(o){return"."+o+'[role="alert"]'}).join(", "),e=document.querySelectorAll(o);if(0!==e.length){var t=e[0];t.setAttribute("tabindex","-1");var n=setTimeout(function(){t.focus(),clearTimeout(n)},500)}});
function focus_populate_live_region(){var e=["woocommerce-message","woocommerce-error","wc-block-components-notice-banner"].map(function(e){return"."+e+'[role="alert"]'}).join(", "),o=document.querySelectorAll(e);if(0!==o.length){var t=o[0];t.setAttribute("tabindex","-1");var n=setTimeout(function(){t.focus(),clearTimeout(n)},500)}}function refresh_sorted_by_live_region(){var e=document.querySelector('.woocommerce-result-count[data-is-sorted-by="true"]');if(e)var o=e.innerHTML,t=setTimeout(function(){e.innerHTML="",e.innerHTML=o,clearTimeout(t)},1e3)}function on_document_ready(){focus_populate_live_region(),refresh_sorted_by_live_region()}jQuery(function(e){e(".woocommerce-ordering").on("change","select.orderby",function(){e(this).closest("form").trigger("submit")}),e("input.qty:not(.product-quantity input.qty)").each(function(){var o=parseFloat(e(this).attr("min"));o>=0&&parseFloat(e(this).val())<o&&e(this).val(o)});var o="store_notice"+(e(".woocommerce-store-notice").data("noticeId")||"");"hidden"===Cookies.get(o)?e(".woocommerce-store-notice").hide():e(".woocommerce-store-notice").show(),e(".woocommerce-store-notice__dismiss-link").on("click",function(t){Cookies.set(o,"hidden",{path:"/"}),e(".woocommerce-store-notice").hide(),t.preventDefault()}),e(".woocommerce-input-wrapper span.description").length&&e(document.body).on("click",function(){e(".woocommerce-input-wrapper span.description:visible").prop("aria-hidden",!0).slideUp(250)}),e(".woocommerce-input-wrapper").on("click",function(e){e.stopPropagation()}),e(".woocommerce-input-wrapper :input").on("keydown",function(o){var t=e(this).parent().find("span.description");if(27===o.which&&t.length&&t.is(":visible"))return t.prop("aria-hidden",!0).slideUp(250),o.preventDefault(),!1}).on("click focus",function(){var o=e(this).parent(),t=o.find("span.description");o.addClass("currentTarget"),e(".woocommerce-input-wrapper:not(.currentTarget) span.description:visible").prop("aria-hidden",!0).slideUp(250),t.length&&t.is(":hidden")&&t.prop("aria-hidden",!1).slideDown(250),o.removeClass("currentTarget")}),e.scroll_to_notices=function(o){o.length&&e("html, body").animate({scrollTop:o.offset().top-100},1e3)},e('.woocommerce form .woocommerce-Input[type="password"]').wrap('<span class="password-input"></span>'),e(".woocommerce form input").filter(":password").parent("span").addClass("password-input"),e(".password-input").append('<span class="show-password-input"></span>'),e(".show-password-input").on("click",function(){e(this).hasClass("display-password")?e(this).removeClass("display-password"):e(this).addClass("display-password"),e(this).hasClass("display-password")?e(this).siblings(['input[type="password"]']).prop("type","text"):e(this).siblings('input[type="text"]').prop("type","password")}),e("a.coming-soon-footer-banner-dismiss").on("click",function(o){var t=e(o.target);e.ajax({type:"post",url:t.data("rest-url"),data:{woocommerce_meta:{coming_soon_banner_dismissed:"yes"}},beforeSend:function(e){e.setRequestHeader("X-WP-Nonce",t.data("rest-nonce"))},complete:function(){e("#coming-soon-footer-banner").hide()}})})}),document.addEventListener("DOMContentLoaded",on_document_ready);