PageSourceSearch

https://bioinnovate.ie/media/nuigalwayie/styleassets/js/quick-search.js

js bioinnovate.ie collected 2026-09-26 03:39:15 UTC 3,520 bytes, 150 lines download raw bytes

1(function($, window, document, undefined) {
2	$.fn.quicksearch = function (target, opt) {
3		
4		var timeout, cache, rowcache, jq_results, val = '', e = this, options = $.extend({ 
5			delay: 100,
6			selector: null,
7			stripeRows: null,
8			loader: null,
9			noResults: '',
10			bind: 'keyup',
11			onBefore: function () { 
12				return;
13			},
14			onAfter: function () { 
15				return;
16			},
17			show: function () {
18				this.style.display = "";
19			},
20			hide: function () {
21				this.style.display = "none";
22			},
23			prepareQuery: function (val) {
24				return val.toLowerCase().split(' ');
25			},
26			testQuery: function (query, txt, _row) {
27				for (var i = 0; i < query.length; i += 1) {
28					if (txt.indexOf(query[i]) === -1) {
29						return false;
30					}
31				}
32				return true;
33			}
34		}, opt);
35		
36		this.go = function () {
37			
38			var i = 0, 
39			noresults = true, 
40			query = options.prepareQuery(val),
41			val_empty = (val.replace(' ', '').length === 0);
42			
43			for (var i = 0, len = rowcache.length; i < len; i++) {
44				if (val_empty || options.testQuery(query, cache[i], rowcache[i])) {
45					options.show.apply(rowcache[i]);
46					noresults = false;
47				} else {
48					options.hide.apply(rowcache[i]);
49				}
50			}
51			
52			if (noresults) {
53				this.results(false);
54			} else {
55				this.results(true);
56				this.stripe();
57			}
58			
59			this.loader(false);
60			options.onAfter();
61			
62			return this;
63		};
64		
65		this.stripe = function () {
66			
67			if (typeof options.stripeRows === "object" && options.stripeRows !== null)
68			{
69				var joined = options.stripeRows.join(' ');
70				var stripeRows_length = options.stripeRows.length;
71				
72				jq_results.not(':hidden').each(function (i) {
73					$(this).removeClass(joined).addClass(options.stripeRows[i % stripeRows_length]);
74				});
75			}
76			
77			return this;
78		};
79		
80		this.strip_html = function (input) {
81			var output = input.replace(new RegExp('<[^<]+\>', 'g'), "");
82			output = $.trim(output.toLowerCase());
83			return output;
84		};
85		
86		this.results = function (bool) {
87			if (typeof options.noResults === "string" && options.noResults !== "") {
88				if (bool) {
89					$(options.noResults).hide();
90				} else {
91					$(options.noResults).show();
92				}
93			}
94			return this;
95		};
96		
97		this.loader = function (bool) {
98			if (typeof options.loader === "string" && options.loader !== "") {
99				 (bool) ? $(options.loader).show() : $(options.loader).hide();
100			}
101			return this;
102		};
103		
104		this.cache = function () {
105			
106			jq_results = $(target);
107			
108			if (typeof options.noResults === "string" && options.noResults !== "") {
109				jq_results = jq_results.not(options.noResults);
110			}
111			
112			var t = (typeof options.selector === "string") ? jq_results.find(options.selector) : $(target).not(options.noResults);
113			cache = t.map(function () {
114				return e.strip_html(this.innerHTML);
115			});
116			
117			rowcache = jq_results.map(function () {
118				return this;
119			});
120			
121			return this.go();
122		};
123		
124		this.trigger = function () {
125			this.loader(true);
126			options.onBefore();
127			
128			window.clearTimeout(timeout);
129			timeout = window.setTimeout(function () {
130				e.go();
131			}, options.delay);
132			
133			return this;
134		};
135		
136		this.cache();
137		this.results(true);
138		this.stripe();
139		this.loader(false);
140		
141		return this.each(function () {
142			$(this).bind(options.bind, function () {
143				val = $(this).val();
144				e.trigger();
145			});
146		});
147		
148	};
149
150}(jQuery, this, document));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.