Created
February 27, 2010 01:02
-
-
Save lsmith/316358 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YAHOO.widget.AutoComplete.prototype.filterResults = | |
function( filter, response, parsedResponse, callback ) { | |
// If AC has passed a filter string value back to itself, grab it | |
if ( callback && callback.argument && callback.argument.query ) { | |
filter = callback.argument.filter; | |
} | |
filter = decodeURIComponent( filter ).toLowerCase(); | |
// Only if a filter string is available to match against | |
if ( filter ) { | |
var results = parsedResponse.results, | |
filtered = [], | |
limit = callback.scope.maxResultsDisplayed, | |
fields = this.responseSchema.fields, | |
key = ( fields ? fields[0].key || fields[0] : null ), | |
lang = YAHOO.lang, | |
isString = lang.isString, | |
isArray = lang.isArray, | |
matched = 0, | |
i, len, result; | |
for( i = 0, len = results.length; i < len; ++i ) { | |
result = results[i]; | |
if ( !isString( result ) ) { | |
if ( isArray( result ) ) { | |
result = result[0]; | |
} else if ( key ) { | |
result = result[ key ]; | |
} else if ( this.key ) { | |
result = result[ this.key ]; | |
} else { | |
result = ''; | |
} | |
} | |
if ( result.toLowerCase().indexOf( filter ) > -1 ) { | |
matched = filtered.push( results[i] ); | |
} | |
// Filter no more if maxResultsDisplayed is reached | |
if ( matched >= limit ) { | |
break; | |
} | |
} | |
parsedResponse.results = filtered; | |
} | |
return parsedResponse; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment