Merge pull request #5148 from splashingpixels/jshint

Jshint
This commit is contained in:
Mike Jolley 2014-03-17 10:03:18 +00:00
commit 5d12647a43
4 changed files with 336 additions and 336 deletions

View File

@ -8,14 +8,15 @@
$.fn.wc_variation_form.find_matching_variations = function( product_variations, settings ) { $.fn.wc_variation_form.find_matching_variations = function( product_variations, settings ) {
var matching = []; var matching = [];
for (var i = 0; i < product_variations.length; i++) { for ( var i = 0; i < product_variations.length; i++ ) {
var variation = product_variations[i]; var variation = product_variations[i];
var variation_id = variation.variation_id; var variation_id = variation.variation_id;
if ( $.fn.wc_variation_form.variations_match( variation.attributes, settings ) ) { if ( $.fn.wc_variation_form.variations_match( variation.attributes, settings ) ) {
matching.push(variation); matching.push( variation );
} }
} }
return matching; return matching;
}; };
@ -23,13 +24,16 @@
var match = true; var match = true;
for ( var attr_name in attrs1 ) { for ( var attr_name in attrs1 ) {
var val1 = attrs1[ attr_name ]; if ( attrs1.hasOwnProperty( attr_name ) ) {
var val2 = attrs2[ 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 ) { if ( val1 !== undefined && val2 !== undefined && val1.length !== 0 && val2.length !== 0 && val1 !== val2 ) {
match = false; match = false;
}
} }
} }
return match; return match;
}; };
@ -41,218 +45,218 @@
// Bind events // Bind events
$form = this $form = this
// On clicking the reset variation button // On clicking the reset variation button
.on( 'click', '.reset_variations', function( event ) { .on( 'click', '.reset_variations', function( event ) {
$( this ).closest( '.variations_form' ).find( '.variations select' ).val( '' ).change(); $( this ).closest( '.variations_form' ).find( '.variations select' ).val( '' ).change();
var $sku = $( this ).closest( '.product' ).find( '.sku' ), var $sku = $( this ).closest( '.product' ).find( '.sku' ),
$weight = $( this ).closest( '.product' ).find( '.product_weight' ), $weight = $( this ).closest( '.product' ).find( '.product_weight' ),
$dimensions = $( this ).closest( '.product' ).find( '.product_dimensions' ); $dimensions = $( this ).closest( '.product' ).find( '.product_dimensions' );
if ( $sku.attr( 'data-o_sku' ) ) if ( $sku.attr( 'data-o_sku' ) )
$sku.text( $sku.attr( 'data-o_sku' ) ); $sku.text( $sku.attr( 'data-o_sku' ) );
if ( $weight.attr( 'data-o_weight' ) ) if ( $weight.attr( 'data-o_weight' ) )
$weight.text( $weight.attr( 'data-o_weight' ) ); $weight.text( $weight.attr( 'data-o_weight' ) );
if ( $dimensions.attr( 'data-o_dimensions' ) ) if ( $dimensions.attr( 'data-o_dimensions' ) )
$dimensions.text( $dimensions.attr( 'data-o_dimensions' ) ); $dimensions.text( $dimensions.attr( 'data-o_dimensions' ) );
return false; return false;
} ) } )
// Upon changing an option // Upon changing an option
.on( 'change', '.variations select', function( event ) { .on( 'change', '.variations select', function( event ) {
$variation_form = $( this ).closest( '.variations_form' ); $variation_form = $( this ).closest( '.variations_form' );
$variation_form.find( 'input[name=variation_id]' ).val( '' ).change(); $variation_form.find( 'input[name=variation_id]' ).val( '' ).change();
$variation_form $variation_form
.trigger( 'woocommerce_variation_select_change' ) .trigger( 'woocommerce_variation_select_change' )
.trigger( 'check_variations', [ '', false ] ); .trigger( 'check_variations', [ '', false ] );
$( this ).blur(); $( this ).blur();
if( $().uniform && $.isFunction( $.uniform.update ) ) { if( $().uniform && $.isFunction( $.uniform.update ) ) {
$.uniform.update(); $.uniform.update();
}
} )
// Upon gaining focus
.on( 'focusin touchstart', '.variations select', function( event ) {
$variation_form = $( this ).closest( '.variations_form' );
$variation_form
.trigger( 'woocommerce_variation_select_focusin' )
.trigger( 'check_variations', [ $( this ).attr( 'name' ), true ] );
} )
// Check variations
.on( 'check_variations', function( event, exclude, focus ) {
var all_set = true,
any_set = false,
showing_variation = false,
current_settings = {},
$variation_form = $( this ),
$reset_variations = $variation_form.find( '.reset_variations' );
$variation_form.find( '.variations select' ).each( function() {
if ( $( this ).val().length === 0 ) {
all_set = false;
} else {
any_set = true;
} }
} ) if ( exclude && $( this ).attr( 'name' ) === exclude ) {
// Upon gaining focus all_set = false;
.on( 'focusin touchstart', '.variations select', function( event ) { current_settings[$( this ).attr( 'name' )] = '';
$variation_form = $( this ).closest( '.variations_form' );
$variation_form
.trigger( 'woocommerce_variation_select_focusin' )
.trigger( 'check_variations', [ $( this ).attr( 'name' ), true ] );
} )
// Check variations
.on( 'check_variations', function( event, exclude, focus ) {
var all_set = true,
any_set = false,
showing_variation = false,
current_settings = {},
$variation_form = $( this ),
$reset_variations = $variation_form.find( '.reset_variations' );
$variation_form.find( '.variations select' ).each( function() {
if ( $( this ).val().length === 0 ) {
all_set = false;
} else {
any_set = true;
}
if ( exclude && $( this ).attr( 'name' ) == exclude ) {
all_set = false;
current_settings[$( this ).attr( 'name' )] = '';
} else {
// Encode entities
value = $( this ).val();
// Add to settings array
current_settings[ $( this ).attr( 'name' ) ] = value;
}
});
var product_id = parseInt( $variation_form.data( 'product_id' ) ),
all_variations = $variation_form.data( 'product_variations' );
// Fallback to window property if not set - backwards compat
if ( ! all_variations )
all_variations = window[ 'product_variations' ][ product_id ];
if ( ! all_variations )
all_variations = window[ 'product_variations' ];
if ( ! all_variations )
all_variations = window[ 'product_variations_' + product_id ];
var matching_variations = $.fn.wc_variation_form.find_matching_variations( all_variations, current_settings );
if ( all_set ) {
var variation = matching_variations.shift();
if ( variation ) {
// Found - set ID
$variation_form
.find( 'input[name=variation_id]' )
.val( variation.variation_id )
.change();
$variation_form.trigger( 'found_variation', [ variation ] );
} else {
// Nothing found - reset fields
$variation_form.find( '.variations select' ).val( '' );
if ( ! focus )
$variation_form.trigger( 'reset_image' );
alert( wc_add_to_cart_variation_params.i18n_no_matching_variations_text );
}
} else { } else {
$variation_form.trigger( 'update_variation_values', [ matching_variations ] ); // Encode entities
value = $( this ).val();
// Add to settings array
current_settings[ $( this ).attr( 'name' ) ] = value;
}
});
var product_id = parseInt( $variation_form.data( 'product_id' ) ),
all_variations = $variation_form.data( 'product_variations' );
// Fallback to window property if not set - backwards compat
if ( ! all_variations )
all_variations = window.product_variations.product_id;
if ( ! all_variations )
all_variations = window.product_variations;
if ( ! all_variations )
all_variations = window['product_variations_' + product_id ];
var matching_variations = $.fn.wc_variation_form.find_matching_variations( all_variations, current_settings );
if ( all_set ) {
var variation = matching_variations.shift();
if ( variation ) {
// Found - set ID
$variation_form
.find( 'input[name=variation_id]' )
.val( variation.variation_id )
.change();
$variation_form.trigger( 'found_variation', [ variation ] );
} else {
// Nothing found - reset fields
$variation_form.find( '.variations select' ).val( '' );
if ( ! focus ) if ( ! focus )
$variation_form.trigger( 'reset_image' ); $variation_form.trigger( 'reset_image' );
if ( ! exclude ) { alert( wc_add_to_cart_variation_params.i18n_no_matching_variations_text );
$variation_form.find( '.single_variation_wrap' ).slideUp( 200 );
}
} }
if ( any_set ) { } else {
if ( $reset_variations.css( 'visibility' ) === 'hidden' ) $variation_form.trigger( 'update_variation_values', [ matching_variations ] );
$reset_variations.css( 'visibility', 'visible' ).hide().fadeIn();
} else { if ( ! focus )
$variation_form.trigger( 'reset_image' );
$reset_variations.css( 'visibility', 'hidden' );
if ( ! exclude ) {
$variation_form.find( '.single_variation_wrap' ).slideUp( 200 );
} }
} ) }
// Reset product image if ( any_set ) {
.on( 'reset_image', function( event ) {
var $product = $(this).closest( '.product' ), if ( $reset_variations.css( 'visibility' ) === 'hidden' )
$product_img = $product.find( 'div.images img:eq(0)' ), $reset_variations.css( 'visibility', 'visible' ).hide().fadeIn();
$product_link = $product.find( 'div.images a.zoom:eq(0)' ),
o_src = $product_img.attr( 'data-o_src' ),
o_title = $product_img.attr( 'data-o_title' ),
o_alt = $product_img.attr( 'data-o_alt' ),
o_href = $product_link.attr( 'data-o_href' );
if ( o_src !== undefined ) { } else {
$product_img
.attr( 'src', o_src );
}
if ( o_href !== undefined ) { $reset_variations.css( 'visibility', 'hidden' );
$product_link
.attr( 'href', o_href );
}
if ( o_title !== undefined ) { }
$product_img
.attr( 'title', o_title );
$product_link
.attr( 'title', o_title );
}
if ( o_alt !== undefined ) { } )
$product_img
.attr( 'alt', o_alt );
}
} )
// Disable option fields that are unavaiable for current set of attributes // Reset product image
.on( 'update_variation_values', function( event, variations ) { .on( 'reset_image', function( event ) {
$variation_form = $( this ).closest( '.variations_form' ); var $product = $(this).closest( '.product' ),
$product_img = $product.find( 'div.images img:eq(0)' ),
$product_link = $product.find( 'div.images a.zoom:eq(0)' ),
o_src = $product_img.attr( 'data-o_src' ),
o_title = $product_img.attr( 'data-o_title' ),
o_alt = $product_img.attr( 'data-o_alt' ),
o_href = $product_link.attr( 'data-o_href' );
// Loop through selects and disable/enable options based on selections if ( o_src !== undefined ) {
$variation_form.find( '.variations select' ).each( function( index, el ) { $product_img
.attr( 'src', o_src );
}
current_attr_select = $( el ); if ( o_href !== undefined ) {
$product_link
.attr( 'href', o_href );
}
// Reset options if ( o_title !== undefined ) {
if ( ! current_attr_select.data( 'attribute_options' ) ) $product_img
current_attr_select.data( 'attribute_options', current_attr_select.find( 'option:gt(0)' ).get() ); .attr( 'title', o_title );
$product_link
.attr( 'title', o_title );
}
current_attr_select.find( 'option:gt(0)' ).remove(); if ( o_alt !== undefined ) {
current_attr_select.append( current_attr_select.data( 'attribute_options' ) ); $product_img
current_attr_select.find( 'option:gt(0)' ).removeClass( 'active' ); .attr( 'alt', o_alt );
}
} )
// Get name // Disable option fields that are unavaiable for current set of attributes
var current_attr_name = current_attr_select.attr( 'name' ); .on( 'update_variation_values', function( event, variations ) {
// Loop through variations $variation_form = $( this ).closest( '.variations_form' );
for ( var num in variations ) {
if ( typeof( variations[ num ] ) != 'undefined' ) { // Loop through selects and disable/enable options based on selections
$variation_form.find( '.variations select' ).each( function( index, el ) {
var attributes = variations[ num ].attributes; current_attr_select = $( el );
for ( var attr_name in attributes ) { // Reset options
if ( ! current_attr_select.data( 'attribute_options' ) )
current_attr_select.data( 'attribute_options', current_attr_select.find( 'option:gt(0)' ).get() );
current_attr_select.find( 'option:gt(0)' ).remove();
current_attr_select.append( current_attr_select.data( 'attribute_options' ) );
current_attr_select.find( 'option:gt(0)' ).removeClass( 'active' );
// Get name
var current_attr_name = current_attr_select.attr( 'name' );
// Loop through variations
for ( var num in variations ) {
if ( typeof( variations[ num ] ) != 'undefined' ) {
var attributes = variations[ num ].attributes;
for ( var attr_name in attributes ) {
if ( attributes.hasOwnProperty( attr_name ) ) {
var attr_val = attributes[ attr_name ]; var attr_val = attributes[ attr_name ];
if ( attr_name == current_attr_name ) { if ( attr_name == current_attr_name ) {
@ -263,8 +267,8 @@
attr_val = $( '<div/>' ).html( attr_val ).text(); attr_val = $( '<div/>' ).html( attr_val ).text();
// Add slashes // Add slashes
attr_val = attr_val.replace(/'/g, "\\'"); attr_val = attr_val.replace( /'/g, "\\'" );
attr_val = attr_val.replace(/"/g, "\\\""); attr_val = attr_val.replace( /"/g, "\\\"" );
// Compare the meerkat // Compare the meerkat
current_attr_select.find( 'option[value="' + attr_val + '"]' ).addClass( 'active' ); current_attr_select.find( 'option[value="' + attr_val + '"]' ).addClass( 'active' );
@ -274,143 +278,140 @@
current_attr_select.find( 'option:gt(0)' ).addClass( 'active' ); current_attr_select.find( 'option:gt(0)' ).addClass( 'active' );
} }
} }
} }
} }
} }
// Detach inactive
current_attr_select.find( 'option:gt(0):not(.active)' ).remove();
});
// Custom event for when variations have been updated
$variation_form.trigger( 'woocommerce_update_variation_values' );
} )
// Show single variation details (price, stock, image)
.on( 'found_variation', function( event, variation ) {
var $variation_form = $( this ),
$product = $( this ).closest( '.product' ),
$product_img = $product.find( 'div.images img:eq(0)' ),
$product_link = $product.find( 'div.images a.zoom:eq(0)' ),
o_src = $product_img.attr( 'data-o_src' ),
o_title = $product_img.attr( 'data-o_title' ),
o_alt = $product_img.attr( 'data-o_alt' ),
o_href = $product_link.attr( 'data-o_href' ),
variation_image = variation.image_src,
variation_link = variation.image_link,
variation_title = variation.image_title,
variation_alt = variation.image_alt;
$variation_form.find( '.variations_button' ).show();
$variation_form.find( '.single_variation' ).html( variation.price_html + variation.availability_html );
if ( o_src === undefined ) {
o_src = ( ! $product_img.attr( 'src' ) ) ? '' : $product_img.attr( 'src' );
$product_img.attr( 'data-o_src', o_src );
} }
if ( o_href === undefined ) { // Detach inactive
o_href = ( ! $product_link.attr( 'href' ) ) ? '' : $product_link.attr( 'href' ); current_attr_select.find( 'option:gt(0):not(.active)' ).remove();
$product_link.attr( 'data-o_href', o_href );
}
if ( o_title === undefined ) {
o_title = ( ! $product_img.attr( 'title' ) ) ? '' : $product_img.attr( 'title' );
$product_img.attr( 'data-o_title', o_title );
}
if ( o_alt === undefined ) {
o_alt = ( ! $product_img.attr( 'alt' ) ) ? '' : $product_img.attr( 'alt' );
$product_img.attr( 'data-o_alt', o_alt );
}
if ( variation_image && variation_image.length > 1 ) {
$product_img
.attr( 'src', variation_image )
.attr( 'alt', variation_alt )
.attr( 'title', variation_title );
$product_link
.attr( 'href', variation_link )
.attr( 'title', variation_title );
} else {
$product_img
.attr( 'src', o_src )
.attr( 'alt', o_alt )
.attr( 'title', o_title );
$product_link
.attr( 'href', o_href )
.attr( 'title', o_title );
}
var $single_variation_wrap = $variation_form.find( '.single_variation_wrap' ),
$sku = $product.find( '.product_meta' ).find( '.sku' ),
$weight = $product.find( '.product_weight' ),
$dimensions = $product.find( '.product_dimensions' );
if ( ! $sku.attr( 'data-o_sku' ) )
$sku.attr( 'data-o_sku', $sku.text() );
if ( ! $weight.attr( 'data-o_weight' ) )
$weight.attr( 'data-o_weight', $weight.text() );
if ( ! $dimensions.attr( 'data-o_dimensions' ) )
$dimensions.attr( 'data-o_dimensions', $dimensions.text() );
if ( variation.sku ) {
$sku.text( variation.sku );
} else {
$sku.text( $sku.attr( 'data-o_sku' ) );
}
if ( variation.weight ) {
$weight.text( variation.weight );
} else {
$weight.text( $weight.attr( 'data-o_weight' ) );
}
if ( variation.dimensions ) {
$dimensions.text( variation.dimensions );
} else {
$dimensions.text( $dimensions.attr( 'data-o_dimensions' ) );
}
$single_variation_wrap.find( '.quantity' ).show();
if ( ! variation.is_in_stock && ! variation.backorders_allowed ) {
$variation_form.find( '.variations_button' ).hide();
}
if ( ! variation.variation_is_visible ) {
$variation_form.find( '.variations_button' ).hide();
$variation_form.find( '.single_variation' ).html( '<p>' + wc_add_to_cart_variation_params.i18n_unavailable_text + '</p>' );
}
if ( variation.min_qty )
$single_variation_wrap.find( 'input[name=quantity]' ).attr( 'min', variation.min_qty ).val( variation.min_qty );
else
$single_variation_wrap.find( 'input[name=quantity]' ).removeAttr( 'min' );
if ( variation.max_qty )
$single_variation_wrap.find( 'input[name=quantity]' ).attr( 'max', variation.max_qty );
else
$single_variation_wrap.find( 'input[name=quantity]' ).removeAttr( 'max' );
if ( variation.is_sold_individually === 'yes' ) {
$single_variation_wrap.find( 'input[name=quantity]' ).val( '1' );
$single_variation_wrap.find( '.quantity' ).hide();
}
$single_variation_wrap.slideDown( 200 ).trigger( 'show_variation', [ variation ] );
}); });
// Custom event for when variations have been updated
$variation_form.trigger( 'woocommerce_update_variation_values' );
} )
// Show single variation details (price, stock, image)
.on( 'found_variation', function( event, variation ) {
var $variation_form = $( this ),
$product = $( this ).closest( '.product' ),
$product_img = $product.find( 'div.images img:eq(0)' ),
$product_link = $product.find( 'div.images a.zoom:eq(0)' ),
o_src = $product_img.attr( 'data-o_src' ),
o_title = $product_img.attr( 'data-o_title' ),
o_alt = $product_img.attr( 'data-o_alt' ),
o_href = $product_link.attr( 'data-o_href' ),
variation_image = variation.image_src,
variation_link = variation.image_link,
variation_title = variation.image_title,
variation_alt = variation.image_alt;
$variation_form.find( '.variations_button' ).show();
$variation_form.find( '.single_variation' ).html( variation.price_html + variation.availability_html );
if ( o_src === undefined ) {
o_src = ( ! $product_img.attr( 'src' ) ) ? '' : $product_img.attr( 'src' );
$product_img.attr( 'data-o_src', o_src );
}
if ( o_href === undefined ) {
o_href = ( ! $product_link.attr( 'href' ) ) ? '' : $product_link.attr( 'href' );
$product_link.attr( 'data-o_href', o_href );
}
if ( o_title === undefined ) {
o_title = ( ! $product_img.attr( 'title' ) ) ? '' : $product_img.attr( 'title' );
$product_img.attr( 'data-o_title', o_title );
}
if ( o_alt === undefined ) {
o_alt = ( ! $product_img.attr( 'alt' ) ) ? '' : $product_img.attr( 'alt' );
$product_img.attr( 'data-o_alt', o_alt );
}
if ( variation_image && variation_image.length > 1 ) {
$product_img
.attr( 'src', variation_image )
.attr( 'alt', variation_alt )
.attr( 'title', variation_title );
$product_link
.attr( 'href', variation_link )
.attr( 'title', variation_title );
} else {
$product_img
.attr( 'src', o_src )
.attr( 'alt', o_alt )
.attr( 'title', o_title );
$product_link
.attr( 'href', o_href )
.attr( 'title', o_title );
}
var $single_variation_wrap = $variation_form.find( '.single_variation_wrap' ),
$sku = $product.find( '.product_meta' ).find( '.sku' ),
$weight = $product.find( '.product_weight' ),
$dimensions = $product.find( '.product_dimensions' );
if ( ! $sku.attr( 'data-o_sku' ) )
$sku.attr( 'data-o_sku', $sku.text() );
if ( ! $weight.attr( 'data-o_weight' ) )
$weight.attr( 'data-o_weight', $weight.text() );
if ( ! $dimensions.attr( 'data-o_dimensions' ) )
$dimensions.attr( 'data-o_dimensions', $dimensions.text() );
if ( variation.sku ) {
$sku.text( variation.sku );
} else {
$sku.text( $sku.attr( 'data-o_sku' ) );
}
if ( variation.weight ) {
$weight.text( variation.weight );
} else {
$weight.text( $weight.attr( 'data-o_weight' ) );
}
if ( variation.dimensions ) {
$dimensions.text( variation.dimensions );
} else {
$dimensions.text( $dimensions.attr( 'data-o_dimensions' ) );
}
$single_variation_wrap.find( '.quantity' ).show();
if ( ! variation.is_in_stock && ! variation.backorders_allowed ) {
$variation_form.find( '.variations_button' ).hide();
}
if ( ! variation.variation_is_visible ) {
$variation_form.find( '.variations_button' ).hide();
$variation_form.find( '.single_variation' ).html( '<p>' + wc_add_to_cart_variation_params.i18n_unavailable_text + '</p>' );
}
if ( variation.min_qty )
$single_variation_wrap.find( 'input[name=quantity]' ).attr( 'min', variation.min_qty ).val( variation.min_qty );
else
$single_variation_wrap.find( 'input[name=quantity]' ).removeAttr( 'min' );
if ( variation.max_qty )
$single_variation_wrap.find( 'input[name=quantity]' ).attr( 'max', variation.max_qty );
else
$single_variation_wrap.find( 'input[name=quantity]' ).removeAttr( 'max' );
if ( variation.is_sold_individually === 'yes' ) {
$single_variation_wrap.find( 'input[name=quantity]' ).val( '1' );
$single_variation_wrap.find( '.quantity' ).hide();
}
$single_variation_wrap.slideDown( 200 ).trigger( 'show_variation', [ variation ] );
});
$form.trigger( 'wc_variation_form' ); $form.trigger( 'wc_variation_form' );
return $form; return $form;

