Skip to content

Instantly share code, notes, and snippets.

@scottgonzalez
Created August 24, 2010 14:03
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 scottgonzalez/547600 to your computer and use it in GitHub Desktop.
Save scottgonzalez/547600 to your computer and use it in GitHub Desktop.
var initSource = $.ui.autocomplete.prototype._initSource;
$.ui.autocomplete.prototype._initSource = function() {
if ( typeof this.options.source === "string" && this.options.cache ) {
var self = this,
cache = {};
this.source = function( request, response ) {
var term = request.term;
if ( cache[ term ] ) {
response( cache[ term ] );
return;
}
self.xhr = $.getJSON( self.options.source, request, function( data, status, xhr ) {
cache[ term ] = data;
if ( xhr === self.xhr ) {
response( data );
}
});
};
} else {
initSource.call( this );
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment