@@ -25,29 +25,22 @@ jQuery.uiTableFilter = function(jq, phrase, column, ifHidden){
2525 var phrase_length = phrase . length ;
2626 var words = phrase . toLowerCase ( ) . split ( " " ) ;
2727
28- var success = function ( elem ) { elem . show ( ) }
29- var failure = function ( elem ) { elem . hide ( ) }
28+ // these function pointers may change
29+ var matches = function ( elem ) { elem . show ( ) }
30+ var noMatch = function ( elem ) { elem . hide ( ) ; new_hidden = true }
31+ var getText = function ( elem ) { return elem . text ( ) }
3032
3133 if ( column ) {
3234 var index = null ;
3335 jq . find ( "thead > tr:last > th" ) . each ( function ( i ) {
3436 if ( $ ( this ) . text ( ) == column ) {
35- index = i ;
36- return false ;
37+ index = i ; return false ;
3738 }
3839 } ) ;
39- var iselector = "td:eq(" + index + ")" ;
40-
41- var search_text = function ( ) {
42- var elem = jQuery ( this ) ;
43- jQuery . uiTableFilter . has_words ( jQuery ( elem . find ( iselector ) ) . text ( ) , words ) ?
44- success ( elem ) : failure ( elem ) ;
45- }
46- }
47- else {
48- var search_text = function ( ) {
49- var elem = jQuery ( this ) ;
50- jQuery . uiTableFilter . has_words ( elem . text ( ) , words ) ? elem . show ( ) : elem . hide ( ) ;
40+ if ( index == null ) throw ( "given column: " + column + " not found" )
41+
42+ getText = function ( elem ) { return jQuery ( elem . find (
43+ ( "td:eq(" + index + ")" ) ) ) . text ( )
5144 }
5245 }
5346
@@ -59,20 +52,29 @@ jQuery.uiTableFilter = function(jq, phrase, column, ifHidden){
5952 if ( phrase [ - 1 ] === " " )
6053 { this . last_phrase = phrase ; return false ; }
6154
62- success = function ( elem ) { elem . hide ( ) ; new_hidden = true ; }
63- failure = function ( elem ) { ; }
64- var words = words [ - 1 ] ;
65- jq . find ( "tbody tr:visible" ) . each ( search_text )
55+ var words = words [ - 1 ] ; // just search for the newest word
56+
57+ // only hide visible rows
58+ matches = function ( elem ) { ; }
59+ var elems = jq . find ( "tbody > tr:visible" )
6660 }
6761 else {
6862 new_hidden = true ;
69- jq . find ( "tbody > tr" ) . each ( search_text ) ;
63+ var elems = jq . find ( "tbody > tr" )
7064 }
7165
66+ elems . each ( function ( ) {
67+ var elem = jQuery ( this ) ;
68+ jQuery . uiTableFilter . has_words ( getText ( elem ) , words , false ) ?
69+ matches ( elem ) : noMatch ( elem ) ;
70+ } ) ;
71+
7272 last_phrase = phrase ;
73- if ( new_hidden ) ifHidden ( ) ;
73+ if ( ifHidden && new_hidden ) ifHidden ( ) ;
7474 return jq ;
7575} ;
76+
77+ // caching for speedup
7678jQuery . uiTableFilter . last_phrase = ""
7779
7880// not jQuery dependent
0 commit comments