Last active
August 29, 2015 14:13
-
-
Save HaNdTriX/c2500d0919de633157b9 to your computer and use it in GitHub Desktop.
Monkey-Patch: jquery-autocomplete.js (_renderItem & _renderMenu)
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
(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