-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdemo.js
831 lines (773 loc) · 25.4 KB
/
demo.js
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
$(function() {
var widgetNames = ["slider", "progressbar", "menubar", "button", "dialog", "checkbox",
"accordion", "tree", "carousel", "tabs", "tooltip", "autocomplete", "datepicker"];
var loadedWidgets = {};
var coreWidgets = ["slider", "button", "checkbox", "tooltip", "tabs", "datepicker", "autocomplete", "accordion", "menubar"];
// update last modifed information
var months= ["January","February","March","April","May","June","July","August","September","October","November","December"];
var lastMod = new Date(document.lastModified);
$("#timeStamp").html(lastMod.getDate() + " " + months[lastMod.getMonth()] + " " + lastMod.getFullYear());
$(document.body).append($("<span id='statusUpdater' aria-live='polite' class='ui-helper-hidden-accessible'></span>"));
// Allow tab to be selected through deep linking
var selectedTabId = 0
var query = document.location.search;
var fragmentId = document.location.hash;
if (query) {
var match = query.match(/(\\?|&)tabId=([^&]+)(\\&|$)/i);
if (match && match[2]) {
if (!isNaN(match[2]))
selectedTabId = match[2];
else
selectedTabId = jQuery.inArray(match[2], widgetNames);
if (selectedTabId == -1)
selectedTabId = 0;
}
}
else if (fragmentId) {
var match = fragmentId.match(/^#goto_(.+)$/i);
if (match && match[1]) {
if (!isNaN(match[1]))
selectedTabId = match[1];
else
selectedTabId = jQuery.inArray(match[1], widgetNames);
if (selectedTabId == -1)
selectedTabId = 0;
}
}
//experimental: GLobal focusin handler that assigns focus classnames
$(document).focusin(function(event){
$(event.target).addClass("ui-global-focus");
})
.focusout(function(event){
$(event.target).removeClass("ui-global-focus");
});
//Load main tabs
$("#demoTabs").tabs({labelledBy: "tabsLbl", selected : selectedTabId});
//Get this fixed in the actual tabs widget if it hasn't already:
$("#demoTabs > div[role='tabpanel']").eq(selectedTabId).attr("aria-hidden", "false");
//show event doesn't fire for selected tab on creation, so manually trigger the handler
createTabPanelContents($("#demoTabs > .ui-tabs-panel").eq(selectedTabId));
setTimeout(function() {
//createSliders($("#slider"));
}, 500);
$('#demoTabs').bind('tabsactivate', function(event, ui) {
createTabPanelContents($(ui.newPanel));
if ($(ui.oldPanel).attr("id") == "tooltip")
$(".toggleTooltips :ui-tooltip").tooltip("close");
});
$('#demoTabs > .ui-tabs-panel').each(function() {
if (jQuery.inArray(this.id, coreWidgets) == -1)
return;
var widgetControls = $(this).find(".widgetControls").andSelf().last();
widgetControls
.prepend($("<button class='enabled'>Disable "+ this.id+"</button>").button().click(
function(){
var btn = $(this);
if (btn.hasClass("enabled")) {
toggleEnabledInPanel(btn.closest(".ui-tabs-panel"), false);
$("#statusUpdater").text(btn.text().replace(/disable/i, "") + " disabled");
btn.toggleClass("enabled").button("option", "label", btn.text().replace(/Disable/i, "Enable"));
}
else {
toggleEnabledInPanel(btn.closest(".ui-tabs-panel"), true);
$("#statusUpdater").text(btn.text().replace(/enable/i, "") + " enabled");
btn.toggleClass("enabled").button("option", "label", btn.text().replace(/Enable/i, "Disable"));
}
}))
.prepend($("<button class='created'>Destroy "+ this.id+"</button>").button().click(
function(){
var btn = $(this);
if (btn.hasClass("created")) {
destroyInPanel(btn.closest(".ui-tabs-panel"));
$("#statusUpdater").text(btn.text().replace(/destroy/i, "") + " destroyed");
btn.toggleClass("created").button("option", "label", btn.text().replace(/Destroy/i, "Create"));
}
else {
createTabPanelContents(btn.closest(".ui-tabs-panel"), true);
$("#statusUpdater").text(btn.text().replace(/create/i, "") + " created");
btn.toggleClass("created").button("option", "label", btn.text().replace(/Create/i, "Destroy"));
}
}));
});
function createTabPanelContents(panel, skipLoadedCheck) {
if (!panel || panel.length == 0)
return;
var widgetId = $(panel).attr("id");
document.location.hash = "#goto_" + widgetId;
if (!widgetId || (loadedWidgets[widgetId] & !skipLoadedCheck) || $.inArray(widgetId, widgetNames) == -1)
return;
switch(widgetId) {
case "accordion":
autoCreateInPanel(panel);
var chk = $("<input id='toggleCollapsible' class='destroyMe' type='checkbox'/>");
chk.click(function(e){
console.log(event.target);
$("#sampleAccordion").accordion("option","collapsible", event.target.checked);
});
chk.appendTo(panel.find(".widgetControls:eq(0)")).after("<label class='destroyMe' for='toggleCollapsible'>Allow all accordion sections to be collapsed at the same time</label>");
break;
case "slider":
createSliders(panel);
break;
case "progressbar":
createProgressBars(panel);
break;
case "button":
$("#repeat").addClass("hiddenFieldset")
createButtons(panel);
break;
case "menubar":
$("#sampleMenubar").menubar({
menuIcon : true,
select : function(event, ui){
$("#menubarStatusUpdater").text("'" + ui.item.text() + "' menubar item selected");
}});
//VERY experimental: Moving focus back when accessing menu by shortcut
/*
$(document).bind("keyup", function(event){
if (event.keyCode == 77 & event.shiftKey && event.altKey) {
if (event.target.nodeType != 1 || !$(event.target).is(":focusable"))
$("#sampleMenubar").data("returnFocusTo", null)
else
$("#sampleMenubar").data("returnFocusTo", event.target)
var tabId = $.inArray("menubar", widgetNames);
if (tabId != -1) {
$("#demoTabs").tabs("select", tabId);
$("#sampleMenubar").find("a[tabindex=0]").get(0).focus();
}
}
})*/
$("#sampleMenubar").after($("<p aria-live='polite' id='menubarStatusUpdater'> </p>"));
break;
case "dialog":
createDialog(panel);
break;
case "tree":
$('#sampleTree').jstree({plugins : ["themes", "html_data", "ui", "hotkeys"]});
break;
case "carousel":
$('#mycarousel1').jcarousel({
animation: 500,
itemSelectedCallback : itemSelectedCallback
});
break;
case "tooltip":
autoCreateInPanel(panel);
$("<input type='checkbox' id='tooltipToggler'/>").appendTo("#tooltipButtonAnchor")
.after("<label for='tooltipToggler'>Toggle tooltips for static elements</label>");
$("#tooltipToggler").click(function() {
if ($(this).is(":checked")) {
$(".toggleTooltips :ui-tooltip").tooltip("open");
}
else {
$(".toggleTooltips :ui-tooltip").tooltip("close");
}
});
break;
case "tabs":
$("#sampleTabs").tabs({labelledBy: "tabsDemoLbl"});
$("#sampleTabs > div[role='tabpanel']").eq(0).attr("aria-hidden", "false");
break;
case "autocomplete":
createAutoComplete(panel);
break;
case "datepicker":
$( "#datepicker1" ).datepicker( {
select: function( event, ui ) {
$( "#datepicker1" ).val( ui.date ).focus( 1 );
}
});
$( "#datepicker2" ).datepicker( {
select: function( event, ui ) {
$( "#dp2-output" ).text( "selected date: " + ui.date );
}
});
break;
default: //No special logic required, simply call component's method on demo objects in tab poanel
autoCreateInPanel(panel);
}
loadedWidgets[widgetId] = true;
}
function autoCreateInPanel(panel) {
var widgetId = panel.attr("id");
var elements = panel.find(".demoWidget");
if (typeof elements[widgetId] == "function")
elements[widgetId]();
}
function destroyInPanel(panel) {
if (!panel || panel.length === 0)
return;
var widgetId = panel.attr("id");
if (!widgetId || $.inArray(widgetId, coreWidgets) == -1)
return;
switch (widgetId) {
case "accordion":
autoDestroyInPanel(panel);
panel.find(".destroyMe").remove();
break;
case "slider":
autoDestroyInPanel(panel);
destroySliders(panel);
break;
case "menubar":
autoDestroyInPanel(panel);
$("#menubarStatusUpdater").remove();
break;
case "button":
$("#toolbar").find(":ui-button").unbind("click");
autoDestroyInPanel(panel);
$("#buttonStatusUpdater").remove();
$("#repeat").buttonset("destroy");
$("#repeat").removeClass("hiddenFieldset");
$("#toolbar").removeClass("ui-widget-header").removeClass("ui-corner-all");
break;
case "autocomplete":
autoDestroyInPanel(panel);
$( "#tags-2" ).unbind();
break;
case "tooltip":
$("#tooltipToggler").remove();
autoDestroyInPanel(panel);
break;
default:
autoDestroyInPanel(panel);
break;
}
}
function autoDestroyInPanel(panel) {
var widgetId = panel.attr("id");
var elements = panel.find(".demoWidget");
if (typeof elements[widgetId] == "function")
elements[widgetId]("destroy");
}
function toggleEnabledInPanel(panel, enable) {
var widgetId = panel.attr("id");
switch (widgetId) {
case "button":
autoToggleEnabled(panel, enable);
$("#repeat :radio").button(enable ? "enable" : "disable");
break;
case "tabs":
$("#sampleTabs").tabs(enable ? "enable" : "disable", 1);
break;
case "autocomplete":
if (enable)
$(":ui-autocomplete").removeAttr("disabled");
else
$(":ui-autocomplete").attr("disabled", "disabled");
break;
default:
autoToggleEnabled(panel, enable);
break;
}
}
function autoToggleEnabled(panel, enable) {
var elements = panel.find(".demoWidget");
var widgetId = panel.attr("id");
if (typeof elements[widgetId] == "function")
elements[widgetId](enable ? "enable" : "disable");
}
//SLIDER
function createSliders(panel) {
//single slider
$(panel).find(".fallback").hide();
$("#singleSlider1").slider({unittext : "MB",
label : "price",
unittext: "$",
slide: function(event, ui) {
updateSliderLabels(ui, ["#slider1Val"]);
},
change : function(event, ui) {
updateSliderLabels(ui, ["#slider1Val"]);
}
});
setTimeout( function() {
$(panel).find(".sliderValue").show();
updateSliderLabels({value : $("#singleSlider1").slider("value"), handle : $("#singleSlider1").find(".ui-slider-handle").eq(0)}, ["#slider1Val"]);
updateSliderLabels({value : $("#singleSlider1").slider("value"), handle : $("#singleSlider1").find(".ui-slider-handle").eq(0)}, ["#slider1Val"]);
}, 100);
// range slider
var rangeSlider = $("#rangeSlider1")
.slider({
range: true,
min: 0,
max: 500,
values: [75, 300],
unittext: "$",
label: "price range",
slide: function(event, ui) {
updateSliderLabels(ui, ["#slider2ValMin", "#slider2ValMax"]);
},
change : function(event, ui) {
updateSliderLabels(ui, ["#slider2ValMin", "#slider2ValMax"]);
}
});
setTimeout(function() {
var sliderValues = rangeSlider.slider("values");
updateSliderLabels({value : sliderValues[0], values : sliderValues, handle : rangeSlider.find(".ui-slider-handle").eq(0)}, ["#slider2ValMin", "#slider2ValMax"]);
updateSliderLabels({value : sliderValues[1], values : sliderValues, handle : rangeSlider.find(".ui-slider-handle").eq(1)}, ["#slider2ValMin", "#slider2ValMax"]);
// need to do this twice for some reason, va;ue is not properly positioned otherwise
updateSliderLabels({value : sliderValues[0], values : sliderValues, handle : rangeSlider.find(".ui-slider-handle").eq(0)}, ["#slider2ValMin", "#slider2ValMax"]);
updateSliderLabels({value : sliderValues[1], values : sliderValues, handle : rangeSlider.find(".ui-slider-handle").eq(1)}, ["#slider2ValMin", "#slider2ValMax"]);
}, 100);
}
function updateSliderLabels(ui, valueLabels) {
if (!ui.values)
ui.values = [ui.value];
// need to be able to determine which of the handles actually changes
var index = $.inArray(ui.value, ui.values);
var myAlign = index == 0 ? "right" : "left";
var atAlign = index == 0 ? "left" : "right";
$(valueLabels[index])
.position({
my: myAlign + " bottom",
at : atAlign + " top",
of: ui.handle
})
.text("$" + ui.value);
return;
}
function destroySliders(panel) {
panel.find(".fallback").show();
panel.find("demoWidget").slider("destroy");
panel.find(".sliderValue").hide();
}
//POGRESSBAR
function createProgressBars(panel) {
$(panel).find('#progressTrigger').button()
.click(function() {
$("#progressMsg").remove();
var progressBar = $("#sampleProgressBar")
.progressbar({
value: 0,
labelledBy: "progressMsg"
});
var progressDialog = $("#progressDialog")
.append("<p id='progressMsg' aria-live='true'>Your file is being downloaded...</p>")
.dialog({autoOpen : true,
modal : true,
title : "progress",
resizable : false,
draggable : false,
dialogClass : "noCloseBtn",
width : 500,
beforeClose : function() {
if ($("#sampleProgressBar").progressbar('value') != 100)
return false;}
})
var progressUpdater;
setTimeout(function() {
$("#sampleProgressBar").progressbar('value', 0);
progressUpdater = setInterval(function() {
if ($("#sampleProgressBar").progressbar('value') == 100) {
clearInterval(progressUpdater);
$("#progressDialog").dialog("close");
$('#progressTrigger').focus();
}
$("#sampleProgressBar").progressbar('value', $("#sampleProgressBar").progressbar('value') + 2);
}, 250);
}, 100);
});
}
// BUTTON
function createButtons(panel) {
$('#beginning').button({
text: false,
icons: {
primary: 'ui-icon-seek-start'
}
});
$('#rewind').button({
text: false,
icons: {
primary: 'ui-icon-seek-prev'
}
});
$('#play').button({
text: false,
icons: {
primary: 'ui-icon-play'
}
})
$('#stop').button({
text: false,
icons: {
primary: 'ui-icon-stop'
}
})
.click(function() {
$('#play').button('option', {
label: 'play',
icons: {
primary: 'ui-icon-play'
}
});
});
$('#forward').button({
text: false,
icons: {
primary: 'ui-icon-seek-next'
}
});
$('#end').button({
text: false,
icons: {
primary: 'ui-icon-seek-end'
}
});
$("#shuffle").button();
$("#repeat").buttonset();
$("#toolbar").after($("<p aria-live='polite' id='buttonStatusUpdater'> </p>"));
$("#toolbar").find(":ui-button").click(function(e) {
var msg = "'" + $(this).button("option", "label") + "' was activated";
$("#buttonStatusUpdater").text(msg)
if (this.id == "play") {
var options;
if ($(this).text() == 'play') {
options = {
label: 'pause',
icons: {
primary: 'ui-icon-pause'
}
};
} else {
options = {
label: 'play',
icons: {
primary: 'ui-icon-play'
}
};
}
$(this).button('option', options);
}
});
}
// DIALOG;
function createDialog(panel) {
$("#sampleDialog").dialog({
draggable : true,
resizable : true,
minHeight: 350,
minWidth: 270,
close : function(e){
$('#dialogTrigger').focus()
}
,autoOpen : false,
describedBy : "dialogDescription",
modal : true,
buttons: { "Ok": function() { $(this).dialog("close"); }}});
$('#dialogTrigger').button()
.click(function() {
$("#sampleDialog").dialog("open")
.find(":input").eq(0).focus();
return false;
});
}
// HELPER FUNCTIONS
// carousel
function itemSelectedCallback(carousel, item, index) {
item = $(item);
var src = item.find("img").attr("src");
var alt = item.find("img").attr("alt");
if (src) {
$("#viewerImg").attr("src", src);
}
if (alt) {
$("#viewerImg").attr("alt", alt);
}
}
// AUTOCOMPLETE
function split( val ) {
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
function createAutoComplete(panel) {
var availableTags = [
"Afghanistan",
"Albania",
"Algeria",
"American Samoa",
"Andorra",
"Angola",
"Anguilla",
"Antigua & Barbuda",
"Argentina",
"Armenia",
"Aruba",
"Australia",
"Austria",
"Azerbaijan",
"Bahamas",
"Bahrain",
"Bangladesh",
"Barbados",
"Belarus",
"Belgium",
"Belize",
"Benin",
"Bermuda",
"Bhutan",
"Bolivia",
"Bonaire",
"Bosnia & Herzegovina",
"Botswana",
"Brazil",
"British Indian Ocean Ter",
"Brunei",
"Bulgaria",
"Burkina Faso",
"Burundi",
"Cambodia",
"Cameroon",
"Canada",
"Canary Islands",
"Cape Verde",
"Cayman Islands",
"Central African Republic",
"Chad",
"Channel Islands",
"Chile",
"China",
"Christmas Island",
"Cocos Island",
"Colombia",
"Comoros",
"Congo",
"Cook Islands",
"Costa Rica",
"Cote D'Ivoire",
"Croatia",
"Cuba",
"Curacao",
"Cyprus",
"Czech Republic",
"Denmark",
"Djibouti",
"Dominica",
"Dominican Republic",
"East Timor",
"Ecuador",
"Egypt",
"El Salvador",
"Equatorial Guinea",
"Eritrea",
"Estonia",
"Ethiopia",
"Falkland Islands",
"Faroe Islands",
"Fiji",
"Finland",
"France",
"French Guiana",
"French Polynesia",
"French Southern Ter",
"Gabon",
"Gambia",
"Georgia",
"Germany",
"Ghana",
"Gibraltar",
"Great Britain",
"Greece",
"Greenland",
"Grenada",
"Guadeloupe",
"Guam",
"Guatemala",
"Guinea",
"Guyana",
"Haiti",
"Hawaii",
"Honduras",
"Hong Kong",
"Hungary",
"Iceland",
"India",
"Indonesia",
"Iran",
"Iraq",
"Ireland",
"Isle of Man",
"Israel",
"Italy",
"Jamaica",
"Japan",
"Jordan",
"Kazakhstan",
"Kenya",
"Kiribati",
"Korea North",
"Korea South",
"Kuwait",
"Kyrgyzstan",
"Laos",
"Latvia",
"Lebanon",
"Lesotho",
"Liberia",
"Libya",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Macau",
"Macedonia",
"Madagascar",
"Malaysia",
"Malawi",
"Maldives",
"Mali",
"Malta",
"Marshall Islands",
"Martinique",
"Mauritania",
"Mauritius",
"Mayotte",
"Mexico",
"Midway Islands",
"Moldova",
"Monaco",
"Mongolia",
"Montserrat",
"Morocco",
"Mozambique",
"Myanmar",
"Nambia",
"Nauru",
"Nepal",
"Netherland Antilles",
"Netherlands (Holland, Europe)",
"Nevis",
"New Caledonia",
"New Zealand",
"Nicaragua",
"Niger",
"Nigeria",
"Niue",
"Norfolk Island",
"Norway",
"Oman",
"Pakistan",
"Palau Island",
"Palestine",
"Panama",
"Papua New Guinea",
"Paraguay",
"Peru",
"Philippines",
"Pitcairn Island",
"Poland",
"Portugal",
"Puerto Rico",
"Qatar",
"Republic of Montenegro",
"Republic of Serbia",
"Reunion",
"Romania",
"Russia",
"Rwanda",
"St Barthelemy",
"St Eustatius",
"St Helena",
"St Kitts-Nevis",
"St Lucia",
"St Maarten",
"St Pierre & Miquelon",
"St Vincent & Grenadines",
"Saipan",
"Samoa",
"Samoa American",
"San Marino",
"Sao Tome & Principe",
"Saudi Arabia",
"Senegal",
"Seychelles",
"Sierra Leone",
"Singapore",
"Slovakia",
"Slovenia",
"Solomon Islands",
"Somalia",
"South Africa",
"Spain",
"Sri Lanka",
"Sudan",
"Suriname",
"Swaziland",
"Sweden",
"Switzerland",
"Syria",
"Tahiti",
"Taiwan",
"Tajikistan",
"Tanzania",
"Thailand",
"Togo",
"Tokelau",
"Tonga",
"Trinidad & Tobago",
"Tunisia",
"Turkey",
"Turkmenistan",
"Turks & Caicos Is",
"Tuvalu",
"Uganda",
"Ukraine",
"United Arab Emirates",
"United Kingdom",
"United States of America",
"Uruguay",
"Uzbekistan",
"Vanuatu",
"Vatican City State",
"Venezuela",
"Vietnam",
"Virgin Islands (Brit)",
"Virgin Islands (USA)",
"Wake Island",
"Wallis & Futana Is",
"Xenos Country",
"X-World",
"Yemen",
"Zaire",
"Zambia",
"Zimbabwe"
];
$( "#tags-1" ).autocomplete({
source: availableTags
});
return;
$( "#tags-2" )
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(
availableTags, extractLast( request.term ) ) );
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
});
}
});