Tax Rate Search: First whack.

This is by no means complete.  A number of things need to be relocated
and optimized still, but it does a rough search, purely in JS, and
highlights the results in yellow.
This commit is contained in:
George Stephanis 2015-08-06 17:41:12 -04:00
parent 817f8476ac
commit cb4e3cb774
1 changed files with 38 additions and 0 deletions

View File

@ -5,6 +5,44 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<h3><?php printf( __( 'Tax Rates for the "%s" Class', 'woocommerce' ), $current_class ? esc_html( $current_class ) : __( 'Standard', 'woocommerce' ) ); ?></h3>
<p><?php printf( __( 'Define tax rates for countries and states below. <a href="%s">See here</a> for available alpha-2 country codes.', 'woocommerce' ), 'http://en.wikipedia.org/wiki/ISO_3166-1#Current_codes' ); ?></p>
<input type="search" class="tax-search" placeholder="<?php esc_attr_e( 'Search…', 'woocommerce' ); ?>" />
<p class="num-results-found"></p>
<script>
(function($){
function processTaxRateSearch() {
var searchText = this.value.toLowerCase(),
$table = $('table.wc_tax_rates'),
$rows = $table.find('tbody tr' ),
results = 0;
if ( 0 === searchText.length ) {
$rows.removeClass('search-result-match');
$('.num-results-found' ).text('');
return;
}
$rows.each(function(){
var rowText = $(this).find(':input').map( function(){ return this.value; } ).get().join(' ');
if ( -1 !== rowText.toLowerCase().indexOf( searchText.toLowerCase() ) ) {
$(this).toggleClass( 'search-result-match', true );
results++;
} else {
$(this).toggleClass( 'search-result-match', false );
}
});
$('.num-results-found').text( ('<?php echo esc_js( __( '%d results found.', 'woocommerce' ) ); ?>').replace( '%d', results ) );
}
$('.tax-search' ).on( 'keyup search', processTaxRateSearch );
})(jQuery);
</script>
<style>
tr.search-result-match input {
background-color: yellow !important;
}
</style>
<table class="wc_tax_rates wc_input_table sortable widefat">
<thead>
<tr>