PluginProbe
Datafeedr API / 1.4.2
Datafeedr API v1.4.2
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 1.0.33 All 181 releases
datafeedr-api / js / searchfilter.js

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

69 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function ($) {
2
3 var timer = 0;
4
5 var sel = function (ptr, context) {
6 if ($.isFunction(ptr))
7 return ptr.apply(context);
8 return typeof ptr == "string" ? context.find(ptr) : ptr;
9 };
10
11 var filter = function (obj, search, opts) {
12 var re = new RegExp(search.replace(/[.\\\\+*?\[\]\{\}\(\)-]/g, "\\$&"),
13 opts.caseSensitive ? "" : "i");
14 var ctx = sel(opts.element, obj);
15 var n = 0;
16 var size = opts.stepSize || 100;
17
18 var step = function () {
19 for (var i = 0; i < size; i++) {
20
21 if (n >= ctx.length) {
22 if (opts.after)
23 opts.after.apply(ctx);
24 return;
25 }
26
27 var e = $(ctx[n++]);
28
29 var box = opts.subject ? sel(opts.subject, e) : this;
30 var val = box.text();
31
32 if (!e.hasClass('hidden')) {
33 if (!search.length) {
34 e.show();
35 if (opts.highlight) {
36 box.html(val);
37 }
38 } else if (val.match(re)) {
39 e.show();
40 if (opts.highlight) {
41 box.html(val.replace(re, opts.highlightRe));
42 }
43 } else {
44 e.hide();
45 }
46 }
47 }
48 timer = setTimeout(step, 1);
49 };
50
51 clearTimeout(timer);
52 step();
53
54 };
55
56 $.fn.searchFilter = function (opts) {
57 if (opts.highlight) {
58 opts.highlightRe = $("<div>@</div>").wrapInner(opts.highlight).html().replace(/@/g, "$$&");
59 }
60 $(this).on("keyup", function () {
61 filter(this, this.value, opts)
62 });
63 $(this).on("change", function () {
64 filter(this, this.value, opts)
65 });
66 }
67
68
69 })(window.jQuery);