Skip to content

Instantly share code, notes, and snippets.

@maranomynet
Created April 18, 2011 14:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maranomynet/925491 to your computer and use it in GitHub Desktop.
Save maranomynet/925491 to your computer and use it in GitHub Desktop.
clone of Scott González' jQuery UI autocomplete html extensionn - with className support added
/*
* jQuery UI Autocomplete HTML Extension
*
* Copyright 2010, Scott González (http://scottgonzalez.com)
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* http://github.com/scottgonzalez/jquery-ui-extensions
*/
(function( $ ) {
var proto = $.ui.autocomplete.prototype,
initSource = proto._initSource;
function filter( array, term ) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), 'i' );
return $.grep( array, function(value) {
return matcher.test( $( '<div/>' ).html( value.label || value.value || value ).text() );
});
}
$.extend( proto, {
_initSource: function() {
if ( this.options.html && $.isArray(this.options.source) )
{
this.source = function( request, response ) {
response( filter( this.options.source, request.term ) );
};
}
else
{
initSource.call( this );
}
},
_renderItem: function( ul, item) {
return $( '<li><a/></li>' )
.data( "item.autocomplete", item )
.find( '<a/>' )
.addClass( item.className )
[ this.options.html ? "html" : "text" ]( item.label )
.end()
.appendTo( ul );
}
});
})( jQuery );
@code56
Copy link

code56 commented Jul 19, 2016

Hi, I am using your script, in my Drupal page. I configured my template.php file to be including your script, under the correct path. But when I load my drupal page, I get the error: jquery.ui.autocomplete.html.js:11 Uncaught TypeError: Cannot read property 'autocomplete' of undefined. could you give me some insight on the above? Thank you in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment