Skip to content

Instantly share code, notes, and snippets.

@jcolebrand
Created November 11, 2011 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcolebrand/1358642 to your computer and use it in GitHub Desktop.
Save jcolebrand/1358642 to your computer and use it in GitHub Desktop.
Goes with my gist 1219990
function SearchFieldKeypressCallBack(event, value) {
//if they entered anything, else use the default like on page load
if (value) {
//TIM: I was debouncing/throttling here
GenerateReportTilesOnSuccess(GetItemsByText(value));
} else {
GenerateReportTilesOnSuccess(reportList.list);
}
}
function GetItemsByText(text) {
return reportList.list.filter(function (element) { return itemTextFilter(element, text) });
}
function itemTextFilter(element, text) {
var caseSensitive = false;
if (
typeof element !== 'undefined' &&
typeof text === 'string'
) {
var t = '';
for (var k in element) {
var e = element[k];
if (element.hasOwnProperty(k)) {
if (typeof e === 'string') {
t += ' ' + e;
}
}
}
if (!caseSensitive) {
t = t.toLowerCase();
text = text.toLowerCase();
}
if (t.indexOf(text) !== -1) {
return element;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment