Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

remove coffeescript

  • Loading branch information...
commit 902643a8f22898aa797bf94c10b2b19b28661d6c 1 parent 01f8c5d
Greg Weber authored June 26, 2011
84  jquery.uitablefilter.coffee
... ...
@@ -1,84 +0,0 @@
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  
- * $('table').uiTableFilter(phrase )
11  
- * </code>
12  
- * arguments:
13  
- *   jQuery object containing table rows
14  
- *   phrase to search for
15  
- *   optional arguments:
16  
- *     column to limit search too (the column title in the table header)
17  
- *     ifHidden - callback to execute if one or more elements was hidden
18  
-###
19  
-(($) ->
20  
-  $.fn.uiTableFilter = (phrase, column, ifHidden) ->
21  
-    jq = $(this)
22  
-    new_hidden = false;
23  
-    return false if $.fn.uiTableFilter.last_phrase == phrase
24  
-
25  
-    phrase_length = phrase.length
26  
-    words = phrase.toLowerCase().split(" ")
27  
-
28  
-    noMatch = (elem) -> elem.hide(); new_hidden = true
29  
-    # these function pointers may change
30  
-    getText = (elem) -> elem.text()
31  
-    matches = (elem) -> elem.show()
32  
-
33  
-    if column
34  
-      index = null
35  
-      jq.find("thead > tr:last > th").each( (i) ->
36  
-        if $.trim($(this).text()) == column
37  
-          index = i
38  
-          return false
39  
-      )
40  
-      if index == null
41  
-        throw("given column: " + column + " not found")
42  
-
43  
-      getText = (elem) -> $(elem.find( ("td:eq(" + index + ")") )).text()
44  
-
45  
-    # if added one letter to last time,
46  
-    # just check newest word and only need to hide
47  
-    if (words.size > 1) && (phrase.substr(0, phrase_length - 1) == $.fn.uiTableFilter.last_phrase)
48  
-      if phrase[-1] == " "
49  
-        $.fn.uiTableFilter.last_phrase = phrase
50  
-        return false
51  
-
52  
-      words = words[-1] # just search for the newest word
53  
-
54  
-      # only hide visible rows
55  
-      matches = (elem) ->
56  
-      elems = jq.find("tbody:first > tr:visible")
57  
-    else
58  
-      new_hidden = true
59  
-      elems = jq.find("tbody:first > tr")
60  
-
61  
-    elems.each(->
62  
-      elem = $(this)
63  
-      if $.fn.uiTableFilter.has_words( getText(elem), words, false )
64  
-        matches(elem)
65  
-      else
66  
-        noMatch(elem)
67  
-    )
68  
-
69  
-    last_phrase = phrase
70  
-    ifHidden() if ifHidden && new_hidden
71  
-    return jq
72  
-
73  
-  # caching for speedup
74  
-  $.fn.uiTableFilter.last_phrase = ""
75  
-
76  
-  # not jQuery dependent
77  
-  # "" [""] -> Boolean
78  
-  # "" [""] Boolean -> Boolean
79  
-  $.fn.uiTableFilter.has_words = ( str, words, caseSensitive ) ->
80  
-    text = caseSensitive ? str : str.toLowerCase()
81  
-    for word in words
82  
-      return false if text.indexOf(word) == -1
83  
-    return true;
84  
-)(jQuery)
124  jquery.uitablefilter.js
@@ -16,80 +16,76 @@
16 16
  *   optional arguments:
17 17
  *     column to limit search too (the column title in the table header)
18 18
  *     ifHidden - callback to execute if one or more elements was hidden
19  
-*/
  19
+ */
20 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;
  21
+  $.uiTableFilter = function(jq, phrase, column, ifHidden){
  22
+    var new_hidden = false;
  23
+    if( this.last_phrase === phrase ) return false;
  24
+
  25
+    var phrase_length = phrase.length;
  26
+    var words = phrase.toLowerCase().split(" ");
  27
+
  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() }
  32
+
  33
+    if( column ) {
  34
+      var index = null;
  35
+      jq.find("thead > tr:last > th").each( function(i){
  36
+        if( $.trim($(this).text()) == column ){
  37
+          index = i; return false;
45 38
         }
46 39
       });
47  
-      if (index === null) {
48  
-        throw "given column: " + column + " not found";
  40
+      if( index == null ) throw("given column: " + column + " not found")
  41
+
  42
+      getText = function(elem){ return $(elem.find(
  43
+        ("td:eq(" + index + ")")  )).text()
49 44
       }
50  
-      getText = function(elem) {
51  
-        return $(elem.find("td:eq(" + index + ")")).text();
52  
-      };
53 45
     }
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");
62  
-    } else {
  46
+
  47
+    // if added one letter to last time,
  48
+    // just check newest word and only need to hide
  49
+    if( (words.size > 1) && (phrase.substr(0, phrase_length - 1) ===
  50
+          this.last_phrase) ) {
  51
+
  52
+      if( phrase[-1] === " " )
  53
+      { this.last_phrase = phrase; return false; }
  54
+
  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:first > tr:visible")
  60
+    }
  61
+    else {
63 62
       new_hidden = true;
64  
-      elems = jq.find("tbody:first > tr");
  63
+      var elems = jq.find("tbody:first > tr")
65 64
     }
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  
-      }
  65
+
  66
+    elems.each(function(){
  67
+      var elem = $(this);
  68
+      $.uiTableFilter.has_words( getText(elem), words, false ) ?
  69
+        matches(elem) : noMatch(elem);
74 70
     });
  71
+
75 72
     last_phrase = phrase;
76  
-    if (ifHidden && new_hidden) {
77  
-      ifHidden();
78  
-    }
  73
+    if( ifHidden && new_hidden ) ifHidden();
79 74
     return jq;
80 75
   };
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  
-      }
  76
+
  77
+  // caching for speedup
  78
+  $.uiTableFilter.last_phrase = ""
  79
+
  80
+  // not jQuery dependent
  81
+  // "" [""] -> Boolean
  82
+  // "" [""] Boolean -> Boolean
  83
+  $.uiTableFilter.has_words = function( str, words, caseSensitive )
  84
+  {
  85
+    var text = caseSensitive ? str : str.toLowerCase();
  86
+    for (var i=0; i < words.length; i++) {
  87
+      if (text.indexOf(words[i]) === -1) return false;
92 88
     }
93 89
     return true;
94  
-  };
95  
-})(jQuery);
  90
+  }
  91
+}) (jQuery);

0 notes on commit 902643a

Please sign in to comment.
Something went wrong with that request. Please try again.