diff --git a/assets/js/frontend/add-to-cart-variation.js b/assets/js/frontend/add-to-cart-variation.js index 5464c50c1ce..9104ec7a89f 100644 --- a/assets/js/frontend/add-to-cart-variation.js +++ b/assets/js/frontend/add-to-cart-variation.js @@ -25,7 +25,7 @@ // On clicking the reset variation button .on( 'click', '.reset_variations', function() { $form.find( '.variations select' ).val( '' ).change(); - $form.triggerHandler( 'reset_data' ); + $form.trigger( 'reset_data' ); return false; } ) @@ -43,8 +43,8 @@ } }); $form.find( '.woocommerce-variation-description' ).remove(); - $form.triggerHandler( 'reset_image' ); - $form.find( '.single_variation_wrap' ).slideUp( 200 ).triggerHandler( 'hide_variation' ); + $form.trigger( 'reset_image' ); + $form.find( '.single_variation_wrap' ).slideUp( 200 ).trigger( 'hide_variation' ); } ) // Reset product image @@ -110,16 +110,16 @@ $form.find( 'input[name="variation_id"], input.variation_id' ) .val( variation.variation_id ) .change(); - $form.triggerHandler( 'found_variation', [ variation ] ); + $form.trigger( 'found_variation', [ variation ] ); } else { - $form.triggerHandler( 'reset_data' ); + $form.trigger( 'reset_data' ); $form.find( '.single_variation_wrap' ).after( '

' + wc_add_to_cart_variation_params.i18n_no_matching_variations_text + '

' ); $form.find( '.wc-no-matching-variations' ).slideDown( 200 ); } } } ); } else { - $form.triggerHandler( 'reset_data' ); + $form.trigger( 'reset_data' ); } if ( some_attributes_chosen ) { if ( $reset_variations.css( 'visibility' ) === 'hidden' ) { @@ -129,20 +129,20 @@ $reset_variations.css( 'visibility', 'hidden' ); } } else { - $form.triggerHandler( 'woocommerce_variation_select_change' ); - $form.triggerHandler( 'check_variations', [ '', false ] ); + $form.trigger( 'woocommerce_variation_select_change' ); + $form.trigger( 'check_variations', [ '', false ] ); $( this ).blur(); } // Custom event for when variation selection has been changed - $form.triggerHandler( 'woocommerce_variation_has_changed' ); + $form.trigger( 'woocommerce_variation_has_changed' ); } ) // Upon gaining focus .on( 'focusin touchstart', '.variations select', function() { if ( ! $use_ajax ) { - $form.triggerHandler( 'woocommerce_variation_select_focusin' ); - $form.triggerHandler( 'check_variations', [ $( this ).data( 'attribute_name' ) || $( this ).attr( 'name' ), true ] ); + $form.trigger( 'woocommerce_variation_select_focusin' ); + $form.trigger( 'check_variations', [ $( this ).data( 'attribute_name' ) || $( this ).attr( 'name' ), true ] ); } } ) @@ -269,7 +269,7 @@ $form.find( '.single_variation_wrap' ).prepend( '
' + variation.variation_description + '
' ); } - $single_variation_wrap.slideDown( 200 ).triggerHandler( 'show_variation', [ variation ] ); + $single_variation_wrap.slideDown( 200 ).trigger( 'show_variation', [ variation ] ); }) // Check variations @@ -312,13 +312,13 @@ $form.find( 'input[name="variation_id"], input.variation_id' ) .val( variation.variation_id ) .change(); - $form.triggerHandler( 'found_variation', [ variation ] ); + $form.trigger( 'found_variation', [ variation ] ); } else { // Nothing found - reset fields $form.find( '.variations select' ).val( '' ); if ( ! focus ) { - $form.triggerHandler( 'reset_data' ); + $form.trigger( 'reset_data' ); } window.alert( wc_add_to_cart_variation_params.i18n_no_matching_variations_text ); @@ -326,14 +326,14 @@ } else { - $form.triggerHandler( 'update_variation_values', [ matching_variations ] ); + $form.trigger( 'update_variation_values', [ matching_variations ] ); if ( ! focus ) { - $form.triggerHandler( 'reset_data' ); + $form.trigger( 'reset_data' ); } if ( ! exclude ) { - $form.find( '.single_variation_wrap' ).slideUp( 200 ).triggerHandler( 'hide_variation' ); + $form.find( '.single_variation_wrap' ).slideUp( 200 ).trigger( 'hide_variation' ); } } if ( some_attributes_chosen ) { @@ -424,10 +424,10 @@ }); // Custom event for when variations have been updated - $form.triggerHandler( 'woocommerce_update_variation_values' ); + $form.trigger( 'woocommerce_update_variation_values' ); }); - $form.triggerHandler( 'wc_variation_form' ); + $form.trigger( 'wc_variation_form' ); return $form; }; @@ -471,4 +471,4 @@ } }); -})( jQuery, window, document ); \ No newline at end of file +})( jQuery, window, document ); diff --git a/assets/js/frontend/add-to-cart-variation.min.js b/assets/js/frontend/add-to-cart-variation.min.js index dc201987d12..18b933b433a 100644 --- a/assets/js/frontend/add-to-cart-variation.min.js +++ b/assets/js/frontend/add-to-cart-variation.min.js @@ -1,4 +1,4 @@ /*! * Variations Plugin */ -!function(a,b,c,d){a.fn.wc_variation_form=function(){var c=this,f=c.closest(".product"),g=parseInt(c.data("product_id"),10),h=c.data("product_variations"),i=h===!1,j=!1,k=c.find(".reset_variations");return c.unbind("check_variations update_variation_values found_variation"),c.find(".reset_variations").unbind("click"),c.find(".variations select").unbind("change focusin"),c.on("click",".reset_variations",function(){return c.find(".variations select").val("").change(),c.triggerHandler("reset_data"),!1}).on("reset_data",function(){var b={".sku":"o_sku",".product_weight":"o_weight",".product_dimensions":"o_dimensions"};a.each(b,function(a,b){var c=f.find(a);c.attr("data-"+b)&&c.text(c.attr("data-"+b))}),c.find(".woocommerce-variation-description").remove(),c.triggerHandler("reset_image"),c.find(".single_variation_wrap").slideUp(200).triggerHandler("hide_variation")}).on("reset_image",function(){var a=f.find("div.images img:eq(0)"),b=f.find("div.images a.zoom:eq(0)"),c=a.attr("data-o_src"),e=a.attr("data-o_title"),g=a.attr("data-o_title"),h=b.attr("data-o_href");c!==d&&a.attr("src",c),h!==d&&b.attr("href",h),e!==d&&(a.attr("title",e),b.attr("title",e)),g!==d&&a.attr("alt",g)}).on("change",".variations select",function(){if(c.find('input[name="variation_id"], input.variation_id').val("").change(),c.find(".wc-no-matching-variations").remove(),i){j&&j.abort();var b=!0,d=!1,e={};c.find(".variations select").each(function(){var c=a(this).data("attribute_name")||a(this).attr("name");0===a(this).val().length?b=!1:d=!0,e[c]=a(this).val()}),b?(e.product_id=g,j=a.ajax({url:wc_cart_fragments_params.wc_ajax_url+"get_variation/",type:"POST",data:e,success:function(a){a?(c.find('input[name="variation_id"], input.variation_id').val(a.variation_id).change(),c.triggerHandler("found_variation",[a])):(c.triggerHandler("reset_data"),c.find(".single_variation_wrap").after('

