Advertisement
valuser

Combobox Auto Complete

Oct 6th, 2014
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.09 KB | None | 0 0
  1. <script type='text/javascript' src='http://code.jquery.com/ui/1.9.1/jquery-ui.min.js'></script>    ( just before </head> )
  2.  
  3. Also
  4.  
  5. IsItChristmas  is disabled="true"  but it just doesn't appear - would prefer that it did but dimmed and unclickable
  6.  
  7.  
  8. <div class="demo">
  9. <div class="ui-widget">
  10. <select id="combobox1">
  11. <option value="">Select one...</option>
  12. <option value="http://www.somethingstore.com">SomethingStore</option>
  13. <option value="http://z0r.de/">Zor</option>
  14. <option value="http://wwwwwwwww.jodi.org">Jodi</option>
  15. <option value="http://www.youfellasleepwatchingadvd.com">FellAsleep</option>
  16. <option value="http://www.staggeringbeauty.com">Staggering</option>
  17. <option value="http://www.theuselessweb.com">Useless</option>
  18. <option value="https://isitchristmas.com" disabled="true">IsItChristmas</option>
  19. <option value="http://www.timecube.com">TimeCube</option>
  20. <option value="http://zombo.com">Zombo</option>
  21. <option value="http://www.pointerpointer.com">Pointer</option>
  22. <option value="http://www.fearthegaychicken.org">FeartheGayChicken</option>
  23. <option value="http://www.pixyland.org/peterpan/">Peter Pan</option>
  24. <option value="http://heyyeyaaeyaaaeyaeyaa.com">HeHa</option>
  25. <option value="http://www.godhatesshrimp.com">God Hates Shrimp</option>
  26. <option value="http://www.koalastothemax.com">Koalas To The Max</option>
  27. <option value="http://www.drunkronswanson.com">Infinite Drunk Ron</option>
  28. <option value="http://www.patience-is-a-virtue.org">Patience is a Virtue</option>
  29. <option value="http://www.brainwash.com/cameras.htm">BrainWash</option>
  30. <option value="http://www.feedthehead.net">Feed the Head</option>
  31. <option value="http://cat-bounce.com">Bouncing Cats</option>
  32. <option value="http://www.shayesaintjohn.net">Shayes Store</option>
  33. <option value="http://111111111111111111111111111111111111111111111111111111111111.com">The One and Only One</option>
  34. <option value="http://www.michaeljfoxnews.com">Not Fox News</option>
  35. <option value="http://procatinator.com">More Cats</option>
  36. <option value="http://www.whitepowermilk.com">White Power Milk</option>
  37. <option value="http://www.jimcarrey.com">Jim Carrey</option>
  38. <option value="http://tane.us">Tane</option>
  39. <option value="http://www.cookevillepolice.com">Cookville Police Dept.</option>
  40. <option value="http://jaredpadaleckisass.com">Jared Padaleckisass</option>
  41. <option value="http://www.wwwdotcom.com">The End</option>
  42. <option value="http://iloveyoulikeafatladylovesapples.com">Fat Lady Love Apples</option>
  43. <option value="http://www.rainymood.com">Rainy Mood</option>
  44. <option value="http://www.simonpanrucker.com/beans.swf">Screamin' Beans</option>
  45. <option value="http://www.thisman.org">Ever Dream This Man</option>
  46. <option value="http://thequietplaceproject.com/thequietplace">The Quiet Place</option>
  47. <option value="http://thenicestplaceontheinter.net">The Nicest Place on the Internet</option>
  48. <option value="http://www.hosanna1.com">Jumble Book</option>
  49. <option value="http://www.haneke.net">Haneke</option>
  50. <option value="http://thebeatlesneverbrokeup.com">Beatle Reborn</option>
  51. <option value="http://www.ilooklikebarackobama.com">Obama Lookalike</option>
  52. <option value="http://momspaghetti.ytmnd.com">Mom's Spaghetti</option>
  53. <option value="http://www.youshouldhaveseenthis.com">See This?</option>
  54. <option value="http://postsecret.com">Post Secret</option>
  55. <option value="http://www.venganza.org">Church of the Flying Spaghetti Monster</option>
  56. <option value="http://failblog.cheezburger.com">Fail Blog</option>
  57. <option value="http://www.rathergood.com">Rather Good</option>
  58. <option value="http://icanhas.cheezburger.com">Cheezburger</option>
  59. <option value="http://www.fugly.com">Fugly</option>
  60. <option value="http://www.dictionaryofobscuresorrows.com">Dictionary of Obscure Sorrows</option>
  61. <option value="http://www.wwwdotcom.com">The End</option>
  62. </select>
  63. </div>
  64.  
  65. <script type="text/javascript">
  66.     (function( jQuery ) {
  67.         jQuery.widget( "ui.combobox", {
  68.             _create: function() {
  69.                 var input,
  70.                     self = this,
  71.                     select = this.element.hide(),
  72.                     selected = select.children( ":selected" ),
  73.                     value = selected.val() ? selected.text() : "",
  74.                     wrapper = this.wrapper =jQuery( "<span>" )
  75.                         .addClass( "ui-combobox" )
  76.                         .insertAfter( select );             input = jQuery( "<input>" )
  77.                     .appendTo( wrapper )
  78. .attr('placeholder', 'Go to .....')
  79. .attr('onfocus', 'if(this.placeholder == "Go to .....") {this.placeholder = "";}')
  80. .attr('onblur', 'if(this.placeholder == "") {this.placeholder = "Go to .....";}')
  81.                     .val( value )
  82.                     .addClass( "ui-state-default ui-combobox-input" )
  83.                     .autocomplete({
  84.                         delay: 0,
  85.                         minLength: 0,
  86.                         source: function( request, response ) {
  87.                             var matcher = new RegExp( jQuery.ui.autocomplete.escapeRegex(request.term), "i" );
  88.                             response( select.children( "option" ).not(':disabled').map(function() {
  89.                                                                
  90.                                 var text = jQuery( this ).text();
  91.                                 if ( this.value && ( !request.term || matcher.test(text) ) )
  92.                                     return {
  93.                                         label: text.replace(
  94.                                             new RegExp(
  95.                                                 "(?![^&;]+;)(?!<[^<>]*)(" +
  96.                                                 jQuery.ui.autocomplete.escapeRegex(request.term) +
  97.                                                 ")(?![^<>]*>)(?![^&;]+;)", "gi"
  98.                                             ), "<strong>$1</strong>" ),
  99.                                         value: text,
  100.                                         option: this
  101.                                     };                          }) );
  102.                         },
  103.                         select: function( event, ui ) {
  104. //alert( comboBoxThis.attr("id") );
  105. //if( jQuery(this).attr("id") == "combobox1")
  106. //document.location.href=ui.item.option.value;                         
  107.                             ui.item.option.selected = true;
  108.                             self._trigger( "selected", event, {
  109.                                 item: ui.item.option
  110.                             });
  111.                         },
  112.                         change: function( event, ui ) {
  113.                             if ( !ui.item ) {
  114.                                 var matcher = new RegExp( "^" + jQuery.ui.autocomplete.escapeRegex( jQuery(this).val() ) + "$", "i" ),
  115.                                     valid = false;
  116.                                 select.children( "option" ).each(function() {
  117.                                     if ( jQuery( this ).text().match( matcher ) ) {
  118.                                         this.selected = valid = true;
  119.                                         return false;
  120.                                     }
  121.                                 });
  122.                                 if ( !valid ) {
  123.                                     // remove invalid value, as it didn't match anything
  124.                                     jQuery( this ).val( "" );
  125.                                     select.val( "" );
  126.                                     input.data( "autocomplete" ).term = "";
  127.                                     return false;
  128.                                 }
  129.                             }
  130.                         }
  131.                     })
  132.                     .addClass( "ui-widget ui-widget-content ui-corner-left" );             
  133.                     input.data( "autocomplete" )._renderItem = function( ul, item ) {
  134.                     return jQuery( "<li></li>" )
  135.                         .data( "item.autocomplete", item )
  136.                         .append( "<a href='"+ item.option.value +"'>" + item.label + "</a>" )
  137.                         .appendTo( ul );                };              jQuery( "<a>" )
  138.                     .attr( "tabIndex", -1 )
  139.                     .attr( "title", "Show All Items" )
  140.                     .appendTo( wrapper )
  141.                     .button({
  142.                         icons: {
  143.                             primary: "ui-icon-triangle-1-s"
  144.                         },
  145.                         text: false
  146.                     })
  147.                     .removeClass( "ui-corner-all" )
  148.                     .addClass( "ui-corner-right ui-combobox-toggle" )
  149.                     .click(function() {
  150.                         // close if already visible
  151.                         if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
  152.                             input.autocomplete( "close" );
  153.                             return;
  154.                         }                      
  155.                         // work around a bug (likely same cause as #5265)
  156.                         jQuery( this ).blur();                     
  157.                         // pass empty string as value to search for, displaying all results
  158.                         input.autocomplete( "search", "" );
  159.                         input.focus();
  160.                     });
  161.             },          destroy: function() {
  162.                 this.wrapper.remove();
  163.                 this.element.show();
  164.                 jQuery.Widget.prototype.destroy.call( this );
  165.             }
  166.         });
  167.     })( jQuery );   jQuery(function() {
  168.         jQuery( "#combobox, #combobox1" ).combobox();
  169.         jQuery( "#toggle" ).click(function() {
  170.             jQuery( "#combobox, #combobox1" ).toggle();
  171.         });
  172. jQuery(document).ready(function(){
  173.     jQuery('.ui-autocomplete:first').addClass('hCombo');
  174.    
  175.         jQuery('.hCombo li a').live('click',function(){
  176.             var cId = jQuery('.demo').find('select ').attr('id');
  177. //            alert( jQuery(this).attr('href') );
  178.             document.location.href= jQuery(this).attr('href');
  179.         });
  180.     });
  181.    
  182. });
  183. //alert(jQuery('.demo').html());
  184. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement