PluginProbe
Datafeedr API / 1.0.28
Datafeedr API v1.0.28
1.4.3 1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 All 182 releases
datafeedr-api / js / searchfilter.js

searchfilter.js in Datafeedr API 1.0.28, at js/searchfilter.js

51 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2
3 var sel = function(ptr, context) {
4 if($.isFunction(ptr))
5 return ptr.apply(context);
6 return typeof ptr == "string" ? context.find(ptr) : ptr;
7 };
8
9 var filter = function(obj, search, opts) {
10 var re = new RegExp(search.replace(/[.\\\\+*?\[\]\{\}\(\)-]/g, "\\$&"),
11 opts.caseSensitive ? "" : "i");
12 var ctx = sel(opts.element, obj);
13
14 ctx.each(function() {
15 var e = $(this);
16
17 var box = opts.subject ? sel(opts.subject, e) : this;
18 var val = box.text();
19
20 if(!search.length) {
21 e.show();
22 if(opts.highlight) {
23 box.html(val);
24 }
25 } else if(val.match(re)) {
26 e.show();
27 if(opts.highlight) {
28 box.html(val.replace(re, opts.highlightRe));
29 }
30 } else {
31 e.hide();
32 }
33
34 });
35
36 if(opts.after)
37 opts.after.apply(ctx);
38
39 };
40
41 $.fn.searchFilter = function(opts) {
42 if(opts.highlight) {
43 opts.highlightRe = $("<div>@</div>").wrapInner(opts.highlight).html().replace(/@/g, "$$&");
44 }
45 $(this).keyup(function() { filter(this, this.value, opts) });
46 $(this).change(function() { filter(this, this.value, opts) });
47 }
48
49
50 })(window.jQuery);
51