steveosoule
6/19/2013 - 4:48 PM

javascript-filter-items-on-page.js

javascript-filter-items-on-page.js

//filter results based on query
function filter(selector, query) {
	query = $.trim(query); //trim white space
	query = query.replace(/ /gi, '|'); //add OR for regex

	$(selector).each(function () {
		($(this).text().search(new RegExp(query, "i")) < 0) ? $(this).hide().removeClass('visible') : $(this).show().addClass('visible');
		$(this).unhighlight({
			element: 'span',
			className: 'highlight'
		});
		$(this).highlight(query, {
			element: 'span',
			className: 'highlight'
		});
	});
}