diff --git a/assets/js/frontend/cart.js b/assets/js/frontend/cart.js index e1c0967ccd0..005eaf3434f 100644 --- a/assets/js/frontend/cart.js +++ b/assets/js/frontend/cart.js @@ -102,7 +102,7 @@ jQuery( function( $ ) { } $( '.woocommerce-cart-form' ).replaceWith( $new_form ); - $( '.woocommerce-cart-form' ).find( 'input[name="update_cart"]' ).prop( 'disabled', true ); + $( '.woocommerce-cart-form' ).find( ':input[name="update_cart"]' ).prop( 'disabled', true ); if ( $notices.length > 0 ) { show_notice( $notices ); @@ -158,7 +158,7 @@ jQuery( function( $ ) { ); $( document ).on( 'change', - 'select.shipping_method, input[name^=shipping_method]', + 'select.shipping_method, :input[name^=shipping_method]', this.shipping_method_selected ); $( document ).on( @@ -185,7 +185,7 @@ jQuery( function( $ ) { shipping_method_selected: function() { var shipping_methods = {}; - $( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).each( function() { + $( '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(); } ); @@ -271,11 +271,11 @@ jQuery( function( $ ) { function() { cart.update_cart.apply( cart, [].slice.call( arguments, 1 ) ); } ); $( document ).on( 'click', - '.woocommerce-cart-form input[type=submit]', + '.woocommerce-cart-form :input[type=submit]', this.submit_click ); $( document ).on( 'keypress', - '.woocommerce-cart-form input[type=number]', + '.woocommerce-cart-form :input[type=number]', this.input_keypress ); $( document ).on( 'submit', @@ -298,14 +298,14 @@ jQuery( function( $ ) { '.woocommerce-cart-form .cart_item :input', this.input_changed ); - $( '.woocommerce-cart-form input[name="update_cart"]' ).prop( 'disabled', true ); + $( '.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 ); + $( '.woocommerce-cart-form :input[name="update_cart"]' ).prop( 'disabled', false ); }, /** @@ -376,9 +376,9 @@ jQuery( function( $ ) { * @param {Object} evt The JQuery event */ cart_submit: function( evt ) { - var $submit = $( document.activeElement ); - var $clicked = $( 'input[type=submit][clicked=true]' ); - var $form = $( evt.currentTarget ); + 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. @@ -394,11 +394,11 @@ jQuery( function( $ ) { return false; } - if ( $clicked.is( 'input[name="update_cart"]' ) || $submit.is( 'input.qty' ) ) { + 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' ) ) { + } else if ( $clicked.is( ':input[name="apply_coupon"]' ) || $submit.is( '#coupon_code' ) ) { evt.preventDefault(); this.apply_coupon( $form ); } @@ -410,7 +410,7 @@ jQuery( function( $ ) { * @param {Object} evt The JQuery event */ submit_click: function( evt ) { - $( 'input[type=submit]', $( evt.target ).parents( 'form' ) ).removeAttr( 'clicked' ); + $( ':input[type=submit]', $( evt.target ).parents( 'form' ) ).removeAttr( 'clicked' ); $( evt.target ).attr( 'clicked', 'true' ); }, diff --git a/assets/js/frontend/cart.min.js b/assets/js/frontend/cart.min.js index f2c808f89be..75f95169ef6 100644 --- a/assets/js/frontend/cart.min.js +++ b/assets/js/frontend/cart.min.js @@ -1 +1 @@ -jQuery(function(t){if("undefined"==typeof wc_cart_params)return!1;var e=function(t){return wc_cart_params.wc_ajax_url.toString().replace("%%endpoint%%",t)},o=function(t){return t.is(".processing")||t.parents(".processing").length},c=function(t){o(t)||t.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},i=function(t){t.removeClass("processing").unblock()},r=function(e,o){var c=t.parseHTML(e),i=t(".woocommerce-cart-form",c),r=t(".cart_totals",c),s=t(".woocommerce-error, .woocommerce-message, .woocommerce-info",c);if(0!==t(".woocommerce-cart-form").length){if(o||t(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove(),0===i.length){if(t(".woocommerce-checkout").length)return void(window.location.href=window.location.href);var p=t(".cart-empty",c).closest(".woocommerce");t(".woocommerce-cart-form__contents").closest(".woocommerce").replaceWith(p),s.length>0&&n(s,t(".cart-empty").closest(".woocommerce"))}else t(".woocommerce-checkout").length&&t(document.body).trigger("update_checkout"),t(".woocommerce-cart-form").replaceWith(i),t(".woocommerce-cart-form").find('input[name="update_cart"]').prop("disabled",!0),s.length>0&&n(s),a(r);t(document.body).trigger("updated_wc_div")}else window.location.href=window.location.href},a=function(e){t(".cart_totals").replaceWith(e),t(document.body).trigger("updated_cart_totals")},n=function(e,o){o||(o=t(".woocommerce-cart-form")),o.before(e)},s={init:function(e){this.cart=e,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),t(document).on("click",".shipping-calculator-button",this.toggle_shipping),t(document).on("change","select.shipping_method, input[name^=shipping_method]",this.shipping_method_selected),t(document).on("submit","form.woocommerce-shipping-calculator",this.shipping_calculator_submit),t(".shipping-calculator-form").hide()},toggle_shipping:function(){return t(".shipping-calculator-form").slideToggle("slow"),t(document.body).trigger("country_to_state_changed"),!1},shipping_method_selected:function(){var o={};t("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(){o[t(this).data("index")]=t(this).val()}),c(t("div.cart_totals"));var r={security:wc_cart_params.update_shipping_method_nonce,shipping_method:o};t.ajax({type:"post",url:e("update_shipping_method"),data:r,dataType:"html",success:function(t){a(t)},complete:function(){i(t("div.cart_totals")),t(document.body).trigger("updated_shipping_method")}})},shipping_calculator_submit:function(e){e.preventDefault();var o=t(e.currentTarget);c(t("div.cart_totals")),c(o),t("").attr("type","hidden").attr("name","calc_shipping").attr("value","x").appendTo(o),t.ajax({type:o.attr("method"),url:o.attr("action"),data:o.serialize(),dataType:"html",success:function(t){r(t)},complete:function(){i(o),i(t("div.cart_totals"))}})}},p={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),t(document).on("wc_update_cart",function(){p.update_cart.apply(p,[].slice.call(arguments,1))}),t(document).on("click",".woocommerce-cart-form input[type=submit]",this.submit_click),t(document).on("keypress",".woocommerce-cart-form input[type=number]",this.input_keypress),t(document).on("submit",".woocommerce-cart-form",this.cart_submit),t(document).on("click","a.woocommerce-remove-coupon",this.remove_coupon_clicked),t(document).on("click",".woocommerce-cart-form .product-remove > a",this.item_remove_clicked),t(document).on("click",".woocommerce-cart .restore-item",this.item_restore_clicked),t(document).on("change input",".woocommerce-cart-form .cart_item :input",this.input_changed),t('.woocommerce-cart-form input[name="update_cart"]').prop("disabled",!0)},input_changed:function(){t('.woocommerce-cart-form input[name="update_cart"]').prop("disabled",!1)},update_cart:function(e){var o=t(".woocommerce-cart-form");c(o),c(t("div.cart_totals")),t.ajax({type:o.attr("method"),url:o.attr("action"),data:o.serialize(),dataType:"html",success:function(t){r(t,e)},complete:function(){i(o),i(t("div.cart_totals"))}})},update_cart_totals:function(){c(t("div.cart_totals")),t.ajax({url:e("get_cart_totals"),dataType:"html",success:function(t){a(t)},complete:function(){i(t("div.cart_totals"))}})},input_keypress:function(t){13===t.keyCode&&(t.preventDefault(),this.cart_submit(t))},cart_submit:function(e){var c=t(document.activeElement),i=t("input[type=submit][clicked=true]"),r=t(e.currentTarget);if(r.is("form")||(r=t(e.currentTarget).parents("form")),0!==r.find(".woocommerce-cart-form__contents").length)return!o(r)&&void(i.is('input[name="update_cart"]')||c.is("input.qty")?(e.preventDefault(),this.quantity_update(r)):(i.is('input[name="apply_coupon"]')||c.is("#coupon_code"))&&(e.preventDefault(),this.apply_coupon(r)))},submit_click:function(e){t("input[type=submit]",t(e.target).parents("form")).removeAttr("clicked"),t(e.target).attr("clicked","true")},apply_coupon:function(o){c(o);var r=this,a=t("#coupon_code"),s=a.val(),p={security:wc_cart_params.apply_coupon_nonce,coupon_code:s};t.ajax({type:"POST",url:e("apply_coupon"),data:p,dataType:"html",success:function(e){t(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove(),n(e),t(document.body).trigger("applied_coupon",[s])},complete:function(){i(o),a.val(""),r.update_cart(!0)}})},remove_coupon_clicked:function(o){o.preventDefault();var r=this,a=t(o.currentTarget).closest(".cart_totals"),s=t(o.currentTarget).attr("data-coupon");c(a);var p={security:wc_cart_params.remove_coupon_nonce,coupon:s};t.ajax({type:"POST",url:e("remove_coupon"),data:p,dataType:"html",success:function(e){t(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove(),n(e),t(document.body).trigger("removed_coupon",[s]),i(a)},complete:function(){r.update_cart(!0)}})},quantity_update:function(e){c(e),c(t("div.cart_totals")),t("").attr("type","hidden").attr("name","update_cart").attr("value","Update Cart").appendTo(e),t.ajax({type:e.attr("method"),url:e.attr("action"),data:e.serialize(),dataType:"html",success:function(t){r(t)},complete:function(){i(e),i(t("div.cart_totals"))}})},item_remove_clicked:function(e){e.preventDefault();var o=t(e.currentTarget),a=o.parents("form");c(a),c(t("div.cart_totals")),t.ajax({type:"GET",url:o.attr("href"),dataType:"html",success:function(t){r(t)},complete:function(){i(a),i(t("div.cart_totals"))}})},item_restore_clicked:function(e){e.preventDefault();var o=t(e.currentTarget),a=t("form.woocommerce-cart-form");c(a),c(t("div.cart_totals")),t.ajax({type:"GET",url:o.attr("href"),dataType:"html",success:function(t){r(t)},complete:function(){i(a),i(t("div.cart_totals"))}})}};s.init(p),p.init()}); \ No newline at end of file +jQuery(function(t){if("undefined"==typeof wc_cart_params)return!1;var e=function(t){return wc_cart_params.wc_ajax_url.toString().replace("%%endpoint%%",t)},o=function(t){return t.is(".processing")||t.parents(".processing").length},c=function(t){o(t)||t.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},i=function(t){t.removeClass("processing").unblock()},r=function(e,o){var c=t.parseHTML(e),i=t(".woocommerce-cart-form",c),r=t(".cart_totals",c),s=t(".woocommerce-error, .woocommerce-message, .woocommerce-info",c);if(0!==t(".woocommerce-cart-form").length){if(o||t(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove(),0===i.length){if(t(".woocommerce-checkout").length)return void(window.location.href=window.location.href);var p=t(".cart-empty",c).closest(".woocommerce");t(".woocommerce-cart-form__contents").closest(".woocommerce").replaceWith(p),s.length>0&&n(s,t(".cart-empty").closest(".woocommerce"))}else t(".woocommerce-checkout").length&&t(document.body).trigger("update_checkout"),t(".woocommerce-cart-form").replaceWith(i),t(".woocommerce-cart-form").find(':input[name="update_cart"]').prop("disabled",!0),s.length>0&&n(s),a(r);t(document.body).trigger("updated_wc_div")}else window.location.href=window.location.href},a=function(e){t(".cart_totals").replaceWith(e),t(document.body).trigger("updated_cart_totals")},n=function(e,o){o||(o=t(".woocommerce-cart-form")),o.before(e)},s={init:function(e){this.cart=e,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),t(document).on("click",".shipping-calculator-button",this.toggle_shipping),t(document).on("change","select.shipping_method, :input[name^=shipping_method]",this.shipping_method_selected),t(document).on("submit","form.woocommerce-shipping-calculator",this.shipping_calculator_submit),t(".shipping-calculator-form").hide()},toggle_shipping:function(){return t(".shipping-calculator-form").slideToggle("slow"),t(document.body).trigger("country_to_state_changed"),!1},shipping_method_selected:function(){var o={};t("select.shipping_method, :input[name^=shipping_method][type=radio]:checked, :input[name^=shipping_method][type=hidden]").each(function(){o[t(this).data("index")]=t(this).val()}),c(t("div.cart_totals"));var r={security:wc_cart_params.update_shipping_method_nonce,shipping_method:o};t.ajax({type:"post",url:e("update_shipping_method"),data:r,dataType:"html",success:function(t){a(t)},complete:function(){i(t("div.cart_totals")),t(document.body).trigger("updated_shipping_method")}})},shipping_calculator_submit:function(e){e.preventDefault();var o=t(e.currentTarget);c(t("div.cart_totals")),c(o),t("").attr("type","hidden").attr("name","calc_shipping").attr("value","x").appendTo(o),t.ajax({type:o.attr("method"),url:o.attr("action"),data:o.serialize(),dataType:"html",success:function(t){r(t)},complete:function(){i(o),i(t("div.cart_totals"))}})}},p={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),t(document).on("wc_update_cart",function(){p.update_cart.apply(p,[].slice.call(arguments,1))}),t(document).on("click",".woocommerce-cart-form :input[type=submit]",this.submit_click),t(document).on("keypress",".woocommerce-cart-form :input[type=number]",this.input_keypress),t(document).on("submit",".woocommerce-cart-form",this.cart_submit),t(document).on("click","a.woocommerce-remove-coupon",this.remove_coupon_clicked),t(document).on("click",".woocommerce-cart-form .product-remove > a",this.item_remove_clicked),t(document).on("click",".woocommerce-cart .restore-item",this.item_restore_clicked),t(document).on("change input",".woocommerce-cart-form .cart_item :input",this.input_changed),t('.woocommerce-cart-form :input[name="update_cart"]').prop("disabled",!0)},input_changed:function(){t('.woocommerce-cart-form :input[name="update_cart"]').prop("disabled",!1)},update_cart:function(e){var o=t(".woocommerce-cart-form");c(o),c(t("div.cart_totals")),t.ajax({type:o.attr("method"),url:o.attr("action"),data:o.serialize(),dataType:"html",success:function(t){r(t,e)},complete:function(){i(o),i(t("div.cart_totals"))}})},update_cart_totals:function(){c(t("div.cart_totals")),t.ajax({url:e("get_cart_totals"),dataType:"html",success:function(t){a(t)},complete:function(){i(t("div.cart_totals"))}})},input_keypress:function(t){13===t.keyCode&&(t.preventDefault(),this.cart_submit(t))},cart_submit:function(e){var c=t(document.activeElement),i=t(":input[type=submit][clicked=true]"),r=t(e.currentTarget);if(r.is("form")||(r=t(e.currentTarget).parents("form")),0!==r.find(".woocommerce-cart-form__contents").length)return!o(r)&&void(i.is(':input[name="update_cart"]')||c.is("input.qty")?(e.preventDefault(),this.quantity_update(r)):(i.is(':input[name="apply_coupon"]')||c.is("#coupon_code"))&&(e.preventDefault(),this.apply_coupon(r)))},submit_click:function(e){t(":input[type=submit]",t(e.target).parents("form")).removeAttr("clicked"),t(e.target).attr("clicked","true")},apply_coupon:function(o){c(o);var r=this,a=t("#coupon_code"),s=a.val(),p={security:wc_cart_params.apply_coupon_nonce,coupon_code:s};t.ajax({type:"POST",url:e("apply_coupon"),data:p,dataType:"html",success:function(e){t(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove(),n(e),t(document.body).trigger("applied_coupon",[s])},complete:function(){i(o),a.val(""),r.update_cart(!0)}})},remove_coupon_clicked:function(o){o.preventDefault();var r=this,a=t(o.currentTarget).closest(".cart_totals"),s=t(o.currentTarget).attr("data-coupon");c(a);var p={security:wc_cart_params.remove_coupon_nonce,coupon:s};t.ajax({type:"POST",url:e("remove_coupon"),data:p,dataType:"html",success:function(e){t(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove(),n(e),t(document.body).trigger("removed_coupon",[s]),i(a)},complete:function(){r.update_cart(!0)}})},quantity_update:function(e){c(e),c(t("div.cart_totals")),t("").attr("type","hidden").attr("name","update_cart").attr("value","Update Cart").appendTo(e),t.ajax({type:e.attr("method"),url:e.attr("action"),data:e.serialize(),dataType:"html",success:function(t){r(t)},complete:function(){i(e),i(t("div.cart_totals"))}})},item_remove_clicked:function(e){e.preventDefault();var o=t(e.currentTarget),a=o.parents("form");c(a),c(t("div.cart_totals")),t.ajax({type:"GET",url:o.attr("href"),dataType:"html",success:function(t){r(t)},complete:function(){i(a),i(t("div.cart_totals"))}})},item_restore_clicked:function(e){e.preventDefault();var o=t(e.currentTarget),a=t("form.woocommerce-cart-form");c(a),c(t("div.cart_totals")),t.ajax({type:"GET",url:o.attr("href"),dataType:"html",success:function(t){r(t)},complete:function(){i(a),i(t("div.cart_totals"))}})}};s.init(p),p.init()}); \ No newline at end of file