File diff suppressed because one or more lines are too long

View File

@ -1,31 +1,31 @@
jQuery(function($) { jQuery( function( $ ) {
// wc_add_to_cart_params is required to continue, ensure the object exists // wc_add_to_cart_params is required to continue, ensure the object exists
if (typeof wc_add_to_cart_params === "undefined") if ( typeof wc_add_to_cart_params === 'undefined' )
return false; return false;
// Ajax add to cart // Ajax add to cart
$(document).on( 'click', '.add_to_cart_button', function() { $( document ).on( 'click', '.add_to_cart_button', function() {
// AJAX add to cart request // AJAX add to cart request
var $thisbutton = $(this); var $thisbutton = $( this );
if ( $thisbutton.is('.product_type_simple') ) { if ( $thisbutton.is( '.product_type_simple' ) ) {
if (!$thisbutton.attr('data-product_id')) if ( ! $thisbutton.attr( 'data-product_id' ) )
return true; return true;
$thisbutton.removeClass('added'); $thisbutton.removeClass( 'added' );
$thisbutton.addClass('loading'); $thisbutton.addClass( 'loading' );
var data = { var data = {
action: 'woocommerce_add_to_cart', action: 'woocommerce_add_to_cart',
product_id: $thisbutton.attr('data-product_id'), product_id: $thisbutton.attr( 'data-product_id' ),
quantity: $thisbutton.attr('data-quantity') quantity: $thisbutton.attr( 'data-quantity' )
}; };
// Trigger event // Trigger event
$('body').trigger( 'adding_to_cart', [ $thisbutton, data ] ); $( 'body' ).trigger( 'adding_to_cart', [ $thisbutton, data ] );
// Ajax action // Ajax action
$.post( wc_add_to_cart_params.ajax_url, data, function( response ) { $.post( wc_add_to_cart_params.ajax_url, data, function( response ) {
@ -43,61 +43,63 @@ jQuery(function($) {
} }
// Redirect to cart option // Redirect to cart option
if ( wc_add_to_cart_params.cart_redirect_after_add == 'yes' ) { if ( wc_add_to_cart_params.cart_redirect_after_add === 'yes' ) {
window.location = wc_add_to_cart_params.cart_url; window.location = wc_add_to_cart_params.cart_url;
return; return;
} else { } else {
$thisbutton.removeClass('loading'); $thisbutton.removeClass( 'loading' );
fragments = response.fragments; fragments = response.fragments;
cart_hash = response.cart_hash; cart_hash = response.cart_hash;
// Block fragments class // Block fragments class
if ( fragments ) { if ( fragments ) {
$.each(fragments, function(key, value) { $.each( fragments, function( key, value ) {
$(key).addClass('updating'); $( key ).addClass( 'updating' );
}); });
} }
// Block widgets and fragments // Block widgets and fragments
$('.shop_table.cart, .updating, .cart_totals').fadeTo('400', '0.6').block({message: null, overlayCSS: {background: 'transparent url(' + wc_add_to_cart_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } } ); $( '.shop_table.cart, .updating, .cart_totals' ).fadeTo( '400', '0.6' ).block({ message: null, overlayCSS: { background: 'transparent url(' + wc_add_to_cart_params.ajax_loader_url + ') no-repeat center', backgroundSize: '16px 16px', opacity: 0.6 } } );
// Changes button classes // Changes button classes
$thisbutton.addClass('added'); $thisbutton.addClass( 'added' );
// View cart text // View cart text
if ( ! wc_add_to_cart_params.is_cart && $thisbutton.parent().find('.added_to_cart').size() == 0 ) if ( ! wc_add_to_cart_params.is_cart && $thisbutton.parent().find( '.added_to_cart' ).size() === 0 ) {
$thisbutton.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>' ); $thisbutton.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>' );
}
// Replace fragments // Replace fragments
if ( fragments ) { if ( fragments ) {
$.each(fragments, function(key, value) { $.each( fragments, function( key, value ) {
$(key).replaceWith(value); $( key ).replaceWith( value );
}); });
} }
// Unblock // Unblock
$('.widget_shopping_cart, .updating').stop(true).css('opacity', '1').unblock(); $( '.widget_shopping_cart, .updating' ).stop( true ).css( 'opacity', '1' ).unblock();
// Cart page elements // Cart page elements
$('.shop_table.cart').load( this_page + ' .shop_table.cart:eq(0) > *', function() { $( '.shop_table.cart' ).load( this_page + ' .shop_table.cart:eq(0) > *', function() {
$("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass('buttons_added').append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />'); $( 'div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)' ).addClass( 'buttons_added' ).append( '<input type="button" value="+" id="add1" class="plus" />' ).prepend( '<input type="button" value="-" id="minus1" class="minus" />' );
$('.shop_table.cart').stop(true).css('opacity', '1').unblock(); $( '.shop_table.cart' ).stop( true ).css( 'opacity', '1' ).unblock();
$('body').trigger('cart_page_refreshed'); $( 'body' ).trigger( 'cart_page_refreshed' );
}); });
$('.cart_totals').load( this_page + ' .cart_totals:eq(0) > *', function() { $( '.cart_totals' ).load( this_page + ' .cart_totals:eq(0) > *', function() {
$('.cart_totals').stop(true).css('opacity', '1').unblock(); $( '.cart_totals' ).stop( true ).css( 'opacity', '1' ).unblock();
}); });
// Trigger event so themes can refresh other areas // Trigger event so themes can refresh other areas
$('body').trigger( 'added_to_cart', [ fragments, cart_hash ] ); $( 'body' ).trigger( 'added_to_cart', [ fragments, cart_hash ] );
} }
}); });

View File

@ -1 +1 @@
jQuery(function(a){return"undefined"==typeof wc_add_to_cart_params?!1:void a(document).on("click",".add_to_cart_button",function(){var b=a(this);if(b.is(".product_type_simple")){if(!b.attr("data-product_id"))return!0;b.removeClass("added"),b.addClass("loading");var c={action:"woocommerce_add_to_cart",product_id:b.attr("data-product_id"),quantity:b.attr("data-quantity")};return a("body").trigger("adding_to_cart",[b,c]),a.post(wc_add_to_cart_params.ajax_url,c,function(c){if(c){var d=window.location.toString();return d=d.replace("add-to-cart","added-to-cart"),c.error&&c.product_url?void(window.location=c.product_url):"yes"==wc_add_to_cart_params.cart_redirect_after_add?void(window.location=wc_add_to_cart_params.cart_url):(b.removeClass("loading"),fragments=c.fragments,cart_hash=c.cart_hash,fragments&&a.each(fragments,function(b){a(b).addClass("updating")}),a(".shop_table.cart, .updating, .cart_totals").fadeTo("400","0.6").block({message:null,overlayCSS:{background:"transparent url("+wc_add_to_cart_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}}),b.addClass("added"),wc_add_to_cart_params.is_cart||0!=b.parent().find(".added_to_cart").size()||b.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>"),fragments&&a.each(fragments,function(b,c){a(b).replaceWith(c)}),a(".widget_shopping_cart, .updating").stop(!0).css("opacity","1").unblock(),a(".shop_table.cart").load(d+" .shop_table.cart:eq(0) > *",function(){a("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />'),a(".shop_table.cart").stop(!0).css("opacity","1").unblock(),a("body").trigger("cart_page_refreshed")}),a(".cart_totals").load(d+" .cart_totals:eq(0) > *",function(){a(".cart_totals").stop(!0).css("opacity","1").unblock()}),a("body").trigger("added_to_cart",[fragments,cart_hash]),void 0)}}),!1}return!0})}); jQuery(function(e){if(typeof wc_add_to_cart_params==="undefined")return false;e(document).on("click",".add_to_cart_button",function(){var t=e(this);if(t.is(".product_type_simple")){if(!t.attr("data-product_id"))return true;t.removeClass("added");t.addClass("loading");var n={action:"woocommerce_add_to_cart",product_id:t.attr("data-product_id"),quantity:t.attr("data-quantity")};e("body").trigger("adding_to_cart",[t,n]);e.post(wc_add_to_cart_params.ajax_url,n,function(n){if(!n)return;var r=window.location.toString();r=r.replace("add-to-cart","added-to-cart");if(n.error&&n.product_url){window.location=n.product_url;return}if(wc_add_to_cart_params.cart_redirect_after_add==="yes"){window.location=wc_add_to_cart_params.cart_url;return}else{t.removeClass("loading");fragments=n.fragments;cart_hash=n.cart_hash;if(fragments){e.each(fragments,function(t,n){e(t).addClass("updating")})}e(".shop_table.cart, .updating, .cart_totals").fadeTo("400","0.6").block({message:null,overlayCSS:{background:"transparent url("+wc_add_to_cart_params.ajax_loader_url+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}});t.addClass("added");if(!wc_add_to_cart_params.is_cart&&t.parent().find(".added_to_cart").size()===0){t.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>")}if(fragments){e.each(fragments,function(t,n){e(t).replaceWith(n)})}e(".widget_shopping_cart, .updating").stop(true).css("opacity","1").unblock();e(".shop_table.cart").load(r+" .shop_table.cart:eq(0) > *",function(){e("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');e(".shop_table.cart").stop(true).css("opacity","1").unblock();e("body").trigger("cart_page_refreshed")});e(".cart_totals").load(r+" .cart_totals:eq(0) > *",function(){e(".cart_totals").stop(true).css("opacity","1").unblock()});e("body").trigger("added_to_cart",[fragments,cart_hash])}});return false}return true})})