'+wc_add_to_cart_variation_params.i18n_no_matching_variations_text+"

"),c.find(".wc-no-matching-variations").slideDown(200))}})):c.triggerHandler("reset_data"),d?"hidden"===k.css("visibility")&&k.css("visibility","visible").hide().fadeIn():k.css("visibility","hidden")}else c.triggerHandler("woocommerce_variation_select_change"),c.triggerHandler("check_variations",["",!1]),a(this).blur();c.triggerHandler("woocommerce_variation_has_changed")}).on("focusin touchstart",".variations select",function(){i||(c.triggerHandler("woocommerce_variation_select_focusin"),c.triggerHandler("check_variations",[a(this).data("attribute_name")||a(this).attr("name"),!0]))}).on("found_variation",function(a,b){var e=f.find("div.images img:eq(0)"),g=f.find("div.images a.zoom:eq(0)"),h=e.attr("data-o_src"),i=e.attr("data-o_title"),j=e.attr("data-o_alt"),k=g.attr("data-o_href"),l=b.image_src,m=b.image_link,n=b.image_caption,o=b.image_title;c.find(".variations_button").show(),c.find(".single_variation").html(b.price_html+b.availability_html),h===d&&(h=e.attr("src")?e.attr("src"):"",e.attr("data-o_src",h)),k===d&&(k=g.attr("href")?g.attr("href"):"",g.attr("data-o_href",k)),i===d&&(i=e.attr("title")?e.attr("title"):"",e.attr("data-o_title",i)),j===d&&(j=e.attr("alt")?e.attr("alt"):"",e.attr("data-o_alt",j)),l&&l.length>1?(e.attr("src",l).attr("alt",o).attr("title",o),g.attr("href",m).attr("title",n)):(e.attr("src",h).attr("alt",j).attr("title",i),g.attr("href",k).attr("title",i));var p=c.find(".single_variation_wrap"),q=f.find(".product_meta").find(".sku"),r=f.find(".product_weight"),s=f.find(".product_dimensions");q.attr("data-o_sku")||q.attr("data-o_sku",q.text()),r.attr("data-o_weight")||r.attr("data-o_weight",r.text()),s.attr("data-o_dimensions")||s.attr("data-o_dimensions",s.text()),b.sku?q.text(b.sku):q.text(q.attr("data-o_sku")),b.weight?r.text(b.weight):r.text(r.attr("data-o_weight")),b.dimensions?s.text(b.dimensions):s.text(s.attr("data-o_dimensions")),p.find(".quantity").show(),b.is_purchasable&&b.is_in_stock&&b.variation_is_visible||c.find(".variations_button").hide(),b.variation_is_visible||c.find(".single_variation").html("

