Skip to content

Commit 01f8c5d

Browse files
committed
fix coffee
1 parent 002d2ad commit 01f8c5d

File tree

2 files changed

+96
-97
lines changed

2 files changed

+96
-97
lines changed

jquery.uitablefilter.coffee

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
*
88
* allows table rows to be filtered (made invisible)
99
* <code>
10-
* t = $('table')
11-
* $.uiTableFilter( t, phrase )
10+
* $('table').uiTableFilter(phrase )
1211
* </code>
1312
* arguments:
1413
* jQuery object containing table rows
@@ -18,9 +17,10 @@
1817
* ifHidden - callback to execute if one or more elements was hidden
1918
###
2019
(($) ->
21-
$.uiTableFilter = (jq, phrase, column, ifHidden) ->
20+
$.fn.uiTableFilter = (phrase, column, ifHidden) ->
21+
jq = $(this)
2222
new_hidden = false;
23-
return false if this.last_phrase == phrase
23+
return false if $.fn.uiTableFilter.last_phrase == phrase
2424

2525
phrase_length = phrase.length
2626
words = phrase.toLowerCase().split(" ")
@@ -44,9 +44,9 @@
4444

4545
# if added one letter to last time,
4646
# just check newest word and only need to hide
47-
if (words.size > 1) && (phrase.substr(0, phrase_length - 1) == this.last_phrase)
47+
if (words.size > 1) && (phrase.substr(0, phrase_length - 1) == $.fn.uiTableFilter.last_phrase)
4848
if phrase[-1] == " "
49-
this.last_phrase = phrase
49+
$.fn.uiTableFilter.last_phrase = phrase
5050
return false
5151

5252
words = words[-1] # just search for the newest word
@@ -60,7 +60,7 @@
6060

6161
elems.each(->
6262
elem = $(this)
63-
if $.uiTableFilter.has_words( getText(elem), words, false )
63+
if $.fn.uiTableFilter.has_words( getText(elem), words, false )
6464
matches(elem)
6565
else
6666
noMatch(elem)
@@ -71,12 +71,12 @@
7171
return jq
7272

7373
# caching for speedup
74-
$.uiTableFilter.last_phrase = ""
74+
$.fn.uiTableFilter.last_phrase = ""
7575

7676
# not jQuery dependent
7777
# "" [""] -> Boolean
7878
# "" [""] Boolean -> Boolean
79-
$.uiTableFilter.has_words = ( str, words, caseSensitive ) ->
79+
$.fn.uiTableFilter.has_words = ( str, words, caseSensitive ) ->
8080
text = caseSensitive ? str : str.toLowerCase()
8181
for word in words
8282
return false if text.indexOf(word) == -1

jquery.uitablefilter.js

Lines changed: 87 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,95 @@
1-
(function() {
2-
/*
3-
* Copyright (c) 2008 Greg Weber greg at gregweber.info
4-
* Dual licensed under the MIT and GPLv2 licenses just as jQuery is:
5-
* http://jquery.org/license
6-
*
7-
* documentation at http://gregweber.info/projects/uitablefilter
8-
*
9-
* allows table rows to be filtered (made invisible)
10-
* <code>
11-
* t = $('table')
12-
* $.uiTableFilter( t, phrase )
13-
* </code>
14-
* arguments:
15-
* jQuery object containing table rows
16-
* phrase to search for
17-
* optional arguments:
18-
* column to limit search too (the column title in the table header)
19-
* ifHidden - callback to execute if one or more elements was hidden
20-
*/ (function($) {
21-
$.uiTableFilter = function(jq, phrase, column, ifHidden) {
22-
var elems, getText, index, last_phrase, matches, new_hidden, noMatch, phrase_length, words;
23-
new_hidden = false;
24-
if (this.last_phrase === phrase) {
25-
return false;
1+
/*
2+
* Copyright (c) 2008 Greg Weber greg at gregweber.info
3+
* Dual licensed under the MIT and GPLv2 licenses just as jQuery is:
4+
* http://jquery.org/license
5+
*
6+
* documentation at http://gregweber.info/projects/uitablefilter
7+
*
8+
* allows table rows to be filtered (made invisible)
9+
* <code>
10+
* t = $('table')
11+
* $.uiTableFilter( t, phrase )
12+
* </code>
13+
* arguments:
14+
* jQuery object containing table rows
15+
* phrase to search for
16+
* optional arguments:
17+
* column to limit search too (the column title in the table header)
18+
* ifHidden - callback to execute if one or more elements was hidden
19+
*/
20+
(function($) {
21+
$.uiTableFilter = function(jq, phrase, column, ifHidden) {
22+
var elems, getText, index, last_phrase, matches, new_hidden, noMatch, phrase_length, words;
23+
new_hidden = false;
24+
if (this.last_phrase === phrase) {
25+
return false;
26+
}
27+
phrase_length = phrase.length;
28+
words = phrase.toLowerCase().split(" ");
29+
noMatch = function(elem) {
30+
elem.hide();
31+
return new_hidden = true;
32+
};
33+
getText = function(elem) {
34+
return elem.text();
35+
};
36+
matches = function(elem) {
37+
return elem.show();
38+
};
39+
if (column) {
40+
index = null;
41+
jq.find("thead > tr:last > th").each(function(i) {
42+
if ($.trim($(this).text()) === column) {
43+
index = i;
44+
return false;
45+
}
46+
});
47+
if (index === null) {
48+
throw "given column: " + column + " not found";
2649
}
27-
phrase_length = phrase.length;
28-
words = phrase.toLowerCase().split(" ");
29-
noMatch = function(elem) {
30-
elem.hide();
31-
return new_hidden = true;
32-
};
3350
getText = function(elem) {
34-
return elem.text();
35-
};
36-
matches = function(elem) {
37-
return elem.show();
51+
return $(elem.find("td:eq(" + index + ")")).text();
3852
};
39-
if (column) {
40-
index = null;
41-
jq.find("thead > tr:last > th").each(function(i) {
42-
if ($.trim($(this).text()) === column) {
43-
index = i;
44-
return false;
45-
}
46-
});
47-
if (index === null) {
48-
throw "given column: " + column + " not found";
49-
}
50-
getText = function(elem) {
51-
return $(elem.find("td:eq(" + index + ")")).text();
52-
};
53+
}
54+
if ((words.size > 1) && (phrase.substr(0, phrase_length - 1) === this.last_phrase)) {
55+
if (phrase[-1] === " ") {
56+
this.last_phrase = phrase;
57+
return false;
5358
}
54-
if ((words.size > 1) && (phrase.substr(0, phrase_length - 1) === this.last_phrase)) {
55-
if (phrase[-1] === " ") {
56-
this.last_phrase = phrase;
57-
return false;
58-
}
59-
words = words[-1];
60-
matches = function(elem) {};
61-
elems = jq.find("tbody:first > tr:visible");
59+
words = words[-1];
60+
matches = function(elem) {};
61+
elems = jq.find("tbody:first > tr:visible");
62+
} else {
63+
new_hidden = true;
64+
elems = jq.find("tbody:first > tr");
65+
}
66+
elems.each(function() {
67+
var elem;
68+
elem = $(this);
69+
if ($.uiTableFilter.has_words(getText(elem), words, false)) {
70+
return matches(elem);
6271
} else {
63-
new_hidden = true;
64-
elems = jq.find("tbody:first > tr");
65-
}
66-
elems.each(function() {
67-
var elem;
68-
elem = $(this);
69-
if ($.uiTableFilter.has_words(getText(elem), words, false)) {
70-
return matches(elem);
71-
} else {
72-
return noMatch(elem);
73-
}
74-
});
75-
last_phrase = phrase;
76-
if (ifHidden && new_hidden) {
77-
ifHidden();
72+
return noMatch(elem);
7873
}
79-
return jq;
74+
});
75+
last_phrase = phrase;
76+
if (ifHidden && new_hidden) {
77+
ifHidden();
78+
}
79+
return jq;
80+
};
81+
$.uiTableFilter.last_phrase = "";
82+
return $.uiTableFilter.has_words = function(str, words, caseSensitive) {
83+
var text, word, _i, _len;
84+
text = caseSensitive != null ? caseSensitive : {
85+
str: str.toLowerCase()
8086
};
81-
$.uiTableFilter.last_phrase = "";
82-
return $.uiTableFilter.has_words = function(str, words, caseSensitive) {
83-
var text, word, _i, _len;
84-
text = caseSensitive != null ? caseSensitive : {
85-
str: str.toLowerCase()
86-
};
87-
for (_i = 0, _len = words.length; _i < _len; _i++) {
88-
word = words[_i];
89-
if (text.indexOf(word) === -1) {
90-
return false;
91-
}
87+
for (_i = 0, _len = words.length; _i < _len; _i++) {
88+
word = words[_i];
89+
if (text.indexOf(word) === -1) {
90+
return false;
9291
}
93-
return true;
94-
};
95-
})(jQuery);
96-
}).call(this);
92+
}
93+
return true;
94+
};
95+
})(jQuery);

0 commit comments

Comments
 (0)