Merged in feature/from-pantheon (pull request #16)
code from pantheon * code from pantheon
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
jQuery( function( $ ) {
|
||||
|
||||
// woocommerce_params is required to continue, ensure the object exists
|
||||
if ( typeof woocommerce_params === 'undefined' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$( '#add_payment_method' )
|
||||
|
||||
/* Payment option selection */
|
||||
|
||||
.on( 'click init_add_payment_method', '.payment_methods input.input-radio', function() {
|
||||
if ( $( '.payment_methods input.input-radio' ).length > 1 ) {
|
||||
var target_payment_box = $( 'div.payment_box.' + $( this ).attr( 'ID' ) );
|
||||
if ( $( this ).is( ':checked' ) && ! target_payment_box.is( ':visible' ) ) {
|
||||
$( 'div.payment_box' ).filter( ':visible' ).slideUp( 250 );
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( 'div.payment_box.' + $( this ).attr( 'ID' ) ).slideDown( 250 );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$( 'div.payment_box' ).show();
|
||||
}
|
||||
})
|
||||
|
||||
// Trigger initial click
|
||||
.find( 'input[name=payment_method]:checked' ).trigger( 'click' );
|
||||
|
||||
$( '#add_payment_method' ).on( 'submit', function() {
|
||||
$( '#add_payment_method' ).block({ message: null, overlayCSS: { background: '#fff', opacity: 0.6 } });
|
||||
});
|
||||
|
||||
$( document.body ).trigger( 'init_add_payment_method' );
|
||||
|
||||
// Prevent firing multiple requests upon double clicking the buttons in payment methods table
|
||||
$(' .woocommerce .payment-method-actions .button.delete' ).on( 'click' , function( event ) {
|
||||
if ( $( this ).hasClass( 'disabled' ) ) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
$( this ).addClass( 'disabled' );
|
||||
});
|
||||
|
||||
});
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/add-payment-method.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/add-payment-method.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(function(e){if("undefined"==typeof woocommerce_params)return!1;e("#add_payment_method").on("click init_add_payment_method",".payment_methods input.input-radio",function(){if(e(".payment_methods input.input-radio").length>1){var t=e("div.payment_box."+e(this).attr("ID"));e(this).is(":checked")&&!t.is(":visible")&&(e("div.payment_box").filter(":visible").slideUp(250),e(this).is(":checked")&&e("div.payment_box."+e(this).attr("ID")).slideDown(250))}else e("div.payment_box").show()}).find("input[name=payment_method]:checked").trigger("click"),e("#add_payment_method").on("submit",function(){e("#add_payment_method").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})}),e(document.body).trigger("init_add_payment_method"),e(" .woocommerce .payment-method-actions .button.delete").on("click",function(t){e(this).hasClass("disabled")&&t.preventDefault(),e(this).addClass("disabled")})});
|
||||
@@ -0,0 +1,818 @@
|
||||
/*global wc_add_to_cart_variation_params */
|
||||
;(function ( $, window, document, undefined ) {
|
||||
/**
|
||||
* VariationForm class which handles variation forms and attributes.
|
||||
*/
|
||||
var VariationForm = function( $form ) {
|
||||
var self = this;
|
||||
|
||||
self.$form = $form;
|
||||
self.$attributeFields = $form.find( '.variations select' );
|
||||
self.$singleVariation = $form.find( '.single_variation' );
|
||||
self.$singleVariationWrap = $form.find( '.single_variation_wrap' );
|
||||
self.$resetVariations = $form.find( '.reset_variations' );
|
||||
self.$product = $form.closest( '.product' );
|
||||
self.variationData = $form.data( 'product_variations' );
|
||||
self.useAjax = false === self.variationData;
|
||||
self.xhr = false;
|
||||
self.loading = true;
|
||||
|
||||
// Initial state.
|
||||
self.$singleVariationWrap.show();
|
||||
self.$form.off( '.wc-variation-form' );
|
||||
|
||||
// Methods.
|
||||
self.getChosenAttributes = self.getChosenAttributes.bind( self );
|
||||
self.findMatchingVariations = self.findMatchingVariations.bind( self );
|
||||
self.isMatch = self.isMatch.bind( self );
|
||||
self.toggleResetLink = self.toggleResetLink.bind( self );
|
||||
|
||||
// Events.
|
||||
$form.on( 'click.wc-variation-form', '.reset_variations', { variationForm: self }, self.onReset );
|
||||
$form.on( 'reload_product_variations', { variationForm: self }, self.onReload );
|
||||
$form.on( 'hide_variation', { variationForm: self }, self.onHide );
|
||||
$form.on( 'show_variation', { variationForm: self }, self.onShow );
|
||||
$form.on( 'click', '.single_add_to_cart_button', { variationForm: self }, self.onAddToCart );
|
||||
$form.on( 'reset_data', { variationForm: self }, self.onResetDisplayedVariation );
|
||||
$form.on( 'reset_image', { variationForm: self }, self.onResetImage );
|
||||
$form.on( 'change.wc-variation-form', '.variations select', { variationForm: self }, self.onChange );
|
||||
$form.on( 'found_variation.wc-variation-form', { variationForm: self }, self.onFoundVariation );
|
||||
$form.on( 'check_variations.wc-variation-form', { variationForm: self }, self.onFindVariation );
|
||||
$form.on( 'update_variation_values.wc-variation-form', { variationForm: self }, self.onUpdateAttributes );
|
||||
|
||||
// Init after gallery.
|
||||
setTimeout( function() {
|
||||
$form.trigger( 'check_variations' );
|
||||
$form.trigger( 'wc_variation_form', self );
|
||||
self.loading = false;
|
||||
}, 100 );
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset all fields.
|
||||
*/
|
||||
VariationForm.prototype.onReset = function( event ) {
|
||||
event.preventDefault();
|
||||
event.data.variationForm.$attributeFields.val( '' ).trigger( 'change' );
|
||||
event.data.variationForm.$form.trigger( 'reset_data' );
|
||||
};
|
||||
|
||||
/**
|
||||
* Reload variation data from the DOM.
|
||||
*/
|
||||
VariationForm.prototype.onReload = function( event ) {
|
||||
var form = event.data.variationForm;
|
||||
form.variationData = form.$form.data( 'product_variations' );
|
||||
form.useAjax = false === form.variationData;
|
||||
form.$form.trigger( 'check_variations' );
|
||||
};
|
||||
|
||||
/**
|
||||
* When a variation is hidden.
|
||||
*/
|
||||
VariationForm.prototype.onHide = function( event ) {
|
||||
event.preventDefault();
|
||||
event.data.variationForm.$form
|
||||
.find( '.single_add_to_cart_button' )
|
||||
.removeClass( 'wc-variation-is-unavailable' )
|
||||
.addClass( 'disabled wc-variation-selection-needed' );
|
||||
event.data.variationForm.$form
|
||||
.find( '.woocommerce-variation-add-to-cart' )
|
||||
.removeClass( 'woocommerce-variation-add-to-cart-enabled' )
|
||||
.addClass( 'woocommerce-variation-add-to-cart-disabled' );
|
||||
};
|
||||
|
||||
/**
|
||||
* When a variation is shown.
|
||||
*/
|
||||
VariationForm.prototype.onShow = function( event, variation, purchasable ) {
|
||||
event.preventDefault();
|
||||
if ( purchasable ) {
|
||||
event.data.variationForm.$form
|
||||
.find( '.single_add_to_cart_button' )
|
||||
.removeClass( 'disabled wc-variation-selection-needed wc-variation-is-unavailable' );
|
||||
event.data.variationForm.$form
|
||||
.find( '.woocommerce-variation-add-to-cart' )
|
||||
.removeClass( 'woocommerce-variation-add-to-cart-disabled' )
|
||||
.addClass( 'woocommerce-variation-add-to-cart-enabled' );
|
||||
} else {
|
||||
event.data.variationForm.$form
|
||||
.find( '.single_add_to_cart_button' )
|
||||
.removeClass( 'wc-variation-selection-needed' )
|
||||
.addClass( 'disabled wc-variation-is-unavailable' );
|
||||
event.data.variationForm.$form
|
||||
.find( '.woocommerce-variation-add-to-cart' )
|
||||
.removeClass( 'woocommerce-variation-add-to-cart-enabled' )
|
||||
.addClass( 'woocommerce-variation-add-to-cart-disabled' );
|
||||
}
|
||||
|
||||
// If present, the media element library needs initialized on the variation description.
|
||||
if ( wp.mediaelement ) {
|
||||
event.data.variationForm.$form.find( '.wp-audio-shortcode, .wp-video-shortcode' )
|
||||
.not( '.mejs-container' )
|
||||
.filter(
|
||||
function () {
|
||||
return ! $( this ).parent().hasClass( 'mejs-mediaelement' );
|
||||
}
|
||||
)
|
||||
.mediaelementplayer( wp.mediaelement.settings );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* When the cart button is pressed.
|
||||
*/
|
||||
VariationForm.prototype.onAddToCart = function( event ) {
|
||||
if ( $( this ).is('.disabled') ) {
|
||||
event.preventDefault();
|
||||
|
||||
if ( $( this ).is('.wc-variation-is-unavailable') ) {
|
||||
window.alert( wc_add_to_cart_variation_params.i18n_unavailable_text );
|
||||
} else if ( $( this ).is('.wc-variation-selection-needed') ) {
|
||||
window.alert( wc_add_to_cart_variation_params.i18n_make_a_selection_text );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* When displayed variation data is reset.
|
||||
*/
|
||||
VariationForm.prototype.onResetDisplayedVariation = function( event ) {
|
||||
var form = event.data.variationForm;
|
||||
form.$product.find( '.product_meta' ).find( '.sku' ).wc_reset_content();
|
||||
form.$product
|
||||
.find( '.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value' )
|
||||
.wc_reset_content();
|
||||
form.$product
|
||||
.find( '.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value' )
|
||||
.wc_reset_content();
|
||||
form.$form.trigger( 'reset_image' );
|
||||
form.$singleVariation.slideUp( 200 ).trigger( 'hide_variation' );
|
||||
};
|
||||
|
||||
/**
|
||||
* When the product image is reset.
|
||||
*/
|
||||
VariationForm.prototype.onResetImage = function( event ) {
|
||||
event.data.variationForm.$form.wc_variations_image_update( false );
|
||||
};
|
||||
|
||||
/**
|
||||
* Looks for matching variations for current selected attributes.
|
||||
*/
|
||||
VariationForm.prototype.onFindVariation = function( event, chosenAttributes ) {
|
||||
var form = event.data.variationForm,
|
||||
attributes = 'undefined' !== typeof chosenAttributes ? chosenAttributes : form.getChosenAttributes(),
|
||||
currentAttributes = attributes.data;
|
||||
|
||||
if ( attributes.count && attributes.count === attributes.chosenCount ) {
|
||||
if ( form.useAjax ) {
|
||||
if ( form.xhr ) {
|
||||
form.xhr.abort();
|
||||
}
|
||||
form.$form.block( { message: null, overlayCSS: { background: '#fff', opacity: 0.6 } } );
|
||||
currentAttributes.product_id = parseInt( form.$form.data( 'product_id' ), 10 );
|
||||
currentAttributes.custom_data = form.$form.data( 'custom_data' );
|
||||
form.xhr = $.ajax( {
|
||||
url: wc_add_to_cart_variation_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_variation' ),
|
||||
type: 'POST',
|
||||
data: currentAttributes,
|
||||
success: function( variation ) {
|
||||
if ( variation ) {
|
||||
form.$form.trigger( 'found_variation', [ variation ] );
|
||||
} else {
|
||||
form.$form.trigger( 'reset_data' );
|
||||
attributes.chosenCount = 0;
|
||||
|
||||
if ( ! form.loading ) {
|
||||
form.$form
|
||||
.find( '.single_variation' )
|
||||
.after(
|
||||
'<p class="wc-no-matching-variations woocommerce-info">' +
|
||||
wc_add_to_cart_variation_params.i18n_no_matching_variations_text +
|
||||
'</p>'
|
||||
);
|
||||
form.$form.find( '.wc-no-matching-variations' ).slideDown( 200 );
|
||||
}
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
form.$form.unblock();
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
form.$form.trigger( 'update_variation_values' );
|
||||
|
||||
var matching_variations = form.findMatchingVariations( form.variationData, currentAttributes ),
|
||||
variation = matching_variations.shift();
|
||||
|
||||
if ( variation ) {
|
||||
form.$form.trigger( 'found_variation', [ variation ] );
|
||||
} else {
|
||||
form.$form.trigger( 'reset_data' );
|
||||
attributes.chosenCount = 0;
|
||||
|
||||
if ( ! form.loading ) {
|
||||
form.$form
|
||||
.find( '.single_variation' )
|
||||
.after(
|
||||
'<p class="wc-no-matching-variations woocommerce-info">' +
|
||||
wc_add_to_cart_variation_params.i18n_no_matching_variations_text +
|
||||
'</p>'
|
||||
);
|
||||
form.$form.find( '.wc-no-matching-variations' ).slideDown( 200 );
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
form.$form.trigger( 'update_variation_values' );
|
||||
form.$form.trigger( 'reset_data' );
|
||||
}
|
||||
|
||||
// Show reset link.
|
||||
form.toggleResetLink( attributes.chosenCount > 0 );
|
||||
};
|
||||
|
||||
/**
|
||||
* Triggered when a variation has been found which matches all attributes.
|
||||
*/
|
||||
VariationForm.prototype.onFoundVariation = function( event, variation ) {
|
||||
var form = event.data.variationForm,
|
||||
$sku = form.$product.find( '.product_meta' ).find( '.sku' ),
|
||||
$weight = form.$product.find(
|
||||
'.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value'
|
||||
),
|
||||
$dimensions = form.$product.find(
|
||||
'.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value'
|
||||
),
|
||||
$qty_input = form.$singleVariationWrap.find( '.quantity input.qty[name="quantity"]' ),
|
||||
$qty = $qty_input.closest( '.quantity' ),
|
||||
purchasable = true,
|
||||
variation_id = '',
|
||||
template = false,
|
||||
$template_html = '';
|
||||
|
||||
if ( variation.sku ) {
|
||||
$sku.wc_set_content( variation.sku );
|
||||
} else {
|
||||
$sku.wc_reset_content();
|
||||
}
|
||||
|
||||
if ( variation.weight ) {
|
||||
$weight.wc_set_content( variation.weight_html );
|
||||
} else {
|
||||
$weight.wc_reset_content();
|
||||
}
|
||||
|
||||
if ( variation.dimensions ) {
|
||||
// Decode HTML entities.
|
||||
$dimensions.wc_set_content( $.parseHTML( variation.dimensions_html )[0].data );
|
||||
} else {
|
||||
$dimensions.wc_reset_content();
|
||||
}
|
||||
|
||||
form.$form.wc_variations_image_update( variation );
|
||||
|
||||
if ( ! variation.variation_is_visible ) {
|
||||
template = wp_template( 'unavailable-variation-template' );
|
||||
} else {
|
||||
template = wp_template( 'variation-template' );
|
||||
variation_id = variation.variation_id;
|
||||
}
|
||||
|
||||
$template_html = template( {
|
||||
variation: variation
|
||||
} );
|
||||
$template_html = $template_html.replace( '/*<![CDATA[*/', '' );
|
||||
$template_html = $template_html.replace( '/*]]>*/', '' );
|
||||
|
||||
form.$singleVariation.html( $template_html );
|
||||
form.$form.find( 'input[name="variation_id"], input.variation_id' ).val( variation.variation_id ).trigger( 'change' );
|
||||
|
||||
// Hide or show qty input
|
||||
if ( variation.is_sold_individually === 'yes' ) {
|
||||
$qty_input.val( '1' ).attr( 'min', '1' ).attr( 'max', '' ).trigger( 'change' );
|
||||
$qty.hide();
|
||||
} else {
|
||||
|
||||
var qty_val = parseFloat( $qty_input.val() );
|
||||
|
||||
if ( isNaN( qty_val ) ) {
|
||||
qty_val = variation.min_qty;
|
||||
} else {
|
||||
qty_val = qty_val > parseFloat( variation.max_qty ) ? variation.max_qty : qty_val;
|
||||
qty_val = qty_val < parseFloat( variation.min_qty ) ? variation.min_qty : qty_val;
|
||||
}
|
||||
|
||||
$qty_input.attr( 'min', variation.min_qty ).attr( 'max', variation.max_qty ).val( qty_val ).trigger( 'change' );
|
||||
$qty.show();
|
||||
}
|
||||
|
||||
// Enable or disable the add to cart button
|
||||
if ( ! variation.is_purchasable || ! variation.is_in_stock || ! variation.variation_is_visible ) {
|
||||
purchasable = false;
|
||||
}
|
||||
|
||||
// Reveal
|
||||
if ( form.$singleVariation.text().trim() ) {
|
||||
form.$singleVariation.slideDown( 200 ).trigger( 'show_variation', [ variation, purchasable ] );
|
||||
} else {
|
||||
form.$singleVariation.show().trigger( 'show_variation', [ variation, purchasable ] );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Triggered when an attribute field changes.
|
||||
*/
|
||||
VariationForm.prototype.onChange = function( event ) {
|
||||
var form = event.data.variationForm;
|
||||
|
||||
form.$form.find( 'input[name="variation_id"], input.variation_id' ).val( '' ).trigger( 'change' );
|
||||
form.$form.find( '.wc-no-matching-variations' ).remove();
|
||||
|
||||
if ( form.useAjax ) {
|
||||
form.$form.trigger( 'check_variations' );
|
||||
} else {
|
||||
form.$form.trigger( 'woocommerce_variation_select_change' );
|
||||
form.$form.trigger( 'check_variations' );
|
||||
}
|
||||
|
||||
// Custom event for when variation selection has been changed
|
||||
form.$form.trigger( 'woocommerce_variation_has_changed' );
|
||||
};
|
||||
|
||||
/**
|
||||
* Escape quotes in a string.
|
||||
* @param {string} string
|
||||
* @return {string}
|
||||
*/
|
||||
VariationForm.prototype.addSlashes = function( string ) {
|
||||
string = string.replace( /'/g, '\\\'' );
|
||||
string = string.replace( /"/g, '\\\"' );
|
||||
return string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates attributes in the DOM to show valid values.
|
||||
*/
|
||||
VariationForm.prototype.onUpdateAttributes = function( event ) {
|
||||
var form = event.data.variationForm,
|
||||
attributes = form.getChosenAttributes(),
|
||||
currentAttributes = attributes.data;
|
||||
|
||||
if ( form.useAjax ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Loop through selects and disable/enable options based on selections.
|
||||
form.$attributeFields.each( function( index, el ) {
|
||||
var current_attr_select = $( el ),
|
||||
current_attr_name = current_attr_select.data( 'attribute_name' ) || current_attr_select.attr( 'name' ),
|
||||
show_option_none = $( el ).data( 'show_option_none' ),
|
||||
option_gt_filter = ':gt(0)',
|
||||
attached_options_count = 0,
|
||||
new_attr_select = $( '<select/>' ),
|
||||
selected_attr_val = current_attr_select.val() || '',
|
||||
selected_attr_val_valid = true;
|
||||
|
||||
// Reference options set at first.
|
||||
if ( ! current_attr_select.data( 'attribute_html' ) ) {
|
||||
var refSelect = current_attr_select.clone();
|
||||
|
||||
refSelect.find( 'option' ).removeAttr( 'attached' ).prop( 'disabled', false ).prop( 'selected', false );
|
||||
|
||||
// Legacy data attribute.
|
||||
current_attr_select.data(
|
||||
'attribute_options',
|
||||
refSelect.find( 'option' + option_gt_filter ).get()
|
||||
);
|
||||
current_attr_select.data( 'attribute_html', refSelect.html() );
|
||||
}
|
||||
|
||||
new_attr_select.html( current_attr_select.data( 'attribute_html' ) );
|
||||
|
||||
// The attribute of this select field should not be taken into account when calculating its matching variations:
|
||||
// The constraints of this attribute are shaped by the values of the other attributes.
|
||||
var checkAttributes = $.extend( true, {}, currentAttributes );
|
||||
|
||||
checkAttributes[ current_attr_name ] = '';
|
||||
|
||||
var variations = form.findMatchingVariations( form.variationData, checkAttributes );
|
||||
|
||||
// Loop through variations.
|
||||
for ( var num in variations ) {
|
||||
if ( typeof( variations[ num ] ) !== 'undefined' ) {
|
||||
var variationAttributes = variations[ num ].attributes;
|
||||
|
||||
for ( var attr_name in variationAttributes ) {
|
||||
if ( variationAttributes.hasOwnProperty( attr_name ) ) {
|
||||
var attr_val = variationAttributes[ attr_name ],
|
||||
variation_active = '';
|
||||
|
||||
if ( attr_name === current_attr_name ) {
|
||||
if ( variations[ num ].variation_is_active ) {
|
||||
variation_active = 'enabled';
|
||||
}
|
||||
|
||||
if ( attr_val ) {
|
||||
// Decode entities.
|
||||
attr_val = $( '<div/>' ).html( attr_val ).text();
|
||||
|
||||
// Attach to matching options by value. This is done to compare
|
||||
// TEXT values rather than any HTML entities.
|
||||
var $option_elements = new_attr_select.find( 'option' );
|
||||
if ( $option_elements.length ) {
|
||||
for (var i = 0, len = $option_elements.length; i < len; i++) {
|
||||
var $option_element = $( $option_elements[i] ),
|
||||
option_value = $option_element.val();
|
||||
|
||||
if ( attr_val === option_value ) {
|
||||
$option_element.addClass( 'attached ' + variation_active );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Attach all apart from placeholder.
|
||||
new_attr_select.find( 'option:gt(0)' ).addClass( 'attached ' + variation_active );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Count available options.
|
||||
attached_options_count = new_attr_select.find( 'option.attached' ).length;
|
||||
|
||||
// Check if current selection is in attached options.
|
||||
if ( selected_attr_val ) {
|
||||
selected_attr_val_valid = false;
|
||||
|
||||
if ( 0 !== attached_options_count ) {
|
||||
new_attr_select.find( 'option.attached.enabled' ).each( function() {
|
||||
var option_value = $( this ).val();
|
||||
|
||||
if ( selected_attr_val === option_value ) {
|
||||
selected_attr_val_valid = true;
|
||||
return false; // break.
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Detach the placeholder if:
|
||||
// - Valid options exist.
|
||||
// - The current selection is non-empty.
|
||||
// - The current selection is valid.
|
||||
// - Placeholders are not set to be permanently visible.
|
||||
if ( attached_options_count > 0 && selected_attr_val && selected_attr_val_valid && ( 'no' === show_option_none ) ) {
|
||||
new_attr_select.find( 'option:first' ).remove();
|
||||
option_gt_filter = '';
|
||||
}
|
||||
|
||||
// Detach unattached.
|
||||
new_attr_select.find( 'option' + option_gt_filter + ':not(.attached)' ).remove();
|
||||
|
||||
// Finally, copy to DOM and set value.
|
||||
current_attr_select.html( new_attr_select.html() );
|
||||
current_attr_select.find( 'option' + option_gt_filter + ':not(.enabled)' ).prop( 'disabled', true );
|
||||
|
||||
// Choose selected value.
|
||||
if ( selected_attr_val ) {
|
||||
// If the previously selected value is no longer available, fall back to the placeholder (it's going to be there).
|
||||
if ( selected_attr_val_valid ) {
|
||||
current_attr_select.val( selected_attr_val );
|
||||
} else {
|
||||
current_attr_select.val( '' ).trigger( 'change' );
|
||||
}
|
||||
} else {
|
||||
current_attr_select.val( '' ); // No change event to prevent infinite loop.
|
||||
}
|
||||
});
|
||||
|
||||
// Custom event for when variations have been updated.
|
||||
form.$form.trigger( 'woocommerce_update_variation_values' );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get chosen attributes from form.
|
||||
* @return array
|
||||
*/
|
||||
VariationForm.prototype.getChosenAttributes = function() {
|
||||
var data = {};
|
||||
var count = 0;
|
||||
var chosen = 0;
|
||||
|
||||
this.$attributeFields.each( function() {
|
||||
var attribute_name = $( this ).data( 'attribute_name' ) || $( this ).attr( 'name' );
|
||||
var value = $( this ).val() || '';
|
||||
|
||||
if ( value.length > 0 ) {
|
||||
chosen ++;
|
||||
}
|
||||
|
||||
count ++;
|
||||
data[ attribute_name ] = value;
|
||||
});
|
||||
|
||||
return {
|
||||
'count' : count,
|
||||
'chosenCount': chosen,
|
||||
'data' : data
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Find matching variations for attributes.
|
||||
*/
|
||||
VariationForm.prototype.findMatchingVariations = function( variations, attributes ) {
|
||||
var matching = [];
|
||||
for ( var i = 0; i < variations.length; i++ ) {
|
||||
var variation = variations[i];
|
||||
|
||||
if ( this.isMatch( variation.attributes, attributes ) ) {
|
||||
matching.push( variation );
|
||||
}
|
||||
}
|
||||
return matching;
|
||||
};
|
||||
|
||||
/**
|
||||
* See if attributes match.
|
||||
* @return {Boolean}
|
||||
*/
|
||||
VariationForm.prototype.isMatch = function( variation_attributes, attributes ) {
|
||||
var match = true;
|
||||
for ( var attr_name in variation_attributes ) {
|
||||
if ( variation_attributes.hasOwnProperty( attr_name ) ) {
|
||||
var val1 = variation_attributes[ attr_name ];
|
||||
var val2 = attributes[ attr_name ];
|
||||
if ( val1 !== undefined && val2 !== undefined && val1.length !== 0 && val2.length !== 0 && val1 !== val2 ) {
|
||||
match = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return match;
|
||||
};
|
||||
|
||||
/**
|
||||
* Show or hide the reset link.
|
||||
*/
|
||||
VariationForm.prototype.toggleResetLink = function( on ) {
|
||||
if ( on ) {
|
||||
if ( this.$resetVariations.css( 'visibility' ) === 'hidden' ) {
|
||||
this.$resetVariations.css( 'visibility', 'visible' ).hide().fadeIn();
|
||||
}
|
||||
} else {
|
||||
this.$resetVariations.css( 'visibility', 'hidden' );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to call wc_variation_form on jquery selector.
|
||||
*/
|
||||
$.fn.wc_variation_form = function() {
|
||||
new VariationForm( this );
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Stores the default text for an element so it can be reset later
|
||||
*/
|
||||
$.fn.wc_set_content = function( content ) {
|
||||
if ( undefined === this.attr( 'data-o_content' ) ) {
|
||||
this.attr( 'data-o_content', this.text() );
|
||||
}
|
||||
this.text( content );
|
||||
};
|
||||
|
||||
/**
|
||||
* Stores the default text for an element so it can be reset later
|
||||
*/
|
||||
$.fn.wc_reset_content = function() {
|
||||
if ( undefined !== this.attr( 'data-o_content' ) ) {
|
||||
this.text( this.attr( 'data-o_content' ) );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stores a default attribute for an element so it can be reset later
|
||||
*/
|
||||
$.fn.wc_set_variation_attr = function( attr, value ) {
|
||||
if ( undefined === this.attr( 'data-o_' + attr ) ) {
|
||||
this.attr( 'data-o_' + attr, ( ! this.attr( attr ) ) ? '' : this.attr( attr ) );
|
||||
}
|
||||
if ( false === value ) {
|
||||
this.removeAttr( attr );
|
||||
} else {
|
||||
this.attr( attr, value );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset a default attribute for an element so it can be reset later
|
||||
*/
|
||||
$.fn.wc_reset_variation_attr = function( attr ) {
|
||||
if ( undefined !== this.attr( 'data-o_' + attr ) ) {
|
||||
this.attr( attr, this.attr( 'data-o_' + attr ) );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the slide position if the variation has a different image than the current one
|
||||
*/
|
||||
$.fn.wc_maybe_trigger_slide_position_reset = function( variation ) {
|
||||
var $form = $( this ),
|
||||
$product = $form.closest( '.product' ),
|
||||
$product_gallery = $product.find( '.images' ),
|
||||
reset_slide_position = false,
|
||||
new_image_id = ( variation && variation.image_id ) ? variation.image_id : '';
|
||||
|
||||
if ( $form.attr( 'current-image' ) !== new_image_id ) {
|
||||
reset_slide_position = true;
|
||||
}
|
||||
|
||||
$form.attr( 'current-image', new_image_id );
|
||||
|
||||
if ( reset_slide_position ) {
|
||||
$product_gallery.trigger( 'woocommerce_gallery_reset_slide_position' );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets product images for the chosen variation
|
||||
*/
|
||||
$.fn.wc_variations_image_update = function( variation ) {
|
||||
var $form = this,
|
||||
$product = $form.closest( '.product' ),
|
||||
$product_gallery = $product.find( '.images' ),
|
||||
$gallery_nav = $product.find( '.flex-control-nav' ),
|
||||
$gallery_img = $gallery_nav.find( 'li:eq(0) img' ),
|
||||
$product_img_wrap = $product_gallery
|
||||
.find( '.woocommerce-product-gallery__image, .woocommerce-product-gallery__image--placeholder' )
|
||||
.eq( 0 ),
|
||||
$product_img = $product_img_wrap.find( '.wp-post-image' ),
|
||||
$product_link = $product_img_wrap.find( 'a' ).eq( 0 );
|
||||
|
||||
if ( variation && variation.image && variation.image.src && variation.image.src.length > 1 ) {
|
||||
// See if the gallery has an image with the same original src as the image we want to switch to.
|
||||
var galleryHasImage = $gallery_nav.find( 'li img[data-o_src="' + variation.image.gallery_thumbnail_src + '"]' ).length > 0;
|
||||
|
||||
// If the gallery has the image, reset the images. We'll scroll to the correct one.
|
||||
if ( galleryHasImage ) {
|
||||
$form.wc_variations_image_reset();
|
||||
}
|
||||
|
||||
// See if gallery has a matching image we can slide to.
|
||||
var slideToImage = $gallery_nav.find( 'li img[src="' + variation.image.gallery_thumbnail_src + '"]' );
|
||||
|
||||
if ( slideToImage.length > 0 ) {
|
||||
slideToImage.trigger( 'click' );
|
||||
$form.attr( 'current-image', variation.image_id );
|
||||
window.setTimeout( function() {
|
||||
$( window ).trigger( 'resize' );
|
||||
$product_gallery.trigger( 'woocommerce_gallery_init_zoom' );
|
||||
}, 20 );
|
||||
return;
|
||||
}
|
||||
|
||||
$product_img.wc_set_variation_attr( 'src', variation.image.src );
|
||||
$product_img.wc_set_variation_attr( 'height', variation.image.src_h );
|
||||
$product_img.wc_set_variation_attr( 'width', variation.image.src_w );
|
||||
$product_img.wc_set_variation_attr( 'srcset', variation.image.srcset );
|
||||
$product_img.wc_set_variation_attr( 'sizes', variation.image.sizes );
|
||||
$product_img.wc_set_variation_attr( 'title', variation.image.title );
|
||||
$product_img.wc_set_variation_attr( 'data-caption', variation.image.caption );
|
||||
$product_img.wc_set_variation_attr( 'alt', variation.image.alt );
|
||||
$product_img.wc_set_variation_attr( 'data-src', variation.image.full_src );
|
||||
$product_img.wc_set_variation_attr( 'data-large_image', variation.image.full_src );
|
||||
$product_img.wc_set_variation_attr( 'data-large_image_width', variation.image.full_src_w );
|
||||
$product_img.wc_set_variation_attr( 'data-large_image_height', variation.image.full_src_h );
|
||||
$product_img_wrap.wc_set_variation_attr( 'data-thumb', variation.image.src );
|
||||
$gallery_img.wc_set_variation_attr( 'src', variation.image.gallery_thumbnail_src );
|
||||
$product_link.wc_set_variation_attr( 'href', variation.image.full_src );
|
||||
} else {
|
||||
$form.wc_variations_image_reset();
|
||||
}
|
||||
|
||||
window.setTimeout( function() {
|
||||
$( window ).trigger( 'resize' );
|
||||
$form.wc_maybe_trigger_slide_position_reset( variation );
|
||||
$product_gallery.trigger( 'woocommerce_gallery_init_zoom' );
|
||||
}, 20 );
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset main image to defaults.
|
||||
*/
|
||||
$.fn.wc_variations_image_reset = function() {
|
||||
var $form = this,
|
||||
$product = $form.closest( '.product' ),
|
||||
$product_gallery = $product.find( '.images' ),
|
||||
$gallery_nav = $product.find( '.flex-control-nav' ),
|
||||
$gallery_img = $gallery_nav.find( 'li:eq(0) img' ),
|
||||
$product_img_wrap = $product_gallery
|
||||
.find( '.woocommerce-product-gallery__image, .woocommerce-product-gallery__image--placeholder' )
|
||||
.eq( 0 ),
|
||||
$product_img = $product_img_wrap.find( '.wp-post-image' ),
|
||||
$product_link = $product_img_wrap.find( 'a' ).eq( 0 );
|
||||
|
||||
$product_img.wc_reset_variation_attr( 'src' );
|
||||
$product_img.wc_reset_variation_attr( 'width' );
|
||||
$product_img.wc_reset_variation_attr( 'height' );
|
||||
$product_img.wc_reset_variation_attr( 'srcset' );
|
||||
$product_img.wc_reset_variation_attr( 'sizes' );
|
||||
$product_img.wc_reset_variation_attr( 'title' );
|
||||
$product_img.wc_reset_variation_attr( 'data-caption' );
|
||||
$product_img.wc_reset_variation_attr( 'alt' );
|
||||
$product_img.wc_reset_variation_attr( 'data-src' );
|
||||
$product_img.wc_reset_variation_attr( 'data-large_image' );
|
||||
$product_img.wc_reset_variation_attr( 'data-large_image_width' );
|
||||
$product_img.wc_reset_variation_attr( 'data-large_image_height' );
|
||||
$product_img_wrap.wc_reset_variation_attr( 'data-thumb' );
|
||||
$gallery_img.wc_reset_variation_attr( 'src' );
|
||||
$product_link.wc_reset_variation_attr( 'href' );
|
||||
};
|
||||
|
||||
$(function() {
|
||||
if ( typeof wc_add_to_cart_variation_params !== 'undefined' ) {
|
||||
$( '.variations_form' ).each( function() {
|
||||
$( this ).wc_variation_form();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Matches inline variation objects to chosen attributes
|
||||
* @deprecated 2.6.9
|
||||
* @type {Object}
|
||||
*/
|
||||
var wc_variation_form_matcher = {
|
||||
find_matching_variations: function( product_variations, settings ) {
|
||||
var matching = [];
|
||||
for ( var i = 0; i < product_variations.length; i++ ) {
|
||||
var variation = product_variations[i];
|
||||
|
||||
if ( wc_variation_form_matcher.variations_match( variation.attributes, settings ) ) {
|
||||
matching.push( variation );
|
||||
}
|
||||
}
|
||||
return matching;
|
||||
},
|
||||
variations_match: function( attrs1, attrs2 ) {
|
||||
var match = true;
|
||||
for ( var attr_name in attrs1 ) {
|
||||
if ( attrs1.hasOwnProperty( attr_name ) ) {
|
||||
var val1 = attrs1[ attr_name ];
|
||||
var val2 = attrs2[ attr_name ];
|
||||
if ( val1 !== undefined && val2 !== undefined && val1.length !== 0 && val2.length !== 0 && val1 !== val2 ) {
|
||||
match = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return match;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Avoids using wp.template where possible in order to be CSP compliant.
|
||||
* wp.template uses internally eval().
|
||||
* @param {string} templateId
|
||||
* @return {Function}
|
||||
*/
|
||||
var wp_template = function( templateId ) {
|
||||
var html = document.getElementById( 'tmpl-' + templateId ).textContent;
|
||||
var hard = false;
|
||||
// any <# #> interpolate (evaluate).
|
||||
hard = hard || /<#\s?data\./.test( html );
|
||||
// any data that is NOT data.variation.
|
||||
hard = hard || /{{{?\s?data\.(?!variation\.).+}}}?/.test( html );
|
||||
// any data access deeper than 1 level e.g.
|
||||
// data.variation.object.item
|
||||
// data.variation.object['item']
|
||||
// data.variation.array[0]
|
||||
hard = hard || /{{{?\s?data\.variation\.[\w-]*[^\s}]/.test ( html );
|
||||
if ( hard ) {
|
||||
return wp.template( templateId );
|
||||
}
|
||||
return function template ( data ) {
|
||||
var variation = data.variation || {};
|
||||
return html.replace( /({{{?)\s?data\.variation\.([\w-]*)\s?(}}}?)/g, function( _, open, key, close ) {
|
||||
// Error in the format, ignore.
|
||||
if ( open.length !== close.length ) {
|
||||
return '';
|
||||
}
|
||||
var replacement = variation[ key ] || '';
|
||||
// {{{ }}} => interpolate (unescaped).
|
||||
// {{ }} => interpolate (escaped).
|
||||
// https://codex.wordpress.org/Javascript_Reference/wp.template
|
||||
if ( open.length === 2 ) {
|
||||
return window.escape( replacement );
|
||||
}
|
||||
return replacement;
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
})( jQuery, window, document );
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart-variation.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart-variation.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,214 @@
|
||||
/* global wc_add_to_cart_params */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
if ( typeof wc_add_to_cart_params === 'undefined' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* AddToCartHandler class.
|
||||
*/
|
||||
var AddToCartHandler = function() {
|
||||
this.requests = [];
|
||||
this.addRequest = this.addRequest.bind( this );
|
||||
this.run = this.run.bind( this );
|
||||
|
||||
$( document.body )
|
||||
.on( 'click', '.add_to_cart_button', { addToCartHandler: this }, this.onAddToCart )
|
||||
.on( 'click', '.remove_from_cart_button', { addToCartHandler: this }, this.onRemoveFromCart )
|
||||
.on( 'added_to_cart', this.updateButton )
|
||||
.on( 'ajax_request_not_sent.adding_to_cart', this.updateButton )
|
||||
.on( 'added_to_cart removed_from_cart', { addToCartHandler: this }, this.updateFragments );
|
||||
};
|
||||
|
||||
/**
|
||||
* Add add to cart event.
|
||||
*/
|
||||
AddToCartHandler.prototype.addRequest = function( request ) {
|
||||
this.requests.push( request );
|
||||
|
||||
if ( 1 === this.requests.length ) {
|
||||
this.run();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Run add to cart events.
|
||||
*/
|
||||
AddToCartHandler.prototype.run = function() {
|
||||
var requestManager = this,
|
||||
originalCallback = requestManager.requests[0].complete;
|
||||
|
||||
requestManager.requests[0].complete = function() {
|
||||
if ( typeof originalCallback === 'function' ) {
|
||||
originalCallback();
|
||||
}
|
||||
|
||||
requestManager.requests.shift();
|
||||
|
||||
if ( requestManager.requests.length > 0 ) {
|
||||
requestManager.run();
|
||||
}
|
||||
};
|
||||
|
||||
$.ajax( this.requests[0] );
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle the add to cart event.
|
||||
*/
|
||||
AddToCartHandler.prototype.onAddToCart = function( e ) {
|
||||
var $thisbutton = $( this );
|
||||
|
||||
if ( $thisbutton.is( '.ajax_add_to_cart' ) ) {
|
||||
if ( ! $thisbutton.attr( 'data-product_id' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
$thisbutton.removeClass( 'added' );
|
||||
$thisbutton.addClass( 'loading' );
|
||||
|
||||
// Allow 3rd parties to validate and quit early.
|
||||
if ( false === $( document.body ).triggerHandler( 'should_send_ajax_request.adding_to_cart', [ $thisbutton ] ) ) {
|
||||
$( document.body ).trigger( 'ajax_request_not_sent.adding_to_cart', [ false, false, $thisbutton ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
var data = {};
|
||||
|
||||
// Fetch changes that are directly added by calling $thisbutton.data( key, value )
|
||||
$.each( $thisbutton.data(), function( key, value ) {
|
||||
data[ key ] = value;
|
||||
});
|
||||
|
||||
// Fetch data attributes in $thisbutton. Give preference to data-attributes because they can be directly modified by javascript
|
||||
// while `.data` are jquery specific memory stores.
|
||||
$.each( $thisbutton[0].dataset, function( key, value ) {
|
||||
data[ key ] = value;
|
||||
});
|
||||
|
||||
// Trigger event.
|
||||
$( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] );
|
||||
|
||||
e.data.addToCartHandler.addRequest({
|
||||
type: 'POST',
|
||||
url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'add_to_cart' ),
|
||||
data: data,
|
||||
success: function( response ) {
|
||||
if ( ! response ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( response.error && response.product_url ) {
|
||||
window.location = response.product_url;
|
||||
return;
|
||||
}
|
||||
|
||||
// Redirect to cart option
|
||||
if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) {
|
||||
window.location = wc_add_to_cart_params.cart_url;
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger event so themes can refresh other areas.
|
||||
$( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] );
|
||||
},
|
||||
dataType: 'json'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update fragments after remove from cart event in mini-cart.
|
||||
*/
|
||||
AddToCartHandler.prototype.onRemoveFromCart = function( e ) {
|
||||
var $thisbutton = $( this ),
|
||||
$row = $thisbutton.closest( '.woocommerce-mini-cart-item' );
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
$row.block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
|
||||
e.data.addToCartHandler.addRequest({
|
||||
type: 'POST',
|
||||
url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'remove_from_cart' ),
|
||||
data: {
|
||||
cart_item_key : $thisbutton.data( 'cart_item_key' )
|
||||
},
|
||||
success: function( response ) {
|
||||
if ( ! response || ! response.fragments ) {
|
||||
window.location = $thisbutton.attr( 'href' );
|
||||
return;
|
||||
}
|
||||
|
||||
$( document.body ).trigger( 'removed_from_cart', [ response.fragments, response.cart_hash, $thisbutton ] );
|
||||
},
|
||||
error: function() {
|
||||
window.location = $thisbutton.attr( 'href' );
|
||||
return;
|
||||
},
|
||||
dataType: 'json'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Update cart page elements after add to cart events.
|
||||
*/
|
||||
AddToCartHandler.prototype.updateButton = function( e, fragments, cart_hash, $button ) {
|
||||
$button = typeof $button === 'undefined' ? false : $button;
|
||||
|
||||
if ( $button ) {
|
||||
$button.removeClass( 'loading' );
|
||||
|
||||
if ( fragments ) {
|
||||
$button.addClass( 'added' );
|
||||
}
|
||||
|
||||
// View cart text.
|
||||
if ( fragments && ! wc_add_to_cart_params.is_cart && $button.parent().find( '.added_to_cart' ).length === 0 ) {
|
||||
$button.after( '<a href="' + wc_add_to_cart_params.cart_url + '" class="added_to_cart wc-forward" title="' +
|
||||
wc_add_to_cart_params.i18n_view_cart + '">' + wc_add_to_cart_params.i18n_view_cart + '</a>' );
|
||||
}
|
||||
|
||||
$( document.body ).trigger( 'wc_cart_button_updated', [ $button ] );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update fragments after add to cart events.
|
||||
*/
|
||||
AddToCartHandler.prototype.updateFragments = function( e, fragments ) {
|
||||
if ( fragments ) {
|
||||
$.each( fragments, function( key ) {
|
||||
$( key )
|
||||
.addClass( 'updating' )
|
||||
.fadeTo( '400', '0.6' )
|
||||
.block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$.each( fragments, function( key, value ) {
|
||||
$( key ).replaceWith( value );
|
||||
$( key ).stop( true ).css( 'opacity', '1' ).unblock();
|
||||
});
|
||||
|
||||
$( document.body ).trigger( 'wc_fragments_loaded' );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Init AddToCartHandler.
|
||||
*/
|
||||
new AddToCartHandler();
|
||||
});
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(function(t){if("undefined"==typeof wc_add_to_cart_params)return!1;var a=function(){this.requests=[],this.addRequest=this.addRequest.bind(this),this.run=this.run.bind(this),t(document.body).on("click",".add_to_cart_button",{addToCartHandler:this},this.onAddToCart).on("click",".remove_from_cart_button",{addToCartHandler:this},this.onRemoveFromCart).on("added_to_cart",this.updateButton).on("ajax_request_not_sent.adding_to_cart",this.updateButton).on("added_to_cart removed_from_cart",{addToCartHandler:this},this.updateFragments)};a.prototype.addRequest=function(t){this.requests.push(t),1===this.requests.length&&this.run()},a.prototype.run=function(){var a=this,e=a.requests[0].complete;a.requests[0].complete=function(){"function"==typeof e&&e(),a.requests.shift(),a.requests.length>0&&a.run()},t.ajax(this.requests[0])},a.prototype.onAddToCart=function(a){var e=t(this);if(e.is(".ajax_add_to_cart")){if(!e.attr("data-product_id"))return!0;if(a.preventDefault(),e.removeClass("added"),e.addClass("loading"),!1===t(document.body).triggerHandler("should_send_ajax_request.adding_to_cart",[e]))return t(document.body).trigger("ajax_request_not_sent.adding_to_cart",[!1,!1,e]),!0;var r={};t.each(e.data(),function(t,a){r[t]=a}),t.each(e[0].dataset,function(t,a){r[t]=a}),t(document.body).trigger("adding_to_cart",[e,r]),a.data.addToCartHandler.addRequest({type:"POST",url:wc_add_to_cart_params.wc_ajax_url.toString().replace("%%endpoint%%","add_to_cart"),data:r,success:function(a){a&&(a.error&&a.product_url?window.location=a.product_url:"yes"!==wc_add_to_cart_params.cart_redirect_after_add?t(document.body).trigger("added_to_cart",[a.fragments,a.cart_hash,e]):window.location=wc_add_to_cart_params.cart_url)},dataType:"json"})}},a.prototype.onRemoveFromCart=function(a){var e=t(this),r=e.closest(".woocommerce-mini-cart-item");a.preventDefault(),r.block({message:null,overlayCSS:{opacity:.6}}),a.data.addToCartHandler.addRequest({type:"POST",url:wc_add_to_cart_params.wc_ajax_url.toString().replace("%%endpoint%%","remove_from_cart"),data:{cart_item_key:e.data("cart_item_key")},success:function(a){a&&a.fragments?t(document.body).trigger("removed_from_cart",[a.fragments,a.cart_hash,e]):window.location=e.attr("href")},error:function(){window.location=e.attr("href")},dataType:"json"})},a.prototype.updateButton=function(a,e,r,d){(d=void 0!==d&&d)&&(d.removeClass("loading"),e&&d.addClass("added"),e&&!wc_add_to_cart_params.is_cart&&0===d.parent().find(".added_to_cart").length&&d.after('<a href="'+wc_add_to_cart_params.cart_url+'" class="added_to_cart wc-forward" title="'+wc_add_to_cart_params.i18n_view_cart+'">'+wc_add_to_cart_params.i18n_view_cart+"</a>"),t(document.body).trigger("wc_cart_button_updated",[d]))},a.prototype.updateFragments=function(a,e){e&&(t.each(e,function(a){t(a).addClass("updating").fadeTo("400","0.6").block({message:null,overlayCSS:{opacity:.6}})}),t.each(e,function(a,e){t(a).replaceWith(e),t(a).stop(!0).css("opacity","1").unblock()}),t(document.body).trigger("wc_fragments_loaded"))},new a});
|
||||
@@ -0,0 +1,151 @@
|
||||
/*global wc_address_i18n_params */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
// wc_address_i18n_params is required to continue, ensure the object exists
|
||||
if ( typeof wc_address_i18n_params === 'undefined' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var locale_json = wc_address_i18n_params.locale.replace( /"/g, '"' ), locale = JSON.parse( locale_json );
|
||||
|
||||
function field_is_required( field, is_required ) {
|
||||
if ( is_required ) {
|
||||
field.find( 'label .optional' ).remove();
|
||||
field.addClass( 'validate-required' );
|
||||
|
||||
if ( field.find( 'label .required' ).length === 0 ) {
|
||||
field.find( 'label' ).append(
|
||||
' <abbr class="required" title="' +
|
||||
wc_address_i18n_params.i18n_required_text +
|
||||
'">*</abbr>'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
field.find( 'label .required' ).remove();
|
||||
field.removeClass( 'validate-required woocommerce-invalid woocommerce-invalid-required-field' );
|
||||
|
||||
if ( field.find( 'label .optional' ).length === 0 ) {
|
||||
field.find( 'label' ).append( ' <span class="optional">(' + wc_address_i18n_params.i18n_optional_text + ')</span>' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle locale
|
||||
$( document.body )
|
||||
.on( 'country_to_state_changing', function( event, country, wrapper ) {
|
||||
var thisform = wrapper, thislocale;
|
||||
|
||||
if ( typeof locale[ country ] !== 'undefined' ) {
|
||||
thislocale = locale[ country ];
|
||||
} else {
|
||||
thislocale = locale['default'];
|
||||
}
|
||||
|
||||
var $postcodefield = thisform.find( '#billing_postcode_field, #shipping_postcode_field' ),
|
||||
$cityfield = thisform.find( '#billing_city_field, #shipping_city_field' ),
|
||||
$statefield = thisform.find( '#billing_state_field, #shipping_state_field' );
|
||||
|
||||
if ( ! $postcodefield.attr( 'data-o_class' ) ) {
|
||||
$postcodefield.attr( 'data-o_class', $postcodefield.attr( 'class' ) );
|
||||
$cityfield.attr( 'data-o_class', $cityfield.attr( 'class' ) );
|
||||
$statefield.attr( 'data-o_class', $statefield.attr( 'class' ) );
|
||||
}
|
||||
|
||||
var locale_fields = JSON.parse( wc_address_i18n_params.locale_fields );
|
||||
|
||||
$.each( locale_fields, function( key, value ) {
|
||||
|
||||
var field = thisform.find( value ),
|
||||
fieldLocale = $.extend( true, {}, locale['default'][ key ], thislocale[ key ] );
|
||||
|
||||
// Labels.
|
||||
if ( typeof fieldLocale.label !== 'undefined' ) {
|
||||
field.find( 'label' ).html( fieldLocale.label );
|
||||
}
|
||||
|
||||
// Placeholders.
|
||||
if ( typeof fieldLocale.placeholder !== 'undefined' ) {
|
||||
field.find( ':input' ).attr( 'placeholder', fieldLocale.placeholder );
|
||||
field.find( ':input' ).attr( 'data-placeholder', fieldLocale.placeholder );
|
||||
field.find( '.select2-selection__placeholder' ).text( fieldLocale.placeholder );
|
||||
}
|
||||
|
||||
// Use the i18n label as a placeholder if there is no label element and no i18n placeholder.
|
||||
if (
|
||||
typeof fieldLocale.placeholder === 'undefined' &&
|
||||
typeof fieldLocale.label !== 'undefined' &&
|
||||
! field.find( 'label' ).length
|
||||
) {
|
||||
field.find( ':input' ).attr( 'placeholder', fieldLocale.label );
|
||||
field.find( ':input' ).attr( 'data-placeholder', fieldLocale.label );
|
||||
field.find( '.select2-selection__placeholder' ).text( fieldLocale.label );
|
||||
}
|
||||
|
||||
// Required.
|
||||
if ( typeof fieldLocale.required !== 'undefined' ) {
|
||||
field_is_required( field, fieldLocale.required );
|
||||
} else {
|
||||
field_is_required( field, false );
|
||||
}
|
||||
|
||||
// Priority.
|
||||
if ( typeof fieldLocale.priority !== 'undefined' ) {
|
||||
field.data( 'priority', fieldLocale.priority );
|
||||
}
|
||||
|
||||
// Hidden fields.
|
||||
if ( 'state' !== key ) {
|
||||
if ( typeof fieldLocale.hidden !== 'undefined' && true === fieldLocale.hidden ) {
|
||||
field.hide().find( ':input' ).val( '' );
|
||||
} else {
|
||||
field.show();
|
||||
}
|
||||
}
|
||||
|
||||
// Class changes.
|
||||
if ( Array.isArray( fieldLocale.class ) ) {
|
||||
field.removeClass( 'form-row-first form-row-last form-row-wide' );
|
||||
field.addClass( fieldLocale.class.join( ' ' ) );
|
||||
}
|
||||
});
|
||||
|
||||
var fieldsets = $(
|
||||
'.woocommerce-billing-fields__field-wrapper,' +
|
||||
'.woocommerce-shipping-fields__field-wrapper,' +
|
||||
'.woocommerce-address-fields__field-wrapper,' +
|
||||
'.woocommerce-additional-fields__field-wrapper .woocommerce-account-fields'
|
||||
);
|
||||
|
||||
fieldsets.each( function( index, fieldset ) {
|
||||
var rows = $( fieldset ).find( '.form-row' );
|
||||
var wrapper = rows.first().parent();
|
||||
|
||||
// Before sorting, ensure all fields have a priority for bW compatibility.
|
||||
var last_priority = 0;
|
||||
|
||||
rows.each( function() {
|
||||
if ( ! $( this ).data( 'priority' ) ) {
|
||||
$( this ).data( 'priority', last_priority + 1 );
|
||||
}
|
||||
last_priority = $( this ).data( 'priority' );
|
||||
} );
|
||||
|
||||
// Sort the fields.
|
||||
rows.sort( function( a, b ) {
|
||||
var asort = parseInt( $( a ).data( 'priority' ), 10 ),
|
||||
bsort = parseInt( $( b ).data( 'priority' ), 10 );
|
||||
|
||||
if ( asort > bsort ) {
|
||||
return 1;
|
||||
}
|
||||
if ( asort < bsort ) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
rows.detach().appendTo( wrapper );
|
||||
});
|
||||
})
|
||||
.trigger( 'wc_address_i18n_ready' );
|
||||
});
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/address-i18n.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/address-i18n.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(function(e){if("undefined"==typeof wc_address_i18n_params)return!1;var a=wc_address_i18n_params.locale.replace(/"/g,'"'),i=JSON.parse(a);function d(e,a){a?(e.find("label .optional").remove(),e.addClass("validate-required"),0===e.find("label .required").length&&e.find("label").append(' <abbr class="required" title="'+wc_address_i18n_params.i18n_required_text+'">*</abbr>')):(e.find("label .required").remove(),e.removeClass("validate-required woocommerce-invalid woocommerce-invalid-required-field"),0===e.find("label .optional").length&&e.find("label").append(' <span class="optional">('+wc_address_i18n_params.i18n_optional_text+")</span>"))}e(document.body).on("country_to_state_changing",function(a,r,t){var l,n=t;l="undefined"!=typeof i[r]?i[r]:i["default"];var o=n.find("#billing_postcode_field, #shipping_postcode_field"),s=n.find("#billing_city_field, #shipping_city_field"),p=n.find("#billing_state_field, #shipping_state_field");o.attr("data-o_class")||(o.attr("data-o_class",o.attr("class")),s.attr("data-o_class",s.attr("class")),p.attr("data-o_class",p.attr("class")));var f=JSON.parse(wc_address_i18n_params.locale_fields);e.each(f,function(a,r){var t=n.find(r),o=e.extend(!0,{},i["default"][a],l[a]);"undefined"!=typeof o.label&&t.find("label").html(o.label),"undefined"!=typeof o.placeholder&&(t.find(":input").attr("placeholder",o.placeholder),t.find(":input").attr("data-placeholder",o.placeholder),t.find(".select2-selection__placeholder").text(o.placeholder)),"undefined"!=typeof o.placeholder||"undefined"==typeof o.label||t.find("label").length||(t.find(":input").attr("placeholder",o.label),t.find(":input").attr("data-placeholder",o.label),t.find(".select2-selection__placeholder").text(o.label)),"undefined"!=typeof o.required?d(t,o.required):d(t,!1),"undefined"!=typeof o.priority&&t.data("priority",o.priority),"state"!==a&&("undefined"!=typeof o.hidden&&!0===o.hidden?t.hide().find(":input").val(""):t.show()),Array.isArray(o["class"])&&(t.removeClass("form-row-first form-row-last form-row-wide"),t.addClass(o["class"].join(" ")))}),e(".woocommerce-billing-fields__field-wrapper,.woocommerce-shipping-fields__field-wrapper,.woocommerce-address-fields__field-wrapper,.woocommerce-additional-fields__field-wrapper .woocommerce-account-fields").each(function(a,i){var d=e(i).find(".form-row"),r=d.first().parent(),t=0;d.each(function(){e(this).data("priority")||e(this).data("priority",t+1),t=e(this).data("priority")}),d.sort(function(a,i){var d=parseInt(e(a).data("priority"),10),r=parseInt(e(i).data("priority"),10);return d>r?1:d<r?-1:0}),d.detach().appendTo(r)})}).trigger("wc_address_i18n_ready")});
|
||||
@@ -0,0 +1,187 @@
|
||||
/* global wc_cart_fragments_params, Cookies */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
// wc_cart_fragments_params is required to continue, ensure the object exists
|
||||
if ( typeof wc_cart_fragments_params === 'undefined' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Storage Handling */
|
||||
var $supports_html5_storage = true,
|
||||
cart_hash_key = wc_cart_fragments_params.cart_hash_key;
|
||||
|
||||
try {
|
||||
$supports_html5_storage = ( 'sessionStorage' in window && window.sessionStorage !== null );
|
||||
window.sessionStorage.setItem( 'wc', 'test' );
|
||||
window.sessionStorage.removeItem( 'wc' );
|
||||
window.localStorage.setItem( 'wc', 'test' );
|
||||
window.localStorage.removeItem( 'wc' );
|
||||
} catch( err ) {
|
||||
$supports_html5_storage = false;
|
||||
}
|
||||
|
||||
/* Cart session creation time to base expiration on */
|
||||
function set_cart_creation_timestamp() {
|
||||
if ( $supports_html5_storage ) {
|
||||
sessionStorage.setItem( 'wc_cart_created', ( new Date() ).getTime() );
|
||||
}
|
||||
}
|
||||
|
||||
/** Set the cart hash in both session and local storage */
|
||||
function set_cart_hash( cart_hash ) {
|
||||
if ( $supports_html5_storage ) {
|
||||
localStorage.setItem( cart_hash_key, cart_hash );
|
||||
sessionStorage.setItem( cart_hash_key, cart_hash );
|
||||
}
|
||||
}
|
||||
|
||||
var $fragment_refresh = {
|
||||
url: wc_cart_fragments_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_refreshed_fragments' ),
|
||||
type: 'POST',
|
||||
data: {
|
||||
time: new Date().getTime()
|
||||
},
|
||||
timeout: wc_cart_fragments_params.request_timeout,
|
||||
success: function( data ) {
|
||||
if ( data && data.fragments ) {
|
||||
|
||||
$.each( data.fragments, function( key, value ) {
|
||||
$( key ).replaceWith( value );
|
||||
});
|
||||
|
||||
if ( $supports_html5_storage ) {
|
||||
sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( data.fragments ) );
|
||||
set_cart_hash( data.cart_hash );
|
||||
|
||||
if ( data.cart_hash ) {
|
||||
set_cart_creation_timestamp();
|
||||
}
|
||||
}
|
||||
|
||||
$( document.body ).trigger( 'wc_fragments_refreshed' );
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$( document.body ).trigger( 'wc_fragments_ajax_error' );
|
||||
}
|
||||
};
|
||||
|
||||
/* Named callback for refreshing cart fragment */
|
||||
function refresh_cart_fragment() {
|
||||
$.ajax( $fragment_refresh );
|
||||
}
|
||||
|
||||
/* Cart Handling */
|
||||
if ( $supports_html5_storage ) {
|
||||
|
||||
var cart_timeout = null,
|
||||
day_in_ms = ( 24 * 60 * 60 * 1000 );
|
||||
|
||||
$( document.body ).on( 'wc_fragment_refresh updated_wc_div', function() {
|
||||
refresh_cart_fragment();
|
||||
});
|
||||
|
||||
$( document.body ).on( 'added_to_cart removed_from_cart', function( event, fragments, cart_hash ) {
|
||||
var prev_cart_hash = sessionStorage.getItem( cart_hash_key );
|
||||
|
||||
if ( prev_cart_hash === null || prev_cart_hash === undefined || prev_cart_hash === '' ) {
|
||||
set_cart_creation_timestamp();
|
||||
}
|
||||
|
||||
sessionStorage.setItem( wc_cart_fragments_params.fragment_name, JSON.stringify( fragments ) );
|
||||
set_cart_hash( cart_hash );
|
||||
});
|
||||
|
||||
$( document.body ).on( 'wc_fragments_refreshed', function() {
|
||||
clearTimeout( cart_timeout );
|
||||
cart_timeout = setTimeout( refresh_cart_fragment, day_in_ms );
|
||||
} );
|
||||
|
||||
// Refresh when storage changes in another tab
|
||||
$( window ).on( 'storage onstorage', function ( e ) {
|
||||
if (
|
||||
cart_hash_key === e.originalEvent.key && localStorage.getItem( cart_hash_key ) !== sessionStorage.getItem( cart_hash_key )
|
||||
) {
|
||||
refresh_cart_fragment();
|
||||
}
|
||||
});
|
||||
|
||||
// Refresh when page is shown after back button (safari)
|
||||
$( window ).on( 'pageshow' , function( e ) {
|
||||
if ( e.originalEvent.persisted ) {
|
||||
$( '.widget_shopping_cart_content' ).empty();
|
||||
$( document.body ).trigger( 'wc_fragment_refresh' );
|
||||
}
|
||||
} );
|
||||
|
||||
try {
|
||||
var wc_fragments = JSON.parse( sessionStorage.getItem( wc_cart_fragments_params.fragment_name ) ),
|
||||
cart_hash = sessionStorage.getItem( cart_hash_key ),
|
||||
cookie_hash = Cookies.get( 'woocommerce_cart_hash'),
|
||||
cart_created = sessionStorage.getItem( 'wc_cart_created' );
|
||||
|
||||
if ( cart_hash === null || cart_hash === undefined || cart_hash === '' ) {
|
||||
cart_hash = '';
|
||||
}
|
||||
|
||||
if ( cookie_hash === null || cookie_hash === undefined || cookie_hash === '' ) {
|
||||
cookie_hash = '';
|
||||
}
|
||||
|
||||
if ( cart_hash && ( cart_created === null || cart_created === undefined || cart_created === '' ) ) {
|
||||
throw 'No cart_created';
|
||||
}
|
||||
|
||||
if ( cart_created ) {
|
||||
var cart_expiration = ( ( 1 * cart_created ) + day_in_ms ),
|
||||
timestamp_now = ( new Date() ).getTime();
|
||||
if ( cart_expiration < timestamp_now ) {
|
||||
throw 'Fragment expired';
|
||||
}
|
||||
cart_timeout = setTimeout( refresh_cart_fragment, ( cart_expiration - timestamp_now ) );
|
||||
}
|
||||
|
||||
if ( wc_fragments && wc_fragments['div.widget_shopping_cart_content'] && cart_hash === cookie_hash ) {
|
||||
|
||||
$.each( wc_fragments, function( key, value ) {
|
||||
$( key ).replaceWith(value);
|
||||
});
|
||||
|
||||
$( document.body ).trigger( 'wc_fragments_loaded' );
|
||||
} else {
|
||||
throw 'No fragment';
|
||||
}
|
||||
|
||||
} catch( err ) {
|
||||
refresh_cart_fragment();
|
||||
}
|
||||
|
||||
} else {
|
||||
refresh_cart_fragment();
|
||||
}
|
||||
|
||||
/* Cart Hiding */
|
||||
if ( Cookies.get( 'woocommerce_items_in_cart' ) > 0 ) {
|
||||
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show();
|
||||
} else {
|
||||
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).hide();
|
||||
}
|
||||
|
||||
$( document.body ).on( 'adding_to_cart', function() {
|
||||
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show();
|
||||
});
|
||||
|
||||
// Customiser support.
|
||||
var hasSelectiveRefresh = (
|
||||
'undefined' !== typeof wp &&
|
||||
wp.customize &&
|
||||
wp.customize.selectiveRefresh &&
|
||||
wp.customize.widgetsPreview &&
|
||||
wp.customize.widgetsPreview.WidgetPartial
|
||||
);
|
||||
if ( hasSelectiveRefresh ) {
|
||||
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
|
||||
refresh_cart_fragment();
|
||||
} );
|
||||
}
|
||||
});
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/cart-fragments.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/cart-fragments.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(function(e){if("undefined"==typeof wc_cart_fragments_params)return!1;var t=!0,r=wc_cart_fragments_params.cart_hash_key;try{t="sessionStorage"in window&&null!==window.sessionStorage,window.sessionStorage.setItem("wc","test"),window.sessionStorage.removeItem("wc"),window.localStorage.setItem("wc","test"),window.localStorage.removeItem("wc")}catch(f){t=!1}function n(){t&&sessionStorage.setItem("wc_cart_created",(new Date).getTime())}function o(e){t&&(localStorage.setItem(r,e),sessionStorage.setItem(r,e))}var a={url:wc_cart_fragments_params.wc_ajax_url.toString().replace("%%endpoint%%","get_refreshed_fragments"),type:"POST",data:{time:(new Date).getTime()},timeout:wc_cart_fragments_params.request_timeout,success:function(r){r&&r.fragments&&(e.each(r.fragments,function(t,r){e(t).replaceWith(r)}),t&&(sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(r.fragments)),o(r.cart_hash),r.cart_hash&&n()),e(document.body).trigger("wc_fragments_refreshed"))},error:function(){e(document.body).trigger("wc_fragments_ajax_error")}};function s(){e.ajax(a)}if(t){var i=null;e(document.body).on("wc_fragment_refresh updated_wc_div",function(){s()}),e(document.body).on("added_to_cart removed_from_cart",function(e,t,a){var s=sessionStorage.getItem(r);null!==s&&s!==undefined&&""!==s||n(),sessionStorage.setItem(wc_cart_fragments_params.fragment_name,JSON.stringify(t)),o(a)}),e(document.body).on("wc_fragments_refreshed",function(){clearTimeout(i),i=setTimeout(s,864e5)}),e(window).on("storage onstorage",function(e){r===e.originalEvent.key&&localStorage.getItem(r)!==sessionStorage.getItem(r)&&s()}),e(window).on("pageshow",function(t){t.originalEvent.persisted&&(e(".widget_shopping_cart_content").empty(),e(document.body).trigger("wc_fragment_refresh"))});try{var c=JSON.parse(sessionStorage.getItem(wc_cart_fragments_params.fragment_name)),_=sessionStorage.getItem(r),g=Cookies.get("woocommerce_cart_hash"),m=sessionStorage.getItem("wc_cart_created");if(null!==_&&_!==undefined&&""!==_||(_=""),null!==g&&g!==undefined&&""!==g||(g=""),_&&(null===m||m===undefined||""===m))throw"No cart_created";if(m){var d=1*m+864e5,w=(new Date).getTime();if(d<w)throw"Fragment expired";i=setTimeout(s,d-w)}if(!c||!c["div.widget_shopping_cart_content"]||_!==g)throw"No fragment";e.each(c,function(t,r){e(t).replaceWith(r)}),e(document.body).trigger("wc_fragments_loaded")}catch(f){s()}}else s();Cookies.get("woocommerce_items_in_cart")>0?e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show():e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").hide(),e(document.body).on("adding_to_cart",function(){e(".hide_cart_widget_if_empty").closest(".widget_shopping_cart").show()}),"undefined"!=typeof wp&&wp.customize&&wp.customize.selectiveRefresh&&wp.customize.widgetsPreview&&wp.customize.widgetsPreview.WidgetPartial&&wp.customize.selectiveRefresh.bind("partial-content-rendered",function(){s()})});
|
||||
619
wp/wp-content/plugins/woocommerce/assets/js/frontend/cart.js
Normal file
619
wp/wp-content/plugins/woocommerce/assets/js/frontend/cart.js
Normal file
@@ -0,0 +1,619 @@
|
||||
/* global wc_cart_params */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
// wc_cart_params is required to continue, ensure the object exists
|
||||
if ( typeof wc_cart_params === 'undefined' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Utility functions for the file.
|
||||
|
||||
/**
|
||||
* Gets a url for a given AJAX endpoint.
|
||||
*
|
||||
* @param {String} endpoint The AJAX Endpoint
|
||||
* @return {String} The URL to use for the request
|
||||
*/
|
||||
var get_url = function( endpoint ) {
|
||||
return wc_cart_params.wc_ajax_url.toString().replace(
|
||||
'%%endpoint%%',
|
||||
endpoint
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if a node is blocked for processing.
|
||||
*
|
||||
* @param {JQuery Object} $node
|
||||
* @return {bool} True if the DOM Element is UI Blocked, false if not.
|
||||
*/
|
||||
var is_blocked = function( $node ) {
|
||||
return $node.is( '.processing' ) || $node.parents( '.processing' ).length;
|
||||
};
|
||||
|
||||
/**
|
||||
* Block a node visually for processing.
|
||||
*
|
||||
* @param {JQuery Object} $node
|
||||
*/
|
||||
var block = function( $node ) {
|
||||
if ( ! is_blocked( $node ) ) {
|
||||
$node.addClass( 'processing' ).block( {
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Unblock a node after processing is complete.
|
||||
*
|
||||
* @param {JQuery Object} $node
|
||||
*/
|
||||
var unblock = function( $node ) {
|
||||
$node.removeClass( 'processing' ).unblock();
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes duplicate notices.
|
||||
*
|
||||
* @param {JQuery Object} $notices
|
||||
*/
|
||||
var remove_duplicate_notices = function( $notices ) {
|
||||
var seen = new Set();
|
||||
var deduplicated_notices = [];
|
||||
|
||||
$notices.each( function() {
|
||||
const text = $( this ).text();
|
||||
|
||||
if ( ! seen.has( text ) ) {
|
||||
seen.add( text );
|
||||
deduplicated_notices.push( this );
|
||||
}
|
||||
} );
|
||||
|
||||
return $( deduplicated_notices );
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the .woocommerce div with a string of html.
|
||||
*
|
||||
* @param {String} html_str The HTML string with which to replace the div.
|
||||
* @param {bool} preserve_notices Should notices be kept? False by default.
|
||||
*/
|
||||
var update_wc_div = function( html_str, preserve_notices ) {
|
||||
var $html = $.parseHTML( html_str );
|
||||
var $new_form = $( '.woocommerce-cart-form', $html );
|
||||
var $new_totals = $( '.cart_totals', $html );
|
||||
var $notices = remove_duplicate_notices( $( '.woocommerce-error, .woocommerce-message, .woocommerce-info', $html ) );
|
||||
|
||||
// No form, cannot do this.
|
||||
if ( $( '.woocommerce-cart-form' ).length === 0 ) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove errors
|
||||
if ( ! preserve_notices ) {
|
||||
$( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove();
|
||||
}
|
||||
|
||||
if ( $new_form.length === 0 ) {
|
||||
// If the checkout is also displayed on this page, trigger reload instead.
|
||||
if ( $( '.woocommerce-checkout' ).length ) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
// No items to display now! Replace all cart content.
|
||||
var $cart_html = $( '.wc-empty-cart-message', $html ).closest( '.woocommerce' );
|
||||
$( '.woocommerce-cart-form__contents' ).closest( '.woocommerce' ).replaceWith( $cart_html );
|
||||
|
||||
// Display errors
|
||||
if ( $notices.length > 0 ) {
|
||||
show_notice( $notices );
|
||||
}
|
||||
|
||||
// Notify plugins that the cart was emptied.
|
||||
$( document.body ).trigger( 'wc_cart_emptied' );
|
||||
} else {
|
||||
// If the checkout is also displayed on this page, trigger update event.
|
||||
if ( $( '.woocommerce-checkout' ).length ) {
|
||||
$( document.body ).trigger( 'update_checkout' );
|
||||
}
|
||||
|
||||
$( '.woocommerce-cart-form' ).replaceWith( $new_form );
|
||||
$( '.woocommerce-cart-form' ).find( ':input[name="update_cart"]' ).prop( 'disabled', true );
|
||||
|
||||
if ( $notices.length > 0 ) {
|
||||
show_notice( $notices );
|
||||
}
|
||||
|
||||
update_cart_totals_div( $new_totals );
|
||||
}
|
||||
|
||||
$( document.body ).trigger( 'updated_wc_div' );
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the .cart_totals div with a string of html.
|
||||
*
|
||||
* @param {String} html_str The HTML string with which to replace the div.
|
||||
*/
|
||||
var update_cart_totals_div = function( html_str ) {
|
||||
$( '.cart_totals' ).replaceWith( html_str );
|
||||
$( document.body ).trigger( 'updated_cart_totals' );
|
||||
};
|
||||
|
||||
/**
|
||||
* Shows new notices on the page.
|
||||
*
|
||||
* @param {Object} The Notice HTML Element in string or object form.
|
||||
*/
|
||||
var show_notice = function( html_element, $target ) {
|
||||
if ( ! $target ) {
|
||||
$target = $( '.woocommerce-notices-wrapper:first' ) ||
|
||||
$( '.wc-empty-cart-message' ).closest( '.woocommerce' ) ||
|
||||
$( '.woocommerce-cart-form' );
|
||||
}
|
||||
$target.prepend( html_element );
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Object to handle AJAX calls for cart shipping changes.
|
||||
*/
|
||||
var cart_shipping = {
|
||||
|
||||
/**
|
||||
* Initialize event handlers and UI state.
|
||||
*/
|
||||
init: function( cart ) {
|
||||
this.cart = cart;
|
||||
this.toggle_shipping = this.toggle_shipping.bind( this );
|
||||
this.shipping_method_selected = this.shipping_method_selected.bind( this );
|
||||
this.shipping_calculator_submit = this.shipping_calculator_submit.bind( this );
|
||||
|
||||
$( document ).on(
|
||||
'click',
|
||||
'.shipping-calculator-button',
|
||||
this.toggle_shipping
|
||||
);
|
||||
$( document ).on(
|
||||
'change',
|
||||
'select.shipping_method, :input[name^=shipping_method]',
|
||||
this.shipping_method_selected
|
||||
);
|
||||
$( document ).on(
|
||||
'submit',
|
||||
'form.woocommerce-shipping-calculator',
|
||||
this.shipping_calculator_submit
|
||||
);
|
||||
|
||||
$( '.shipping-calculator-form' ).hide();
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle Shipping Calculator panel
|
||||
*/
|
||||
toggle_shipping: function() {
|
||||
$( '.shipping-calculator-form' ).slideToggle( 'slow' );
|
||||
$( 'select.country_to_state, input.country_to_state' ).trigger( 'change' );
|
||||
$( document.body ).trigger( 'country_to_state_changed' ); // Trigger select2 to load.
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles when a shipping method is selected.
|
||||
*/
|
||||
shipping_method_selected: function() {
|
||||
var shipping_methods = {};
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
$( 'select.shipping_method, :input[name^=shipping_method][type=radio]:checked, :input[name^=shipping_method][type=hidden]' ).each( function() {
|
||||
shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val();
|
||||
} );
|
||||
|
||||
block( $( 'div.cart_totals' ) );
|
||||
|
||||
var data = {
|
||||
security: wc_cart_params.update_shipping_method_nonce,
|
||||
shipping_method: shipping_methods
|
||||
};
|
||||
|
||||
$.ajax( {
|
||||
type: 'post',
|
||||
url: get_url( 'update_shipping_method' ),
|
||||
data: data,
|
||||
dataType: 'html',
|
||||
success: function( response ) {
|
||||
update_cart_totals_div( response );
|
||||
},
|
||||
complete: function() {
|
||||
unblock( $( 'div.cart_totals' ) );
|
||||
$( document.body ).trigger( 'updated_shipping_method' );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Handles a shipping calculator form submit.
|
||||
*
|
||||
* @param {Object} evt The JQuery event.
|
||||
*/
|
||||
shipping_calculator_submit: function( evt ) {
|
||||
evt.preventDefault();
|
||||
|
||||
var $form = $( evt.currentTarget );
|
||||
|
||||
block( $( 'div.cart_totals' ) );
|
||||
block( $form );
|
||||
|
||||
// Provide the submit button value because wc-form-handler expects it.
|
||||
$( '<input />' ).attr( 'type', 'hidden' )
|
||||
.attr( 'name', 'calc_shipping' )
|
||||
.attr( 'value', 'x' )
|
||||
.appendTo( $form );
|
||||
|
||||
// Make call to actual form post URL.
|
||||
$.ajax( {
|
||||
type: $form.attr( 'method' ),
|
||||
url: $form.attr( 'action' ),
|
||||
data: $form.serialize(),
|
||||
dataType: 'html',
|
||||
success: function( response ) {
|
||||
update_wc_div( response );
|
||||
},
|
||||
complete: function() {
|
||||
unblock( $form );
|
||||
unblock( $( 'div.cart_totals' ) );
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Object to handle cart UI.
|
||||
*/
|
||||
var cart = {
|
||||
/**
|
||||
* Initialize cart UI events.
|
||||
*/
|
||||
init: function() {
|
||||
this.update_cart_totals = this.update_cart_totals.bind( this );
|
||||
this.input_keypress = this.input_keypress.bind( this );
|
||||
this.cart_submit = this.cart_submit.bind( this );
|
||||
this.submit_click = this.submit_click.bind( this );
|
||||
this.apply_coupon = this.apply_coupon.bind( this );
|
||||
this.remove_coupon_clicked = this.remove_coupon_clicked.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 );
|
||||
this.update_cart = this.update_cart.bind( this );
|
||||
|
||||
$( document ).on(
|
||||
'wc_update_cart added_to_cart',
|
||||
function() { cart.update_cart.apply( cart, [].slice.call( arguments, 1 ) ); } );
|
||||
$( document ).on(
|
||||
'click',
|
||||
'.woocommerce-cart-form :input[type=submit]',
|
||||
this.submit_click );
|
||||
$( document ).on(
|
||||
'keypress',
|
||||
'.woocommerce-cart-form :input[type=number]',
|
||||
this.input_keypress );
|
||||
$( document ).on(
|
||||
'submit',
|
||||
'.woocommerce-cart-form',
|
||||
this.cart_submit );
|
||||
$( document ).on(
|
||||
'click',
|
||||
'a.woocommerce-remove-coupon',
|
||||
this.remove_coupon_clicked );
|
||||
$( document ).on(
|
||||
'click',
|
||||
'.woocommerce-cart-form .product-remove > a',
|
||||
this.item_remove_clicked );
|
||||
$( document ).on(
|
||||
'click',
|
||||
'.woocommerce-cart .restore-item',
|
||||
this.item_restore_clicked );
|
||||
$( document ).on(
|
||||
'change input',
|
||||
'.woocommerce-cart-form .cart_item :input',
|
||||
this.input_changed );
|
||||
|
||||
$( '.woocommerce-cart-form :input[name="update_cart"]' ).prop( 'disabled', true );
|
||||
},
|
||||
|
||||
/**
|
||||
* After an input is changed, enable the update cart button.
|
||||
*/
|
||||
input_changed: function() {
|
||||
$( '.woocommerce-cart-form :input[name="update_cart"]' ).prop( 'disabled', false );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update entire cart via ajax.
|
||||
*/
|
||||
update_cart: function( preserve_notices ) {
|
||||
var $form = $( '.woocommerce-cart-form' );
|
||||
|
||||
block( $form );
|
||||
block( $( 'div.cart_totals' ) );
|
||||
|
||||
// Make call to actual form post URL.
|
||||
$.ajax( {
|
||||
type: $form.attr( 'method' ),
|
||||
url: $form.attr( 'action' ),
|
||||
data: $form.serialize(),
|
||||
dataType: 'html',
|
||||
success: function( response ) {
|
||||
update_wc_div( response, preserve_notices );
|
||||
},
|
||||
complete: function() {
|
||||
unblock( $form );
|
||||
unblock( $( 'div.cart_totals' ) );
|
||||
$.scroll_to_notices( $( '[role="alert"]' ) );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the cart after something has changed.
|
||||
*/
|
||||
update_cart_totals: function() {
|
||||
block( $( 'div.cart_totals' ) );
|
||||
|
||||
$.ajax( {
|
||||
url: get_url( 'get_cart_totals' ),
|
||||
dataType: 'html',
|
||||
success: function( response ) {
|
||||
update_cart_totals_div( response );
|
||||
},
|
||||
complete: function() {
|
||||
unblock( $( 'div.cart_totals' ) );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle the <ENTER> key for quantity fields.
|
||||
*
|
||||
* @param {Object} evt The JQuery event
|
||||
*
|
||||
* For IE, if you hit enter on a quantity field, it makes the
|
||||
* document.activeElement the first submit button it finds.
|
||||
* For us, that is the Apply Coupon button. This is required
|
||||
* to catch the event before that happens.
|
||||
*/
|
||||
input_keypress: function( evt ) {
|
||||
|
||||
// Catch the enter key and don't let it submit the form.
|
||||
if ( 13 === evt.keyCode ) {
|
||||
var $form = $( evt.currentTarget ).parents( 'form' );
|
||||
|
||||
try {
|
||||
// If there are no validation errors, handle the submit.
|
||||
if ( $form[0].checkValidity() ) {
|
||||
evt.preventDefault();
|
||||
this.cart_submit( evt );
|
||||
}
|
||||
} catch( err ) {
|
||||
evt.preventDefault();
|
||||
this.cart_submit( evt );
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle cart form submit and route to correct logic.
|
||||
*
|
||||
* @param {Object} evt The JQuery event
|
||||
*/
|
||||
cart_submit: function( evt ) {
|
||||
var $submit = $( document.activeElement ),
|
||||
$clicked = $( ':input[type=submit][clicked=true]' ),
|
||||
$form = $( evt.currentTarget );
|
||||
|
||||
// For submit events, currentTarget is form.
|
||||
// For keypress events, currentTarget is input.
|
||||
if ( ! $form.is( 'form' ) ) {
|
||||
$form = $( evt.currentTarget ).parents( 'form' );
|
||||
}
|
||||
|
||||
if ( 0 === $form.find( '.woocommerce-cart-form__contents' ).length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_blocked( $form ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( $clicked.is( ':input[name="update_cart"]' ) || $submit.is( 'input.qty' ) ) {
|
||||
evt.preventDefault();
|
||||
this.quantity_update( $form );
|
||||
|
||||
} else if ( $clicked.is( ':input[name="apply_coupon"]' ) || $submit.is( '#coupon_code' ) ) {
|
||||
evt.preventDefault();
|
||||
this.apply_coupon( $form );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Special handling to identify which submit button was clicked.
|
||||
*
|
||||
* @param {Object} evt The JQuery event
|
||||
*/
|
||||
submit_click: function( evt ) {
|
||||
$( ':input[type=submit]', $( evt.target ).parents( 'form' ) ).removeAttr( 'clicked' );
|
||||
$( evt.target ).attr( 'clicked', 'true' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Apply Coupon code
|
||||
*
|
||||
* @param {JQuery Object} $form The cart form.
|
||||
*/
|
||||
apply_coupon: function( $form ) {
|
||||
block( $form );
|
||||
|
||||
var cart = this;
|
||||
var $text_field = $( '#coupon_code' );
|
||||
var coupon_code = $text_field.val();
|
||||
|
||||
var data = {
|
||||
security: wc_cart_params.apply_coupon_nonce,
|
||||
coupon_code: coupon_code
|
||||
};
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: get_url( 'apply_coupon' ),
|
||||
data: data,
|
||||
dataType: 'html',
|
||||
success: function( response ) {
|
||||
$( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove();
|
||||
show_notice( response );
|
||||
$( document.body ).trigger( 'applied_coupon', [ coupon_code ] );
|
||||
},
|
||||
complete: function() {
|
||||
unblock( $form );
|
||||
$text_field.val( '' );
|
||||
cart.update_cart( true );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle when a remove coupon link is clicked.
|
||||
*
|
||||
* @param {Object} evt The JQuery event
|
||||
*/
|
||||
remove_coupon_clicked: function( evt ) {
|
||||
evt.preventDefault();
|
||||
|
||||
var cart = this;
|
||||
var $wrapper = $( evt.currentTarget ).closest( '.cart_totals' );
|
||||
var coupon = $( evt.currentTarget ).attr( 'data-coupon' );
|
||||
|
||||
block( $wrapper );
|
||||
|
||||
var data = {
|
||||
security: wc_cart_params.remove_coupon_nonce,
|
||||
coupon: coupon
|
||||
};
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: get_url( 'remove_coupon' ),
|
||||
data: data,
|
||||
dataType: 'html',
|
||||
success: function( response ) {
|
||||
$( '.woocommerce-error, .woocommerce-message, .woocommerce-info' ).remove();
|
||||
show_notice( response );
|
||||
$( document.body ).trigger( 'removed_coupon', [ coupon ] );
|
||||
unblock( $wrapper );
|
||||
},
|
||||
complete: function() {
|
||||
cart.update_cart( true );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle a cart Quantity Update
|
||||
*
|
||||
* @param {JQuery Object} $form The cart form.
|
||||
*/
|
||||
quantity_update: function( $form ) {
|
||||
block( $form );
|
||||
block( $( 'div.cart_totals' ) );
|
||||
|
||||
// Provide the submit button value because wc-form-handler expects it.
|
||||
$( '<input />' ).attr( 'type', 'hidden' )
|
||||
.attr( 'name', 'update_cart' )
|
||||
.attr( 'value', 'Update Cart' )
|
||||
.appendTo( $form );
|
||||
|
||||
// Make call to actual form post URL.
|
||||
$.ajax( {
|
||||
type: $form.attr( 'method' ),
|
||||
url: $form.attr( 'action' ),
|
||||
data: $form.serialize(),
|
||||
dataType: 'html',
|
||||
success: function( response ) {
|
||||
update_wc_div( response );
|
||||
},
|
||||
complete: function() {
|
||||
unblock( $form );
|
||||
unblock( $( 'div.cart_totals' ) );
|
||||
$.scroll_to_notices( $( '[role="alert"]' ) );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle when a remove item link is clicked.
|
||||
*
|
||||
* @param {Object} evt The JQuery event
|
||||
*/
|
||||
item_remove_clicked: function( evt ) {
|
||||
evt.preventDefault();
|
||||
|
||||
var $a = $( evt.currentTarget );
|
||||
var $form = $a.parents( 'form' );
|
||||
|
||||
block( $form );
|
||||
block( $( 'div.cart_totals' ) );
|
||||
|
||||
$.ajax( {
|
||||
type: 'GET',
|
||||
url: $a.attr( 'href' ),
|
||||
dataType: 'html',
|
||||
success: function( response ) {
|
||||
update_wc_div( response );
|
||||
},
|
||||
complete: function() {
|
||||
unblock( $form );
|
||||
unblock( $( 'div.cart_totals' ) );
|
||||
$.scroll_to_notices( $( '[role="alert"]' ) );
|
||||
}
|
||||
} );
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle when a restore item link is clicked.
|
||||
*
|
||||
* @param {Object} evt The JQuery event
|
||||
*/
|
||||
item_restore_clicked: function( evt ) {
|
||||
evt.preventDefault();
|
||||
|
||||
var $a = $( evt.currentTarget );
|
||||
var $form = $( 'form.woocommerce-cart-form' );
|
||||
|
||||
block( $form );
|
||||
block( $( 'div.cart_totals' ) );
|
||||
|
||||
$.ajax( {
|
||||
type: 'GET',
|
||||
url: $a.attr( 'href' ),
|
||||
dataType: 'html',
|
||||
success: function( response ) {
|
||||
update_wc_div( response );
|
||||
},
|
||||
complete: function() {
|
||||
unblock( $form );
|
||||
unblock( $( 'div.cart_totals' ) );
|
||||
}
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
cart_shipping.init( cart );
|
||||
cart.init();
|
||||
} );
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/cart.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/cart.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
731
wp/wp-content/plugins/woocommerce/assets/js/frontend/checkout.js
Normal file
731
wp/wp-content/plugins/woocommerce/assets/js/frontend/checkout.js
Normal file
@@ -0,0 +1,731 @@
|
||||
/* global wc_checkout_params */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
// wc_checkout_params is required to continue, ensure the object exists
|
||||
if ( typeof wc_checkout_params === 'undefined' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$.blockUI.defaults.overlayCSS.cursor = 'default';
|
||||
|
||||
var wc_checkout_form = {
|
||||
updateTimer: false,
|
||||
dirtyInput: false,
|
||||
selectedPaymentMethod: false,
|
||||
xhr: false,
|
||||
$order_review: $( '#order_review' ),
|
||||
$checkout_form: $( 'form.checkout' ),
|
||||
init: function() {
|
||||
$( document.body ).on( 'update_checkout', this.update_checkout );
|
||||
$( document.body ).on( 'init_checkout', this.init_checkout );
|
||||
|
||||
// Payment methods
|
||||
this.$checkout_form.on( 'click', 'input[name="payment_method"]', this.payment_method_selected );
|
||||
|
||||
if ( $( document.body ).hasClass( 'woocommerce-order-pay' ) ) {
|
||||
this.$order_review.on( 'click', 'input[name="payment_method"]', this.payment_method_selected );
|
||||
this.$order_review.on( 'submit', this.submitOrder );
|
||||
this.$order_review.attr( 'novalidate', 'novalidate' );
|
||||
}
|
||||
|
||||
// Prevent HTML5 validation which can conflict.
|
||||
this.$checkout_form.attr( 'novalidate', 'novalidate' );
|
||||
|
||||
// Form submission
|
||||
this.$checkout_form.on( 'submit', this.submit );
|
||||
|
||||
// Inline validation
|
||||
this.$checkout_form.on( 'input validate change', '.input-text, select, input:checkbox', this.validate_field );
|
||||
|
||||
// Manual trigger
|
||||
this.$checkout_form.on( 'update', this.trigger_update_checkout );
|
||||
|
||||
// Inputs/selects which update totals
|
||||
this.$checkout_form.on( 'change', 'select.shipping_method, input[name^="shipping_method"], #ship-to-different-address input, .update_totals_on_change select, .update_totals_on_change input[type="radio"], .update_totals_on_change input[type="checkbox"]', this.trigger_update_checkout ); // eslint-disable-line max-len
|
||||
this.$checkout_form.on( 'change', '.address-field select', this.input_changed );
|
||||
this.$checkout_form.on( 'change', '.address-field input.input-text, .update_totals_on_change input.input-text', this.maybe_input_changed ); // eslint-disable-line max-len
|
||||
this.$checkout_form.on( 'keydown', '.address-field input.input-text, .update_totals_on_change input.input-text', this.queue_update_checkout ); // eslint-disable-line max-len
|
||||
|
||||
// Address fields
|
||||
this.$checkout_form.on( 'change', '#ship-to-different-address input', this.ship_to_different_address );
|
||||
|
||||
// Trigger events
|
||||
this.$checkout_form.find( '#ship-to-different-address input' ).trigger( 'change' );
|
||||
this.init_payment_methods();
|
||||
|
||||
// Update on page load
|
||||
if ( wc_checkout_params.is_checkout === '1' ) {
|
||||
$( document.body ).trigger( 'init_checkout' );
|
||||
}
|
||||
if ( wc_checkout_params.option_guest_checkout === 'yes' ) {
|
||||
$( 'input#createaccount' ).on( 'change', this.toggle_create_account ).trigger( 'change' );
|
||||
}
|
||||
},
|
||||
init_payment_methods: function() {
|
||||
var $payment_methods = $( '.woocommerce-checkout' ).find( 'input[name="payment_method"]' );
|
||||
|
||||
// If there is one method, we can hide the radio input
|
||||
if ( 1 === $payment_methods.length ) {
|
||||
$payment_methods.eq(0).hide();
|
||||
}
|
||||
|
||||
// If there was a previously selected method, check that one.
|
||||
if ( wc_checkout_form.selectedPaymentMethod ) {
|
||||
$( '#' + wc_checkout_form.selectedPaymentMethod ).prop( 'checked', true );
|
||||
}
|
||||
|
||||
// If there are none selected, select the first.
|
||||
if ( 0 === $payment_methods.filter( ':checked' ).length ) {
|
||||
$payment_methods.eq(0).prop( 'checked', true );
|
||||
}
|
||||
|
||||
// Get name of new selected method.
|
||||
var checkedPaymentMethod = $payment_methods.filter( ':checked' ).eq(0).prop( 'id' );
|
||||
|
||||
if ( $payment_methods.length > 1 ) {
|
||||
// Hide open descriptions.
|
||||
$( 'div.payment_box:not(".' + checkedPaymentMethod + '")' ).filter( ':visible' ).slideUp( 0 );
|
||||
}
|
||||
|
||||
// Trigger click event for selected method
|
||||
$payment_methods.filter( ':checked' ).eq(0).trigger( 'click' );
|
||||
},
|
||||
get_payment_method: function() {
|
||||
return wc_checkout_form.$checkout_form.find( 'input[name="payment_method"]:checked' ).val();
|
||||
},
|
||||
payment_method_selected: function( e ) {
|
||||
e.stopPropagation();
|
||||
|
||||
if ( $( '.payment_methods input.input-radio' ).length > 1 ) {
|
||||
var target_payment_box = $( 'div.payment_box.' + $( this ).attr( 'ID' ) ),
|
||||
is_checked = $( this ).is( ':checked' );
|
||||
|
||||
if ( is_checked && ! target_payment_box.is( ':visible' ) ) {
|
||||
$( 'div.payment_box' ).filter( ':visible' ).slideUp( 230 );
|
||||
|
||||
if ( is_checked ) {
|
||||
target_payment_box.slideDown( 230 );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$( 'div.payment_box' ).show();
|
||||
}
|
||||
|
||||
if ( $( this ).data( 'order_button_text' ) ) {
|
||||
$( '#place_order' ).text( $( this ).data( 'order_button_text' ) );
|
||||
} else {
|
||||
$( '#place_order' ).text( $( '#place_order' ).data( 'value' ) );
|
||||
}
|
||||
|
||||
var selectedPaymentMethod = $( '.woocommerce-checkout input[name="payment_method"]:checked' ).attr( 'id' );
|
||||
|
||||
if ( selectedPaymentMethod !== wc_checkout_form.selectedPaymentMethod ) {
|
||||
$( document.body ).trigger( 'payment_method_selected' );
|
||||
}
|
||||
|
||||
wc_checkout_form.selectedPaymentMethod = selectedPaymentMethod;
|
||||
},
|
||||
toggle_create_account: function() {
|
||||
$( 'div.create-account' ).hide();
|
||||
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
// Ensure password is not pre-populated.
|
||||
$( '#account_password' ).val( '' ).trigger( 'change' );
|
||||
$( 'div.create-account' ).slideDown();
|
||||
}
|
||||
},
|
||||
init_checkout: function() {
|
||||
$( document.body ).trigger( 'update_checkout' );
|
||||
},
|
||||
maybe_input_changed: function( e ) {
|
||||
if ( wc_checkout_form.dirtyInput ) {
|
||||
wc_checkout_form.input_changed( e );
|
||||
}
|
||||
},
|
||||
input_changed: function( e ) {
|
||||
wc_checkout_form.dirtyInput = e.target;
|
||||
wc_checkout_form.maybe_update_checkout();
|
||||
},
|
||||
queue_update_checkout: function( e ) {
|
||||
var code = e.keyCode || e.which || 0;
|
||||
|
||||
if ( code === 9 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
wc_checkout_form.dirtyInput = this;
|
||||
wc_checkout_form.reset_update_checkout_timer();
|
||||
wc_checkout_form.updateTimer = setTimeout( wc_checkout_form.maybe_update_checkout, '1000' );
|
||||
},
|
||||
trigger_update_checkout: function() {
|
||||
wc_checkout_form.reset_update_checkout_timer();
|
||||
wc_checkout_form.dirtyInput = false;
|
||||
$( document.body ).trigger( 'update_checkout' );
|
||||
},
|
||||
maybe_update_checkout: function() {
|
||||
var update_totals = true;
|
||||
|
||||
if ( $( wc_checkout_form.dirtyInput ).length ) {
|
||||
var $required_inputs = $( wc_checkout_form.dirtyInput ).closest( 'div' ).find( '.address-field.validate-required' );
|
||||
|
||||
if ( $required_inputs.length ) {
|
||||
$required_inputs.each( function() {
|
||||
if ( $( this ).find( 'input.input-text' ).val() === '' ) {
|
||||
update_totals = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if ( update_totals ) {
|
||||
wc_checkout_form.trigger_update_checkout();
|
||||
}
|
||||
},
|
||||
ship_to_different_address: function() {
|
||||
$( 'div.shipping_address' ).hide();
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
$( 'div.shipping_address' ).slideDown();
|
||||
}
|
||||
},
|
||||
reset_update_checkout_timer: function() {
|
||||
clearTimeout( wc_checkout_form.updateTimer );
|
||||
},
|
||||
is_valid_json: function( raw_json ) {
|
||||
try {
|
||||
var json = JSON.parse( raw_json );
|
||||
|
||||
return ( json && 'object' === typeof json );
|
||||
} catch ( e ) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
validate_field: function( e ) {
|
||||
var $this = $( this ),
|
||||
$parent = $this.closest( '.form-row' ),
|
||||
validated = true,
|
||||
validate_required = $parent.is( '.validate-required' ),
|
||||
validate_email = $parent.is( '.validate-email' ),
|
||||
validate_phone = $parent.is( '.validate-phone' ),
|
||||
pattern = '',
|
||||
event_type = e.type;
|
||||
|
||||
if ( 'input' === event_type ) {
|
||||
$parent.removeClass( 'woocommerce-invalid woocommerce-invalid-required-field woocommerce-invalid-email woocommerce-invalid-phone woocommerce-validated' ); // eslint-disable-line max-len
|
||||
}
|
||||
|
||||
if ( 'validate' === event_type || 'change' === event_type ) {
|
||||
|
||||
if ( validate_required ) {
|
||||
if ( 'checkbox' === $this.attr( 'type' ) && ! $this.is( ':checked' ) ) {
|
||||
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-required-field' );
|
||||
validated = false;
|
||||
} else if ( $this.val() === '' ) {
|
||||
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-required-field' );
|
||||
validated = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( validate_email ) {
|
||||
if ( $this.val() ) {
|
||||
/* https://stackoverflow.com/questions/2855865/jquery-validate-e-mail-address-regex */
|
||||
pattern = new RegExp( /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[0-9a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i ); // eslint-disable-line max-len
|
||||
|
||||
if ( ! pattern.test( $this.val() ) ) {
|
||||
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-email woocommerce-invalid-phone' ); // eslint-disable-line max-len
|
||||
validated = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( validate_phone ) {
|
||||
pattern = new RegExp( /[\s\#0-9_\-\+\/\(\)\.]/g );
|
||||
|
||||
if ( 0 < $this.val().replace( pattern, '' ).length ) {
|
||||
$parent.removeClass( 'woocommerce-validated' ).addClass( 'woocommerce-invalid woocommerce-invalid-phone' );
|
||||
validated = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( validated ) {
|
||||
$parent.removeClass( 'woocommerce-invalid woocommerce-invalid-required-field woocommerce-invalid-email woocommerce-invalid-phone' ).addClass( 'woocommerce-validated' ); // eslint-disable-line max-len
|
||||
}
|
||||
}
|
||||
},
|
||||
update_checkout: function( event, args ) {
|
||||
// Small timeout to prevent multiple requests when several fields update at the same time
|
||||
wc_checkout_form.reset_update_checkout_timer();
|
||||
wc_checkout_form.updateTimer = setTimeout( wc_checkout_form.update_checkout_action, '5', args );
|
||||
},
|
||||
update_checkout_action: function( args ) {
|
||||
if ( wc_checkout_form.xhr ) {
|
||||
wc_checkout_form.xhr.abort();
|
||||
}
|
||||
|
||||
if ( $( 'form.checkout' ).length === 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
args = typeof args !== 'undefined' ? args : {
|
||||
update_shipping_method: true
|
||||
};
|
||||
|
||||
var country = $( '#billing_country' ).val(),
|
||||
state = $( '#billing_state' ).val(),
|
||||
postcode = $( ':input#billing_postcode' ).val(),
|
||||
city = $( '#billing_city' ).val(),
|
||||
address = $( ':input#billing_address_1' ).val(),
|
||||
address_2 = $( ':input#billing_address_2' ).val(),
|
||||
s_country = country,
|
||||
s_state = state,
|
||||
s_postcode = postcode,
|
||||
s_city = city,
|
||||
s_address = address,
|
||||
s_address_2 = address_2,
|
||||
$required_inputs = $( wc_checkout_form.$checkout_form ).find( '.address-field.validate-required:visible' ),
|
||||
has_full_address = true;
|
||||
|
||||
if ( $required_inputs.length ) {
|
||||
$required_inputs.each( function() {
|
||||
if ( $( this ).find( ':input' ).val() === '' ) {
|
||||
has_full_address = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if ( $( '#ship-to-different-address' ).find( 'input' ).is( ':checked' ) ) {
|
||||
s_country = $( '#shipping_country' ).val();
|
||||
s_state = $( '#shipping_state' ).val();
|
||||
s_postcode = $( ':input#shipping_postcode' ).val();
|
||||
s_city = $( '#shipping_city' ).val();
|
||||
s_address = $( ':input#shipping_address_1' ).val();
|
||||
s_address_2 = $( ':input#shipping_address_2' ).val();
|
||||
}
|
||||
|
||||
var data = {
|
||||
security : wc_checkout_params.update_order_review_nonce,
|
||||
payment_method : wc_checkout_form.get_payment_method(),
|
||||
country : country,
|
||||
state : state,
|
||||
postcode : postcode,
|
||||
city : city,
|
||||
address : address,
|
||||
address_2 : address_2,
|
||||
s_country : s_country,
|
||||
s_state : s_state,
|
||||
s_postcode : s_postcode,
|
||||
s_city : s_city,
|
||||
s_address : s_address,
|
||||
s_address_2 : s_address_2,
|
||||
has_full_address: has_full_address,
|
||||
post_data : $( 'form.checkout' ).serialize()
|
||||
};
|
||||
|
||||
if ( false !== args.update_shipping_method ) {
|
||||
var shipping_methods = {};
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
$( 'select.shipping_method, input[name^="shipping_method"][type="radio"]:checked, input[name^="shipping_method"][type="hidden"]' ).each( function() {
|
||||
shipping_methods[ $( this ).data( 'index' ) ] = $( this ).val();
|
||||
} );
|
||||
|
||||
data.shipping_method = shipping_methods;
|
||||
}
|
||||
|
||||
$( '.woocommerce-checkout-payment, .woocommerce-checkout-review-order-table' ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
|
||||
wc_checkout_form.xhr = $.ajax({
|
||||
type: 'POST',
|
||||
url: wc_checkout_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'update_order_review' ),
|
||||
data: data,
|
||||
success: function( data ) {
|
||||
|
||||
// Reload the page if requested
|
||||
if ( data && true === data.reload ) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove any notices added previously
|
||||
$( '.woocommerce-NoticeGroup-updateOrderReview' ).remove();
|
||||
|
||||
var termsCheckBoxChecked = $( '#terms' ).prop( 'checked' );
|
||||
|
||||
// Save payment details to a temporary object
|
||||
var paymentDetails = {};
|
||||
$( '.payment_box :input' ).each( function() {
|
||||
var ID = $( this ).attr( 'id' );
|
||||
|
||||
if ( ID ) {
|
||||
if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) {
|
||||
paymentDetails[ ID ] = $( this ).prop( 'checked' );
|
||||
} else {
|
||||
paymentDetails[ ID ] = $( this ).val();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Always update the fragments
|
||||
if ( data && data.fragments ) {
|
||||
$.each( data.fragments, function ( key, value ) {
|
||||
if ( ! wc_checkout_form.fragments || wc_checkout_form.fragments[ key ] !== value ) {
|
||||
$( key ).replaceWith( value );
|
||||
}
|
||||
$( key ).unblock();
|
||||
} );
|
||||
wc_checkout_form.fragments = data.fragments;
|
||||
}
|
||||
|
||||
// Recheck the terms and conditions box, if needed
|
||||
if ( termsCheckBoxChecked ) {
|
||||
$( '#terms' ).prop( 'checked', true );
|
||||
}
|
||||
|
||||
// Fill in the payment details if possible without overwriting data if set.
|
||||
if ( ! $.isEmptyObject( paymentDetails ) ) {
|
||||
$( '.payment_box :input' ).each( function() {
|
||||
var ID = $( this ).attr( 'id' );
|
||||
if ( ID ) {
|
||||
if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) {
|
||||
$( this ).prop( 'checked', paymentDetails[ ID ] ).trigger( 'change' );
|
||||
} else if ( $.inArray( $( this ).attr( 'type' ), [ 'select' ] ) !== -1 ) {
|
||||
$( this ).val( paymentDetails[ ID ] ).trigger( 'change' );
|
||||
} else if ( null !== $( this ).val() && 0 === $( this ).val().length ) {
|
||||
$( this ).val( paymentDetails[ ID ] ).trigger( 'change' );
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Check for error
|
||||
if ( data && 'failure' === data.result ) {
|
||||
|
||||
var $form = $( 'form.checkout' );
|
||||
|
||||
// Remove notices from all sources
|
||||
$( '.woocommerce-error, .woocommerce-message' ).remove();
|
||||
|
||||
// Add new errors returned by this event
|
||||
if ( data.messages ) {
|
||||
$form.prepend( '<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-updateOrderReview">' + data.messages + '</div>' ); // eslint-disable-line max-len
|
||||
} else {
|
||||
$form.prepend( data );
|
||||
}
|
||||
|
||||
// Lose focus for all fields
|
||||
$form.find( '.input-text, select, input:checkbox' ).trigger( 'validate' ).trigger( 'blur' );
|
||||
|
||||
wc_checkout_form.scroll_to_notices();
|
||||
}
|
||||
|
||||
// Re-init methods
|
||||
wc_checkout_form.init_payment_methods();
|
||||
|
||||
// Fire updated_checkout event.
|
||||
$( document.body ).trigger( 'updated_checkout', [ data ] );
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
handleUnloadEvent: function( e ) {
|
||||
// Modern browsers have their own standard generic messages that they will display.
|
||||
// Confirm, alert, prompt or custom message are not allowed during the unload event
|
||||
// Browsers will display their own standard messages
|
||||
|
||||
// Check if the browser is Internet Explorer
|
||||
if((navigator.userAgent.indexOf('MSIE') !== -1 ) || (!!document.documentMode)) {
|
||||
// IE handles unload events differently than modern browsers
|
||||
e.preventDefault();
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
attachUnloadEventsOnSubmit: function() {
|
||||
$( window ).on('beforeunload', this.handleUnloadEvent);
|
||||
},
|
||||
detachUnloadEventsOnSubmit: function() {
|
||||
$( window ).off('beforeunload', this.handleUnloadEvent);
|
||||
},
|
||||
blockOnSubmit: function( $form ) {
|
||||
var isBlocked = $form.data( 'blockUI.isBlocked' );
|
||||
|
||||
if ( 1 !== isBlocked ) {
|
||||
$form.block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
submitOrder: function() {
|
||||
wc_checkout_form.blockOnSubmit( $( this ) );
|
||||
},
|
||||
submit: function() {
|
||||
wc_checkout_form.reset_update_checkout_timer();
|
||||
var $form = $( this );
|
||||
|
||||
if ( $form.is( '.processing' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Trigger a handler to let gateways manipulate the checkout if needed
|
||||
// eslint-disable-next-line max-len
|
||||
if ( $form.triggerHandler( 'checkout_place_order', [ wc_checkout_form ] ) !== false && $form.triggerHandler( 'checkout_place_order_' + wc_checkout_form.get_payment_method(), [ wc_checkout_form ] ) !== false ) {
|
||||
|
||||
$form.addClass( 'processing' );
|
||||
|
||||
wc_checkout_form.blockOnSubmit( $form );
|
||||
|
||||
// Attach event to block reloading the page when the form has been submitted
|
||||
wc_checkout_form.attachUnloadEventsOnSubmit();
|
||||
|
||||
// ajaxSetup is global, but we use it to ensure JSON is valid once returned.
|
||||
$.ajaxSetup( {
|
||||
dataFilter: function( raw_response, dataType ) {
|
||||
// We only want to work with JSON
|
||||
if ( 'json' !== dataType ) {
|
||||
return raw_response;
|
||||
}
|
||||
|
||||
if ( wc_checkout_form.is_valid_json( raw_response ) ) {
|
||||
return raw_response;
|
||||
} else {
|
||||
// Attempt to fix the malformed JSON
|
||||
var maybe_valid_json = raw_response.match( /{"result.*}/ );
|
||||
|
||||
if ( null === maybe_valid_json ) {
|
||||
console.log( 'Unable to fix malformed JSON' );
|
||||
} 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' );
|
||||
}
|
||||
}
|
||||
|
||||
return raw_response;
|
||||
}
|
||||
} );
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: wc_checkout_params.checkout_url,
|
||||
data: $form.serialize(),
|
||||
dataType: 'json',
|
||||
success: function( result ) {
|
||||
// Detach the unload handler that prevents a reload / redirect
|
||||
wc_checkout_form.detachUnloadEventsOnSubmit();
|
||||
|
||||
try {
|
||||
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 {
|
||||
window.location = decodeURI( result.redirect );
|
||||
}
|
||||
} else if ( 'failure' === result.result ) {
|
||||
throw 'Result failure';
|
||||
} else {
|
||||
throw 'Invalid response';
|
||||
}
|
||||
} catch( err ) {
|
||||
// Reload page
|
||||
if ( true === result.reload ) {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
// Trigger update in case we need a fresh nonce
|
||||
if ( true === result.refresh ) {
|
||||
$( document.body ).trigger( 'update_checkout' );
|
||||
}
|
||||
|
||||
// Add new errors
|
||||
if ( result.messages ) {
|
||||
wc_checkout_form.submit_error( result.messages );
|
||||
} else {
|
||||
wc_checkout_form.submit_error( '<div class="woocommerce-error">' + wc_checkout_params.i18n_checkout_error + '</div>' ); // eslint-disable-line max-len
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function( jqXHR, textStatus, errorThrown ) {
|
||||
// Detach the unload handler that prevents a reload / redirect
|
||||
wc_checkout_form.detachUnloadEventsOnSubmit();
|
||||
|
||||
wc_checkout_form.submit_error(
|
||||
'<div class="woocommerce-error">' +
|
||||
( errorThrown || wc_checkout_params.i18n_checkout_error ) +
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
submit_error: function( error_message ) {
|
||||
$( '.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message' ).remove();
|
||||
wc_checkout_form.$checkout_form.prepend( '<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">' + error_message + '</div>' ); // eslint-disable-line max-len
|
||||
wc_checkout_form.$checkout_form.removeClass( 'processing' ).unblock();
|
||||
wc_checkout_form.$checkout_form.find( '.input-text, select, input:checkbox' ).trigger( 'validate' ).trigger( 'blur' );
|
||||
wc_checkout_form.scroll_to_notices();
|
||||
$( document.body ).trigger( 'checkout_error' , [ error_message ] );
|
||||
},
|
||||
scroll_to_notices: function() {
|
||||
var scrollElement = $( '.woocommerce-NoticeGroup-updateOrderReview, .woocommerce-NoticeGroup-checkout' );
|
||||
|
||||
if ( ! scrollElement.length ) {
|
||||
scrollElement = $( 'form.checkout' );
|
||||
}
|
||||
$.scroll_to_notices( scrollElement );
|
||||
}
|
||||
};
|
||||
|
||||
var wc_checkout_coupons = {
|
||||
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 );
|
||||
},
|
||||
show_coupon_form: function() {
|
||||
$( '.checkout_coupon' ).slideToggle( 400, function() {
|
||||
$( '.checkout_coupon' ).find( ':input:eq(0)' ).trigger( 'focus' );
|
||||
});
|
||||
return false;
|
||||
},
|
||||
submit: function() {
|
||||
var $form = $( this );
|
||||
|
||||
if ( $form.is( '.processing' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$form.addClass( 'processing' ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
|
||||
var data = {
|
||||
security: wc_checkout_params.apply_coupon_nonce,
|
||||
coupon_code: $form.find( 'input[name="coupon_code"]' ).val()
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: wc_checkout_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'apply_coupon' ),
|
||||
data: data,
|
||||
success: function( code ) {
|
||||
$( '.woocommerce-error, .woocommerce-message' ).remove();
|
||||
$form.removeClass( 'processing' ).unblock();
|
||||
|
||||
if ( code ) {
|
||||
$form.before( code );
|
||||
$form.slideUp();
|
||||
|
||||
$( document.body ).trigger( 'applied_coupon_in_checkout', [ data.coupon_code ] );
|
||||
$( document.body ).trigger( 'update_checkout', { update_shipping_method: false } );
|
||||
}
|
||||
},
|
||||
dataType: 'html'
|
||||
});
|
||||
|
||||
return false;
|
||||
},
|
||||
remove_coupon: function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
var container = $( this ).parents( '.woocommerce-checkout-review-order' ),
|
||||
coupon = $( this ).data( 'coupon' );
|
||||
|
||||
container.addClass( 'processing' ).block({
|
||||
message: null,
|
||||
overlayCSS: {
|
||||
background: '#fff',
|
||||
opacity: 0.6
|
||||
}
|
||||
});
|
||||
|
||||
var data = {
|
||||
security: wc_checkout_params.remove_coupon_nonce,
|
||||
coupon: coupon
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: wc_checkout_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'remove_coupon' ),
|
||||
data: data,
|
||||
success: function( code ) {
|
||||
$( '.woocommerce-error, .woocommerce-message' ).remove();
|
||||
container.removeClass( 'processing' ).unblock();
|
||||
|
||||
if ( code ) {
|
||||
$( 'form.woocommerce-checkout' ).before( code );
|
||||
|
||||
$( document.body ).trigger( 'removed_coupon_in_checkout', [ data.coupon ] );
|
||||
$( document.body ).trigger( 'update_checkout', { update_shipping_method: false } );
|
||||
|
||||
// Remove coupon code from coupon field
|
||||
$( 'form.checkout_coupon' ).find( 'input[name="coupon_code"]' ).val( '' );
|
||||
}
|
||||
},
|
||||
error: function ( jqXHR ) {
|
||||
if ( wc_checkout_params.debug_mode ) {
|
||||
/* jshint devel: true */
|
||||
console.log( jqXHR.responseText );
|
||||
}
|
||||
},
|
||||
dataType: 'html'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var wc_checkout_login_form = {
|
||||
init: function() {
|
||||
$( document.body ).on( 'click', 'a.showlogin', this.show_login_form );
|
||||
},
|
||||
show_login_form: function() {
|
||||
$( 'form.login, form.woocommerce-form--login' ).slideToggle();
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
var wc_terms_toggle = {
|
||||
init: function() {
|
||||
$( document.body ).on( 'click', 'a.woocommerce-terms-and-conditions-link', this.toggle_terms );
|
||||
},
|
||||
|
||||
toggle_terms: function() {
|
||||
if ( $( '.woocommerce-terms-and-conditions' ).length ) {
|
||||
$( '.woocommerce-terms-and-conditions' ).slideToggle( function() {
|
||||
var link_toggle = $( '.woocommerce-terms-and-conditions-link' );
|
||||
|
||||
if ( $( '.woocommerce-terms-and-conditions' ).is( ':visible' ) ) {
|
||||
link_toggle.addClass( 'woocommerce-terms-and-conditions-link--open' );
|
||||
link_toggle.removeClass( 'woocommerce-terms-and-conditions-link--closed' );
|
||||
} else {
|
||||
link_toggle.removeClass( 'woocommerce-terms-and-conditions-link--open' );
|
||||
link_toggle.addClass( 'woocommerce-terms-and-conditions-link--closed' );
|
||||
}
|
||||
} );
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
wc_checkout_form.init();
|
||||
wc_checkout_coupons.init();
|
||||
wc_checkout_login_form.init();
|
||||
wc_terms_toggle.init();
|
||||
});
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/checkout.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/checkout.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,181 @@
|
||||
/*global wc_country_select_params */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
// wc_country_select_params is required to continue, ensure the object exists
|
||||
if ( typeof wc_country_select_params === 'undefined' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select2 Enhancement if it exists
|
||||
if ( $().selectWoo ) {
|
||||
var getEnhancedSelectFormatString = function() {
|
||||
return {
|
||||
'language': {
|
||||
errorLoading: function() {
|
||||
// Workaround for https://github.com/select2/select2/issues/4355 instead of i18n_ajax_error.
|
||||
return wc_country_select_params.i18n_searching;
|
||||
},
|
||||
inputTooLong: function( args ) {
|
||||
var overChars = args.input.length - args.maximum;
|
||||
|
||||
if ( 1 === overChars ) {
|
||||
return wc_country_select_params.i18n_input_too_long_1;
|
||||
}
|
||||
|
||||
return wc_country_select_params.i18n_input_too_long_n.replace( '%qty%', overChars );
|
||||
},
|
||||
inputTooShort: function( args ) {
|
||||
var remainingChars = args.minimum - args.input.length;
|
||||
|
||||
if ( 1 === remainingChars ) {
|
||||
return wc_country_select_params.i18n_input_too_short_1;
|
||||
}
|
||||
|
||||
return wc_country_select_params.i18n_input_too_short_n.replace( '%qty%', remainingChars );
|
||||
},
|
||||
loadingMore: function() {
|
||||
return wc_country_select_params.i18n_load_more;
|
||||
},
|
||||
maximumSelected: function( args ) {
|
||||
if ( args.maximum === 1 ) {
|
||||
return wc_country_select_params.i18n_selection_too_long_1;
|
||||
}
|
||||
|
||||
return wc_country_select_params.i18n_selection_too_long_n.replace( '%qty%', args.maximum );
|
||||
},
|
||||
noResults: function() {
|
||||
return wc_country_select_params.i18n_no_matches;
|
||||
},
|
||||
searching: function() {
|
||||
return wc_country_select_params.i18n_searching;
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var wc_country_select_select2 = function() {
|
||||
$( 'select.country_select:visible, select.state_select:visible' ).each( function() {
|
||||
var $this = $( this );
|
||||
|
||||
var select2_args = $.extend({
|
||||
placeholder: $this.attr( 'data-placeholder' ) || $this.attr( 'placeholder' ) || '',
|
||||
label: $this.attr( 'data-label' ) || null,
|
||||
width: '100%'
|
||||
}, getEnhancedSelectFormatString() );
|
||||
|
||||
$( this )
|
||||
.on( 'select2:select', function() {
|
||||
$( this ).trigger( 'focus' ); // Maintain focus after select https://github.com/select2/select2/issues/4384
|
||||
} )
|
||||
.selectWoo( select2_args );
|
||||
});
|
||||
};
|
||||
|
||||
wc_country_select_select2();
|
||||
|
||||
$( document.body ).on( 'country_to_state_changed', function() {
|
||||
wc_country_select_select2();
|
||||
});
|
||||
}
|
||||
|
||||
/* State/Country select boxes */
|
||||
var states_json = wc_country_select_params.countries.replace( /"/g, '"' ),
|
||||
states = JSON.parse( states_json ),
|
||||
wrapper_selectors = '.woocommerce-billing-fields,' +
|
||||
'.woocommerce-shipping-fields,' +
|
||||
'.woocommerce-address-fields,' +
|
||||
'.woocommerce-shipping-calculator';
|
||||
|
||||
$( document.body ).on( 'change refresh', 'select.country_to_state, input.country_to_state', function() {
|
||||
// Grab wrapping element to target only stateboxes in same 'group'
|
||||
var $wrapper = $( this ).closest( wrapper_selectors );
|
||||
|
||||
if ( ! $wrapper.length ) {
|
||||
$wrapper = $( this ).closest('.form-row').parent();
|
||||
}
|
||||
|
||||
var country = $( this ).val(),
|
||||
$statebox = $wrapper.find( '#billing_state, #shipping_state, #calc_shipping_state' ),
|
||||
$parent = $statebox.closest( '.form-row' ),
|
||||
input_name = $statebox.attr( 'name' ),
|
||||
input_id = $statebox.attr('id'),
|
||||
input_classes = $statebox.attr('data-input-classes'),
|
||||
value = $statebox.val(),
|
||||
placeholder = $statebox.attr( 'placeholder' ) || $statebox.attr( 'data-placeholder' ) || '',
|
||||
$newstate;
|
||||
|
||||
if ( states[ country ] ) {
|
||||
if ( $.isEmptyObject( states[ country ] ) ) {
|
||||
$newstate = $( '<input type="hidden" />' )
|
||||
.prop( 'id', input_id )
|
||||
.prop( 'name', input_name )
|
||||
.prop( 'placeholder', placeholder )
|
||||
.attr( 'data-input-classes', input_classes )
|
||||
.addClass( 'hidden ' + input_classes );
|
||||
$parent.hide().find( '.select2-container' ).remove();
|
||||
$statebox.replaceWith( $newstate );
|
||||
$( document.body ).trigger( 'country_to_state_changed', [ country, $wrapper ] );
|
||||
} else {
|
||||
var state = states[ country ],
|
||||
$defaultOption = $( '<option value=""></option>' ).text( wc_country_select_params.i18n_select_state_text );
|
||||
|
||||
if ( ! placeholder ) {
|
||||
placeholder = wc_country_select_params.i18n_select_state_text;
|
||||
}
|
||||
|
||||
$parent.show();
|
||||
|
||||
if ( $statebox.is( 'input' ) ) {
|
||||
$newstate = $( '<select></select>' )
|
||||
.prop( 'id', input_id )
|
||||
.prop( 'name', input_name )
|
||||
.data( 'placeholder', placeholder )
|
||||
.attr( 'data-input-classes', input_classes )
|
||||
.addClass( 'state_select ' + input_classes );
|
||||
$statebox.replaceWith( $newstate );
|
||||
$statebox = $wrapper.find( '#billing_state, #shipping_state, #calc_shipping_state' );
|
||||
}
|
||||
|
||||
$statebox.empty().append( $defaultOption );
|
||||
|
||||
$.each( state, function( index ) {
|
||||
var $option = $( '<option></option>' )
|
||||
.prop( 'value', index )
|
||||
.text( state[ index ] );
|
||||
$statebox.append( $option );
|
||||
} );
|
||||
|
||||
$statebox.val( value ).trigger( 'change' );
|
||||
|
||||
$( document.body ).trigger( 'country_to_state_changed', [country, $wrapper ] );
|
||||
}
|
||||
} else {
|
||||
if ( $statebox.is( 'select, input[type="hidden"]' ) ) {
|
||||
$newstate = $( '<input type="text" />' )
|
||||
.prop( 'id', input_id )
|
||||
.prop( 'name', input_name )
|
||||
.prop('placeholder', placeholder)
|
||||
.attr('data-input-classes', input_classes )
|
||||
.addClass( 'input-text ' + input_classes );
|
||||
$parent.show().find( '.select2-container' ).remove();
|
||||
$statebox.replaceWith( $newstate );
|
||||
$( document.body ).trigger( 'country_to_state_changed', [country, $wrapper ] );
|
||||
}
|
||||
}
|
||||
|
||||
$( document.body ).trigger( 'country_to_state_changing', [country, $wrapper ] );
|
||||
});
|
||||
|
||||
$( document.body ).on( 'wc_address_i18n_ready', function() {
|
||||
// Init country selects with their default value once the page loads.
|
||||
$( wrapper_selectors ).each( function() {
|
||||
var $country_input = $( this ).find( '#billing_country, #shipping_country, #calc_shipping_country' );
|
||||
|
||||
if ( 0 === $country_input.length || 0 === $country_input.val().length ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$country_input.trigger( 'refresh' );
|
||||
});
|
||||
});
|
||||
});
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/country-select.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/country-select.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(function(t){if("undefined"==typeof wc_country_select_params)return!1;if(t().selectWoo){var e=function(){t("select.country_select:visible, select.state_select:visible").each(function(){var e=t(this),n=t.extend({placeholder:e.attr("data-placeholder")||e.attr("placeholder")||"",label:e.attr("data-label")||null,width:"100%"},{language:{errorLoading:function(){return wc_country_select_params.i18n_searching},inputTooLong:function(t){var e=t.input.length-t.maximum;return 1===e?wc_country_select_params.i18n_input_too_long_1:wc_country_select_params.i18n_input_too_long_n.replace("%qty%",e)},inputTooShort:function(t){var e=t.minimum-t.input.length;return 1===e?wc_country_select_params.i18n_input_too_short_1:wc_country_select_params.i18n_input_too_short_n.replace("%qty%",e)},loadingMore:function(){return wc_country_select_params.i18n_load_more},maximumSelected:function(t){return 1===t.maximum?wc_country_select_params.i18n_selection_too_long_1:wc_country_select_params.i18n_selection_too_long_n.replace("%qty%",t.maximum)},noResults:function(){return wc_country_select_params.i18n_no_matches},searching:function(){return wc_country_select_params.i18n_searching}}});t(this).on("select2:select",function(){t(this).trigger("focus")}).selectWoo(n)})};e(),t(document.body).on("country_to_state_changed",function(){e()})}var n=wc_country_select_params.countries.replace(/"/g,'"'),o=JSON.parse(n),a=".woocommerce-billing-fields,.woocommerce-shipping-fields,.woocommerce-address-fields,.woocommerce-shipping-calculator";t(document.body).on("change refresh","select.country_to_state, input.country_to_state",function(){var e=t(this).closest(a);e.length||(e=t(this).closest(".form-row").parent());var n,c=t(this).val(),r=e.find("#billing_state, #shipping_state, #calc_shipping_state"),i=r.closest(".form-row"),s=r.attr("name"),_=r.attr("id"),l=r.attr("data-input-classes"),p=r.val(),u=r.attr("placeholder")||r.attr("data-placeholder")||"";if(o[c])if(t.isEmptyObject(o[c]))n=t('<input type="hidden" />').prop("id",_).prop("name",s).prop("placeholder",u).attr("data-input-classes",l).addClass("hidden "+l),i.hide().find(".select2-container").remove(),r.replaceWith(n),t(document.body).trigger("country_to_state_changed",[c,e]);else{var d=o[c],h=t('<option value=""></option>').text(wc_country_select_params.i18n_select_state_text);u||(u=wc_country_select_params.i18n_select_state_text),i.show(),r.is("input")&&(n=t("<select></select>").prop("id",_).prop("name",s).data("placeholder",u).attr("data-input-classes",l).addClass("state_select "+l),r.replaceWith(n),r=e.find("#billing_state, #shipping_state, #calc_shipping_state")),r.empty().append(h),t.each(d,function(e){var n=t("<option></option>").prop("value",e).text(d[e]);r.append(n)}),r.val(p).trigger("change"),t(document.body).trigger("country_to_state_changed",[c,e])}else r.is('select, input[type="hidden"]')&&(n=t('<input type="text" />').prop("id",_).prop("name",s).prop("placeholder",u).attr("data-input-classes",l).addClass("input-text "+l),i.show().find(".select2-container").remove(),r.replaceWith(n),t(document.body).trigger("country_to_state_changed",[c,e]));t(document.body).trigger("country_to_state_changing",[c,e])}),t(document.body).on("wc_address_i18n_ready",function(){t(a).each(function(){var e=t(this).find("#billing_country, #shipping_country, #calc_shipping_country");0!==e.length&&0!==e.val().length&&e.trigger("refresh")})})});
|
||||
@@ -0,0 +1,13 @@
|
||||
jQuery( function( $ ) {
|
||||
$( '.wc-credit-card-form-card-number' ).payment( 'formatCardNumber' );
|
||||
$( '.wc-credit-card-form-card-expiry' ).payment( 'formatCardExpiry' );
|
||||
$( '.wc-credit-card-form-card-cvc' ).payment( 'formatCardCVC' );
|
||||
|
||||
$( document.body )
|
||||
.on( 'updated_checkout wc-credit-card-form-init', function() {
|
||||
$( '.wc-credit-card-form-card-number' ).payment( 'formatCardNumber' );
|
||||
$( '.wc-credit-card-form-card-expiry' ).payment( 'formatCardExpiry' );
|
||||
$( '.wc-credit-card-form-card-cvc' ).payment( 'formatCardCVC' );
|
||||
})
|
||||
.trigger( 'wc-credit-card-form-init' );
|
||||
} );
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/credit-card-form.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/credit-card-form.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(function(r){r(".wc-credit-card-form-card-number").payment("formatCardNumber"),r(".wc-credit-card-form-card-expiry").payment("formatCardExpiry"),r(".wc-credit-card-form-card-cvc").payment("formatCardCVC"),r(document.body).on("updated_checkout wc-credit-card-form-init",function(){r(".wc-credit-card-form-card-number").payment("formatCardNumber"),r(".wc-credit-card-form-card-expiry").payment("formatCardExpiry"),r(".wc-credit-card-form-card-cvc").payment("formatCardCVC")}).trigger("wc-credit-card-form-init")});
|
||||
@@ -0,0 +1,142 @@
|
||||
/*global wc_geolocation_params */
|
||||
jQuery( function( $ ) {
|
||||
/**
|
||||
* Contains the current geo hash (or false if the hash
|
||||
* is not set/cannot be determined).
|
||||
*
|
||||
* @type {boolean|string}
|
||||
*/
|
||||
var geo_hash = false;
|
||||
|
||||
/**
|
||||
* Obtains the current geo hash from the `woocommerce_geo_hash` cookie, if set.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function get_geo_hash() {
|
||||
var geo_hash_cookie = Cookies.get( 'woocommerce_geo_hash' );
|
||||
|
||||
if ( 'string' === typeof geo_hash_cookie && geo_hash_cookie.length ) {
|
||||
geo_hash = geo_hash_cookie;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If we have an active geo hash value but it does not match the `?v=` query var in
|
||||
* current page URL, that indicates that we need to refresh the page.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function needs_refresh() {
|
||||
return geo_hash && ( new URLSearchParams( window.location.search ) ).get( 'v' ) !== geo_hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends (or replaces) the geo hash used for links on the current page.
|
||||
*/
|
||||
var $append_hashes = function() {
|
||||
if ( ! geo_hash ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$( 'a[href^="' + wc_geolocation_params.home_url + '"]:not(a[href*="v="]), a[href^="/"]:not(a[href*="v="])' ).each( function() {
|
||||
var $this = $( this ),
|
||||
href = $this.attr( 'href' ),
|
||||
href_parts = href.split( '#' );
|
||||
|
||||
href = href_parts[0];
|
||||
|
||||
if ( href.indexOf( '?' ) > 0 ) {
|
||||
href = href + '&v=' + geo_hash;
|
||||
} else {
|
||||
href = href + '?v=' + geo_hash;
|
||||
}
|
||||
|
||||
if ( typeof href_parts[1] !== 'undefined' && href_parts[1] !== null ) {
|
||||
href = href + '#' + href_parts[1];
|
||||
}
|
||||
|
||||
$this.attr( 'href', href );
|
||||
});
|
||||
};
|
||||
|
||||
var $geolocate_customer = {
|
||||
url: wc_geolocation_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'get_customer_location' ),
|
||||
type: 'GET',
|
||||
success: function( response ) {
|
||||
if ( response.success && response.data.hash && response.data.hash !== geo_hash ) {
|
||||
$geolocation_redirect( response.data.hash );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Once we have a new hash, we redirect so a new version of the current page
|
||||
* (with correct pricing for the current region, etc) is displayed.
|
||||
*
|
||||
* @param {string} hash
|
||||
*/
|
||||
var $geolocation_redirect = function( hash ) {
|
||||
// Updates our (cookie-based) cache of the hash value. Expires in 1 hour.
|
||||
Cookies.set( 'woocommerce_geo_hash', hash, { expires: 1 / 24 } );
|
||||
|
||||
const urlQuery = new URL( window.location ).searchParams;
|
||||
const existingHash = urlQuery.get( 'v' );
|
||||
|
||||
// If the current URL does not contain the expected hash, redirect.
|
||||
if ( existingHash !== hash ) {
|
||||
urlQuery.set( 'v', hash );
|
||||
window.location.search = '?' + urlQuery.toString();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates any forms on the page so they use the current geo hash.
|
||||
*/
|
||||
function update_forms() {
|
||||
if ( ! geo_hash ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$( 'form' ).each( function () {
|
||||
var $this = $( this );
|
||||
var method = $this.attr( 'method' );
|
||||
var hasField = $this.find( 'input[name="v"]' ).length > 0;
|
||||
|
||||
if ( method && 'get' === method.toLowerCase() && ! hasField ) {
|
||||
$this.append( '<input type="hidden" name="v" value="' + geo_hash + '" />' );
|
||||
} else {
|
||||
var href = $this.attr( 'action' );
|
||||
if ( href ) {
|
||||
if ( href.indexOf( '?' ) > 0 ) {
|
||||
$this.attr( 'action', href + '&v=' + geo_hash );
|
||||
} else {
|
||||
$this.attr( 'action', href + '?v=' + geo_hash );
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Get the current geo hash. If it doesn't exist, or if it doesn't match the current
|
||||
// page URL, perform a geolocation request.
|
||||
if ( ! get_geo_hash() || needs_refresh() ) {
|
||||
$.ajax( $geolocate_customer );
|
||||
}
|
||||
|
||||
// Page updates.
|
||||
update_forms();
|
||||
$append_hashes();
|
||||
|
||||
$( document.body ).on( 'added_to_cart', function() {
|
||||
$append_hashes();
|
||||
});
|
||||
|
||||
// Enable user to trigger manual append hashes on AJAX operations
|
||||
$( document.body ).on( 'woocommerce_append_geo_hashes', function() {
|
||||
$append_hashes();
|
||||
});
|
||||
});
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/geolocation.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/geolocation.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(function(e){var t=!1;var o,a=function(){t&&e('a[href^="'+wc_geolocation_params.home_url+'"]:not(a[href*="v="]), a[href^="/"]:not(a[href*="v="])').each(function(){var o=e(this),a=o.attr("href"),n=a.split("#");a=(a=n[0]).indexOf("?")>0?a+"&v="+t:a+"?v="+t,"undefined"!=typeof n[1]&&null!==n[1]&&(a=a+"#"+n[1]),o.attr("href",a)})},n={url:wc_geolocation_params.wc_ajax_url.toString().replace("%%endpoint%%","get_customer_location"),type:"GET",success:function(e){e.success&&e.data.hash&&e.data.hash!==t&&c(e.data.hash)}},c=function(e){Cookies.set("woocommerce_geo_hash",e,{expires:1/24});const t=new URL(window.location).searchParams;t.get("v")!==e&&(t.set("v",e),window.location.search="?"+t.toString())};("string"!=typeof(o=Cookies.get("woocommerce_geo_hash"))||!o.length||(t=o,0)||t&&new URLSearchParams(window.location.search).get("v")!==t)&&e.ajax(n),t&&e("form").each(function(){var o=e(this),a=o.attr("method"),n=o.find('input[name="v"]').length>0;if(a&&"get"===a.toLowerCase()&&!n)o.append('<input type="hidden" name="v" value="'+t+'" />');else{var c=o.attr("action");c&&(c.indexOf("?")>0?o.attr("action",c+"&v="+t):o.attr("action",c+"?v="+t))}}),a(),e(document.body).on("added_to_cart",function(){a()}),e(document.body).on("woocommerce_append_geo_hashes",function(){a()})});
|
||||
@@ -0,0 +1,5 @@
|
||||
jQuery( function( $ ) {
|
||||
$( '.lost_reset_password' ).on( 'submit', function () {
|
||||
$( 'button[type="submit"]', this ).attr( 'disabled', 'disabled' );
|
||||
});
|
||||
});
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/lost-password.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/lost-password.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(function(t){t(".lost_reset_password").on("submit",function(){t('button[type="submit"]',this).attr("disabled","disabled")})});
|
||||
@@ -0,0 +1,132 @@
|
||||
/* global wp, pwsL10n, wc_password_strength_meter_params */
|
||||
( function( $ ) {
|
||||
'use strict';
|
||||
/**
|
||||
* Password Strength Meter class.
|
||||
*/
|
||||
var wc_password_strength_meter = {
|
||||
|
||||
/**
|
||||
* Initialize strength meter actions.
|
||||
*/
|
||||
init: function() {
|
||||
$( document.body )
|
||||
.on(
|
||||
'keyup change',
|
||||
'form.register #reg_password, form.checkout #account_password, ' +
|
||||
'form.edit-account #password_1, form.lost_reset_password #password_1',
|
||||
this.strengthMeter
|
||||
);
|
||||
$( 'form.checkout #createaccount' ).trigger( 'change' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Strength Meter.
|
||||
*/
|
||||
strengthMeter: function() {
|
||||
var wrapper = $( 'form.register, form.checkout, form.edit-account, form.lost_reset_password' ),
|
||||
submit = $( 'button[type="submit"]', wrapper ),
|
||||
field = $( '#reg_password, #account_password, #password_1', wrapper ),
|
||||
strength = 1,
|
||||
fieldValue = field.val(),
|
||||
stop_checkout = ! wrapper.is( 'form.checkout' ); // By default is disabled on checkout.
|
||||
|
||||
wc_password_strength_meter.includeMeter( wrapper, field );
|
||||
|
||||
strength = wc_password_strength_meter.checkPasswordStrength( wrapper, field );
|
||||
|
||||
// Allow password strength meter stop checkout.
|
||||
if ( wc_password_strength_meter_params.stop_checkout ) {
|
||||
stop_checkout = true;
|
||||
}
|
||||
|
||||
if (
|
||||
fieldValue.length > 0 &&
|
||||
strength < wc_password_strength_meter_params.min_password_strength &&
|
||||
-1 !== strength &&
|
||||
stop_checkout
|
||||
) {
|
||||
submit.attr( 'disabled', 'disabled' ).addClass( 'disabled' );
|
||||
} else {
|
||||
submit.prop( 'disabled', false ).removeClass( 'disabled' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Include meter HTML.
|
||||
*
|
||||
* @param {Object} wrapper
|
||||
* @param {Object} field
|
||||
*/
|
||||
includeMeter: function( wrapper, field ) {
|
||||
var meter = wrapper.find( '.woocommerce-password-strength' );
|
||||
|
||||
if ( '' === field.val() ) {
|
||||
meter.hide();
|
||||
$( document.body ).trigger( 'wc-password-strength-hide' );
|
||||
} else if ( 0 === meter.length ) {
|
||||
field.after( '<div class="woocommerce-password-strength" aria-live="polite"></div>' );
|
||||
$( document.body ).trigger( 'wc-password-strength-added' );
|
||||
} else {
|
||||
meter.show();
|
||||
$( document.body ).trigger( 'wc-password-strength-show' );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Check password strength.
|
||||
*
|
||||
* @param {Object} field
|
||||
*
|
||||
* @return {Int}
|
||||
*/
|
||||
checkPasswordStrength: function( wrapper, field ) {
|
||||
var meter = wrapper.find( '.woocommerce-password-strength' ),
|
||||
hint = wrapper.find( '.woocommerce-password-hint' ),
|
||||
hint_html = '<small class="woocommerce-password-hint">' + wc_password_strength_meter_params.i18n_password_hint + '</small>',
|
||||
strength = wp.passwordStrength.meter( field.val(), wp.passwordStrength.userInputDisallowedList() ),
|
||||
error = '';
|
||||
|
||||
// Reset.
|
||||
meter.removeClass( 'short bad good strong' );
|
||||
hint.remove();
|
||||
|
||||
if ( meter.is( ':hidden' ) ) {
|
||||
return strength;
|
||||
}
|
||||
|
||||
// Error to append
|
||||
if ( strength < wc_password_strength_meter_params.min_password_strength ) {
|
||||
error = ' - ' + wc_password_strength_meter_params.i18n_password_error;
|
||||
}
|
||||
|
||||
switch ( strength ) {
|
||||
case 0 :
|
||||
meter.addClass( 'short' ).html( pwsL10n['short'] + error );
|
||||
meter.after( hint_html );
|
||||
break;
|
||||
case 1 :
|
||||
meter.addClass( 'bad' ).html( pwsL10n.bad + error );
|
||||
meter.after( hint_html );
|
||||
break;
|
||||
case 2 :
|
||||
meter.addClass( 'bad' ).html( pwsL10n.bad + error );
|
||||
meter.after( hint_html );
|
||||
break;
|
||||
case 3 :
|
||||
meter.addClass( 'good' ).html( pwsL10n.good + error );
|
||||
break;
|
||||
case 4 :
|
||||
meter.addClass( 'strong' ).html( pwsL10n.strong + error );
|
||||
break;
|
||||
case 5 :
|
||||
meter.addClass( 'short' ).html( pwsL10n.mismatch );
|
||||
break;
|
||||
}
|
||||
|
||||
return strength;
|
||||
}
|
||||
};
|
||||
|
||||
wc_password_strength_meter.init();
|
||||
})( jQuery );
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/password-strength-meter.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/password-strength-meter.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(s){"use strict";var r={init:function(){s(document.body).on("keyup change","form.register #reg_password, form.checkout #account_password, form.edit-account #password_1, form.lost_reset_password #password_1",this.strengthMeter),s("form.checkout #createaccount").trigger("change")},strengthMeter:function(){var e,t=s("form.register, form.checkout, form.edit-account, form.lost_reset_password"),o=s('button[type="submit"]',t),a=s("#reg_password, #account_password, #password_1",t),d=a.val(),n=!t.is("form.checkout");r.includeMeter(t,a),e=r.checkPasswordStrength(t,a),wc_password_strength_meter_params.stop_checkout&&(n=!0),d.length>0&&e<wc_password_strength_meter_params.min_password_strength&&-1!==e&&n?o.attr("disabled","disabled").addClass("disabled"):o.prop("disabled",!1).removeClass("disabled")},includeMeter:function(r,e){var t=r.find(".woocommerce-password-strength");""===e.val()?(t.hide(),s(document.body).trigger("wc-password-strength-hide")):0===t.length?(e.after('<div class="woocommerce-password-strength" aria-live="polite"></div>'),s(document.body).trigger("wc-password-strength-added")):(t.show(),s(document.body).trigger("wc-password-strength-show"))},checkPasswordStrength:function(s,r){var e=s.find(".woocommerce-password-strength"),t=s.find(".woocommerce-password-hint"),o='<small class="woocommerce-password-hint">'+wc_password_strength_meter_params.i18n_password_hint+"</small>",a=wp.passwordStrength.meter(r.val(),wp.passwordStrength.userInputDisallowedList()),d="";if(e.removeClass("short bad good strong"),t.remove(),e.is(":hidden"))return a;switch(a<wc_password_strength_meter_params.min_password_strength&&(d=" - "+wc_password_strength_meter_params.i18n_password_error),a){case 0:e.addClass("short").html(pwsL10n.short+d),e.after(o);break;case 1:case 2:e.addClass("bad").html(pwsL10n.bad+d),e.after(o);break;case 3:e.addClass("good").html(pwsL10n.good+d);break;case 4:e.addClass("strong").html(pwsL10n.strong+d);break;case 5:e.addClass("short").html(pwsL10n.mismatch)}return a}};r.init()}(jQuery);
|
||||
@@ -0,0 +1,83 @@
|
||||
/* global woocommerce_price_slider_params, accounting */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
// woocommerce_price_slider_params is required to continue, ensure the object exists
|
||||
if ( typeof woocommerce_price_slider_params === 'undefined' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$( document.body ).on( 'price_slider_create price_slider_slide', function( event, min, max ) {
|
||||
|
||||
$( '.price_slider_amount span.from' ).html( accounting.formatMoney( min, {
|
||||
symbol: woocommerce_price_slider_params.currency_format_symbol,
|
||||
decimal: woocommerce_price_slider_params.currency_format_decimal_sep,
|
||||
thousand: woocommerce_price_slider_params.currency_format_thousand_sep,
|
||||
precision: woocommerce_price_slider_params.currency_format_num_decimals,
|
||||
format: woocommerce_price_slider_params.currency_format
|
||||
} ) );
|
||||
|
||||
$( '.price_slider_amount span.to' ).html( accounting.formatMoney( max, {
|
||||
symbol: woocommerce_price_slider_params.currency_format_symbol,
|
||||
decimal: woocommerce_price_slider_params.currency_format_decimal_sep,
|
||||
thousand: woocommerce_price_slider_params.currency_format_thousand_sep,
|
||||
precision: woocommerce_price_slider_params.currency_format_num_decimals,
|
||||
format: woocommerce_price_slider_params.currency_format
|
||||
} ) );
|
||||
|
||||
$( document.body ).trigger( 'price_slider_updated', [ min, max ] );
|
||||
});
|
||||
|
||||
function init_price_filter() {
|
||||
$( 'input#min_price, input#max_price' ).hide();
|
||||
$( '.price_slider, .price_label' ).show();
|
||||
|
||||
var min_price = $( '.price_slider_amount #min_price' ).data( 'min' ),
|
||||
max_price = $( '.price_slider_amount #max_price' ).data( 'max' ),
|
||||
step = $( '.price_slider_amount' ).data( 'step' ) || 1,
|
||||
current_min_price = $( '.price_slider_amount #min_price' ).val(),
|
||||
current_max_price = $( '.price_slider_amount #max_price' ).val();
|
||||
|
||||
$( '.price_slider:not(.ui-slider)' ).slider({
|
||||
range: true,
|
||||
animate: true,
|
||||
min: min_price,
|
||||
max: max_price,
|
||||
step: step,
|
||||
values: [ current_min_price, current_max_price ],
|
||||
create: function() {
|
||||
|
||||
$( '.price_slider_amount #min_price' ).val( current_min_price );
|
||||
$( '.price_slider_amount #max_price' ).val( current_max_price );
|
||||
|
||||
$( document.body ).trigger( 'price_slider_create', [ current_min_price, current_max_price ] );
|
||||
},
|
||||
slide: function( event, ui ) {
|
||||
|
||||
$( 'input#min_price' ).val( ui.values[0] );
|
||||
$( 'input#max_price' ).val( ui.values[1] );
|
||||
|
||||
$( document.body ).trigger( 'price_slider_slide', [ ui.values[0], ui.values[1] ] );
|
||||
},
|
||||
change: function( event, ui ) {
|
||||
|
||||
$( document.body ).trigger( 'price_slider_change', [ ui.values[0], ui.values[1] ] );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
init_price_filter();
|
||||
$( document.body ).on( 'init_price_filter', init_price_filter );
|
||||
|
||||
var hasSelectiveRefresh = (
|
||||
'undefined' !== typeof wp &&
|
||||
wp.customize &&
|
||||
wp.customize.selectiveRefresh &&
|
||||
wp.customize.widgetsPreview &&
|
||||
wp.customize.widgetsPreview.WidgetPartial
|
||||
);
|
||||
if ( hasSelectiveRefresh ) {
|
||||
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
|
||||
init_price_filter();
|
||||
} );
|
||||
}
|
||||
});
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/price-slider.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/price-slider.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(function(e){if("undefined"==typeof woocommerce_price_slider_params)return!1;function r(){e("input#min_price, input#max_price").hide(),e(".price_slider, .price_label").show();var r=e(".price_slider_amount #min_price").data("min"),i=e(".price_slider_amount #max_price").data("max"),c=e(".price_slider_amount").data("step")||1,o=e(".price_slider_amount #min_price").val(),_=e(".price_slider_amount #max_price").val();e(".price_slider:not(.ui-slider)").slider({range:!0,animate:!0,min:r,max:i,step:c,values:[o,_],create:function(){e(".price_slider_amount #min_price").val(o),e(".price_slider_amount #max_price").val(_),e(document.body).trigger("price_slider_create",[o,_])},slide:function(r,i){e("input#min_price").val(i.values[0]),e("input#max_price").val(i.values[1]),e(document.body).trigger("price_slider_slide",[i.values[0],i.values[1]])},change:function(r,i){e(document.body).trigger("price_slider_change",[i.values[0],i.values[1]])}})}e(document.body).on("price_slider_create price_slider_slide",function(r,i,c){e(".price_slider_amount span.from").html(accounting.formatMoney(i,{symbol:woocommerce_price_slider_params.currency_format_symbol,decimal:woocommerce_price_slider_params.currency_format_decimal_sep,thousand:woocommerce_price_slider_params.currency_format_thousand_sep,precision:woocommerce_price_slider_params.currency_format_num_decimals,format:woocommerce_price_slider_params.currency_format})),e(".price_slider_amount span.to").html(accounting.formatMoney(c,{symbol:woocommerce_price_slider_params.currency_format_symbol,decimal:woocommerce_price_slider_params.currency_format_decimal_sep,thousand:woocommerce_price_slider_params.currency_format_thousand_sep,precision:woocommerce_price_slider_params.currency_format_num_decimals,format:woocommerce_price_slider_params.currency_format})),e(document.body).trigger("price_slider_updated",[i,c])}),r(),e(document.body).on("init_price_filter",r),"undefined"!=typeof wp&&wp.customize&&wp.customize.selectiveRefresh&&wp.customize.widgetsPreview&&wp.customize.widgetsPreview.WidgetPartial&&wp.customize.selectiveRefresh.bind("partial-content-rendered",function(){r()})});
|
||||
@@ -0,0 +1,346 @@
|
||||
/*global wc_single_product_params, PhotoSwipe, PhotoSwipeUI_Default */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
// wc_single_product_params is required to continue.
|
||||
if ( typeof wc_single_product_params === 'undefined' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$( 'body' )
|
||||
// Tabs
|
||||
.on( 'init', '.wc-tabs-wrapper, .woocommerce-tabs', function() {
|
||||
$( this ).find( '.wc-tab, .woocommerce-tabs .panel:not(.panel .panel)' ).hide();
|
||||
|
||||
var hash = window.location.hash;
|
||||
var url = window.location.href;
|
||||
var $tabs = $( this ).find( '.wc-tabs, ul.tabs' ).first();
|
||||
|
||||
if ( hash.toLowerCase().indexOf( 'comment-' ) >= 0 || hash === '#reviews' || hash === '#tab-reviews' ) {
|
||||
$tabs.find( 'li.reviews_tab a' ).trigger( 'click' );
|
||||
} else if ( url.indexOf( 'comment-page-' ) > 0 || url.indexOf( 'cpage=' ) > 0 ) {
|
||||
$tabs.find( 'li.reviews_tab a' ).trigger( 'click' );
|
||||
} else if ( hash === '#tab-additional_information' ) {
|
||||
$tabs.find( 'li.additional_information_tab a' ).trigger( 'click' );
|
||||
} else {
|
||||
$tabs.find( 'li:first a' ).trigger( 'click' );
|
||||
}
|
||||
} )
|
||||
.on( 'click', '.wc-tabs li a, ul.tabs li a', function( e ) {
|
||||
e.preventDefault();
|
||||
var $tab = $( this );
|
||||
var $tabs_wrapper = $tab.closest( '.wc-tabs-wrapper, .woocommerce-tabs' );
|
||||
var $tabs = $tabs_wrapper.find( '.wc-tabs, ul.tabs' );
|
||||
|
||||
$tabs.find( 'li' ).removeClass( 'active' );
|
||||
$tabs_wrapper.find( '.wc-tab, .panel:not(.panel .panel)' ).hide();
|
||||
|
||||
$tab.closest( 'li' ).addClass( 'active' );
|
||||
$tabs_wrapper.find( '#' + $tab.attr( 'href' ).split( '#' )[1] ).show();
|
||||
} )
|
||||
// Review link
|
||||
.on( 'click', 'a.woocommerce-review-link', function() {
|
||||
$( '.reviews_tab a' ).trigger( 'click' );
|
||||
return true;
|
||||
} )
|
||||
// Star ratings for comments
|
||||
.on( 'init', '#rating', function() {
|
||||
$( '#rating' )
|
||||
.hide()
|
||||
.before(
|
||||
'<p class="stars">\
|
||||
<span>\
|
||||
<a class="star-1" href="#">1</a>\
|
||||
<a class="star-2" href="#">2</a>\
|
||||
<a class="star-3" href="#">3</a>\
|
||||
<a class="star-4" href="#">4</a>\
|
||||
<a class="star-5" href="#">5</a>\
|
||||
</span>\
|
||||
</p>'
|
||||
);
|
||||
} )
|
||||
.on( 'click', '#respond p.stars a', function() {
|
||||
var $star = $( this ),
|
||||
$rating = $( this ).closest( '#respond' ).find( '#rating' ),
|
||||
$container = $( this ).closest( '.stars' );
|
||||
|
||||
$rating.val( $star.text() );
|
||||
$star.siblings( 'a' ).removeClass( 'active' );
|
||||
$star.addClass( 'active' );
|
||||
$container.addClass( 'selected' );
|
||||
|
||||
return false;
|
||||
} )
|
||||
.on( 'click', '#respond #submit', function() {
|
||||
var $rating = $( this ).closest( '#respond' ).find( '#rating' ),
|
||||
rating = $rating.val();
|
||||
|
||||
if ( $rating.length > 0 && ! rating && wc_single_product_params.review_rating_required === 'yes' ) {
|
||||
window.alert( wc_single_product_params.i18n_required_rating_text );
|
||||
|
||||
return false;
|
||||
}
|
||||
} );
|
||||
|
||||
// Init Tabs and Star Ratings
|
||||
$( '.wc-tabs-wrapper, .woocommerce-tabs, #rating' ).trigger( 'init' );
|
||||
|
||||
/**
|
||||
* Product gallery class.
|
||||
*/
|
||||
var ProductGallery = function( $target, args ) {
|
||||
this.$target = $target;
|
||||
this.$images = $( '.woocommerce-product-gallery__image', $target );
|
||||
|
||||
// No images? Abort.
|
||||
if ( 0 === this.$images.length ) {
|
||||
this.$target.css( 'opacity', 1 );
|
||||
return;
|
||||
}
|
||||
|
||||
// Make this object available.
|
||||
$target.data( 'product_gallery', this );
|
||||
|
||||
// Pick functionality to initialize...
|
||||
this.flexslider_enabled = 'function' === typeof $.fn.flexslider && wc_single_product_params.flexslider_enabled;
|
||||
this.zoom_enabled = 'function' === typeof $.fn.zoom && wc_single_product_params.zoom_enabled;
|
||||
this.photoswipe_enabled = typeof PhotoSwipe !== 'undefined' && wc_single_product_params.photoswipe_enabled;
|
||||
|
||||
// ...also taking args into account.
|
||||
if ( args ) {
|
||||
this.flexslider_enabled = false === args.flexslider_enabled ? false : this.flexslider_enabled;
|
||||
this.zoom_enabled = false === args.zoom_enabled ? false : this.zoom_enabled;
|
||||
this.photoswipe_enabled = false === args.photoswipe_enabled ? false : this.photoswipe_enabled;
|
||||
}
|
||||
|
||||
// ...and what is in the gallery.
|
||||
if ( 1 === this.$images.length ) {
|
||||
this.flexslider_enabled = false;
|
||||
}
|
||||
|
||||
// Bind functions to this.
|
||||
this.initFlexslider = this.initFlexslider.bind( this );
|
||||
this.initZoom = this.initZoom.bind( this );
|
||||
this.initZoomForTarget = this.initZoomForTarget.bind( this );
|
||||
this.initPhotoswipe = this.initPhotoswipe.bind( this );
|
||||
this.onResetSlidePosition = this.onResetSlidePosition.bind( this );
|
||||
this.getGalleryItems = this.getGalleryItems.bind( this );
|
||||
this.openPhotoswipe = this.openPhotoswipe.bind( this );
|
||||
|
||||
if ( this.flexslider_enabled ) {
|
||||
this.initFlexslider( args.flexslider );
|
||||
$target.on( 'woocommerce_gallery_reset_slide_position', this.onResetSlidePosition );
|
||||
} else {
|
||||
this.$target.css( 'opacity', 1 );
|
||||
}
|
||||
|
||||
if ( this.zoom_enabled ) {
|
||||
this.initZoom();
|
||||
$target.on( 'woocommerce_gallery_init_zoom', this.initZoom );
|
||||
}
|
||||
|
||||
if ( this.photoswipe_enabled ) {
|
||||
this.initPhotoswipe();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize flexSlider.
|
||||
*/
|
||||
ProductGallery.prototype.initFlexslider = function( args ) {
|
||||
var $target = this.$target,
|
||||
gallery = this;
|
||||
|
||||
var options = $.extend( {
|
||||
selector: '.woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image',
|
||||
start: function() {
|
||||
$target.css( 'opacity', 1 );
|
||||
},
|
||||
after: function( slider ) {
|
||||
gallery.initZoomForTarget( gallery.$images.eq( slider.currentSlide ) );
|
||||
}
|
||||
}, args );
|
||||
|
||||
$target.flexslider( options );
|
||||
|
||||
// Trigger resize after main image loads to ensure correct gallery size.
|
||||
$( '.woocommerce-product-gallery__wrapper .woocommerce-product-gallery__image:eq(0) .wp-post-image' ).one( 'load', function() {
|
||||
var $image = $( this );
|
||||
|
||||
if ( $image ) {
|
||||
setTimeout( function() {
|
||||
var setHeight = $image.closest( '.woocommerce-product-gallery__image' ).height();
|
||||
var $viewport = $image.closest( '.flex-viewport' );
|
||||
|
||||
if ( setHeight && $viewport ) {
|
||||
$viewport.height( setHeight );
|
||||
}
|
||||
}, 100 );
|
||||
}
|
||||
} ).each( function() {
|
||||
if ( this.complete ) {
|
||||
$( this ).trigger( 'load' );
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Init zoom.
|
||||
*/
|
||||
ProductGallery.prototype.initZoom = function() {
|
||||
this.initZoomForTarget( this.$images.first() );
|
||||
};
|
||||
|
||||
/**
|
||||
* Init zoom.
|
||||
*/
|
||||
ProductGallery.prototype.initZoomForTarget = function( zoomTarget ) {
|
||||
if ( ! this.zoom_enabled ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var galleryWidth = this.$target.width(),
|
||||
zoomEnabled = false;
|
||||
|
||||
$( zoomTarget ).each( function( index, target ) {
|
||||
var image = $( target ).find( 'img' );
|
||||
|
||||
if ( image.data( 'large_image_width' ) > galleryWidth ) {
|
||||
zoomEnabled = true;
|
||||
return false;
|
||||
}
|
||||
} );
|
||||
|
||||
// But only zoom if the img is larger than its container.
|
||||
if ( zoomEnabled ) {
|
||||
var zoom_options = $.extend( {
|
||||
touch: false
|
||||
}, wc_single_product_params.zoom_options );
|
||||
|
||||
if ( 'ontouchstart' in document.documentElement ) {
|
||||
zoom_options.on = 'click';
|
||||
}
|
||||
|
||||
zoomTarget.trigger( 'zoom.destroy' );
|
||||
zoomTarget.zoom( zoom_options );
|
||||
|
||||
setTimeout( function() {
|
||||
if ( zoomTarget.find(':hover').length ) {
|
||||
zoomTarget.trigger( 'mouseover' );
|
||||
}
|
||||
}, 100 );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Init PhotoSwipe.
|
||||
*/
|
||||
ProductGallery.prototype.initPhotoswipe = function() {
|
||||
if ( this.zoom_enabled && this.$images.length > 0 ) {
|
||||
this.$target.prepend( '<a href="#" class="woocommerce-product-gallery__trigger">🔍</a>' );
|
||||
this.$target.on( 'click', '.woocommerce-product-gallery__trigger', this.openPhotoswipe );
|
||||
this.$target.on( 'click', '.woocommerce-product-gallery__image a', function( e ) {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
// If flexslider is disabled, gallery images also need to trigger photoswipe on click.
|
||||
if ( ! this.flexslider_enabled ) {
|
||||
this.$target.on( 'click', '.woocommerce-product-gallery__image a', this.openPhotoswipe );
|
||||
}
|
||||
} else {
|
||||
this.$target.on( 'click', '.woocommerce-product-gallery__image a', this.openPhotoswipe );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset slide position to 0.
|
||||
*/
|
||||
ProductGallery.prototype.onResetSlidePosition = function() {
|
||||
this.$target.flexslider( 0 );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get product gallery image items.
|
||||
*/
|
||||
ProductGallery.prototype.getGalleryItems = function() {
|
||||
var $slides = this.$images,
|
||||
items = [];
|
||||
|
||||
if ( $slides.length > 0 ) {
|
||||
$slides.each( function( i, el ) {
|
||||
var img = $( el ).find( 'img' );
|
||||
|
||||
if ( img.length ) {
|
||||
var large_image_src = img.attr( 'data-large_image' ),
|
||||
large_image_w = img.attr( 'data-large_image_width' ),
|
||||
large_image_h = img.attr( 'data-large_image_height' ),
|
||||
alt = img.attr( 'alt' ),
|
||||
item = {
|
||||
alt : alt,
|
||||
src : large_image_src,
|
||||
w : large_image_w,
|
||||
h : large_image_h,
|
||||
title: img.attr( 'data-caption' ) ? img.attr( 'data-caption' ) : img.attr( 'title' )
|
||||
};
|
||||
items.push( item );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
return items;
|
||||
};
|
||||
|
||||
/**
|
||||
* Open photoswipe modal.
|
||||
*/
|
||||
ProductGallery.prototype.openPhotoswipe = function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
var pswpElement = $( '.pswp' )[0],
|
||||
items = this.getGalleryItems(),
|
||||
eventTarget = $( e.target ),
|
||||
clicked;
|
||||
|
||||
if ( 0 < eventTarget.closest( '.woocommerce-product-gallery__trigger' ).length ) {
|
||||
clicked = this.$target.find( '.flex-active-slide' );
|
||||
} else {
|
||||
clicked = eventTarget.closest( '.woocommerce-product-gallery__image' );
|
||||
}
|
||||
|
||||
var options = $.extend( {
|
||||
index: $( clicked ).index(),
|
||||
addCaptionHTMLFn: function( item, captionEl ) {
|
||||
if ( ! item.title ) {
|
||||
captionEl.children[0].textContent = '';
|
||||
return false;
|
||||
}
|
||||
captionEl.children[0].textContent = item.title;
|
||||
return true;
|
||||
}
|
||||
}, wc_single_product_params.photoswipe_options );
|
||||
|
||||
// Initializes and opens PhotoSwipe.
|
||||
var photoswipe = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, items, options );
|
||||
photoswipe.init();
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to call wc_product_gallery on jquery selector.
|
||||
*/
|
||||
$.fn.wc_product_gallery = function( args ) {
|
||||
new ProductGallery( this, args || wc_single_product_params );
|
||||
return this;
|
||||
};
|
||||
|
||||
/*
|
||||
* Initialize all galleries on page.
|
||||
*/
|
||||
$( '.woocommerce-product-gallery' ).each( function() {
|
||||
|
||||
$( this ).trigger( 'wc-product-gallery-before-init', [ this, wc_single_product_params ] );
|
||||
|
||||
$( this ).wc_product_gallery( wc_single_product_params );
|
||||
|
||||
$( this ).trigger( 'wc-product-gallery-after-init', [ this, wc_single_product_params ] );
|
||||
|
||||
} );
|
||||
} );
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/single-product.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/single-product.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,117 @@
|
||||
/*global wc_tokenization_form_params */
|
||||
jQuery( function( $ ) {
|
||||
|
||||
/**
|
||||
* WCTokenizationForm class.
|
||||
*/
|
||||
var TokenizationForm = function( $target ) {
|
||||
this.$target = $target;
|
||||
this.$formWrap = $target.closest( '.payment_box' );
|
||||
|
||||
// Params.
|
||||
this.params = $.extend( {}, {
|
||||
'is_registration_required': false,
|
||||
'is_logged_in' : false
|
||||
}, wc_tokenization_form_params );
|
||||
|
||||
// Bind functions to this.
|
||||
this.onDisplay = this.onDisplay.bind( this );
|
||||
this.hideForm = this.hideForm.bind( this );
|
||||
this.showForm = this.showForm.bind( this );
|
||||
this.showSaveNewCheckbox = this.showSaveNewCheckbox.bind( this );
|
||||
this.hideSaveNewCheckbox = this.hideSaveNewCheckbox.bind( this );
|
||||
|
||||
// When a radio button is changed, make sure to show/hide our new CC info area.
|
||||
this.$target.on(
|
||||
'click change',
|
||||
':input.woocommerce-SavedPaymentMethods-tokenInput',
|
||||
{ tokenizationForm: this },
|
||||
this.onTokenChange
|
||||
);
|
||||
|
||||
// OR if create account is checked.
|
||||
$( 'input#createaccount' ).on( 'change', { tokenizationForm: this }, this.onCreateAccountChange );
|
||||
|
||||
// First display.
|
||||
this.onDisplay();
|
||||
};
|
||||
|
||||
TokenizationForm.prototype.onDisplay = function() {
|
||||
// Make sure a radio button is selected if there is no is_default for this payment method..
|
||||
if ( 0 === $( ':input.woocommerce-SavedPaymentMethods-tokenInput:checked', this.$target ).length ) {
|
||||
$( ':input.woocommerce-SavedPaymentMethods-tokenInput:last', this.$target ).prop( 'checked', true );
|
||||
}
|
||||
|
||||
// Don't show the "use new" radio button if we only have one method..
|
||||
if ( 0 === this.$target.data( 'count' ) ) {
|
||||
$( '.woocommerce-SavedPaymentMethods-new', this.$target ).remove();
|
||||
}
|
||||
|
||||
// Hide "save card" if "Create Account" is not checked and registration is not forced.
|
||||
var hasCreateAccountCheckbox = 0 < $( 'input#createaccount' ).length,
|
||||
createAccount = hasCreateAccountCheckbox && $( 'input#createaccount' ).is( ':checked' );
|
||||
|
||||
if ( createAccount || this.params.is_logged_in || this.params.is_registration_required ) {
|
||||
this.showSaveNewCheckbox();
|
||||
} else {
|
||||
this.hideSaveNewCheckbox();
|
||||
}
|
||||
|
||||
// Trigger change event
|
||||
$( ':input.woocommerce-SavedPaymentMethods-tokenInput:checked', this.$target ).trigger( 'change' );
|
||||
};
|
||||
|
||||
TokenizationForm.prototype.onTokenChange = function( event ) {
|
||||
if ( 'new' === $( this ).val() ) {
|
||||
event.data.tokenizationForm.showForm();
|
||||
event.data.tokenizationForm.showSaveNewCheckbox();
|
||||
} else {
|
||||
event.data.tokenizationForm.hideForm();
|
||||
event.data.tokenizationForm.hideSaveNewCheckbox();
|
||||
}
|
||||
};
|
||||
|
||||
TokenizationForm.prototype.onCreateAccountChange = function( event ) {
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
event.data.tokenizationForm.showSaveNewCheckbox();
|
||||
} else {
|
||||
event.data.tokenizationForm.hideSaveNewCheckbox();
|
||||
}
|
||||
};
|
||||
|
||||
TokenizationForm.prototype.hideForm = function() {
|
||||
$( '.wc-payment-form', this.$formWrap ).hide();
|
||||
};
|
||||
|
||||
TokenizationForm.prototype.showForm = function() {
|
||||
$( '.wc-payment-form', this.$formWrap ).show();
|
||||
};
|
||||
|
||||
TokenizationForm.prototype.showSaveNewCheckbox = function() {
|
||||
$( '.woocommerce-SavedPaymentMethods-saveNew', this.$formWrap ).show();
|
||||
};
|
||||
|
||||
TokenizationForm.prototype.hideSaveNewCheckbox = function() {
|
||||
$( '.woocommerce-SavedPaymentMethods-saveNew', this.$formWrap ).hide();
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to call wc_product_gallery on jquery selector.
|
||||
*/
|
||||
$.fn.wc_tokenization_form = function( args ) {
|
||||
new TokenizationForm( this, args );
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
*/
|
||||
$( document.body ).on( 'updated_checkout wc-credit-card-form-init', function() {
|
||||
// Loop over gateways with saved payment methods
|
||||
var $saved_payment_methods = $( 'ul.woocommerce-SavedPaymentMethods' );
|
||||
|
||||
$saved_payment_methods.each( function() {
|
||||
$( this ).wc_tokenization_form();
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/tokenization-form.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/tokenization-form.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jQuery(function(e){var t=function(t){this.$target=t,this.$formWrap=t.closest(".payment_box"),this.params=e.extend({},{is_registration_required:!1,is_logged_in:!1},wc_tokenization_form_params),this.onDisplay=this.onDisplay.bind(this),this.hideForm=this.hideForm.bind(this),this.showForm=this.showForm.bind(this),this.showSaveNewCheckbox=this.showSaveNewCheckbox.bind(this),this.hideSaveNewCheckbox=this.hideSaveNewCheckbox.bind(this),this.$target.on("click change",":input.woocommerce-SavedPaymentMethods-tokenInput",{tokenizationForm:this},this.onTokenChange),e("input#createaccount").on("change",{tokenizationForm:this},this.onCreateAccountChange),this.onDisplay()};t.prototype.onDisplay=function(){0===e(":input.woocommerce-SavedPaymentMethods-tokenInput:checked",this.$target).length&&e(":input.woocommerce-SavedPaymentMethods-tokenInput:last",this.$target).prop("checked",!0),0===this.$target.data("count")&&e(".woocommerce-SavedPaymentMethods-new",this.$target).remove(),0<e("input#createaccount").length&&e("input#createaccount").is(":checked")||this.params.is_logged_in||this.params.is_registration_required?this.showSaveNewCheckbox():this.hideSaveNewCheckbox(),e(":input.woocommerce-SavedPaymentMethods-tokenInput:checked",this.$target).trigger("change")},t.prototype.onTokenChange=function(t){"new"===e(this).val()?(t.data.tokenizationForm.showForm(),t.data.tokenizationForm.showSaveNewCheckbox()):(t.data.tokenizationForm.hideForm(),t.data.tokenizationForm.hideSaveNewCheckbox())},t.prototype.onCreateAccountChange=function(t){e(this).is(":checked")?t.data.tokenizationForm.showSaveNewCheckbox():t.data.tokenizationForm.hideSaveNewCheckbox()},t.prototype.hideForm=function(){e(".wc-payment-form",this.$formWrap).hide()},t.prototype.showForm=function(){e(".wc-payment-form",this.$formWrap).show()},t.prototype.showSaveNewCheckbox=function(){e(".woocommerce-SavedPaymentMethods-saveNew",this.$formWrap).show()},t.prototype.hideSaveNewCheckbox=function(){e(".woocommerce-SavedPaymentMethods-saveNew",this.$formWrap).hide()},e.fn.wc_tokenization_form=function(e){return new t(this,e),this},e(document.body).on("updated_checkout wc-credit-card-form-init",function(){e("ul.woocommerce-SavedPaymentMethods").each(function(){e(this).wc_tokenization_form()})})});
|
||||
@@ -0,0 +1,102 @@
|
||||
/* global Cookies */
|
||||
jQuery( function( $ ) {
|
||||
// Orderby
|
||||
$( '.woocommerce-ordering' ).on( 'change', 'select.orderby', function() {
|
||||
$( this ).closest( 'form' ).trigger( 'submit' );
|
||||
});
|
||||
|
||||
// Target quantity inputs on product pages
|
||||
$( 'input.qty:not(.product-quantity input.qty)' ).each( function() {
|
||||
var min = parseFloat( $( this ).attr( 'min' ) );
|
||||
|
||||
if ( min >= 0 && parseFloat( $( this ).val() ) < min ) {
|
||||
$( this ).val( min );
|
||||
}
|
||||
});
|
||||
|
||||
var noticeID = $( '.woocommerce-store-notice' ).data( 'noticeId' ) || '',
|
||||
cookieName = 'store_notice' + noticeID;
|
||||
|
||||
// Check the value of that cookie and show/hide the notice accordingly
|
||||
if ( 'hidden' === Cookies.get( cookieName ) ) {
|
||||
$( '.woocommerce-store-notice' ).hide();
|
||||
} else {
|
||||
$( '.woocommerce-store-notice' ).show();
|
||||
}
|
||||
|
||||
// Set a cookie and hide the store notice when the dismiss button is clicked
|
||||
$( '.woocommerce-store-notice__dismiss-link' ).on( 'click', function( event ) {
|
||||
Cookies.set( cookieName, 'hidden', { path: '/' } );
|
||||
$( '.woocommerce-store-notice' ).hide();
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
// Make form field descriptions toggle on focus.
|
||||
if ( $( '.woocommerce-input-wrapper span.description' ).length ) {
|
||||
$( document.body ).on( 'click', function() {
|
||||
$( '.woocommerce-input-wrapper span.description:visible' ).prop( 'aria-hidden', true ).slideUp( 250 );
|
||||
} );
|
||||
}
|
||||
|
||||
$( '.woocommerce-input-wrapper' ).on( 'click', function( event ) {
|
||||
event.stopPropagation();
|
||||
} );
|
||||
|
||||
$( '.woocommerce-input-wrapper :input' )
|
||||
.on( 'keydown', function( event ) {
|
||||
var input = $( this ),
|
||||
parent = input.parent(),
|
||||
description = parent.find( 'span.description' );
|
||||
|
||||
if ( 27 === event.which && description.length && description.is( ':visible' ) ) {
|
||||
description.prop( 'aria-hidden', true ).slideUp( 250 );
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
} )
|
||||
.on( 'click focus', function() {
|
||||
var input = $( this ),
|
||||
parent = input.parent(),
|
||||
description = parent.find( 'span.description' );
|
||||
|
||||
parent.addClass( 'currentTarget' );
|
||||
|
||||
$( '.woocommerce-input-wrapper:not(.currentTarget) span.description:visible' ).prop( 'aria-hidden', true ).slideUp( 250 );
|
||||
|
||||
if ( description.length && description.is( ':hidden' ) ) {
|
||||
description.prop( 'aria-hidden', false ).slideDown( 250 );
|
||||
}
|
||||
|
||||
parent.removeClass( 'currentTarget' );
|
||||
} );
|
||||
|
||||
// Common scroll to element code.
|
||||
$.scroll_to_notices = function( scrollElement ) {
|
||||
if ( scrollElement.length ) {
|
||||
$( 'html, body' ).animate( {
|
||||
scrollTop: ( scrollElement.offset().top - 100 )
|
||||
}, 1000 );
|
||||
}
|
||||
};
|
||||
|
||||
// Show password visibility hover icon on woocommerce forms
|
||||
$( '.woocommerce form .woocommerce-Input[type="password"]' ).wrap( '<span class="password-input"></span>' );
|
||||
// Add 'password-input' class to the password wrapper in checkout page.
|
||||
$( '.woocommerce form input' ).filter(':password').parent('span').addClass('password-input');
|
||||
$( '.password-input' ).append( '<span class="show-password-input"></span>' );
|
||||
|
||||
$( '.show-password-input' ).on( 'click',
|
||||
function() {
|
||||
if ( $( this ).hasClass( 'display-password' ) ) {
|
||||
$( this ).removeClass( 'display-password' );
|
||||
} else {
|
||||
$( this ).addClass( 'display-password' );
|
||||
}
|
||||
if ( $( this ).hasClass( 'display-password' ) ) {
|
||||
$( this ).siblings( ['input[type="password"]'] ).prop( 'type', 'text' );
|
||||
} else {
|
||||
$( this ).siblings( 'input[type="text"]' ).prop( 'type', 'password' );
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/woocommerce.min.js
vendored
Normal file
1
wp/wp-content/plugins/woocommerce/assets/js/frontend/woocommerce.min.js
vendored
Normal file
@@ -0,0 +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")})});
|
||||
Reference in New Issue
Block a user