Merge pull request #10841 from coderkevin/fix_safari_submit

Fix cart ajax submit buttons for Safari.
This commit is contained in:
Mike Jolley 2016-05-03 12:21:39 +01:00
commit 37b8bebd03
2 changed files with 20 additions and 4 deletions

View File

@ -213,11 +213,16 @@ jQuery( function( $ ) {
init: function() { init: function() {
this.update_cart_totals = this.update_cart_totals.bind( this ); this.update_cart_totals = this.update_cart_totals.bind( this );
this.cart_submit = this.cart_submit.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.apply_coupon = this.apply_coupon.bind( this );
this.remove_coupon_clicked = this.remove_coupon_clicked.bind( this ); this.remove_coupon_clicked = this.remove_coupon_clicked.bind( this );
this.quantity_update = this.quantity_update.bind( this ); this.quantity_update = this.quantity_update.bind( this );
this.item_remove_clicked = this.item_remove_clicked.bind( this ); this.item_remove_clicked = this.item_remove_clicked.bind( this );
$( document ).on(
'click',
'div.woocommerce > form input[type=submit]',
this.submit_click );
$( document ).on( $( document ).on(
'submit', 'submit',
'div.woocommerce > form', 'div.woocommerce > form',
@ -239,7 +244,7 @@ jQuery( function( $ ) {
}, },
/** /**
* After and input is changed, enabled the update cart button. * After an input is changed, enable the update cart button.
*/ */
input_changed: function() { input_changed: function() {
$( 'div.woocommerce > form input[name="update_cart"]' ).prop( 'disabled', false ); $( 'div.woocommerce > form input[name="update_cart"]' ).prop( 'disabled', false );
@ -270,6 +275,7 @@ jQuery( function( $ ) {
var $form = $( evt.target ); var $form = $( evt.target );
var $submit = $( document.activeElement ); var $submit = $( document.activeElement );
var $clicked = $( 'input[type=submit][clicked=true]' );
if ( 0 === $form.find( 'table.shop_table.cart' ).length ) { if ( 0 === $form.find( 'table.shop_table.cart' ).length ) {
return false; return false;
@ -278,14 +284,24 @@ jQuery( function( $ ) {
return false; return false;
} }
if ( $submit.is( '[name="update_cart"]' ) || $submit.is( 'input.qty' ) ) { if ( $clicked.is( '[name="update_cart"]' ) || $submit.is( 'input.qty' ) ) {
this.quantity_update( $form ); this.quantity_update( $form );
} else if ( $submit.is( '[name="apply_coupon"]' ) || $submit.is( '#coupon_code' ) ) { } else if ( $clicked.is( '[name="apply_coupon"]' ) || $submit.is( '#coupon_code' ) ) {
this.apply_coupon( $form ); 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 * Apply Coupon code
* *

File diff suppressed because one or more lines are too long