PageSourceSearch

https://asia-guide.biz/wp-content/themes/noo-jobmonster/framework/vendor/jquery.quicksearch.js

js asia-guide.biz collected 2026-10-08 09:23:04 UTC 4,179 bytes, 181 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			matchedResultsCount: 0,
11			bind: 'keyup',
12			onBefore: function () { 
13				return;
14			},
15			onAfter: function () { 
16				return;
17			},
18			show: function () {
19				this.style.display = "";
20			},
21			hide: function () {
22				this.style.display = "none";
23			},
24			prepareQuery: function (val) {
25				return val.toLowerCase().split(' ');
26			},
27			testQuery: function (query, txt, _row) {
28				for (var i = 0; i < query.length; i += 1) {
29					if (txt.indexOf(query[i]) === -1) {
30						return false;
31					}
32				}
33				return true;
34			}
35		}, opt);
36		
37		this.go = function () {
38			
39			var i = 0,
40				numMatchedRows = 0,
41				noresults = true, 
42				query = options.prepareQuery(val),
43				val_empty = (val.replace(' ', '').length === 0);
44			
45			for (var i = 0, len = rowcache.length; i < len; i++) {
46				if (val_empty || options.testQuery(query, cache[i], rowcache[i])) {
47					options.show.apply(rowcache[i]);
48					noresults = false;
49					numMatchedRows++;
50				} else {
51					options.hide.apply(rowcache[i]);
52				}
53			}
54			
55			if (noresults) {
56				this.results(false);
57			} else {
58				this.results(true);
59				this.stripe();
60			}
61			
62			this.matchedResultsCount = numMatchedRows;
63			this.loader(false);
64			options.onAfter();
65			
66			return this;
67		};
68		
69		/*
70		 * External API so that users can perform search programatically. 
71		 * */
72		this.search = function (submittedVal) {
73			val = submittedVal;
74			e.trigger();
75		};
76		
77		/*
78		 * External API to get the number of matched results as seen in 
79		 * https://github.com/ruiz107/quicksearch/commit/f78dc440b42d95ce9caed1d087174dd4359982d6
80		 * */
81		this.currentMatchedResults = function() {
82			return this.matchedResultsCount;
83		};
84		
85		this.stripe = function () {
86			
87			if (typeof options.stripeRows === "object" && options.stripeRows !== null)
88			{
89				var joined = options.stripeRows.join(' ');
90				var stripeRows_length = options.stripeRows.length;
91				
92				jq_results.not(':hidden').each(function (i) {
93					$(this).removeClass(joined).addClass(options.stripeRows[i % stripeRows_length]);
94				});
95			}
96			
97			return this;
98		};
99		
100		this.strip_html = function (input) {
101			var output = input.replace(new RegExp('<[^<]+\>', 'g'), "");
102			output = $.trim(output.toLowerCase());
103			return output;
104		};
105		
106		this.results = function (bool) {
107			if (typeof options.noResults === "string" && options.noResults !== "") {
108				if (bool) {
109					$(options.noResults).hide();
110				} else {
111					$(options.noResults).show();
112				}
113			}
114			return this;
115		};
116		
117		this.loader = function (bool) {
118			if (typeof options.loader === "string" && options.loader !== "") {
119				 (bool) ? $(options.loader).show() : $(options.loader).hide();
120			}
121			return this;
122		};
123		
124		this.cache = function () {
125			
126			jq_results = $(target);
127			
128			if (typeof options.noResults === "string" && options.noResults !== "") {
129				jq_results = jq_results.not(options.noResults);
130			}
131			
132			var t = (typeof options.selector === "string") ? jq_results.find(options.selector) : $(target).not(options.noResults);
133			cache = t.map(function () {
134				return e.strip_html(this.innerHTML);
135			});
136			
137			rowcache = jq_results.map(function () {
138				return this;
139			});
140
141			/*
142			 * Modified fix for sync-ing "val". 
143			 * Original fix https://github.com/michaellwest/quicksearch/commit/4ace4008d079298a01f97f885ba8fa956a9703d1
144			 * */
145			val = val || this.val() || "";
146			
147			return this.go();
148		};
149		
150		this.trigger = function () {
151			this.loader(true);
152			options.onBefore();
153			
154			window.clearTimeout(timeout);
155			timeout = window.setTimeout(function () {
156				e.go();
157			}, options.delay);
158			
159			return this;
160		};
161		
162		this.cache();
163		this.results(true);
164		this.stripe();
165		this.loader(false);
166		
167		return this.each(function () {
168			
169			/*
170			 * Changed from .bind to .on.
171			 * */
172			$(this).on(options.bind, function () {
173				
174				val = $(this).val();
175				e.trigger();
176			});
177		});
178		
179	};
180
181}(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.