Move js in from php template file.
This commit is contained in:
parent
b0a485a5e6
commit
974b337fbb
|
@ -12,4 +12,128 @@
|
|||
$tbody.append( rowTemplate( rowData ) );
|
||||
} );
|
||||
});
|
||||
|
||||
jQuery('.wc_tax_rates .remove_tax_rates').click(function() {
|
||||
var $tbody = jQuery('.wc_tax_rates').find('tbody');
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$current = $tbody.find('tr.current');
|
||||
$current.find('input').val('');
|
||||
$current.find('input.remove_tax_rate').val('1');
|
||||
|
||||
$current.each(function(){
|
||||
if ( jQuery(this).is('.new') )
|
||||
jQuery(this).remove();
|
||||
else
|
||||
jQuery(this).hide();
|
||||
});
|
||||
} else {
|
||||
alert('<?php echo esc_js( __( 'No row(s) selected', 'woocommerce' ) ); ?>');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.wc_tax_rates .export').click(function() {
|
||||
|
||||
var csv_data = "data:application/csv;charset=utf-8,<?php echo esc_js( implode( ',', array(
|
||||
__( 'Country Code', 'woocommerce' ),
|
||||
__( 'State Code', 'woocommerce' ),
|
||||
__( 'ZIP/Postcode', 'woocommerce' ),
|
||||
__( 'City', 'woocommerce' ),
|
||||
__( 'Rate %', 'woocommerce' ),
|
||||
__( 'Tax Name', 'woocommerce' ),
|
||||
__( 'Priority', 'woocommerce' ),
|
||||
__( 'Compound', 'woocommerce' ),
|
||||
__( 'Shipping', 'woocommerce' ),
|
||||
__( 'Tax Class', 'woocommerce' ),
|
||||
) ) ); ?>\n";
|
||||
|
||||
jQuery('#rates tr:visible').each(function() {
|
||||
var row = '';
|
||||
jQuery(this).find('td:not(.sort) input').each(function() {
|
||||
|
||||
if ( jQuery(this).is('.checkbox') ) {
|
||||
|
||||
if ( jQuery(this).is(':checked') ) {
|
||||
val = 1;
|
||||
} else {
|
||||
val = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
var val = jQuery(this).val();
|
||||
|
||||
if ( ! val )
|
||||
val = jQuery(this).attr('placeholder');
|
||||
}
|
||||
|
||||
row = row + val + ',';
|
||||
});
|
||||
row = row + '<?php echo $current_class; ?>';
|
||||
//row.substring( 0, row.length - 1 );
|
||||
csv_data = csv_data + row + "\n";
|
||||
});
|
||||
|
||||
jQuery(this).attr( 'href', encodeURI( csv_data ) );
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
jQuery('.wc_tax_rates .insert').click(function() {
|
||||
var $tbody = jQuery('.wc_tax_rates').find('tbody');
|
||||
var size = $tbody.find('tr').size();
|
||||
var code = wp.template( 'wc-tax-table-row' )( {
|
||||
tax_rate_id : 'new-' + size,
|
||||
tax_rate_priority : 1,
|
||||
tax_rate_shipping : 1,
|
||||
new : true
|
||||
} );
|
||||
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$tbody.find('tr.current').after( code );
|
||||
} else {
|
||||
$tbody.append( code );
|
||||
}
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.wc_tax_rates td.postcode, .wc_tax_rates td.city').find('input').change(function() {
|
||||
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
|
||||
});
|
||||
|
||||
var availableCountries = [<?php
|
||||
$countries = array();
|
||||
foreach ( WC()->countries->get_allowed_countries() as $value => $label )
|
||||
$countries[] = '{ label: "' . esc_attr( $label ) . '", value: "' . $value . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
var availableStates = [<?php
|
||||
$countries = array();
|
||||
foreach ( WC()->countries->get_allowed_country_states() as $value => $label )
|
||||
foreach ( $label as $code => $state )
|
||||
$countries[] = '{ label: "' . esc_attr( $state ) . '", value: "' . $code . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
})(jQuery, htmlSettingsTaxLocalizeScript, wp);
|
||||
|
|
|
@ -123,131 +123,3 @@ wp_enqueue_script( 'wc-settings-tax' );
|
|||
</td>
|
||||
</tr>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
jQuery( function() {
|
||||
jQuery('.wc_tax_rates .remove_tax_rates').click(function() {
|
||||
var $tbody = jQuery('.wc_tax_rates').find('tbody');
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$current = $tbody.find('tr.current');
|
||||
$current.find('input').val('');
|
||||
$current.find('input.remove_tax_rate').val('1');
|
||||
|
||||
$current.each(function(){
|
||||
if ( jQuery(this).is('.new') )
|
||||
jQuery(this).remove();
|
||||
else
|
||||
jQuery(this).hide();
|
||||
});
|
||||
} else {
|
||||
alert('<?php echo esc_js( __( 'No row(s) selected', 'woocommerce' ) ); ?>');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.wc_tax_rates .export').click(function() {
|
||||
|
||||
var csv_data = "data:application/csv;charset=utf-8,<?php echo esc_js( implode( ',', array(
|
||||
__( 'Country Code', 'woocommerce' ),
|
||||
__( 'State Code', 'woocommerce' ),
|
||||
__( 'ZIP/Postcode', 'woocommerce' ),
|
||||
__( 'City', 'woocommerce' ),
|
||||
__( 'Rate %', 'woocommerce' ),
|
||||
__( 'Tax Name', 'woocommerce' ),
|
||||
__( 'Priority', 'woocommerce' ),
|
||||
__( 'Compound', 'woocommerce' ),
|
||||
__( 'Shipping', 'woocommerce' ),
|
||||
__( 'Tax Class', 'woocommerce' ),
|
||||
) ) ); ?>\n";
|
||||
|
||||
jQuery('#rates tr:visible').each(function() {
|
||||
var row = '';
|
||||
jQuery(this).find('td:not(.sort) input').each(function() {
|
||||
|
||||
if ( jQuery(this).is('.checkbox') ) {
|
||||
|
||||
if ( jQuery(this).is(':checked') ) {
|
||||
val = 1;
|
||||
} else {
|
||||
val = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
var val = jQuery(this).val();
|
||||
|
||||
if ( ! val )
|
||||
val = jQuery(this).attr('placeholder');
|
||||
}
|
||||
|
||||
row = row + val + ',';
|
||||
});
|
||||
row = row + '<?php echo $current_class; ?>';
|
||||
//row.substring( 0, row.length - 1 );
|
||||
csv_data = csv_data + row + "\n";
|
||||
});
|
||||
|
||||
jQuery(this).attr( 'href', encodeURI( csv_data ) );
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
jQuery('.wc_tax_rates .insert').click(function() {
|
||||
var $tbody = jQuery('.wc_tax_rates').find('tbody');
|
||||
var size = $tbody.find('tr').size();
|
||||
var code = wp.template( 'wc-tax-table-row' )( {
|
||||
tax_rate_id : 'new-' + size,
|
||||
tax_rate_priority : 1,
|
||||
tax_rate_shipping : 1,
|
||||
new : true
|
||||
} );
|
||||
|
||||
if ( $tbody.find('tr.current').size() > 0 ) {
|
||||
$tbody.find('tr.current').after( code );
|
||||
} else {
|
||||
$tbody.append( code );
|
||||
}
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery('.wc_tax_rates td.postcode, .wc_tax_rates td.city').find('input').change(function() {
|
||||
jQuery(this).attr( 'name', jQuery(this).attr( 'data-name' ) );
|
||||
});
|
||||
|
||||
var availableCountries = [<?php
|
||||
$countries = array();
|
||||
foreach ( WC()->countries->get_allowed_countries() as $value => $label )
|
||||
$countries[] = '{ label: "' . esc_attr( $label ) . '", value: "' . $value . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
var availableStates = [<?php
|
||||
$countries = array();
|
||||
foreach ( WC()->countries->get_allowed_country_states() as $value => $label )
|
||||
foreach ( $label as $code => $state )
|
||||
$countries[] = '{ label: "' . esc_attr( $state ) . '", value: "' . $code . '" }';
|
||||
echo implode( ', ', $countries );
|
||||
?>];
|
||||
|
||||
jQuery( "td.country input" ).autocomplete({
|
||||
source: availableCountries,
|
||||
minLength: 3
|
||||
});
|
||||
|
||||
jQuery( "td.state input" ).autocomplete({
|
||||
source: availableStates,
|
||||
minLength: 3
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue