|
78 | 78 | }
|
79 | 79 | }
|
80 | 80 |
|
| 81 | + function is_blocked( $node ) { |
| 82 | + return $node.is( '.processing' ) || $node.parents( '.processing' ).length; |
| 83 | + } |
| 84 | + |
| 85 | + function block( $node ) { |
| 86 | + if ( ! is_blocked( $node ) ) { |
| 87 | + $node.addClass( 'processing' ).block( { |
| 88 | + message: null, |
| 89 | + overlayCSS: { |
| 90 | + background: '#fff', |
| 91 | + opacity: 0.6 |
| 92 | + } |
| 93 | + } ); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + function unblock( $node ) { |
| 98 | + $node.removeClass( 'processing' ).unblock(); |
| 99 | + } |
| 100 | + |
| 101 | + function sendConfirmationCode( e ) { |
| 102 | + var $this = $( this ); |
| 103 | + e.preventDefault(); |
| 104 | + |
| 105 | + if ( $this.data( 'sending' ) ) { |
| 106 | + return; |
| 107 | + } |
| 108 | + |
| 109 | + $this.data( 'sending', true ); |
| 110 | + |
| 111 | + var $thisArea = $this.parents('.create-account'); |
| 112 | + |
| 113 | + block( $thisArea ); |
| 114 | + |
| 115 | + $.ajax( |
| 116 | + { |
| 117 | + type: 'post', |
| 118 | + url: $this.prop( 'href' ), |
| 119 | + success: function( result ) { |
| 120 | + unblock( $thisArea ); |
| 121 | + $this.data( 'sending', false ); |
| 122 | + // TODO: Maybe display some feedback |
| 123 | + }, |
| 124 | + error: function( jqXHR, textStatus, errorThrown ) { |
| 125 | + unblock( $thisArea ); |
| 126 | + $this.data( 'sending', false ); |
| 127 | + // TODO: Maybe display some feedback about what went wrong? |
| 128 | + } |
| 129 | + } |
| 130 | + ); |
| 131 | + } |
| 132 | + |
81 | 133 | function initAmazonPaymentFields() {
|
82 | 134 | if ( ! isAmazonCheckout() ) {
|
83 | 135 | return;
|
|
103 | 155 | $( '.woocommerce-shipping-fields' ).insertBefore( '#payment' );
|
104 | 156 | }
|
105 | 157 | $( '.woocommerce-additional-fields' ).insertBefore( '#payment' );
|
| 158 | + |
| 159 | + $( '.wc-apa-send-confirm-ownership-code' ).on( 'click', sendConfirmationCode ); |
106 | 160 | }
|
107 | 161 |
|
108 | 162 | initAmazonPaymentFields();
|
|
0 commit comments