source: main/trunk/greenstone3/web/interfaces/oran/js/jquery-ui-1.8rc1/demos/autocomplete/combobox.html@ 24245

Last change on this file since 24245 was 24245, checked in by sjb48, 13 years ago

Oran code for supporting format changes to document.

  • Property svn:executable set to *
File size: 4.0 KB
Line 
1<!doctype html>
2<html>
3<head>
4 <title>jQuery UI Autocomplete Combobox Demo</title>
5 <link type="text/css" href="../../themes/base/ui.all.css" rel="stylesheet" />
6 <script type="text/javascript" src="../../jquery-1.4.1.js"></script>
7 <script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
8 <script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
9 <script type="text/javascript" src="../../ui/jquery.ui.button.js"></script>
10 <script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
11 <script type="text/javascript" src="../../ui/jquery.ui.autocomplete.js"></script>
12 <link type="text/css" href="../demos.css" rel="stylesheet" />
13 <script type="text/javascript">
14 (function($) {
15 $.widget("ui.combobox", {
16 _create: function() {
17 var self = this;
18 var select = this.element.hide();
19 var input = $("<input>")
20 .insertAfter(select)
21 .autocomplete({
22 source: function(request, response) {
23 var matcher = new RegExp(request.term, "i");
24 response(select.children("option").map(function() {
25 var text = $(this).text();
26 if (!request.term || matcher.test(text))
27 return {
28 id: $(this).val(),
29 label: text.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + request.term.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
30 value: text
31 };
32 }));
33 },
34 delay: 0,
35 select: function(e, ui) {
36 if (!ui.item) {
37 // remove invalid value, as it didn't match anything
38 $(this).val("");
39 return false;
40 }
41 $(this).focus();
42 select.val(ui.item.id);
43 self._trigger("selected", null, {
44 item: select.find("[value='" + ui.item.id + "']")
45 });
46
47 },
48 minLength: 0
49 })
50 .removeClass("ui-corner-all")
51 .addClass("ui-corner-left");
52 $("<button>&nbsp;</button>")
53 .insertAfter(input)
54 .button({
55 icons: {
56 primary: "ui-icon-triangle-1-s"
57 },
58 text: false
59 }).removeClass("ui-corner-all")
60 .addClass("ui-corner-right ui-button-icon")
61 .position({
62 my: "left center",
63 at: "right center",
64 of: input,
65 offset: "-1 0"
66 }).css("top", "")
67 .click(function() {
68 // close if already visible
69 if (input.autocomplete("widget").is(":visible")) {
70 input.autocomplete("close");
71 return;
72 }
73 // pass empty string as value to search for, displaying all results
74 input.autocomplete("search", "");
75 input.focus();
76 });
77 }
78 });
79
80 })(jQuery);
81
82 $(function() {
83 $("select").combobox();
84 });
85 </script>
86 <style>
87 /* TODO shouldn't be necessary */
88 .ui-button-icon-only .ui-button-text { padding: 0; }
89 </style>
90</head>
91<body>
92
93<div class="demo">
94
95<div class="ui-widget">
96 <label>Your preferred programming language: </label>
97 <select>
98 <option value="a">asp</option>
99 <option value="c">c</option>
100 <option value="cpp">c++</option>
101 <option value="cf">coldfusion</option>
102 <option value="g">groovy</option>
103 <option value="h">haskell</option>
104 <option value="j">java</option>
105 <option value="js">javascript</option>
106 <option value="p1">pearl</option>
107 <option value="p2">php</option>
108 <option value="p3">python</option>
109 <option value="r">ruby</option>
110 <option value="s">scala</option>
111 </select>
112</div>
113
114</div><!-- End demo -->
115
116<div class="demo-description">
117<p>
118A 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.
119</p>
120<p>
121The input is read from an existing select-element for progressive enhancement, passed to Autocomplete with a customized source-option.
122</p>
123</div><!-- End demo-description -->
124
125</body>
126</html>
Note: See TracBrowser for help on using the repository browser.