OSDN Git Service

WordPressテンプレート機能更新。
[magic3/magic3.git] / scripts / wp / woocommerce / assets / js / admin / wc-setup.js
1 /*global wc_setup_params */
2 jQuery( function( $ ) {
3
4         var locale_info = $.parseJSON( wc_setup_params.locale_info );
5
6         $( 'select[name="store_location"]' ).change( function() {
7                 var country_option      = $(this).val().split( ':' );
8                 var country             = country_option[0];
9                 var state               = country_option[1] || false;
10                 var country_locale_info = locale_info[ country ];
11                 var hide_if_set = [ 'thousand_sep', 'decimal_sep', 'num_decimals', 'currency_pos' ];
12
13                 if ( country_locale_info ) {
14                         $.each( country_locale_info, function( index, value ) {
15                                 $(':input[name="' + index + '"]').val( value ).change();
16
17                                 if ( -1 !== $.inArray( index, hide_if_set ) ) {
18                                         $(':input[name="' + index + '"]').closest('tr').hide();
19                                 }
20                         } );
21
22                         if ( ! $.isArray( country_locale_info.tax_rates ) ) {
23                                 var tax_rates = [];
24
25                                 if ( state && country_locale_info.tax_rates[ state ] ) {
26                                         tax_rates = tax_rates.concat( country_locale_info.tax_rates[ state ] );
27                                 } else if ( country_locale_info.tax_rates[ '' ] ) {
28                                         tax_rates = tax_rates.concat( country_locale_info.tax_rates[ '' ] );
29                                 }
30
31                                 tax_rates = tax_rates.concat( country_locale_info.tax_rates[ '*' ] || [] );
32
33                                 if ( tax_rates.length ) {
34                                         var $rate_table = $( 'table.tax-rates tbody' ).empty();
35
36                                         $.each( tax_rates, function( index, rate ) {
37                                                 $( '<tr>', {
38                                                         html: [
39                                                                 $( '<td>', { 'class': 'readonly', text: rate.country || ''  } ),
40                                                                 $( '<td>', { 'class': 'readonly', text: rate.state   || '*' } ),
41                                                                 $( '<td>', { 'class': 'readonly', text: rate.rate    || ''  } ),
42                                                                 $( '<td>', { 'class': 'readonly', text: rate.name    || ''  } )
43                                                         ]
44                                                 } ).appendTo( $rate_table );
45                                         } );
46
47                                         $( '.tax-rates' ).show();
48                                 } else {
49                                         $( '.tax-rates' ).hide();
50                                 }
51                         }
52                 } else {
53                         $(':input[name="currency_pos"]').closest('tr').show();
54                         $(':input[name="thousand_sep"]').closest('tr').show();
55                         $(':input[name="decimal_sep"]').closest('tr').show();
56                         $(':input[name="num_decimals"]').closest('tr').show();
57                         $( '.tax-rates' ).hide();
58                 }
59         } ).change();
60
61         $( 'input[name="woocommerce_calc_taxes"]' ).change( function() {
62                 if ( $(this).is( ':checked' ) ) {
63                         $(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest('tr').show();
64                         $('tr.tax-rates').show();
65                 } else {
66                         $(':input[name="woocommerce_prices_include_tax"], :input[name="woocommerce_import_tax_rates"]').closest('tr').hide();
67                         $('tr.tax-rates').hide();
68                 }
69         } ).change();
70
71         $( '.button-next' ).on( 'click', function() {
72                 $('.wc-setup-content').block({
73                         message: null,
74                         overlayCSS: {
75                                 background: '#fff',
76                                 opacity: 0.6
77                         }
78                 });
79                 return true;
80         } );
81
82         $( '.wc-wizard-payment-gateways, .wc-wizard-shipping-methods' ).on( 'change', '.wc-wizard-gateway-enable input, .wc-wizard-shipping-enable input', function() {
83                 if ( $( this ).is( ':checked' ) ) {
84                         $( this ).closest( 'li' ).addClass( 'checked' );
85                 } else {
86                         $( this ).closest( 'li' ).removeClass( 'checked' );
87                 }
88         } );
89
90         $( '.wc-wizard-payment-gateways, .wc-wizard-shipping-methods' ).on( 'click', 'li.wc-wizard-gateway, li.wc-wizard-shipping', function() {
91                 var $enabled = $( this ).find( '.wc-wizard-gateway-enable input, .wc-wizard-shipping-enable input' );
92
93                 $enabled.prop( 'checked', ! $enabled.prop( 'checked' ) ).change();
94         } );
95
96         $( '.wc-wizard-payment-gateways li, .wc-wizard-shipping-methods li' ).on( 'click', 'table, a', function( e ) {
97                 e.stopPropagation();
98         } );
99 } );