Skip to content

Instantly share code, notes, and snippets.

@HaNdTriX
Last active August 29, 2015 14:13
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 HaNdTriX/c2500d0919de633157b9 to your computer and use it in GitHub Desktop.
Save HaNdTriX/c2500d0919de633157b9 to your computer and use it in GitHub Desktop.
Monkey-Patch: jquery-autocomplete.js (_renderItem & _renderMenu)
(function monkeyPatchJQueryAutocomplete($) {
/**
* Proxies a private
* prototype method to the
* options Object
*
* @param {Object} obj
* @param {String} funcName
*/
function proxyPrivateMethodToOptions(obj, funcName) {
var __super = obj.prototype[funcName];
obj.prototype[funcName] = function() {
if (this.options[funcName]) {
return this.options[funcName].apply(this, arguments);
}
return __super.apply(this, arguments);
};
}
// Make the private _renderItem
// method available through the options Object
proxyPrivateMethodToOptions($.ui.autocomplete, '_renderItem');
// We can do this for other methods as well:
proxyPrivateMethodToOptions($.ui.autocomplete, '_renderMenu');
// @example
//
// $('.some-input').autocomplete({
// _renderItem: function(ul, item) {
// console.log(__super);
// return $("<li>")
// .append($("<a>").text(item.label))
// .appendTo(ul);
// }
// });
//
}($));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment