Skip to content

Instantly share code, notes, and snippets.

@tfluehr
Created December 16, 2010 14:08
Show Gist options
  • Save tfluehr/743428 to your computer and use it in GitHub Desktop.
Save tfluehr/743428 to your computer and use it in GitHub Desktop.
Example of how to extend/overwrite Scriptaculous Autocompleter.Base
if (typeof(Autocompleter) != 'undefined') { // check if Autocompleter exists
Autocompleter.Base.addMethods({ // adds the listed functions to Autocompleter.Base
onKeyPress: Autocompleter.Base.prototype.onKeyPress.wrap(function(proceed, event){ // "wrap" the existing "onKeyPress" in this new function, exclude the "wrap" and just do onKeyPress: function(event) if you want to always overwrite the existing function
var args = $A(arguments);
args.shift(); // removes "proceed" from the arguments so only the original arguments will get passed to the original function
// place any code here you wish to execute before the original function
var returnVal = proceed.apply(this, args); // runs the original function
// place any code here you wish to execute after the original function
return returnVal;
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment