Permalink
Browse files

remove coffeescript

  • Loading branch information...
1 parent 01f8c5d commit 902643a8f22898aa797bf94c10b2b19b28661d6c @gregwebs committed Jun 26, 2011
Showing with 60 additions and 148 deletions.
  1. +0 −84 jquery.uitablefilter.coffee
  2. +60 −64 jquery.uitablefilter.js
@@ -1,84 +0,0 @@
-###
- * Copyright (c) 2008 Greg Weber greg at gregweber.info
- * Dual licensed under the MIT and GPLv2 licenses just as jQuery is:
- * http://jquery.org/license
- *
- * documentation at http://gregweber.info/projects/uitablefilter
- *
- * allows table rows to be filtered (made invisible)
- * <code>
- * $('table').uiTableFilter(phrase )
- * </code>
- * arguments:
- * jQuery object containing table rows
- * phrase to search for
- * optional arguments:
- * column to limit search too (the column title in the table header)
- * ifHidden - callback to execute if one or more elements was hidden
-###
-(($) ->
- $.fn.uiTableFilter = (phrase, column, ifHidden) ->
- jq = $(this)
- new_hidden = false;
- return false if $.fn.uiTableFilter.last_phrase == phrase
-
- phrase_length = phrase.length
- words = phrase.toLowerCase().split(" ")
-
- noMatch = (elem) -> elem.hide(); new_hidden = true
- # these function pointers may change
- getText = (elem) -> elem.text()
- matches = (elem) -> elem.show()
-
- if column
- index = null
- jq.find("thead > tr:last > th").each( (i) ->
- if $.trim($(this).text()) == column
- index = i
- return false
- )
- if index == null
- throw("given column: " + column + " not found")
-
- getText = (elem) -> $(elem.find( ("td:eq(" + index + ")") )).text()
-
- # if added one letter to last time,
- # just check newest word and only need to hide
- if (words.size > 1) && (phrase.substr(0, phrase_length - 1) == $.fn.uiTableFilter.last_phrase)
- if phrase[-1] == " "
- $.fn.uiTableFilter.last_phrase = phrase
- return false
-
- words = words[-1] # just search for the newest word
-
- # only hide visible rows
- matches = (elem) ->
- elems = jq.find("tbody:first > tr:visible")
- else
- new_hidden = true
- elems = jq.find("tbody:first > tr")
-
- elems.each(->
- elem = $(this)
- if $.fn.uiTableFilter.has_words( getText(elem), words, false )
- matches(elem)
- else
- noMatch(elem)
- )
-
- last_phrase = phrase
- ifHidden() if ifHidden && new_hidden
- return jq
-
- # caching for speedup
- $.fn.uiTableFilter.last_phrase = ""
-
- # not jQuery dependent
- # "" [""] -> Boolean
- # "" [""] Boolean -> Boolean
- $.fn.uiTableFilter.has_words = ( str, words, caseSensitive ) ->
- text = caseSensitive ? str : str.toLowerCase()
- for word in words
- return false if text.indexOf(word) == -1
- return true;
-)(jQuery)
View
@@ -16,80 +16,76 @@
* optional arguments:
* column to limit search too (the column title in the table header)
* ifHidden - callback to execute if one or more elements was hidden
-*/
+ */
(function($) {
- $.uiTableFilter = function(jq, phrase, column, ifHidden) {
- var elems, getText, index, last_phrase, matches, new_hidden, noMatch, phrase_length, words;
- new_hidden = false;
- if (this.last_phrase === phrase) {
- return false;
- }
- phrase_length = phrase.length;
- words = phrase.toLowerCase().split(" ");
- noMatch = function(elem) {
- elem.hide();
- return new_hidden = true;
- };
- getText = function(elem) {
- return elem.text();
- };
- matches = function(elem) {
- return elem.show();
- };
- if (column) {
- index = null;
- jq.find("thead > tr:last > th").each(function(i) {
- if ($.trim($(this).text()) === column) {
- index = i;
- return false;
+ $.uiTableFilter = function(jq, phrase, column, ifHidden){
+ var new_hidden = false;
+ if( this.last_phrase === phrase ) return false;
+
+ var phrase_length = phrase.length;
+ var words = phrase.toLowerCase().split(" ");
+
+ // these function pointers may change
+ var matches = function(elem) { elem.show() }
+ var noMatch = function(elem) { elem.hide(); new_hidden = true }
+ var getText = function(elem) { return elem.text() }
+
+ if( column ) {
+ var index = null;
+ jq.find("thead > tr:last > th").each( function(i){
+ if( $.trim($(this).text()) == column ){
+ index = i; return false;
}
});
- if (index === null) {
- throw "given column: " + column + " not found";
+ if( index == null ) throw("given column: " + column + " not found")
+
+ getText = function(elem){ return $(elem.find(
+ ("td:eq(" + index + ")") )).text()
}
- getText = function(elem) {
- return $(elem.find("td:eq(" + index + ")")).text();
- };
}
- if ((words.size > 1) && (phrase.substr(0, phrase_length - 1) === this.last_phrase)) {
- if (phrase[-1] === " ") {
- this.last_phrase = phrase;
- return false;
- }
- words = words[-1];
- matches = function(elem) {};
- elems = jq.find("tbody:first > tr:visible");
- } else {
+
+ // if added one letter to last time,
+ // just check newest word and only need to hide
+ if( (words.size > 1) && (phrase.substr(0, phrase_length - 1) ===
+ this.last_phrase) ) {
+
+ if( phrase[-1] === " " )
+ { this.last_phrase = phrase; return false; }
+
+ var words = words[-1]; // just search for the newest word
+
+ // only hide visible rows
+ matches = function(elem) {;}
+ var elems = jq.find("tbody:first > tr:visible")
+ }
+ else {
new_hidden = true;
- elems = jq.find("tbody:first > tr");
+ var elems = jq.find("tbody:first > tr")
}
- elems.each(function() {
- var elem;
- elem = $(this);
- if ($.uiTableFilter.has_words(getText(elem), words, false)) {
- return matches(elem);
- } else {
- return noMatch(elem);
- }
+
+ elems.each(function(){
+ var elem = $(this);
+ $.uiTableFilter.has_words( getText(elem), words, false ) ?
+ matches(elem) : noMatch(elem);
});
+
last_phrase = phrase;
- if (ifHidden && new_hidden) {
- ifHidden();
- }
+ if( ifHidden && new_hidden ) ifHidden();
return jq;
};
- $.uiTableFilter.last_phrase = "";
- return $.uiTableFilter.has_words = function(str, words, caseSensitive) {
- var text, word, _i, _len;
- text = caseSensitive != null ? caseSensitive : {
- str: str.toLowerCase()
- };
- for (_i = 0, _len = words.length; _i < _len; _i++) {
- word = words[_i];
- if (text.indexOf(word) === -1) {
- return false;
- }
+
+ // caching for speedup
+ $.uiTableFilter.last_phrase = ""
+
+ // not jQuery dependent
+ // "" [""] -> Boolean
+ // "" [""] Boolean -> Boolean
+ $.uiTableFilter.has_words = function( str, words, caseSensitive )
+ {
+ var text = caseSensitive ? str : str.toLowerCase();
+ for (var i=0; i < words.length; i++) {
+ if (text.indexOf(words[i]) === -1) return false;
}
return true;
- };
-})(jQuery);
+ }
+}) (jQuery);

0 comments on commit 902643a

Please sign in to comment.