Permalink
Newer
100644
41 lines (35 sloc)
1.04 KB
19a6d0b | ||
1 | /* | |
2 | * jQuery UI Autocomplete HTML Extension | |
3 | * | |
4 | * Copyright 2010, Scott González (http://scottgonzalez.com) | |
5 | * Dual licensed under the MIT or GPL Version 2 licenses. | |
6 | * | |
7 | * http://github.com/scottgonzalez/jquery-ui-extensions | |
8 | */ | |
9b0e95a | ||
9 | (function( $ ) { | |
10 | ||
f85e922 | ||
11 | var proto = $.ui.autocomplete.prototype, | |
12 | initSource = proto._initSource; | |
13 | ||
14 | function filter( array, term ) { | |
15 | var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" ); | |
16 | return $.grep( array, function(value) { | |
17 | return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() ); | |
18 | }); | |
19 | } | |
20 | ||
21 | $.extend( proto, { | |
22 | _initSource: function() { | |
e34c945 | ||
23 | if ( this.options.html && $.isArray(this.options.source) ) { | |
f85e922 | ||
24 | this.source = function( request, response ) { | |
25 | response( filter( this.options.source, request.term ) ); | |
26 | }; | |
27 | } else { | |
28 | initSource.call( this ); | |
29 | } | |
30 | }, | |
31 | ||
32 | _renderItem: function( ul, item) { | |
33 | return $( "<li></li>" ) | |
34 | .data( "item.autocomplete", item ) | |
35 | .append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) ) | |
36 | .appendTo( ul ); | |
37 | } | |
38 | }); | |
9b0e95a | ||
39 | ||
40 | })( jQuery ); |