Skip to content

Commit b1ded6b

Browse files
committed
Use jquery-uitablefilter package and sync vendor file
Ref: code-lts/jquery-uitablefilter#13 Signed-off-by: William Desportes <[email protected]>
1 parent 2851f65 commit b1ded6b

File tree

4 files changed

+78
-82
lines changed

4 files changed

+78
-82
lines changed

js/vendor/jquery/jquery.uitablefilter.js

Lines changed: 70 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
* Dual licensed under the MIT and GPLv2 licenses just as jQuery is:
44
* http://jquery.org/license
55
*
6-
* Multi-columns fork by natinusala
6+
* Multi-columns support by natinusala
77
*
88
* documentation at http://gregweber.info/projects/uitablefilter
9-
* https://github.com/natinusala/jquery-uitablefilter
109
*
1110
* allows table rows to be filtered (made invisible)
1211
* <code>
@@ -23,95 +22,87 @@
2322
* default:whole <td>. useful if <td> has more than one elements inside but want to
2423
* limit search within only some of elements or only visible elements. eg tdElem can be "td span"
2524
*/
26-
(function($) {
27-
$.uiTableFilter = function(jq, phrase, column, ifHidden, tdElem){
28-
if(!tdElem) tdElem = "td";
29-
var new_hidden = false;
30-
if( this.last_phrase === phrase ) return false;
25+
(function ($) {
26+
$.uiTableFilter = function (jq, phrase, column, ifHidden, tdElem) {
27+
if (!tdElem) tdElem = "td";
28+
var new_hidden = false;
29+
if (this.last_phrase === phrase) return false;
3130

32-
var phrase_length = phrase.length;
33-
var words = phrase.toLowerCase().split(" ");
31+
var phrase_length = phrase.length;
32+
var words = phrase.toLowerCase().split(" ");
3433

35-
// these function pointers may change
36-
var matches = function(elem) { elem.show() }
37-
var noMatch = function(elem) { elem.hide(); new_hidden = true }
38-
var getText = function(elem) { return elem.text() }
34+
// these function pointers may change
35+
var matches = function (elem) { elem.show() }
36+
var noMatch = function (elem) { elem.hide(); new_hidden = true }
37+
var getText = function (elem) { return elem.text() }
3938

40-
if( column )
41-
{
42-
if (!$.isArray(column))
43-
{
44-
column = new Array(column);
45-
}
39+
if (column) {
40+
if (!$.isArray(column)) {
41+
column = new Array(column);
42+
}
4643

47-
var index = new Array();
44+
var index = new Array();
4845

49-
jq.find("thead > tr:last > th").each(function(i)
50-
{
51-
for (var j = 0; j < column.length; j++)
52-
{
53-
if ($.trim($(this).text()) == column[j])
54-
{
55-
index[j] = i;
56-
break;
57-
}
58-
}
46+
jq.find("thead > tr:last > th").each(function (i) {
47+
for (var j = 0; j < column.length; j++) {
48+
if ($.trim($(this).text()) == column[j]) {
49+
index[j] = i;
50+
break;
51+
}
52+
}
5953

60-
});
54+
});
6155

62-
getText = function(elem) {
63-
var selector = "";
64-
for (var i = 0; i < index.length; i++)
65-
{
66-
if (i != 0) {selector += ",";}
67-
selector += tdElem + ":eq(" + index[i] + ")";
68-
}
69-
return $(elem.find((selector))).text();
70-
}
71-
}
56+
getText = function (elem) {
57+
var selector = "";
58+
for (var i = 0; i < index.length; i++) {
59+
if (i != 0) { selector += ","; }
60+
selector += tdElem + ":eq(" + index[i] + ")";
61+
}
62+
return $(elem.find((selector))).text();
63+
}
64+
}
7265

73-
// if added one letter to last time,
74-
// just check newest word and only need to hide
75-
if( (words.size > 1) && (phrase.substr(0, phrase_length - 1) ===
76-
this.last_phrase) ) {
66+
// if added one letter to last time,
67+
// just check newest word and only need to hide
68+
if ((words.size > 1) && (phrase.substr(0, phrase_length - 1) ===
69+
this.last_phrase)) {
7770

78-
if( phrase[-1] === " " )
79-
{ this.last_phrase = phrase; return false; }
71+
if (phrase[-1] === " ") { this.last_phrase = phrase; return false; }
8072

81-
var words = words[-1]; // just search for the newest word
73+
var words = words[-1]; // just search for the newest word
8274

83-
// only hide visible rows
84-
matches = function(elem) {;}
85-
var elems = jq.find("tbody:first > tr:visible")
86-
}
87-
else {
88-
new_hidden = true;
89-
var elems = jq.find("tbody:first > tr")
90-
}
75+
// only hide visible rows
76+
matches = function (elem) { ; }
77+
var elems = jq.find("tbody:first > tr:visible")
78+
}
79+
else {
80+
new_hidden = true;
81+
var elems = jq.find("tbody:first > tr")
82+
}
9183

92-
elems.each(function(){
93-
var elem = $(this);
94-
$.uiTableFilter.has_words( getText(elem), words, false ) ?
95-
matches(elem) : noMatch(elem);
96-
});
84+
elems.each(function () {
85+
var elem = $(this);
86+
$.uiTableFilter.has_words(getText(elem), words, false) ?
87+
matches(elem) : noMatch(elem);
88+
});
9789

98-
last_phrase = phrase;
99-
if( ifHidden && new_hidden ) ifHidden();
100-
return jq;
101-
};
90+
last_phrase = phrase;
91+
if (ifHidden && new_hidden) ifHidden();
92+
return jq;
93+
};
10294

103-
// caching for speedup
104-
$.uiTableFilter.last_phrase = ""
95+
// caching for speedup
96+
$.uiTableFilter.last_phrase = ""
10597

106-
// not jQuery dependent
107-
// "" [""] -> Boolean
108-
// "" [""] Boolean -> Boolean
109-
$.uiTableFilter.has_words = function( str, words, caseSensitive )
110-
{
111-
var text = caseSensitive ? str : str.toLowerCase();
112-
for (var i=0; i < words.length; i++) {
113-
if (text.indexOf(words[i]) === -1) return false;
114-
}
115-
return true;
116-
}
117-
}) (jQuery);
98+
// not jQuery dependent
99+
// "" [""] -> Boolean
100+
// "" [""] Boolean -> Boolean
101+
$.uiTableFilter.has_words = function (str, words, caseSensitive) {
102+
var text = caseSensitive ? str : str.toLowerCase();
103+
for (var i = 0; i < words.length; i++) {
104+
if (text.indexOf(words[i]) === -1) return false;
105+
}
106+
return true;
107+
}
108+
})(jQuery);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"jquery-mousewheel": "3.1.13",
2020
"jquery-ui": "1.12.1",
2121
"jquery-ui-timepicker-addon": "1.6.3",
22+
"jquery-uitablefilter": "^1.0.0",
2223
"jquery-validation": "1.19.1",
2324
"jquery.event.drag": "2.2.2",
2425
"js-cookie": "2.2.1",

