Skip to content

Be ready to ship into NPM and clean all the old code #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Apr 19, 2020
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format the JS file
  • Loading branch information
williamdes committed Apr 18, 2020
commit 7730b589485657de26d1c5a9e6ed15e75c5af084
70 changes: 31 additions & 39 deletions jquery.uitablefilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,79 +20,72 @@
* array of columns 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){
(function ($) {
$.uiTableFilter = function (jq, phrase, column, ifHidden) {
var new_hidden = false;
if( this.last_phrase === phrase ) return 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() }
var matches = function (elem) { elem.show() }
var noMatch = function (elem) { elem.hide(); new_hidden = true }
var getText = function (elem) { return elem.text() }

if( column )
{
if (!$.isArray(column))
{
if (column) {
if (!$.isArray(column)) {
column = new Array(column);
}

var index = new Array();

jq.find("thead > tr:last > th").each(function(i)
{
for (var j = 0; j < column.length; j++)
{
if ($.trim($(this).text()) == column[j])
{
index[j] = i;
break;
}
jq.find("thead > tr:last > th").each(function (i) {
for (var j = 0; j < column.length; j++) {
if ($.trim($(this).text()) == column[j]) {
index[j] = i;
break;
}
}

});

getText = function(elem) {
var selector = "";
for (var i = 0; i < index.length; i++)
{
if (i != 0) {selector += ",";}
selector += "td:eq(" + index[i] + ")";
}
return $(elem.find((selector))).text();
getText = function (elem) {
var selector = "";
for (var i = 0; i < index.length; i++) {
if (i != 0) { selector += ","; }
selector += "td:eq(" + index[i] + ")";
}
return $(elem.find((selector))).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) ===
this.last_phrase) ) {
if ((words.size > 1) && (phrase.substr(0, phrase_length - 1) ===
this.last_phrase)) {

if( phrase[-1] === " " )
{ this.last_phrase = phrase; return false; }
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) {;}
matches = function (elem) { ; }
var elems = jq.find("tbody:first > tr:visible")
}
else {
new_hidden = true;
var elems = jq.find("tbody:first > tr")
}

elems.each(function(){
elems.each(function () {
var elem = $(this);
$.uiTableFilter.has_words( getText(elem), words, false ) ?
$.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;
};

Expand All @@ -102,12 +95,11 @@
// not jQuery dependent
// "" [""] -> Boolean
// "" [""] Boolean -> Boolean
$.uiTableFilter.has_words = function( str, words, caseSensitive )
{
$.uiTableFilter.has_words = function (str, words, caseSensitive) {
var text = caseSensitive ? str : str.toLowerCase();
for (var i=0; i < words.length; i++) {
for (var i = 0; i < words.length; i++) {
if (text.indexOf(words[i]) === -1) return false;
}
return true;
}
}) (jQuery);
})(jQuery);