jquery.ui.autocomplete.html.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. */
  9. (function( $ ) {
  10. var proto = $.ui.autocomplete.prototype,
  11. initSource = proto._initSource;
  12. function filter( array, term ) {
  13. var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
  14. return $.grep( array, function(value) {
  15. return matcher.test( $( "<div>" ).html( value.label || value.value || value ).text() );
  16. });
  17. }
  18. $.extend( proto, {
  19. _initSource: function() {
  20. if ( this.options.html && $.isArray(this.options.source) ) {
  21. this.source = function( request, response ) {
  22. response( filter( this.options.source, request.term ) );
  23. };
  24. } else {
  25. initSource.call( this );
  26. }
  27. },
  28. _renderItem: function( ul, item) {
  29. return $( "<li></li>" )
  30. .data( "item.autocomplete", item )
  31. .append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )
  32. .appendTo( ul );
  33. }
  34. });
  35. })( jQuery );