forked from bseth99/jquery-ui-multisearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1145 lines (921 loc) · 35.6 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
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
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!Doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQueryUI MultiSearch</title>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.1.0/lodash.underscore.min.js"></script>
<script src="src/jqueryui-multisearch.js"></script>
</head>
<body>
<style>
.fixed-font {
font-family: Monaco,Menlo,Consolas,"Courier New",monospace;
font-size: 13px;
}
.list-unstyled {
padding-left: 10px;
}
input[data-role="input"] {
outline: none;
border: none;
font-size: 14px;
font-weight: normal;
line-height: 1.42857;
vertical-align: middle;
padding: 6px 12px;
}
a.list-group-item.hover {
background-color: #F5F5F5;
text-decoration: none;
}
a.label-info {
margin: 4px 3px;
font-size: 14px;
}
a.label-info.hover {
background-color: #31B0D5;
}
a.label-info.active {
background-color: #ADE0EE !important;
}
a.label-info .badge {
font-size: 9px;
padding: 1px 5px;
}
</style>
<br/><br/>
<div class="container">
<div class="row">
<div class="col-lg-3">
</div>
<div class="col-lg-6">
<h3>jQuery UI MultiSearch</h3>
<p>
A jQuery UI widget that enables building a list of multiple items using an autocomplete entry box
without imposing specific HTML structure or CSS style rules.
</p>
<p class="text-center">
<iframe src="http://ghbtns.com/github-btn.html?user=bseth99&repo=jquery-ui-multisearch&type=fork"
allowtransparency="true" frameborder="0" scrolling="0" width="53" height="20"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=bseth99&repo=jquery-ui-multisearch&type=watch"
allowtransparency="true" frameborder="0" scrolling="0" width="62" height="20"></iframe>
<iframe src="http://ghbtns.com/github-btn.html?user=bseth99&type=follow"
allowtransparency="true" frameborder="0" scrolling="0" width="132" height="20"></iframe>
</p>
<p class="text-center">
<a class="btn btn-primary" rel="nofollow" href="https://github.com/bseth99/jquery-ui-multisearch/archive/v0.0.3.zip" >
Download Latest Version
</a>
</p>
<h3>Overview</h3>
<p>
The goal of this project is to create a widget that is as unopinionated about the structure and
styling of the content as possible. There are many variations of building a list of items by
looking each item up using a type ahead field but few will ever look the same. However, the basic
underlying functionality is very similar. This widget emphasizes building features that encapsulate
that control logic and provide many hooks along the way to customize the behavior.
</p>
<h3>Quick Demo</h3>
<p>
The source for this search is the top 200 baby names of 2012.
</p>
<div id="name-search">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body" data-role="selected-list">
<input class="pull-left" data-role="input" type="text" placeholder="Search..."/>
</div>
</div>
</div>
</div>
<div data-role="picker" class="panel panel-default">
<div class="list-group" data-role="picker-list">
</div>
</div>
</div>
<p>
Learn more about this demo <a href="examples/bootstrap.html">here</a>.
</p>
<h3>Features</h3>
<ul>
<li>Type ahead partial searching with suggested results against either a remote or local data source </li>
<li>Built-in caching and throttling logic to help alleviate load on a remote data source </li>
<li>Result records can have any number of attributes which are passed through to template functions and triggered event handlers </li>
<li>Multiple keys and search fields can be defined to enable duplicate detection, lookups, and hit highlighting </li>
<li>Keyboard interaction to navigate suggestion list and selected items </li>
<li>Many event hooks and callbacks to customize behavior and control layout and styling </li>
<li>API methods to get/set the list of selected items and add/remove individual items </li>
</ul>
<h3>Quick Start</h3>
<p>
MultiSearch has dependencies on jQuery, jQuery UI, and Underscore (if you prefer LoDash, it can be used instead).
The widget makes extensive use of several of the data transversal and manipulation function in the Underscore library
which helps reduce the code size and maintenance (no reason to reinvent that wheel). You can download these
or just use the CDN versions:
</p>
<pre>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.1.0/lodash.underscore.min.js"></script>
</pre>
<p>
Next, include the MultiSearch file and you're ready to go:
</p>
<pre>
<script src="jqueryui-multisearch.min.js"></script>
</pre>
<p>
Here's some example mark up that defines the container of the widget and the
four required points in that structure where the widget should attach certain
functionality:
</p>
<pre>
<code class="prettyprint">
<div id="myMultiSearch">
<div data-role="selected-list">
<input data-role="input" type="text" placeholder="Search..."/>
</div>
<div data-role="picker" class="picker">
<ul class="list-group" data-role="picker-list">
</ul>
</div>
</div>
</code>
</pre>
<p>
These roles can be placed anywhere inside the widget's containing element (although, you
may need to change a few options on the widget so it makes the right assuptions about where
a given item is located).
</p>
<p>
Once that is defined, you can target the containing element and initialize it with the
multisearch widget plugin. The only required option is the <code>source</code> data which
can simply be an array of objects. Everything else will default to provide basic functionality.
</p>
<pre>
<code class="prettyprint">
$(function() {
$("#myMultiSearch").multisearch({
source: [
{name: 'One'},
{name: 'Two'},
{name: 'Three'},
{name: 'Four'}
],
});
});
</code>
</pre>
<p>
If you run the above code with no styling, it will work fine but there won't be any
highlighting and the selected items will run together. With the HTML defined above,
these styles will make it look a little better:
</p>
<pre>
<code class="prettyprint">
ul {
list-style: none;
margin: 0;
padding: 0;
}
li {
margin: 0;
padding: 0;
}
a {
color: black;
margin: 3px;
}
a:hover, a.hover, li.hover a {
color: green;
}
.picker {
border: 1px solid silver;
padding: 10px;
}
</code>
</pre>
<p>
The example is straight from the basic demo below. Take a look at it for the full source and
to see it working (with and without the styling). I also setup a
<a href="http://jsfiddle.net/bseth99/mWerB/" target="_fiddle">jsFiddle</a> with the basic demo
that you can use to tinker with some of the options and styling.
</p>
<h3>Demos</h3>
<ul>
<li><a href="examples/base.html">The Basics</a></li>
<li><a href="examples/bootstrap.html">Bootstrap Structure and Styling</a></li>
<li><a href="examples/position.html">Alternative Positioning of the Search Input</a></li>
<li><a href="examples/api.html">Using the API Methods to Get/Set Values</a></li>
<li><a href="examples/movies.html">Using a Backbone Collection and Model</a></li>
<li><a href="examples/contact.html">Entering Recipients from an Address Book</a></li>
</ul>
<h3>Reference</h3>
<p>
The mark up needs to define several roles via a <code>data-role</code> attribute. The widget
will use those binding points to attach the required control logic. The list of roles include:
</p>
<ul>
<li><code>selected-list</code> - the containing element where selected items should be rendered</li>
<li><code>selected-item</code> - auto-assigned by the widget as new items are generated with the
factory template function defined by <code>formatSelectedItem</code>. These elements will be direct children
of the <code>selected-list</code> element</li>
<li><code>input</code> - this should be the input box where the user will type searches. Depending on where it
is positioned relative to selected-list, you may need to adjust the <code>pickerPosition</code> option so
keyboard interation works as expected</li>
<li><code>picker</code> - container for the picker list. This will be the target of positioning and show/hide
methods as a search is performed</li>
<li><code>picker-list</code> - the containing element where search results should be rendered</li>
<li><code>picker-item</code> - auto-assigned by the widget as new items are generated with the
factory template function defined by <code>formatPickerItem</code>. These elements will be direct children
of the <code>picker-list</code> element</li>
</ul>
<p>
The keyboard can be used to navigate both the picker items when a search is being performed and
the list of selected items when no text is in the input box. The navigation will trigger the same
hover/active events that would occur if using the mouse.
</p>
<h4>Options</h4>
<p>
This is the list of available options when initializing the widget. The only required option
is the <code>source</code> the widget will use for searching and the item content.
</p>
<p>
<code>source</code>: The data source to search. Can be a string, function, or array of objects
</p>
<ul>
<li>A string should be a valid remote datasource</li>
<li>A function can implement a data search and should call the passed in
callback with the results:
<p>
<span class="text-primary fixed-font">function ( term, callback ) { ... }</span>
</p>
</li>
<li>An array repesents a local dataset and all searches will be done locally
on the contents</li>
</ul>
<p>
Default: <span class="text-primary fixed-font">null</span>
</p>
<br/>
<p>
<code>ajaxOptions</code>:Hash of options that are used in the $.ajax call on a remote resource.
Only used when source is a string representing the path of the resource.
Currently accepts overrides for dataType and method options. Also adds
a custom options:
</p>
<ul>
<li>
<strong>searchTerm</strong>: the parameter name that will contain the search term
( ie path/to/resource?term=abc )
</li>
</ul>
<p>
Default:
<span class="text-primary fixed-font">{ <br/>
searchTerm: 'term', <br/>
dataType: 'json', <br/>
method: 'GET' <br/>
}</span>
</p>
<br/>
<p>
<code>keyAttrs</code>: An array of fields in the result object which represent the unique key for the object.
Used to detect duplicate items. If not set, will default to ['id']
</p>
<p>
Default: <span class="text-primary fixed-font">[ 'id' ]</span>
</p>
<br/>
<p>
<code>searchAttrs</code>: An array of fields in the result object to search for the entered criteria.
</p>
<p>
Default: <span class="text-primary fixed-font">[ 'name' ]</span>
</p>
<br/>
<p>
<code>formatPickerItem</code>: A function that returns an HTML string repesenting the item to add to the suggestion picker
as a search is entered into the input.. The hash returned by the remote server or local cache
is passed to the function. This can be a Underscore template() function.
</p>
<p>
Default: <span class="text-primary fixed-font">function( data ) { return '<li><a href="#">'+data.name+'</a></li>'; }</span>
</p>
<br/>
<p>
<code>formatSelectedItem</code>: A function that returns an HTML string repesenting the item to add to the selected
items list. Called each time a search term is selected from the suggestion picker or,
when not found items are allowed, a new entry is completed. The hash from the result
set is passed to the function. This can be a Underscore template() function.
</p>
<p>
Default: <span class="text-primary fixed-font">function( data ) { return '<a href="#">'+data.name+'</a>'; }</span>
</p>
<br/>
<p>
<code>buildNewItem</code>: When adding items that are not found in the suggestion picker, this function is called
to define the object that is expected in the formatSelectedItem() template. Generally,
you'll leave the keyAttrs attributes null and set the primary display field with the
text from the input box which is passed to the function.
</p>
<p>
Default: <span class="text-primary fixed-font">function( text ) { return { id: null, name: text }; }</span>
</p>
<br/>
<p>
<code>minSearchChars</code>: How many characters need to be typed to trigger a search
</p>
<p>
Default: <span class="text-primary fixed-font">2</span>
</p>
<br/>
<p>
<code>searchThrottle</code>: How quickly can successive searches be triggered. The value is in milliseconds
and uses Underscore's throttle() function to control triggering calls to the
remote resource. This does not affect local cache searching.
</p>
<p>
Default: <span class="text-primary fixed-font">200</span>
</p>
<br/>
<p>
<code>maxShowOptions</code>: How many results to show in the picker. Even if 200 are returned by the server, you
can control how many are actually displayed in the suggestion picker. Set it to zero
to show everything. Ensure you enable some kind of scrolling on the element you define
as the picker/picker-list role if you allow longer lists of items.
</p>
<p>
Default: <span class="text-primary fixed-font">5</span>
</p>
<br/>
<p>
<code>minLocalCache</code>: When to start refining a search against the local cache. Each remote search is saved by term
if the remote result set has less than minLocalCache items in it, each subsequent character typed
will use that result as a basis for searching. This can reduce the number of hits on the remote
resource and can be fine-tuned to match your needs. Set it to zero to disable local refinements
against the cache. If you do use it, make sure any limits on the server side are set high enough
to ensure that a search term that refines the remote search below this threshold will contain all
possible items that could be found if the subsequent searches were run against the server.
</p>
<p>
Default: <span class="text-primary fixed-font">50</span>
</p>
<br/>
<p>
<code>preventNotFound</code>: Can items not found in the suggestion picker be added to the seleced item list. If allowed,
buildNewItem() will be called to allow setting defaults on the object that represents the
search data to be prefilled before calling formatSelectedItem(). The adding and added events
will have the notfound flag set to true when an item will be added that in not in the picker.
</p>
<p>
Default: <span class="text-primary fixed-font">false</span>
</p>
<br/>
<p>
<code>preventDuplicates</code>: Using the keyAttrs, should duplicates be prevented. A duplicate event is triggered if one is found
allowing custom UI logic to be defined externally. Otherwise, nothing will happen. The suggestion
picker will remain open and it will appear that the widget is not responding. Items that are not
found in the picker but are added to the selected item list will not be considered a duplicate
unless you provide custom logic during adding that would assign a key.
</p>
<p>
Default: <span class="text-primary fixed-font">true</span>
</p>
<br/>
<p>
<code>useAutoWidth</code>: Automatically resize the input box to match the text. Helpful for inline/floating elements so
the input only wraps as needed. Disable if using block elements that you want to fill the
parent space.
</p>
<p>
Default: <span class="text-primary fixed-font">true</span>
</p>
<br/>
<p>
<code>pickerPosition</code>: Use jQueryUI.position plugin to position the picker box relative to the input control. The default is the
basic drop-down menu box under the input entry box. Depending on the structure, you may want to adjust this
setting.
</p>
<p>
Default: <span class="text-primary fixed-font">{ my: 'left top', at: 'left bottom' }</span>
</p>
<br/>
<p>
<code>inputPosition</code>: Where is the input relative to the item list. Determines how the keyboard navigation
moves through the items and where new items are added. Valid values are "start" and "end"
defaults to "end". Depending on where you position the input box, adjust this setting
so the UI interactions make sense.
</p>
<p>
Default: <span class="text-primary fixed-font">end</span>
</p>
<br/>
<p>
<code>localMatcher</code>:
</p>
<p>
For each field defined in searchAttrs, search for the input text using the function below. This is used
for both local cache searches and hit highlighting. It should match with the search method from the remote.
The default is to look for the search string anywhere in the target field. If you want to match only from
the leading edge of the field, you'll need to override this function. If you override it, the function
must accept two parameters and return true (needle found in haystack) or false (not found):
</p>
<p>
<span class="text-primary fixed-font">function( needle, haystack ) { ... }</span>
</p>
<h4>API</h4>
<p>
Several methods are available to interact with the selected items list via code. These methods all suppress
any events that would normally be triggered by user interaction.
</p>
<p>
<code>value</code>: Getter/Setter for list of selected items. Use it to retreive the list of items
entered by the user or seed the list with existing items (from a database, etc).
</p>
<p>
Getting the value returns a shallow clone of the objects in the item list. If
you're using nested objects from a shared dataset, be aware you may be referencing
them in the returned set.
</p>
<p>
Setting the value will destory the current selections. If you want more control,
use add/remove to selectively update the list.
</p>
<br/>
<p>
<code>add</code>: Add an item to the selection list. Optional second arguement can be used to specify
the position to insert the item. If the item already exists, it will be merged
and trigger rendering the content of the item again such that updated data can be
applied to the list.
</p>
<br/>
<p>
<code>remove</code>: Remove one or all items form the selected list:
</p>
<ul>
<li>No arguements will remove everything</li>
<li>Pass an Integer representing the ordinal index of the item to remove</li>
<li>Pass an Object containing the keys of the item to remove</li>
</ul>
<h4>Events</h4>
<p>
Uses the standard jQuery UI interface for triggering events. You can either
define a callback in the options hash or listen to the event by binding to multisearch + event name
ie <code>$.on( 'multisearchadding', ... )</code>.
</p>
<p>
Handler function will receive an event and ui argument. The ui object is defined below with each
event that is triggered.
</p>
<p>
<code>duplicate</code>: trigger when preventDuplicates is true and a selected item from the picker matches
an item already in the item list based on keyAttrs
</p>
<span class="fixed-font">
<ul class="list-unstyled">
<li>ui: {</li>
<li>
<ul class="list-unstyled">
<li> <strong>existing</strong>: Object representing the duplicate already present in the item list </li>
<li> <strong>adding</strong>: Object representing the item that is attempting to be added </li>
</ul>
</li>
<li>}</li>
</ul>
</span>
<br/>
<p>
<code>adding</code>: triggered before actually adding the item to the item list. Return false to
prevent the the action. You can modify data to affect what is passed to the
template function and retained in the item list.
</p>
<span class="fixed-font">
<ul class="list-unstyled">
<li>ui: {</li>
<li>
<ul class="list-unstyled">
<li> <strong>data</strong>: Object containing the selected item </li>
<li> <strong>notfound</strong>: Flag indicating whether the item was found in the picker list </li>
</ul>
</li>
<li>}</li>
</ul>
</span>
<br/>
<p>
<code>added</code>: once the item is added, this event is triggered with the data and element.
</p>
<span class="fixed-font">
<ul class="list-unstyled">
<li>ui: {</li>
<li>
<ul class="list-unstyled">
<li> <strong>data</strong>: Object containing the selected item </li>
<li> <strong>element</strong>: jQuery object of the newly added element representing the data in the UI </li>
</ul>
</li>
<li>}</li>
</ul>
</span>
<br/>
<p>
<code>removing</code>: prior to removing the item, this event is triggered to allow canceling
the operation by returning false.
</p>
<span class="fixed-font">
<ul class="list-unstyled">
<li>ui: {</li>
<li>
<ul class="list-unstyled">
<li> <strong>data</strong>: Object containing the selected item </li>
</ul>
</li>
<li>}</li>
</ul>
</span>
<br/>
<p>
<code>removed</code>: upon removing the item, this event is triggered
</p>
<span class="fixed-font">
<ul class="list-unstyled">
<li>ui: {</li>
<li>
<ul class="list-unstyled">
<li> <strong>data</strong>: Object containing the selected item </li>
</ul>
</li>
<li>}</li>
</ul>
</span>
<br/>
<p>
<code>searching</code>: triggered before searching but immediately after displaying the picker
</p>
<span class="fixed-font">
<ul class="list-unstyled">
<li>ui: {</li>
<li>
<ul class="list-unstyled">
<li> <strong>term</strong>: String that will be used in the search </li>
<li> <strong>picker</strong>: jQuery object representing the main picker container element </li>
</ul>
</li>
<li>}</li>
</ul>
</span>
<br/>
<p>
<code>searched</code>: triggered after searching has completed and results have been returned by the source
</p>
<span class="fixed-font">
<ul class="list-unstyled">
<li>ui: {</li>
<li>
<ul class="list-unstyled">
<li> <strong>term</strong>: String that will be used in the search </li>
<li> <strong>picker</strong>: jQuery object representing the main picker container element </li>
<li> <strong>list</strong>: Array of objects returned by the search </li>
</ul>
</li>
<li>}</li>
</ul>
</span>
<br/>
<p>
<code>itemaction</code>: triggered when an element with <code>data-action</code> is clicked in the item list
</p>
<span class="fixed-font">
<ul class="list-unstyled">
<li>ui: {</li>
<li>
<ul class="list-unstyled">
<li> <strong>data</strong>: Object containing the selected item </li>
<li> <strong>element</strong>: jQuery object of the element representing the data in the UI </li>
</ul>
</li>
<li>}</li>
</ul>
</span>
<br/>
<p>
<code>itemselect</code>: triggered when an item is clicked in the item list (no <code>data-action</code> defined)
</p>
<span class="fixed-font">
<ul class="list-unstyled">
<li>ui: {</li>
<li>
<ul class="list-unstyled">
<li> <strong>data</strong>: Object containing the selected item </li>
<li> <strong>element</strong>: jQuery object of the element representing the data in the UI </li>
</ul>
</li>
<li>}</li>
</ul>
</span>
<br/>
<p>
Hover/Active events are triggered either when the user uses the mouse (hover/click) or
uses the keyboard to navigate (arrows, space bar). A handler can return false to prevent
the default action which simply changes classes on the elements. Each event provides the
following ui object:
</p>
<span class="fixed-font">
<ul class="list-unstyled">
<li>ui: {</li>
<li>
<ul class="list-unstyled">
<li> <strong>target</strong>: A jQuery object representing the item receiving the event </li>
<li> <strong>siblings</strong>:
jQuery object of the siblings of the target filtering out any elements that
do not have the data-role defined. Generally, you need to remove classes from
the siblings when adding them to the target.
</li>
</ul>
</li>
<li>}</li>
</ul>
</span>
<p>
Here is the list of interaction events:
</p>
<ul>
<li><code>selectedactive</code>: When a selected item is clicked or selected with the space bar </li>
<li><code>selectedhoverin</code>: When mousing into an item or using the arrows to navigate </li>
<li><code>selectedhoverout</code>: When leaving a selected item </li>
<li><code>pickerhoverin</code>: When mouseover or arrows to a suggested item in the picker list </li>
<li><code>pickerhoverout</code>: When leaving the item </li>
</ul>
<h3>Ideas, Issues, and Requests</h3>
<p>
Please open a ticket via the issue log on the GitHub project page:
</p>
<p>
<a href="https://github.com/bseth99/jquery-ui-multisearch/issues">
https://github.com/bseth99/jqueryui-multisearch/issues
</a>
</p>
<h3>License</h3>
<p>
Copyright (c) 2013 Ben Olson
</p>
<p>
Licensed under the MIT License
</p>
<br/><br/>
</div>
<div class="col-lg-3">
</div>
</div>
</div>
<script id="picker-item" type="text/template">
<a href="#" class="list-group-item"><%= name %></a>
</script>
<script id="selected-item" type="text/template">
<a href="#" class="label label-info pull-left"><%= name %>
<% if ( times > 1 ) { %>
<span class="badge"><%= times %></span>
<% } %>
</a>
</script>
<script>
$(function() {
$("#name-search").multisearch({
source: babyNames,
keyAttrs: ['name'],
formatPickerItem: _.template( $('#picker-item').html() ),
formatSelectedItem: _.template( $('#selected-item').html() ),
adding: function( event, ui ) {
if ( !ui.data.times )
ui.data.times = 0;
ui.data.times++;
},
duplicate: function( event, ui ) {
ui.existing.times++;
$('#name-search').multisearch( 'add', ui.existing );
},
});
});
var babyNames = [
{ name: 'Aaliyah' },
{ name: 'Aaron' },
{ name: 'Abigail' },
{ name: 'Adam' },
{ name: 'Addison' },
{ name: 'Adrian' },
{ name: 'Aiden' },
{ name: 'Alex' },
{ name: 'Alexa' },
{ name: 'Alexander' },
{ name: 'Alexandra' },
{ name: 'Alexis' },
{ name: 'Alice' },
{ name: 'Allison' },
{ name: 'Alyssa' },
{ name: 'Amelia' },
{ name: 'Andrew' },
{ name: 'Anna' },
{ name: 'Annabelle' },
{ name: 'Anthony' },
{ name: 'Aria' },
{ name: 'Arianna' },
{ name: 'Asher' },
{ name: 'Aubrey' },
{ name: 'Audrey' },
{ name: 'Austin' },
{ name: 'Ava' },
{ name: 'Avery' },
{ name: 'Bailey' },
{ name: 'Bella' },
{ name: 'Benjamin' },
{ name: 'Bentley' },
{ name: 'Blake' },
{ name: 'Brandon' },
{ name: 'Brayden' },
{ name: 'Brianna' },
{ name: 'Brody' },
{ name: 'Brooke' },
{ name: 'Brooklyn' },
{ name: 'Caleb' },
{ name: 'Cameron' },
{ name: 'Caroline' },
{ name: 'Carson' },
{ name: 'Carter' },
{ name: 'Charlie' },
{ name: 'Charlotte' },
{ name: 'Chase' },
{ name: 'Chloe' },
{ name: 'Christian' },
{ name: 'Christopher' },
{ name: 'Claire' },
{ name: 'Clara' },
{ name: 'Cole' },
{ name: 'Colin' },
{ name: 'Colton' },
{ name: 'Connor' },
{ name: 'Cooper' },
{ name: 'Daniel' },
{ name: 'David' },
{ name: 'Declan' },
{ name: 'Dominic' },
{ name: 'Dylan' },
{ name: 'Easton' },
{ name: 'Eleanor' },
{ name: 'Elena' },
{ name: 'Eli' },
{ name: 'Eliana' },
{ name: 'Elijah' },
{ name: 'Elise' },
{ name: 'Elizabeth' },
{ name: 'Ella' },
{ name: 'Ellie' },
{ name: 'Emily' },
{ name: 'Emma' },
{ name: 'Ethan' },
{ name: 'Eva' },
{ name: 'Evan' },
{ name: 'Evelyn' },