forked from rmm5t/jquery-flexselect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
271 lines (245 loc) · 12.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="microid" content="mailto+http:sha1:90c9a60ac311baa89f1b48b4a805b0f310361b9d" />
<title>flexselect: a jQuery plugin</title>
<link rel="stylesheet" href="flexselect.css" type="text/css" media="screen" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script src="liquidmetal.js" type="text/javascript"></script>
<script src="jquery.flexselect.js" type="text/javascript"></script>
<script type="text/javascript">
$.fn.example = function(select, type) {
var div = $("<div></div>").addClass(type)
.append(select.clone().attr({ id: select.attr("id") + "_" + type, "class": type }));
this.append(div);
};
$(document).ready(function() {
$("a.download").attr("href", "http://cloud.github.com/downloads/rmm5t/jquery-flexselect/jquery.flexselect-0.2.2.zip");
var president = $("select#president");
$("#example1").example(president, "dull");
$("#example1").example(president, "flexselect");
var animal = $("select#animal");
$("#example2").example(animal, "dull");
$("#example2").example(animal, "flexselect");
$("select.flexselect").flexselect();
$("input#president_flexselect_flexselect").val("")
$("select").attr("tabindex", -1);
$("input.flexselect").each(function(index) { $(this).attr("tabindex", index+1) });
});
</script>
<style>
* { margin: 0; padding: 0; }
body { font-family: Helvetica,Arial,sans-serif; color: #333; background-color: #ccc; font-size: 16px; line-height: 24px; }
h1 { margin: 0; font-size: 60px; line-height: 100px; text-align: center; }
h2 { margin: -30px 0 40px 125px; font-size: 20px; line-height: 20px; text-align: center; color: #999; }
h3 { margin: 24px 0 6px 0; font-size: 18px; line-height: 18px; border-bottom: 1px solid #ccc; }
h4 { margin: 24px 0 0 0; font-size: 16px; line-height: 24px; }
h1 img { vertical-align: middle; }
p { margin: 0 0 24px 0; }
p.example { margin: 0 0 12px 0; }
p.how, p.last { margin: 0; }
ul { margin: 0 24px 24px; }
li { line-height: 24px; }
pre { background-color: #333; color: #fff; margin: 12px 0; font-size: 12px; padding: 0 6px; }
pre em { font-style: normal; background-color: #554; }
pre, tt { font-family: monaco,"courier new",mono; }
abbr { border-bottom: 1px dotted #333; }
tt { font-size: 14px; }
a { color: #06e; padding: 1px; }
em { font-style: normal; background-color: #feb }
a:hover { background-color: #06c; color: #fff; text-decoration: none; }
#content { margin:0 auto; padding: 24px; width:700px; background-color:#fff; border: 1px solid #999; border-width: 0 1px 1px 1px; }
#footer { margin:0 auto 24px; padding: 12px; width:700px; line-height: 24px; }
.help { font-size: 14px; color: #888; }
select, input { font-size: 16px; }
.example div.dull, .example div.flexselect { width: 350px; }
.example div.dull { float: left; }
.example div.flexselect { float: right; }
</style>
</head>
<body>
<div id="content">
<h1>flexselect</h1>
<h2>a jQuery plugin</h2>
<h3>What?</h3>
<p>
Flexselect is a jQuery plugin that turns select boxes into flex-matching incremental-finding controls. Think of it as Quicksilver squished into a select box. <a class="download">Download</a>, view the examples, and enjoy.
</p>
<p>
Flexselect takes the select box, and creates a hidden input element to track the associated value and creates a text input for the selection. It uses the <a href="http://github.com/rmm5t/liquidmetal/">LiquidMetal</a> scoring algorithm to narrow the selection.
</p>
<h3>Examples</h3>
<p>
On the <em>left is a traditional select box</em>. On the <em>right is a flexselect control</em>. Just start typing to narrow the selection.
</p>
<div id="example1" class="example">
<h4>Pick a U.S. President <small>(not pre-selected)</small></h4>
</div><div style="clear:both;"></div>
<div id="example2" class="example">
<h4>Pick an animal <small>(pre-selected)</small></h4>
</div><div style="clear:both;"></div>
<p></p>
<p><i>TODO: Add more examples for common option overrides</i></p>
<h3>How?</h3>
<p class="how">
First, load the default styles, <a href="http://jquery.com/">jQuery</a>, the <a href="http://github.com/rmm5t/liquidmetal/">LiquidMetal</a> scoring algorithm, and the plugin.
</p>
<pre>
<link rel="stylesheet" href="flexselect.css" type="text/css" media="screen" />
<script src="jquery.min.js" type="text/javascript"></script>
<script src="liquidmetal.js" type="text/javascript"></script>
<script src="jquery.flexselect.js" type="text/javascript"></script></pre>
<p class="how">
It's important that the styles come before the javascript. Now, let's convert your select boxes into some flexselect goodness on DOM ready:
</p>
<pre>
jQuery(document).ready(function() {
$("select.flexselect").flexselect();
});</pre>
<p class="how">
This will turn all <tt>select</tt> elements with a class of <tt>flexselect</tt> into a flex matching masterpiece:
</p>
<pre>
<select class="<em>flexselect</em>">
<option value="1">George Washington</option>
<option value="2">John Adams</option>
<option value="3">Thomas Jefferson</option>
...
</select></pre>
<p>
Flexselect also supports some options to override the default behavior:
</p>
<p class="how">
<strong>Experimental Ad Hoc Entry:</strong> (The technique for handling this might change) It's possible to allow ad hoc entries into a flexselect input field that don't match the values in the underlying select box. Suppose you had a select box like this:
</p>
<pre>
<select name="email" class="flexselect"> ... </select></pre>
<p class="how">
If you enable flexselect with custom options that look like this:
</p>
<pre>
$("select.flexselect").flexselect({
allowMismatch: true,
inputNameTransform: function(name) { return "new_" + name; }
});</pre>
<p>
The input text field that replaces the select box will not only allow you to match custom values that weren't in the select box, but it will have a name attribute of <code>new_email</code> assigned to it. You can customize the <code>inputNameTransform</code> function however you like. The argument value passed to it is the original name from the select box.
</p>
<p>
When the form is submitted (with allowMismatch set to true), the original <code>email</code> param will be an empty string and the <code>new_email</code> param will be the value of the text in the input box.
</p>
<p>
<i>TODO: Add a detailed list of all the options</i>
</p>
<h3>Where?</h3>
<p><a class="download">Download the "stable" release</a>.</p>
<p>
The code is hosted on
GitHub: <a href="http://github.com/rmm5t/jquery-flexselect">http://github.com/rmm5t/jquery-flexselect</a>.
Go on, live on the edge.
</p>
<h3>Who?</h3>
<p>
Flexselect was built by <a href="http://ryan.mcgeary.org">Ryan McGeary</a>
(<a href="http://twitter.com/rmm5t">@rmm5t</a>) and was inspired by <a href="https://github.com/dcparker/jquery_plugins/tree/master/quickselect">jQuery.quickselect</a>, <a href="http://warpspire.com/tipsresources/interface-scripting/select-autocompleter/">MooTools Select Autocompleter</a>, <a href="http://orderedlist.com/articles/live-search-with-quicksilver-style-for-jquery">Live Search with QuickSilver</a>, and <a href="http://ejohn.org/blog/jquery-livesearch/">jQuery LiveSearch</a>.
</p>
</div>
<div id="footer">
<div style="float:right;">
<a href="http://www.opensource.org/licenses/mit-license.php">MIT
License</a>
</div>
Copyright © 2009 <a href="http://ryan.mcgeary.org">Ryan McGeary</a>
(<a href="http://twitter.com/rmm5t">@rmm5t</a>)
</div>
<a href="http://github.com/rmm5t/jquery-flexselect"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png" alt="Fork me on GitHub" /></a>
<div style="display:none;">
<select id="president" name="president">
<option value="1">George Washington</option>
<option value="2">John Adams</option>
<option value="3">Thomas Jefferson</option>
<option value="4">James Madison</option>
<option value="5">James Monroe</option>
<option value="6">John Quincy Adams</option>
<option value="7">Andrew Jackson</option>
<option value="8">Martin Van Buren</option>
<option value="9">William Henry Harrison</option>
<option value="10">John Tyler</option>
<option value="11">James Knox Polk</option>
<option value="12">Zachary Taylor</option>
<option value="13">Millard Fillmore</option>
<option value="14">Franklin Pierce</option>
<option value="15">James Buchanan</option>
<option value="16">Abraham Lincoln</option>
<option value="17">Andrew Johnson</option>
<option value="18">Ulysses S. Grant</option>
<option value="19">Rutherford B. Hayes</option>
<option value="20">James Garfield</option>
<option value="21">Chester Arthur</option>
<option value="22">Grover Cleveland</option>
<option value="23">Benjamin Harrison</option>
<option value="24">Grover Cleveland</option>
<option value="25">William McKinley</option>
<option value="26">Theodore Roosevelt</option>
<option value="27">William Howard Taft</option>
<option value="28">Woodrow Wilson</option>
<option value="29">Warren Harding</option>
<option value="30">Calvin Coolidge</option>
<option value="31">Herbert Hoover</option>
<option value="32">Franklin D. Roosevelt</option>
<option value="33">Harry S Truman</option>
<option value="34">Dwight D. Eisenhower</option>
<option value="35">John F. Kennedy</option>
<option value="36">Lyndon Johnson</option>
<option value="37">Richard Nixon</option>
<option value="38">Gerald Ford</option>
<option value="39">James Carter</option>
<option value="40">Ronald Reagan</option>
<option value="41">George H. W. Bush</option>
<option value="42">William J. Clinton</option>
<option value="43">George W. Bush</option>
<option value="44">Barack H. Obama</option>
</select>
<select id="animal" name="animal">
<option value="a">angelfish</option>
<option value="b">buffalo</option>
<option value="c" selected="selected">canary</option>
<option value="d">dinosaur</option>
<option value="e">eel</option>
<option value="f">flamingo</option>
<option value="g">goldfish</option>
<option value="h">hippo</option>
<option value="i">iguana</option>
<option value="j">jellyfish</option>
<option value="k">kangaroo</option>
<option value="l">llama</option>
<option value="m">moose</option>
<option value="n">narwhal</option>
<option value="o">ostrich</option>
<option value="p">pelican</option>
<option value="q">quail</option>
<option value="r">raccoon</option>
<option value="s">snail</option>
<option value="t">toucan</option>
<option value="u">unicorn</option>
<option value="v">vulture</option>
<option value="w">wildebeest</option>
<option value="f">fox</option>
<option value="x">xenopus</option>
<option value="y">yak</option>
<option value="z">zebra</option>
</select>
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-604149-6");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>