Created
April 18, 2011 14:47
-
-
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
This file contains hidden or 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
/* | |
* 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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!