Guest User

Untitled

a guest
May 20th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 3.27 KB | None | 0 0
  1. (function( $ ) {
  2.         $.widget( "ui.combobox", {
  3.             _create: function() {
  4.                 var self = this,
  5.                     select = this.element.hide(),
  6.                     selected = select.children( ":selected" ),
  7.                     value = selected.val() ? selected.text() : "";
  8.                 var input = this.input = $( "<input>" )
  9.                     .insertAfter( select )
  10.                     .val( value )
  11.                     .autocomplete({
  12.                         delay: 0,
  13.                         minLength: 0,
  14.                         source: function( request, response ) {
  15.                             var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
  16.                             response( select.children( "option" ).map(function() {
  17.                                 var text = $( this ).text();
  18.                                 if ( this.value && ( !request.term || matcher.test(text) ) )
  19.                                     return {
  20.                                         label: $( this ).attr('value').replace(
  21.                                             new RegExp(
  22.                                                 "(?![^&;]+;)(?!<[^<>]*)(" +
  23.                                                 $.ui.autocomplete.escapeRegex(request.term) +
  24.                                                 ")(?![^<>]*>)(?![^&;]+;)", "gi"
  25.                                             ), "<strong>$1</strong>" ),
  26.                                         value: $( this ).attr('value'),
  27.                                         option: this
  28.                                     };
  29.                             }) );
  30.                         },
  31.                         select: function( event, ui ) {
  32.                             ui.item.option.selected = true;
  33.                             self._trigger( "selected", event, {
  34.                                 item: ui.item.option
  35.                             });
  36.                         },
  37.                         change: function( event, ui ) {
  38.                             if ( !ui.item ) {
  39.                                 var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
  40.                                     valid = false;
  41.                                 select.children( "option" ).each(function() {
  42.                                     if ( $( this ).text().match( matcher ) ) {
  43.                                         this.selected = valid = true;
  44.                                         return false;
  45.                                     }
  46.                                 });
  47.                                 if ( !valid ) {
  48.                                     // remove invalid value, as it didn't match anything
  49.                                     $( this ).val( "" );
  50.                                     select.val( "" );
  51.                                     input.data( "autocomplete" ).term = "";
  52.                                     return false;
  53.                                 }
  54.                             }
  55.                         }
  56.                     })
  57.                     .addClass( "ui-widget ui-widget-content ui-corner-left" );
  58.  
  59.                 input.data( "autocomplete" )._renderItem = function( ul, item ) {
  60.                    
  61.                    
  62.                     return $( "<li></li>" )
  63.                         .data( "item.autocomplete", item )
  64.                         .append( "<a>" + item.label + "</a>" )
  65.                         .appendTo( ul );
  66.                 };
  67.  
  68.                 this.button = $( "<button type='button'>&nbsp;</button>" )
  69.                     .attr( "tabIndex", -1 )
  70.                     .attr( "title", "Show All Items" )
  71.                     .attr("style","width:18px;  border: #707070 solid 2px; border-left: #707070 solid 1px; ")
  72.                     .insertAfter( input )
  73.                     .button({
  74.                         icons: {
  75.                             primary: "ui-icon-triangle-1-s"
  76.                         },
  77.                         text: false
  78.                     })
  79.                     .removeClass( "ui-corner-all" )
  80.                     .addClass( "ui-button-icon" )
  81.                     .click(function() {
  82.                         // close if already visible
  83.                         if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
  84.                             input.autocomplete( "close" );
  85.                             return;
  86.                         }
  87.  
  88.                         // work around a bug (likely same cause as #5265)
  89.                         $( this ).blur();
  90.  
  91.                         // pass empty string as value to search for, displaying all results
  92.                         input.autocomplete( "search", "" );
  93.                         input.focus();
  94.                     });
  95.             },
  96.  
  97.             destroy: function() {
  98.                 this.input.remove();
  99.                 this.button.remove();
  100.                 this.element.show();
  101.                 $.Widget.prototype.destroy.call( this );
  102.             }
  103.         });
  104.     })( jQuery );
  105.  
  106. $(function() {
  107.         if(!$.browser.msie){
  108.             $( "#estado_civil" ).combobox();
  109.         }
  110.  
  111.     });
Add Comment
Please, Sign In to add comment