"+wc_add_to_cart_variation_params.i18n_unavailable_text+"

"),""!==b.min_qty?p.find(".quantity input.qty").attr("min",b.min_qty).val(b.min_qty):p.find(".quantity input.qty").removeAttr("min"),""!==b.max_qty?p.find(".quantity input.qty").attr("max",b.max_qty):p.find(".quantity input.qty").removeAttr("max"),"yes"===b.is_sold_individually&&(p.find(".quantity input.qty").val("1"),p.find(".quantity").hide()),c.find(".woocommerce-variation-description").remove(),b.variation_description&&c.find(".single_variation_wrap").prepend('
'+b.variation_description+"
"),p.slideDown(200).triggerHandler("show_variation",[b])}).on("check_variations",function(c,d,f){if(!i){var g=!0,j=!1,k={},l=a(this),m=l.find(".reset_variations");l.find(".variations select").each(function(){var b=a(this).data("attribute_name")||a(this).attr("name");0===a(this).val().length?g=!1:j=!0,d&&b===d?(g=!1,k[b]=""):k[b]=a(this).val()});var n=e.find_matching_variations(h,k);if(g){var o=n.shift();o?(l.find('input[name="variation_id"], input.variation_id').val(o.variation_id).change(),l.triggerHandler("found_variation",[o])):(l.find(".variations select").val(""),f||l.triggerHandler("reset_data"),b.alert(wc_add_to_cart_variation_params.i18n_no_matching_variations_text))}else l.triggerHandler("update_variation_values",[n]),f||l.triggerHandler("reset_data"),d||l.find(".single_variation_wrap").slideUp(200).triggerHandler("hide_variation");j?"hidden"===m.css("visibility")&&m.css("visibility","visible").hide().fadeIn():m.css("visibility","hidden")}}).on("update_variation_values",function(b,d){i||(c.find(".variations select").each(function(b,c){var e,f=a(c);f.data("attribute_options")||f.data("attribute_options",f.find("option:gt(0)").get()),f.find("option:gt(0)").remove(),f.append(f.data("attribute_options")),f.find("option:gt(0)").removeClass("attached"),f.find("option:gt(0)").removeClass("enabled"),f.find("option:gt(0)").removeAttr("disabled"),e="undefined"!=typeof f.data("attribute_name")?f.data("attribute_name"):f.attr("name");for(var g in d)if("undefined"!=typeof d[g]){var h=d[g].attributes;for(var i in h)if(h.hasOwnProperty(i)){var j=h[i];if(i===e){var k="";d[g].variation_is_active&&(k="enabled"),j?(j=a("
").html(j).text(),j=j.replace(/'/g,"\\'"),j=j.replace(/"/g,'\\"'),f.find('option[value="'+j+'"]').addClass("attached "+k)):f.find("option:gt(0)").addClass("attached "+k)}}}f.find("option:gt(0):not(.attached)").remove(),f.find("option:gt(0):not(.enabled)").attr("disabled","disabled")}),c.triggerHandler("woocommerce_update_variation_values"))}),c.triggerHandler("wc_variation_form"),c};var e={find_matching_variations:function(a,b){for(var c=[],d=0;d'+wc_add_to_cart_variation_params.i18n_no_matching_variations_text+"

