auto-patch 638-dev-dev01-2024-05-14T20_44_36

This commit is contained in:
root
2024-05-14 20:44:36 +00:00
parent a941559057
commit 5dbb0b284e
1812 changed files with 29671 additions and 14588 deletions

View File

@@ -501,13 +501,13 @@ jQuery( function( $ ) {
var maybe_valid_json = raw_response.match( /{"result.*}/ );
if ( null === maybe_valid_json ) {
console.log( 'Unable to fix malformed JSON' );
console.log( 'Unable to fix malformed JSON #1' );
} else if ( wc_checkout_form.is_valid_json( maybe_valid_json[0] ) ) {
console.log( 'Fixed malformed JSON. Original:' );
console.log( raw_response );
raw_response = maybe_valid_json[0];
} else {
console.log( 'Unable to fix malformed JSON' );
console.log( 'Unable to fix malformed JSON #2' );
}
}
@@ -560,10 +560,21 @@ jQuery( function( $ ) {
// Detach the unload handler that prevents a reload / redirect
wc_checkout_form.detachUnloadEventsOnSubmit();
// This is just a technical error fallback. i18_checkout_error is expected to be always defined and localized.
var errorMessage = errorThrown;
if (
typeof wc_checkout_params === 'object' &&
wc_checkout_params !== null &&
wc_checkout_params.hasOwnProperty( 'i18n_checkout_error' ) &&
typeof wc_checkout_params.i18n_checkout_error === 'string' &&
wc_checkout_params.i18n_checkout_error.trim() !== ''
) {
errorMessage = wc_checkout_params.i18n_checkout_error;
}
wc_checkout_form.submit_error(
'<div class="woocommerce-error">' +
( errorThrown || wc_checkout_params.i18n_checkout_error ) +
'</div>'
'<div class="woocommerce-error">' + errorMessage + '</div>'
);
}
});
@@ -617,8 +628,9 @@ jQuery( function( $ ) {
});
var data = {
security: wc_checkout_params.apply_coupon_nonce,
coupon_code: $form.find( 'input[name="coupon_code"]' ).val()
security: wc_checkout_params.apply_coupon_nonce,
coupon_code: $form.find('input[name="coupon_code"]').val(),
billing_email: wc_checkout_form.$checkout_form.find('input[name="billing_email"]').val()
};
$.ajax({

File diff suppressed because one or more lines are too long

View File

@@ -7,6 +7,7 @@
const $ = document.querySelector.bind( document );
const propertyAccessor = ( obj, path ) => path.split( '.' ).reduce( ( acc, part ) => acc && acc[ part ], obj );
const returnNull = () => null;
const stringifyFalsyInputValue = ( value ) => value === null || value === undefined ? '' : value;
// Hardcode Checkout store key (`wc.wcBlocksData.CHECKOUT_STORE_KEY`), as we no longer have `wc-blocks-checkout` as a dependency.
const CHECKOUT_STORE_KEY = 'wc/store/checkout';
@@ -31,11 +32,9 @@
* @param {Object} values Object containing field values.
*/
function updateFormValues( values ) {
// Update inputs if any exist.
if( $( `input[name^="${params.prefix}"]` ) ) {
for( const key of Object.keys( wc_order_attribution.fields ) ) {
$( `input[name="${params.prefix}${key}"]` ).value = values && values[ key ] || '';
}
// Update `<wc-order-attribution-inputs>` elements if any exist.
for( const element of document.querySelectorAll( 'wc-order-attribution-inputs' ) ) {
element.values = values;
}
};
@@ -66,6 +65,8 @@
if ( ! allow ) {
// Reset cookies, and clear form data.
removeTrackingCookies();
} else if ( typeof sbjs === 'undefined' ) {
return; // Do nothing, as sourcebuster.js is not loaded.
} else {
// If not done yet, initialize sourcebuster.js which populates `sbjs.get` object.
sbjs.init( {
@@ -105,15 +106,6 @@
// Run init.
wc_order_attribution.setOrderTracking( params.allowTracking );
// Wait for (async) classic checkout initialization and set source values once loaded.
if ( $( 'form.woocommerce-checkout' ) !== null ) {
const previousInitCheckout = document.body.oninit_checkout;
document.body.oninit_checkout = () => {
updateFormValues( getData() );
previousInitCheckout && previousInitCheckout();
};
}
// Work around the lack of explicit script dependency for the checkout block.
// Conditionally, wait for and use 'wp-data' & 'wc-blocks-checkout.
@@ -136,4 +128,61 @@
eventuallyInitializeCheckoutBlock();
}
/**
* Define an element to contribute order attribute values to the enclosing form.
* To be used with the classic checkout.
*/
window.customElements.define( 'wc-order-attribution-inputs', class extends HTMLElement {
// Our bundler version does not support private class members, so we use a convention of `_` prefix.
// #values
// #fieldNames
constructor(){
super();
// Cache fieldNames available at the construction time, to avoid malformed behavior if they change in runtime.
this._fieldNames = Object.keys( wc_order_attribution.fields );
// Allow values to be lazily set before CE upgrade.
if ( this.hasOwnProperty( '_values' ) ) {
let values = this.values;
// Restore the setter.
delete this.values;
this.values = values || {};
}
}
/**
* Stamp input elements to the element's light DOM.
*
* We could use `.elementInternals.setFromValue` and avoid sprouting `<input>` elements,
* but it's not yet supported in Safari.
*/
connectedCallback() {
let inputs = '';
for( const fieldName of this._fieldNames ) {
const value = stringifyFalsyInputValue( this.values[ fieldName ] );
inputs += `<input type="hidden" name="${params.prefix}${fieldName}" value="${value}"/>`;
}
this.innerHTML = inputs;
}
/**
* Update form values.
*/
set values( values ) {
this._values = values;
if( this.isConnected ) {
for( const fieldName of this._fieldNames ) {
const input = this.querySelector( `input[name="${params.prefix}${fieldName}"]` );
if( input ) {
input.value = stringifyFalsyInputValue( this.values[ fieldName ] );
} else {
console.warn( `Field "${fieldName}" not found. Most likely, the '<wc-order-attribution-inputs>' element was manipulated.`);
}
}
}
}
get values() {
return this._values;
}
} );
}( window.wc_order_attribution ) );

View File

@@ -1 +1 @@
!function(n){"use strict";const t=n.params,o=document.querySelector.bind(document),e=(n,t)=>t.split(".").reduce((n,t)=>n&&n[t],n),i=()=>null,c="wc/store/checkout";function s(){const o=t.allowTracking?e:i,c=Object.entries(n.fields).map(([n,t])=>[n,o(sbjs.get,t)]);return Object.fromEntries(c)}function a(e){if(o(`input[name^="${t.prefix}"]`))for(const i of Object.keys(n.fields))o(`input[name="${t.prefix}${i}"]`).value=e&&e[i]||""}function d(n){window.wp&&window.wp.data&&window.wp.data.dispatch&&window.wc&&window.wc.wcBlocksData&&window.wp.data.dispatch(window.wc.wcBlocksData.CHECKOUT_STORE_KEY).__internalSetExtensionData("woocommerce/order-attribution",n,!0)}if(n.setOrderTracking=function(n){t.allowTracking=n,n?sbjs.init({lifetime:Number(t.lifetime),session_length:Number(t.session),timezone_offset:"0"}):function(){const n=window.location.hostname;["sbjs_current","sbjs_current_add","sbjs_first","sbjs_first_add","sbjs_session","sbjs_udata","sbjs_migrations","sbjs_promo"].forEach(t=>{document.cookie=`${t}=; path=/; max-age=-999; domain=.${n};`})}();const o=s();a(o),d(o)},n.setOrderTracking(t.allowTracking),null!==o("form.woocommerce-checkout")){const n=document.body.oninit_checkout;document.body.oninit_checkout=(()=>{a(s()),n&&n()})}function r(){if(window.wp&&window.wp.data&&"function"==typeof window.wp.data.subscribe){const n=window.wp.data.subscribe(function(){n(),d(s())},c)}}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",r):r()}(window.wc_order_attribution);
!function(e){"use strict";const t=e.params,n=(document.querySelector.bind(document),(e,t)=>t.split(".").reduce((e,t)=>e&&e[t],e)),s=()=>null,i=e=>null===e||e===undefined?"":e,o="wc/store/checkout";function a(){const i=t.allowTracking?n:s,o=Object.entries(e.fields).map(([e,t])=>[e,i(sbjs.get,t)]);return Object.fromEntries(o)}function c(e){window.wp&&window.wp.data&&window.wp.data.dispatch&&window.wc&&window.wc.wcBlocksData&&window.wp.data.dispatch(window.wc.wcBlocksData.CHECKOUT_STORE_KEY).__internalSetExtensionData("woocommerce/order-attribution",e,!0)}function r(){if(window.wp&&window.wp.data&&"function"==typeof window.wp.data.subscribe){const e=window.wp.data.subscribe(function(){e(),c(a())},o)}}e.setOrderTracking=function(e){if(t.allowTracking=e,e){if("undefined"==typeof sbjs)return;sbjs.init({lifetime:Number(t.lifetime),session_length:Number(t.session),timezone_offset:"0"})}else!function(){const e=window.location.hostname;["sbjs_current","sbjs_current_add","sbjs_first","sbjs_first_add","sbjs_session","sbjs_udata","sbjs_migrations","sbjs_promo"].forEach(t=>{document.cookie=`${t}=; path=/; max-age=-999; domain=.${e};`})}();const n=a();!function(e){for(const t of document.querySelectorAll("wc-order-attribution-inputs"))t.values=e}(n),c(n)},e.setOrderTracking(t.allowTracking),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",r):r(),window.customElements.define("wc-order-attribution-inputs",class extends HTMLElement{constructor(){if(super(),this._fieldNames=Object.keys(e.fields),this.hasOwnProperty("_values")){let e=this.values;delete this.values,this.values=e||{}}}connectedCallback(){let e="";for(const n of this._fieldNames){const s=i(this.values[n]);e+=`<input type="hidden" name="${t.prefix}${n}" value="${s}"/>`}this.innerHTML=e}set values(e){if(this._values=e,this.isConnected)for(const e of this._fieldNames){const n=this.querySelector(`input[name="${t.prefix}${e}"]`);n?n.value=i(this.values[e]):console.warn(`Field "${e}" not found. Most likely, the '<wc-order-attribution-inputs>' element was manipulated.`)}}get values(){return this._values}})}(window.wc_order_attribution);

View File

@@ -99,4 +99,24 @@ jQuery( function( $ ) {
}
}
);
$( 'a.coming-soon-footer-banner-dismiss' ).on( 'click', function( e ) {
var target = $( e.target );
$.ajax( {
type: 'post',
url: target.data( 'rest-url' ),
data: {
meta: {
'woocommerce_coming_soon_banner_dismissed': 'yes'
}
},
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-WP-Nonce', target.data( 'rest-nonce' ) );
},
complete: function () {
$('#coming-soon-footer-banner').hide();
}
} );
} );
});

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(s){Cookies.set(e,"hidden",{path:"/"}),o(".woocommerce-store-notice").hide(),s.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 s=o(this).parent().find("span.description");if(27===e.which&&s.length&&s.is(":visible"))return s.prop("aria-hidden",!0).slideUp(250),e.preventDefault(),!1}).on("click focus",function(){var e=o(this).parent(),s=e.find("span.description");e.addClass("currentTarget"),o(".woocommerce-input-wrapper:not(.currentTarget) span.description:visible").prop("aria-hidden",!0).slideUp(250),s.length&&s.is(":hidden")&&s.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")})});
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(s){Cookies.set(e,"hidden",{path:"/"}),o(".woocommerce-store-notice").hide(),s.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 s=o(this).parent().find("span.description");if(27===e.which&&s.length&&s.is(":visible"))return s.prop("aria-hidden",!0).slideUp(250),e.preventDefault(),!1}).on("click focus",function(){var e=o(this).parent(),s=e.find("span.description");e.addClass("currentTarget"),o(".woocommerce-input-wrapper:not(.currentTarget) span.description:visible").prop("aria-hidden",!0).slideUp(250),s.length&&s.is(":hidden")&&s.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 s=o(e.target);o.ajax({type:"post",url:s.data("rest-url"),data:{meta:{woocommerce_coming_soon_banner_dismissed:"yes"}},beforeSend:function(o){o.setRequestHeader("X-WP-Nonce",s.data("rest-nonce"))},complete:function(){o("#coming-soon-footer-banner").hide()}})})});