forked from hailwood/jQuery-Tagit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
454 lines (398 loc) · 14.2 KB
/
index.php
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
<?php $color = isset($_GET['theme']) ? $_GET['theme'] : 'stylish-yellow'; ?>
<!doctype html>
<html>
<head>
<title>jQuery Tagit Demo Page (PHP)</title>
<link href="demo/css/jquery-ui-base-1.8.20.css" rel="stylesheet" type="text/css"/>
<link href="demo/css/demo.css" rel="stylesheet" type="text/css"/>
<link href="css/tagit-<?php echo $color; ?>.css" rel="stylesheet" type="text/css"/>
<script src="demo/js/jquery.1.7.2.min.js"></script>
<script src="demo/js/jquery-ui.1.8.20.min.js"></script>
<script src="js/tagit.js"></script>
<script>
$(function () {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$('#demo1').tagit({tagSource:availableTags, select:true, sortable:true});
$('#demo2').tagit({tagSource:availableTags});
$('#demo3').tagit({tagSource:availableTags, triggerKeys:['enter', 'comma', 'tab']});
$('#demo4').tagit({tagSource:availableTags, sortable:true, tagsChanged:function (a, b) {
$('#demo4Out').html(a + ' was ' + b);
} });
$('#demo5').tagit({maxLength:5, maxTags:5 });
$('#demo6').tagit({tagSource:availableTags, sortable:true});
$('#demo7').tagit({tagSource:availableTags, sortable:'handle'});
$('#demo1GetTags').click(function () {
showTags($('#demo1').tagit('tags'))
});
$('#demo2GetTags').click(function () {
showTags($('#demo2').tagit('tags'))
});
$('#demo2ResetTags').click(function () {
$('#demo2').tagit('reset')
});
$('#demo3GetTags').click(function () {
showTags($('#demo3').tagit('tags'))
});
$('#demo4GetTags').click(function () {
showTags($('#demo4').tagit('tags'))
});
$('#demo5GetTags').click(function () {
showTags($('#demo5').tagit('tags'))
});
$('#demo6GetTags').click(function () {
showTags($('#demo6').tagit('tags'))
});
$('#demo7GetTags').click(function () {
showTags($('#demo7').tagit('tags'))
});
function showTags(tags) {
console.log(tags);
var string = "Tags (label : value)\r\n";
string += "--------\r\n";
for (var i in tags)
string += tags[i].label + " : " + tags[i].value + "\r\n";
alert(string);
}
$('.browser').hover(
function () {
$(this).children('a').children('div').show('fast');
},
function () {
$(this).children('a').children('div').hide('fast');
});
});
</script>
</head>
<body>
<div id="wrap">
<h1>jQuery Tagit Demo Page</h1>
<div id="description" class="box"><a name="description"></a>
The jQuery Tagit plugin transforms an html unordered list into a unique tagging plugin.<br/>
Why unique? Because jQuery Tagit uses jQuery Ui's auto-complete plugin to supply suggestions to users
as they type.
</div>
<div class="box"><a href="#demos">Jump straight to the demos!</a></div>
<h2><a name="browsers">Browser Support</a></h2>
<div class="box">
<div class="browser">
<a id="chrome" href="http://www.google.com/chrome">
<div>Works in Google Chrome!</div>
</a>
</div>
<div class="browser">
<a id="firefox" href="http://www.mozilla.com">
<div>Works in Firefox!</div>
</a>
</div>
<div class="browser">
<a id="ie" href="http://www.microsoft.com/windows/internet-explorer">
<div>Works in IE7+!</div>
</a>
</div>
<div class="browser">
<a id="opera" href="http://www.opera.com">
<div>Works in Opera!</div>
</a>
</div>
<div class="browser" style="margin-right: 0">
<a id="safari" href="http://www.apple.com/safari">
<div>Works in Safari!</div>
</a>
</div>
<div style="clear: both;"></div>
</div>
<h2><a name="features">Features</a></h2>
<div class="box features">
<ul>
<li>Convenient way for users to enter a list of items</li>
<li>Fully integrated with jQuery ui auto complete</li>
<li>Automatically adds current input as tag if input loses focus</li>
<li>Easy to use public methods</li>
<li>Easy to theme e.g.(<a href="?theme=simple-green#demos">Simple Green</a> <a href="?theme=simple-blue#demos">Simple
Blue</a> <a href="?theme=simple-grey#demos">Simple Grey</a>)
</li>
<li>Customizable <em>accept</em> keys</li>
<li>Backspace on empty input deletes previous tag</li>
<li>Ability to provide <em>initial tags</em> on creation through options</li>
<li>Ability to provide <em>initial tags</em> on creation via list items</li>
<li>Option to toggle usage of a hidden select so the tags can be sent using a normal form!</li>
<li>Ability to re-arrange tags by drag and drop!</li>
</ul>
</div>
<h2><a name="code">The Minimum Code Required</a></h2>
<div class="box">
<div class="code">
<div class="wrap">
<<span class="blue">script</span>>
$(<span class="blue">function</span>(){
$(<span class="green">'#tags'</span>).tagit();
});
</<span class="blue">script</span>>
<<span class="blue">ul id=</span><span class="green">"tags"</span>></<span class="blue">ul</span>>
</div>
</div>
<div class="note">Seriously, Can you beat that?</div>
</div>
<h2><a name="options">Options</a></h2>
<div class="box">
<table class="options">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Note</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>tagSource</td>
<td>String, Array, Callback</td>
<td>[]</td>
<td class="left">This option maps directly to the <a href="http://jqueryui.com/demos/autocomplete/">jQuery
UI Autocomplete source option</a></td>
</tr>
<tr class="even">
<td>triggerKeys</td>
<td>Array</td>
<td>['enter', 'space', 'comma', 'tab']</td>
<td class="left">An array containing all or any of the default options.<br/>
These are the keys that will trigger a tag completion
</td>
</tr>
<tr class="odd">
<td>initialTags</td>
<td>Array</td>
<td>[]</td>
<td class="left">An array containing tags to pre-populate the field with</td>
</tr>
<tr class="even">
<td>minLength</td>
<td>Int</td>
<td>1</td>
<td class="left">The minimum length before a triggerKey will create a tag</td>
</tr>
<tr class="odd">
<td>select</td>
<td>Bool</td>
<td>false</td>
<td class="left">Maintain a hidden select in place for form submissions<br/>
To name the select simply give your UL a name attribute!
<hr/>
Don't forget
to include [ and ] if your language (e.g. PHP) requires them!
</td>
</tr>
<tr class="even">
<td>tagsChanged</td>
<td>Callback</td>
<td>function(tagValue, action, element)</td>
<td class="left">Callback on changed tags:<br>
<b>tagValue:</b> string<br>
<b>action:</b> string - either 'added', 'popped', 'moved' or 'reset'<br>
<b>element:</b> object - reference to the added LI element
</td>
</tr>
<tr class="odd">
<td>caseSensitive</td>
<td>Bool</td>
<td>false</td>
<td class="left">
The check for existing tags is case sensitive. If false the words "Foo" and "foo" considered the same
</td>
</tr>
<tr class="even">
<td>highlightOnExistColor</td>
<td>String</td>
<td>#0F0</td>
<td class="left">
If the user tries to add a tag, that already exists, the existing tag will run a highlight effect using
the defined background color.
If null, the highlight effect is turned off.
</td>
</tr>
<tr class="odd">
<td>maxLength</td>
<td>Int</td>
<td><em>unlimited</em></td>
<td class="left">
The maximum allowable length of a tag.<br/>
If omitted, tags of unlimited length are allowed.
</td>
</tr>
<tr class="even">
<td>maxTags</td>
<td>Int</td>
<td><em>unlimited</em></td>
<td class="left">
The maximum number of tags that the user can enter.<br/>
If omitted, an unlimited number of tags are allowed.
</td>
</tr>
<tr class="odd">
<td>sortable</td>
<td>Bool, String</td>
<td><em>false</em></td>
<td class="left">
Allows the user to re-order the tags using drag and drop.<br/>
If true the whole tag is draggable, if 'handle' a handle is <br/>
rendered and the tag is only draggable using the handle.
</td>
</tr>
</tbody>
</table>
</div>
<h2><a name="methods">Methods</a></h2>
<div class="box">
<table class="methods">
<thead>
<tr>
<th>Name</th>
<th>Return</th>
<th>Note</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>.tagit("destroy")</td>
<td>null</td>
<td class="left">Returns the ul to its original state</td>
</tr>
<tr class="even">
<td>.tagit("tags")</td>
<td>Array</td>
<td class="left">Returns an array of objects about all the tags.</td>
</tr>
<tr class="odd">
<td>.tagit("reset")</td>
<td>null</td>
<td class="left">Resets the tags list to the initial value</td>
</tr>
<tr class="even">
<td>.tagit("fill", [{label: 'tag', value: 12}, {label: 'stuff', value: 13}])</td>
<td>null</td>
<td class="left">Empties the tags and fills the plugin with the provided tags.</td>
</tr>
<tr class="odd">
<td>.tagit("add", {label: 'tag', value: 12})</td>
<td>Bool</td>
<td class="left">Adds a tag to the plugin.</td>
</tr>
</tbody>
</table>
</div>
<h2><a name="demos">Demos</a></h2>
<div class="box"><strong>Theme: </strong>
<a href="?theme=simple-green#demos">Simple Green</a> |
<a href="?theme=simple-blue#demos">Simple Blue</a> |
<a href="?theme=simple-grey#demos">Simple Grey</a> |
<a href="?theme=stylish-yellow#demos">Stylish Yellow</a> |
<a href="?theme=dark-grey#demos">Dark Grey</a> |
<a href="?theme=awesome-orange#demos">Awesome Orange</a> |
<a href="?theme=awesome-blue#demos">Awesome Bluey</a> |
</div>
<div class="box">
<h3>Hidden Select</h3>
<div class="box">
<div class="note">Normally the select is hidden!</div>
<ul id="demo1" name="nameOfSelect"></ul>
<div class="buttons">
<button id="demo1GetTags" value="Get Tags">Get Tags</button>
</div>
</div>
<h3>Initial Tags</h3>
<div class="box">
<ul id="demo2" name="demo2">
<li>here</li>
<li>are</li>
<li>some</li>
<li>initial</li>
<li>tags</li>
</ul>
<div class="buttons">
<button id="demo2GetTags" value="Get Tags">Get Tags</button>
<button id="demo2ResetTags" value="Reset Tags">Reset Tags</button>
</div>
</div>
<h3>Allowing Spaces</h3>
<div class="box">
<ul id="demo3"></ul>
<div class="buttons">
<button id="demo3GetTags" value="Get Tags">Get Tags</button>
</div>
</div>
<h3>Callback</h3>
<div class="box">
<ul id="demo4"></ul>
<div class="buttons">
<button id="demo4GetTags" value="Get Tags">Get Tags</button>
</div>
<p>Action:
<div id="demo4Out">none</div>
<p>
</div>
<h3>Limits</h3>
<div class="box">
<ul id="demo5"></ul>
<div class="buttons">
<button id="demo5GetTags" value="Get Tags">Get Tags</button>
</div>
<p>Maximum of 5 tags and 5 characters per tag.</p>
</div>
<h3>Sortable : true</h3>
<div class="box">
<ul id="demo6" name="demo6">
<li>here</li>
<li>are</li>
<li>some</li>
<li>initial</li>
<li>tags</li>
</ul>
<div class="buttons">
<button id="demo6GetTags" value="Get Tags">Get Tags</button>
</div>
</div>
<h3>Sortable : handle</h3>
<div class="box">
<ul id="demo7" name="demo7">
<li>here</li>
<li>are</li>
<li>some</li>
<li>initial</li>
<li>tags</li>
</ul>
<div class="buttons">
<button id="demo7GetTags" value="Get Tags">Get Tags</button>
</div>
</div>
</div>
<h2></h2>
<div class="box">
© Content and Design Matthew Hailwood <?php echo Date('Y'); ?><br/>
</div>
</div>
</body>
</html>