github github
  • Home
  • Pricing and Signup
  • Training
  • Gist
  • Blog
  • Login

jquery / jquery-ui

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 919
    • 211
  • Source
  • Commits
  • Network (211)
  • Graphs
  • Tree: ba09165

click here to add a description

click here to add a homepage

  • Switch Branches (8)
    • bind
    • devpreview
    • formcontrols
    • master
    • menu
    • panel
    • tooltip
    • widget-super
  • Switch Tags (21)
    • 1.9m2
    • 1.9m1
    • 1.8rc3
    • 1.8rc2
    • 1.8rc1
    • 1.8b1
    • 1.8a2
    • 1.8a1
    • 1.8.4
    • 1.8.3
    • 1.8.2
    • 1.8.1
    • 1.8
    • 1.7
    • 1.6rc6
    • 1.6rc5
    • 1.6rc3
    • 1.6rc2
    • 1.6
    • 1.5.2
    • 1.5.1
  • Comments
  • Contributors
Sending Request…

The official jQuery user interface library. — Read more

  Cancel

http://jqueryui.com/

  Cancel
  • HTTP
  • Git Read-Only

This URL has Read+Write access

Autcomplete: Refactored combobox demo.
scottgonzalez (author)
Tue Jul 20 11:20:46 -0700 2010
commit  ba091650ffdd2e359624
tree    884d1d6660b70c339517
parent  c2c09e89538ce071efba
M demos/autocomplete/combobox.html 110 ••••
Txt demos/autocomplete/combobox.html
  • View file @ ba09165
... ...
@@ -18,75 +18,85 @@
18 18
     .ui-autocomplete-input { margin: 0; padding: 0.48em 0 0.47em 0.45em; }
19 19
   </style>
20 20
   <script type="text/javascript">
21  
-  (function($) {
22  
-    $.widget("ui.combobox", {
  21
+  (function( $ ) {
  22
+    $.widget( "ui.combobox", {
23 23
       _create: function() {
24 24
         var self = this;
25 25
         var select = this.element.hide();
26  
-        var input = $("<input>")
27  
-          .insertAfter(select)
  26
+        var input = $( "<input>" )
  27
+          .insertAfter( select )
28 28
           .autocomplete({
29  
-            source: function(request, response) {
30  
-              var matcher = new RegExp(request.term, "i");
31  
-              response(select.children("option").map(function() {
32  
-                var text = $(this).text();
33  
-                if (this.value && (!request.term || matcher.test(text)))
  29
+            delay: 0,
  30
+            minLength: 0,
  31
+            source: function( request, response ) {
  32
+              var matcher = new RegExp( request.term, "i" );
  33
+              response( select.children( "option" ).map(function() {
  34
+                var text = $( this ).text();
  35
+                if ( this.value && ( !request.term || matcher.test(text) ) )
34 36
                   return {
35  
-                    id: this.value,
36  
-                    label: text.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(request.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
37  
-                    value: text
  37
+                    label: text.replace(
  38
+                      new RegExp(
  39
+                        "(?![^&;]+;)(?!<[^<>]*)(" +
  40
+                        $.ui.autocomplete.escapeRegex(request.term) +
  41
+                        ")(?![^<>]*>)(?![^&;]+;)", "gi"
  42
+                      ), "<strong>$1</strong>" ),
  43
+                    value: text,
  44
+                    option: this
38 45
                   };
39  
-              }));
  46
+              }) );
40 47
             },
41  
-            delay: 0,
42  
-            change: function(event, ui) {
43  
-              if (!ui.item) {
  48
+            select: function( event, ui ) {
  49
+              ui.item.option.selected = true;
  50
+              //select.val( ui.item.option.value );
  51
+              self._trigger( "selected", event, {
  52
+                item: ui.item.option
  53
+              });
  54
+            },
  55
+            change: function( event, ui ) {
  56
+              if ( !ui.item ) {
44 57
                 // remove invalid value, as it didn't match anything
45  
-                $(this).val("");
46  
-                select.val("");
  58
+                $( this ).val( "" );
  59
+                select.val( "" );
47 60
                 return false;
48 61
               }
49  
-              select.val(ui.item.id);
50  
-              self._trigger("selected", event, {
51  
-                item: select.find("[value='" + ui.item.id + "']")
52  
-              });
53  
-              
54  
-            },
55  
-            minLength: 0
  62
+            }
56 63
           })
57  
-          .addClass("ui-widget ui-widget-content ui-corner-left");
58  
-        input.data("autocomplete")._renderItem = function( ul, item) {
  64
+          .addClass( "ui-widget ui-widget-content ui-corner-left" );
  65
+
  66
+        input.data( "autocomplete" )._renderItem = function( ul, item ) {
59 67
           return $( "<li></li>" )
60 68
             .data( "item.autocomplete", item )
61 69
             .append( "<a>" + item.label + "</a>" )
62 70
             .appendTo( ul );
63 71
         };
64  
-        $("<button>&nbsp;</button>")
65  
-        .attr("tabIndex", -1)
66  
-        .attr("title", "Show All Items")
67  
-        .insertAfter(input)
68  
-        .button({
69  
-          icons: {
70  
-            primary: "ui-icon-triangle-1-s"
71  
-          },
72  
-          text: false
73  
-        }).removeClass("ui-corner-all")
74  
-        .addClass("ui-corner-right ui-button-icon")
75  
-        .click(function() {
76  
-          // close if already visible
77  
-          if (input.autocomplete("widget").is(":visible")) {
78  
-            input.autocomplete("close");
79  
-            return;
80  
-          }
81  
-          // pass empty string as value to search for, displaying all results
82  
-          input.autocomplete("search", "");
83  
-          input.focus();
84  
-        });
  72
+
  73
+        $( "<button>&nbsp;</button>" )
  74
+          .attr( "tabIndex", -1 )
  75
+          .attr( "title", "Show All Items" )
  76
+          .insertAfter( input )
  77
+          .button({
  78
+            icons: {
  79
+              primary: "ui-icon-triangle-1-s"
  80
+            },
  81
+            text: false
  82
+          })
  83
+          .removeClass( "ui-corner-all" )
  84
+          .addClass( "ui-corner-right ui-button-icon" )
  85
+          .click(function() {
  86
+            // close if already visible
  87
+            if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
  88
+              input.autocomplete( "close" );
  89
+              return;
  90
+            }
  91
+
  92
+            // pass empty string as value to search for, displaying all results
  93
+            input.autocomplete( "search", "" );
  94
+            input.focus();
  95
+          });
85 96
       }
86 97
     });
87  
-
88 98
   })(jQuery);
89  
-    
  99
+
90 100
   $(function() {
91 101
     $("#combobox").combobox();
92 102
     $("#toggle").click(function() {

0 notes on commit ba09165

Please log in to comment.
Dedicated Server Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
  • Blog
  • Support
  • Training
  • Job Board
  • Shop
  • Contact
  • API
  • Status
  • © 2010 GitHub Inc. All rights reserved.
  • Terms of Service
  • Privacy
  • Security
  • English
  • Deutsch
  • Français
  • 日本語
  • Português (BR)
  • 中文
  • See all available languages

Your current locale selection: English. Choose another?

  • English
  • Afrikaans
  • Català
  • Čeština
  • Deutsch
  • Español
  • Français
  • Hrvatski
  • Indonesia
  • Italiano
  • 日本語
  • Nederlands
  • Norsk
  • Polski
  • Português (BR)
  • Српски
  • Svenska
  • 中文