comparison war/scripts/jQuery/demos/autocomplete/combobox.html @ 3:cf06b77a8bbd

Committed branch of the e4D repos sti-gwt branch 16384. git-svn-id: http://dev.dariah.eu/svn/repos/eu.dariah.de/ap1/sti-gwt-dariah-geobrowser@36 f2b5be40-def6-11e0-8a09-b3c1cc336c6b
author StefanFunk <StefanFunk@f2b5be40-def6-11e0-8a09-b3c1cc336c6b>
date Tue, 17 Jul 2012 13:34:40 +0000
parents
children
comparison
equal deleted inserted replaced
2:2897af43ccc6 3:cf06b77a8bbd
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery UI Autocomplete - Combobox</title>
6 <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
7 <script src="../../jquery-1.5.1.js"></script>
8 <script src="../../ui/jquery.ui.core.js"></script>
9 <script src="../../ui/jquery.ui.widget.js"></script>
10 <script src="../../ui/jquery.ui.button.js"></script>
11 <script src="../../ui/jquery.ui.position.js"></script>
12 <script src="../../ui/jquery.ui.autocomplete.js"></script>
13 <link rel="stylesheet" href="../demos.css">
14 <style>
15 .ui-button { margin-left: -1px; }
16 .ui-button-icon-only .ui-button-text { padding: 0.35em; }
17 .ui-autocomplete-input { margin: 0; padding: 0.48em 0 0.47em 0.45em; }
18 </style>
19 <script>
20 (function( $ ) {
21 $.widget( "ui.combobox", {
22 _create: function() {
23 var self = this,
24 select = this.element.hide(),
25 selected = select.children( ":selected" ),
26 value = selected.val() ? selected.text() : "";
27 var input = this.input = $( "<input>" )
28 .insertAfter( select )
29 .val( value )
30 .autocomplete({
31 delay: 0,
32 minLength: 0,
33 source: function( request, response ) {
34 var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
35 response( select.children( "option" ).map(function() {
36 var text = $( this ).text();
37 if ( this.value && ( !request.term || matcher.test(text) ) )
38 return {
39 label: text.replace(
40 new RegExp(
41 "(?![^&;]+;)(?!<[^<>]*)(" +
42 $.ui.autocomplete.escapeRegex(request.term) +
43 ")(?![^<>]*>)(?![^&;]+;)", "gi"
44 ), "<strong>$1</strong>" ),
45 value: text,
46 option: this
47 };
48 }) );
49 },
50 select: function( event, ui ) {
51 ui.item.option.selected = true;
52 self._trigger( "selected", event, {
53 item: ui.item.option
54 });
55 },
56 change: function( event, ui ) {
57 if ( !ui.item ) {
58 var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
59 valid = false;
60 select.children( "option" ).each(function() {
61 if ( $( this ).text().match( matcher ) ) {
62 this.selected = valid = true;
63 return false;
64 }
65 });
66 if ( !valid ) {
67 // remove invalid value, as it didn't match anything
68 $( this ).val( "" );
69 select.val( "" );
70 input.data( "autocomplete" ).term = "";
71 return false;
72 }
73 }
74 }
75 })
76 .addClass( "ui-widget ui-widget-content ui-corner-left" );
77
78 input.data( "autocomplete" )._renderItem = function( ul, item ) {
79 return $( "<li></li>" )
80 .data( "item.autocomplete", item )
81 .append( "<a>" + item.label + "</a>" )
82 .appendTo( ul );
83 };
84
85 this.button = $( "<button type='button'>&nbsp;</button>" )
86 .attr( "tabIndex", -1 )
87 .attr( "title", "Show All Items" )
88 .insertAfter( input )
89 .button({
90 icons: {
91 primary: "ui-icon-triangle-1-s"
92 },
93 text: false
94 })
95 .removeClass( "ui-corner-all" )
96 .addClass( "ui-corner-right ui-button-icon" )
97 .click(function() {
98 // close if already visible
99 if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
100 input.autocomplete( "close" );
101 return;
102 }
103
104 // work around a bug (likely same cause as #5265)
105 $( this ).blur();
106
107 // pass empty string as value to search for, displaying all results
108 input.autocomplete( "search", "" );
109 input.focus();
110 });
111 },
112
113 destroy: function() {
114 this.input.remove();
115 this.button.remove();
116 this.element.show();
117 $.Widget.prototype.destroy.call( this );
118 }
119 });
120 })( jQuery );
121
122 $(function() {
123 $( "#combobox" ).combobox();
124 $( "#toggle" ).click(function() {
125 $( "#combobox" ).toggle();
126 });
127 });
128 </script>
129 </head>
130 <body>
131
132 <div class="demo">
133
134 <div class="ui-widget">
135 <label>Your preferred programming language: </label>
136 <select id="combobox">
137 <option value="">Select one...</option>
138 <option value="ActionScript">ActionScript</option>
139 <option value="AppleScript">AppleScript</option>
140 <option value="Asp">Asp</option>
141 <option value="BASIC">BASIC</option>
142 <option value="C">C</option>
143 <option value="C++">C++</option>
144 <option value="Clojure">Clojure</option>
145 <option value="COBOL">COBOL</option>
146 <option value="ColdFusion">ColdFusion</option>
147 <option value="Erlang">Erlang</option>
148 <option value="Fortran">Fortran</option>
149 <option value="Groovy">Groovy</option>
150 <option value="Haskell">Haskell</option>
151 <option value="Java">Java</option>
152 <option value="JavaScript">JavaScript</option>
153 <option value="Lisp">Lisp</option>
154 <option value="Perl">Perl</option>
155 <option value="PHP">PHP</option>
156 <option value="Python">Python</option>
157 <option value="Ruby">Ruby</option>
158 <option value="Scala">Scala</option>
159 <option value="Scheme">Scheme</option>
160 </select>
161 </div>
162 <button id="toggle">Show underlying select</button>
163
164 </div><!-- End demo -->
165
166
167
168 <div class="demo-description">
169 <p>A custom widget built by composition of Autocomplete and Button. You can either type something into the field to get filtered suggestions based on your input, or use the button to get the full list of selections.</p>
170 <p>The input is read from an existing select-element for progressive enhancement, passed to Autocomplete with a customized source-option.</p>
171 </div><!-- End demo-description -->
172
173 </body>
174 </html>