"),c.find(".wc-no-matching-variations").slideDown(200))}})):c.trigger("reset_data"),d?"hidden"===k.css("visibility")&&k.css("visibility","visible").hide().fadeIn():k.css("visibility","hidden")}else c.trigger("woocommerce_variation_select_change"),c.trigger("check_variations",["",!1]),a(this).blur();c.trigger("woocommerce_variation_has_changed")}).on("focusin touchstart",".variations select",function(){i||(c.trigger("woocommerce_variation_select_focusin"),c.trigger("check_variations",[a(this).data("attribute_name")||a(this).attr("name"),!0]))}).on("found_variation",function(a,b){var e=f.find("div.images img:eq(0)"),g=f.find("div.images a.zoom:eq(0)"),h=e.attr("data-o_src"),i=e.attr("data-o_title"),j=e.attr("data-o_alt"),k=g.attr("data-o_href"),l=b.image_src,m=b.image_link,n=b.image_caption,o=b.image_title;c.find(".variations_button").show(),c.find(".single_variation").html(b.price_html+b.availability_html),h===d&&(h=e.attr("src")?e.attr("src"):"",e.attr("data-o_src",h)),k===d&&(k=g.attr("href")?g.attr("href"):"",g.attr("data-o_href",k)),i===d&&(i=e.attr("title")?e.attr("title"):"",e.attr("data-o_title",i)),j===d&&(j=e.attr("alt")?e.attr("alt"):"",e.attr("data-o_alt",j)),l&&l.length>1?(e.attr("src",l).attr("alt",o).attr("title",o),g.attr("href",m).attr("title",n)):(e.attr("src",h).attr("alt",j).attr("title",i),g.attr("href",k).attr("title",i));var p=c.find(".single_variation_wrap"),q=f.find(".product_meta").find(".sku"),r=f.find(".product_weight"),s=f.find(".product_dimensions");q.attr("data-o_sku")||q.attr("data-o_sku",q.text()),r.attr("data-o_weight")||r.attr("data-o_weight",r.text()),s.attr("data-o_dimensions")||s.attr("data-o_dimensions",s.text()),b.sku?q.text(b.sku):q.text(q.attr("data-o_sku")),b.weight?r.text(b.weight):r.text(r.attr("data-o_weight")),b.dimensions?s.text(b.dimensions):s.text(s.attr("data-o_dimensions")),p.find(".quantity").show(),b.is_purchasable&&b.is_in_stock&&b.variation_is_visible||c.find(".variations_button").hide(),b.variation_is_visible||c.find(".single_variation").html("

"+wc_add_to_cart_variation_params.i18n_unavailable_text+"

"),""!==b.min_qty?p.find(".quantity input.qty").attr("min",b.min_qty).val(b.min_qty):p.find(".quantity input.qty").removeAttr("min"),""!==b.max_qty?p.find(".quantity input.qty").attr("max",b.max_qty):p.find(".quantity input.qty").removeAttr("max"),"yes"===b.is_sold_individually&&(p.find(".quantity input.qty").val("1"),p.find(".quantity").hide()),c.find(".woocommerce-variation-description").remove(),b.variation_description&&c.find(".single_variation_wrap").prepend('
'+b.variation_description+"
"),p.slideDown(200).trigger("show_variation",[b])}).on("check_variations",function(c,d,f){if(!i){var g=!0,j=!1,k={},l=a(this),m=l.find(".reset_variations");l.find(".variations select").each(function(){var b=a(this).data("attribute_name")||a(this).attr("name");0===a(this).val().length?g=!1:j=!0,d&&b===d?(g=!1,k[b]=""):k[b]=a(this).val()});var n=e.find_matching_variations(h,k);if(g){var o=n.shift();o?(l.find('input[name="variation_id"], input.variation_id').val(o.variation_id).change(),l.trigger("found_variation",[o])):(l.find(".variations select").val(""),f||l.trigger("reset_data"),b.alert(wc_add_to_cart_variation_params.i18n_no_matching_variations_text))}else l.trigger("update_variation_values",[n]),f||l.trigger("reset_data"),d||l.find(".single_variation_wrap").slideUp(200).trigger("hide_variation");j?"hidden"===m.css("visibility")&&m.css("visibility","visible").hide().fadeIn():m.css("visibility","hidden")}}).on("update_variation_values",function(b,d){i||(c.find(".variations select").each(function(b,c){var e,f=a(c);f.data("attribute_options")||f.data("attribute_options",f.find("option:gt(0)").get()),f.find("option:gt(0)").remove(),f.append(f.data("attribute_options")),f.find("option:gt(0)").removeClass("attached"),f.find("option:gt(0)").removeClass("enabled"),f.find("option:gt(0)").removeAttr("disabled"),e="undefined"!=typeof f.data("attribute_name")?f.data("attribute_name"):f.attr("name");for(var g in d)if("undefined"!=typeof d[g]){var h=d[g].attributes;for(var i in h)if(h.hasOwnProperty(i)){var j=h[i];if(i===e){var k="";d[g].variation_is_active&&(k="enabled"),j?(j=a("
").html(j).text(),j=j.replace(/'/g,"\\'"),j=j.replace(/"/g,'\\"'),f.find('option[value="'+j+'"]').addClass("attached "+k)):f.find("option:gt(0)").addClass("attached "+k)}}}f.find("option:gt(0):not(.attached)").remove(),f.find("option:gt(0):not(.enabled)").attr("disabled","disabled")}),c.trigger("woocommerce_update_variation_values"))}),c.trigger("wc_variation_form"),c};var e={find_matching_variations:function(a,b){for(var c=[],d=0;d