api-keys.js
5 years ago
api-keys.min.js
2 years ago
backbone-modal.js
2 years ago
backbone-modal.min.js
2 years ago
marketplace-suggestions.js
10 months ago
marketplace-suggestions.min.js
10 months ago
meta-boxes-coupon.js
1 year ago
meta-boxes-coupon.min.js
1 year ago
meta-boxes-order.js
1 month ago
meta-boxes-order.min.js
1 month ago
meta-boxes-product-variation.js
1 year ago
meta-boxes-product-variation.min.js
1 year ago
meta-boxes-product.js
1 month ago
meta-boxes-product.min.js
1 month ago
meta-boxes.js
4 months ago
meta-boxes.min.js
4 months ago
network-orders.js
8 years ago
network-orders.min.js
2 years ago
order-attribution-admin.js
2 years ago
order-attribution-admin.min.js
2 years ago
product-editor.js
11 months ago
product-editor.min.js
11 months ago
product-ordering.js
3 months ago
product-ordering.min.js
3 months ago
quick-edit.js
1 year ago
quick-edit.min.js
1 year ago
reports.js
1 year ago
reports.min.js
1 year ago
settings-views-html-settings-tax.js
1 year ago
settings-views-html-settings-tax.min.js
1 year ago
settings.js
1 year ago
settings.min.js
1 year ago
system-status.js
3 months ago
system-status.min.js
3 months ago
term-ordering.js
3 months ago
term-ordering.min.js
3 months ago
users.js
5 years ago
users.min.js
2 years ago
variation-gallery.js
1 month ago
variation-gallery.min.js
1 month ago
wc-brands-enhanced-select.js
1 year ago
wc-brands-enhanced-select.min.js
1 year ago
wc-clipboard.js
5 years ago
wc-clipboard.min.js
5 years ago
wc-customer-stock-notifications.js
10 months ago
wc-customer-stock-notifications.min.js
10 months ago
wc-enhanced-select.js
2 years ago
wc-enhanced-select.min.js
2 years ago
wc-orders.js
3 years ago
wc-orders.min.js
2 years ago
wc-product-export.js
1 year ago
wc-product-export.min.js
1 year ago
wc-product-import.js
3 years ago
wc-product-import.min.js
2 years ago
wc-recent-reviews-widget-async.js
4 months ago
wc-recent-reviews-widget-async.min.js
4 months ago
wc-setup.js
5 years ago
wc-setup.min.js
2 years ago
wc-shipping-classes.js
1 year ago
wc-shipping-classes.min.js
1 year ago
wc-shipping-providers.js
3 months ago
wc-shipping-providers.min.js
3 months ago
wc-shipping-zone-methods.js
5 months ago
wc-shipping-zone-methods.min.js
5 months ago
wc-shipping-zones.js
1 year ago
wc-shipping-zones.min.js
1 year ago
wc-status-widget-async.js
4 months ago
wc-status-widget-async.min.js
4 months ago
wc-status-widget.js
1 year ago
wc-status-widget.min.js
1 year ago
woocommerce_admin.js
1 month ago
woocommerce_admin.min.js
1 month ago
users.js
121 lines
| 1 | /*global wc_users_params */ |
| 2 | jQuery( function ( $ ) { |
| 3 | |
| 4 | /** |
| 5 | * Users country and state fields |
| 6 | */ |
| 7 | var wc_users_fields = { |
| 8 | states: null, |
| 9 | init: function() { |
| 10 | if ( typeof wc_users_params.countries !== 'undefined' ) { |
| 11 | /* State/Country select boxes */ |
| 12 | this.states = JSON.parse( wc_users_params.countries.replace( /"/g, '"' ) ); |
| 13 | } |
| 14 | |
| 15 | $( '.js_field-country' ).selectWoo().on( 'change', this.change_country ); |
| 16 | $( '.js_field-country' ).trigger( 'change', [ true ] ); |
| 17 | $( document.body ).on( 'change', 'select.js_field-state', this.change_state ); |
| 18 | |
| 19 | $( document.body ).on( 'click', 'button.js_copy-billing', this.copy_billing ); |
| 20 | }, |
| 21 | |
| 22 | change_country: function( e, stickValue ) { |
| 23 | // Check for stickValue before using it |
| 24 | if ( typeof stickValue === 'undefined' ) { |
| 25 | stickValue = false; |
| 26 | } |
| 27 | |
| 28 | // Prevent if we don't have the metabox data |
| 29 | if ( wc_users_fields.states === null ) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | var $this = $( this ), |
| 34 | country = $this.val(), |
| 35 | $state = $this.parents( '.form-table' ).find( ':input.js_field-state' ), |
| 36 | $parent = $state.parent(), |
| 37 | input_name = $state.attr( 'name' ), |
| 38 | input_id = $state.attr( 'id' ), |
| 39 | stickstatefield = 'woocommerce.stickState-' + country, |
| 40 | value = $this.data( stickstatefield ) ? $this.data( stickstatefield ) : $state.val(), |
| 41 | placeholder = $state.attr( 'placeholder' ), |
| 42 | $newstate; |
| 43 | |
| 44 | if ( stickValue ){ |
| 45 | $this.data( 'woocommerce.stickState-' + country, value ); |
| 46 | } |
| 47 | |
| 48 | // Remove the previous DOM element |
| 49 | $parent.show().find( '.select2-container' ).remove(); |
| 50 | |
| 51 | if ( ! $.isEmptyObject( wc_users_fields.states[ country ] ) ) { |
| 52 | var state = wc_users_fields.states[ country ], |
| 53 | $defaultOption = $( '<option value=""></option>' ) |
| 54 | .text( wc_users_fields.i18n_select_state_text ); |
| 55 | |
| 56 | $newstate = $( '<select style="width: 25em;"></select>' ) |
| 57 | .prop( 'id', input_id ) |
| 58 | .prop( 'name', input_name ) |
| 59 | .prop( 'placeholder', placeholder ) |
| 60 | .addClass( 'js_field-state' ) |
| 61 | .append( $defaultOption ); |
| 62 | |
| 63 | $.each( state, function( index ) { |
| 64 | var $option = $( '<option></option>' ) |
| 65 | .prop( 'value', index ) |
| 66 | .text( state[ index ] ); |
| 67 | $newstate.append( $option ); |
| 68 | } ); |
| 69 | |
| 70 | $newstate.val( value ); |
| 71 | |
| 72 | $state.replaceWith( $newstate ); |
| 73 | |
| 74 | $newstate.show().selectWoo().hide().trigger( 'change' ); |
| 75 | } else { |
| 76 | $newstate = $( '<input type="text" />' ) |
| 77 | .prop( 'id', input_id ) |
| 78 | .prop( 'name', input_name ) |
| 79 | .prop( 'placeholder', placeholder ) |
| 80 | .addClass( 'js_field-state regular-text' ) |
| 81 | .val( value ); |
| 82 | $state.replaceWith( $newstate ); |
| 83 | } |
| 84 | |
| 85 | // This event has a typo - deprecated in 2.5.0 |
| 86 | $( document.body ).trigger( 'contry-change.woocommerce', [country, $( this ).closest( 'div' )] ); |
| 87 | $( document.body ).trigger( 'country-change.woocommerce', [country, $( this ).closest( 'div' )] ); |
| 88 | }, |
| 89 | |
| 90 | change_state: function() { |
| 91 | // Here we will find if state value on a select has changed and stick it to the country data |
| 92 | var $this = $( this ), |
| 93 | state = $this.val(), |
| 94 | $country = $this.parents( '.form-table' ).find( ':input.js_field-country' ), |
| 95 | country = $country.val(); |
| 96 | |
| 97 | $country.data( 'woocommerce.stickState-' + country, state ); |
| 98 | }, |
| 99 | |
| 100 | copy_billing: function( event ) { |
| 101 | event.preventDefault(); |
| 102 | |
| 103 | $( '#fieldset-billing' ).find( 'input, select' ).each( function( i, el ) { |
| 104 | // The address keys match up, except for the prefix |
| 105 | var shipName = el.name.replace( /^billing_/, 'shipping_' ); |
| 106 | // Swap prefix, then check if there are any elements |
| 107 | var shipEl = $( '[name="' + shipName + '"]' ); |
| 108 | // No corresponding shipping field, skip this item |
| 109 | if ( ! shipEl.length ) { |
| 110 | return; |
| 111 | } |
| 112 | // Found a matching shipping element, update the value |
| 113 | shipEl.val( el.value ).trigger( 'change' ); |
| 114 | } ); |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | wc_users_fields.init(); |
| 119 | |
| 120 | }); |
| 121 |