Created
December 16, 2010 14:08
-
-
Save tfluehr/743428 to your computer and use it in GitHub Desktop.
Example of how to extend/overwrite Scriptaculous Autocompleter.Base
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
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