scripts/sync-js-vendor-files.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ find ./js/vendor/ \
1919
-not -path './js/vendor/jqplot/jquery.jqplot.js' \
2020
-not -path './js/vendor/jqplot/plugins/jqplot.*.js' \
2121
-not -path './js/vendor/jquery/jquery-ui.min.js' \
22-
-not -path './js/vendor/jquery/jquery.uitablefilter.js' \
2322
-not -path './js/vendor/jquery/jquery.sortableTable.js' \
2423
-not -path './js/vendor/jquery/jquery.svg.js' \
2524
-not -path './js/vendor/jquery/jquery.fullscreen.js' \
@@ -75,8 +74,8 @@ cp ./node_modules/blueimp-md5/js/md5.js ./js/vendor/jquery/jquery.md5.js
7574
#see: https://github.com/kbwood/svg/blob/master/jquery.svg.js
7675
#echo 'Updating jquery-hashchange'
7776
#see: https://github.com/cowboy/jquery-hashchange/blob/master/jquery.ba-hashchange.js
78-
#echo 'Updating jquery-uitablefilter'
79-
#see: https://github.com/natinusala/jquery-uitablefilter/blob/master/jquery.uitablefilter.js
77+
echo 'Updating jquery-uitablefilter'
78+
cp ./node_modules/jquery-uitablefilter/jquery.uitablefilter.js js/vendor/jquery/jquery.uitablefilter.js
8079
echo 'Updating jquery-tablesorter'
8180
cp ./node_modules/tablesorter/dist/js/jquery.tablesorter.js ./js/vendor/jquery/jquery.tablesorter.js
8281
#echo 'Updating jquery-fullscreen-plugin'

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,11 @@ [email protected]:
12531253
resolved "https://registry.yarnpkg.com/jquery-ui/-/jquery-ui-1.12.1.tgz#bcb4045c8dd0539c134bc1488cdd3e768a7a9e51"
12541254
integrity sha1-vLQEXI3QU5wTS8FIjN0+dop6nlE=
12551255

1256+
jquery-uitablefilter@^1.0.0:
1257+
version "1.0.0"
1258+
resolved "https://registry.yarnpkg.com/jquery-uitablefilter/-/jquery-uitablefilter-1.0.0.tgz#ba90c5345826b2fd1fe90ec127826f9e9e7bad39"
1259+
integrity sha512-iH3k0iiNXKtf6z9qV5htz0iGhSb+Hs9Za6V9GIAOeHdij77U96S2UT7j7FwMEyNZQmgrsKKzjfnLJq7lMGaANw==
1260+
12561261
12571262
version "1.19.1"
12581263
resolved "https://registry.yarnpkg.com/jquery-validation/-/jquery-validation-1.19.1.tgz#a85043467dc2b70d9fff05778646d150e747742f"

0 commit comments

Comments
 (0)