1
+ /*!
2
+ * jQuery Sieve v0.3.0 (2013-04-04)
3
+ * http://rmm5t.github.io/jquery-sieve/
4
+ * Copyright (c) 2013 Ryan McGeary; Licensed MIT
5
+ */
6
+ ( function ( ) {
7
+ var $ ;
8
+
9
+ $ = jQuery ;
10
+
11
+ $ . fn . sieve = function ( options ) {
12
+ var compact ;
13
+ compact = function ( array ) {
14
+ var item , _i , _len , _results ;
15
+ _results = [ ] ;
16
+ for ( _i = 0 , _len = array . length ; _i < _len ; _i ++ ) {
17
+ item = array [ _i ] ;
18
+ if ( item ) {
19
+ _results . push ( item ) ;
20
+ }
21
+ }
22
+ return _results ;
23
+ } ;
24
+ return this . each ( function ( ) {
25
+ var container , searchBar , settings ;
26
+ container = $ ( this ) ;
27
+ settings = $ . extend ( {
28
+ searchInput : null ,
29
+ searchTemplate : "<div><label>Search: <input type='text'></label></div>" ,
30
+ itemSelector : "tbody tr" ,
31
+ textSelector : null ,
32
+ toggle : function ( item , match ) {
33
+ return item . toggle ( match ) ;
34
+ } ,
35
+ complete : function ( ) { }
36
+ } , options ) ;
37
+ if ( ! settings . searchInput ) {
38
+ searchBar = $ ( settings . searchTemplate ) ;
39
+ settings . searchInput = searchBar . find ( "input" ) ;
40
+ container . before ( searchBar ) ;
41
+ }
42
+ return settings . searchInput . on ( "keyup.sieve change.sieve" , function ( ) {
43
+ var items , query ;
44
+ query = compact ( $ ( this ) . val ( ) . toLowerCase ( ) . split ( / \s + / ) ) ;
45
+ items = container . find ( settings . itemSelector ) ;
46
+ items . each ( function ( ) {
47
+ var cells , item , match , q , text , _i , _len ;
48
+ item = $ ( this ) ;
49
+ if ( settings . textSelector ) {
50
+ cells = item . find ( settings . textSelector ) ;
51
+ text = cells . text ( ) . toLowerCase ( ) ;
52
+ } else {
53
+ text = item . text ( ) . toLowerCase ( ) ;
54
+ }
55
+ match = true ;
56
+ for ( _i = 0 , _len = query . length ; _i < _len ; _i ++ ) {
57
+ q = query [ _i ] ;
58
+ match && ( match = text . indexOf ( q ) >= 0 ) ;
59
+ }
60
+ return settings . toggle ( item , match ) ;
61
+ } ) ;
62
+ return settings . complete ( ) ;
63
+ } ) ;
64
+ } ) ;
65
+ } ;
66
+
67
+ } ) . call ( this ) ;
0 commit comments