Mercurial > hg > dml-open-vis
comparison src/DML/MainVisBundle/Resources/assets/lib/jquery.ui/combobox.js @ 0:493bcb69166c
added public content
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 20:54:02 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:493bcb69166c |
---|---|
1 (function($) { | |
2 $.widget( "custom.combobox", { | |
3 _create : function() { | |
4 this.wrapper = $("<span>").addClass( | |
5 "custom-combobox") | |
6 .insertAfter(this.element); | |
7 this.element.hide(); | |
8 this._createAutocomplete(); | |
9 this._createShowAllButton(); | |
10 }, | |
11 | |
12 _createAutocomplete : function() { | |
13 var selected = this.element.children(":selected"), value = selected | |
14 .val() ? selected.text() : ""; | |
15 this.input = $("<input>") | |
16 .appendTo(this.wrapper) | |
17 .val(value) | |
18 .attr("title", "") | |
19 .addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left") | |
20 .autocomplete({ | |
21 delay : 0, | |
22 minLength : 0, | |
23 source : $.proxy(this, "_source") | |
24 }); | |
25 this._on(this.input, { | |
26 autocompleteselect : function(event, ui) { | |
27 ui.item.option.selected = true; | |
28 this._trigger("select", event, { | |
29 item : ui.item.option | |
30 }); | |
31 }, | |
32 autocompletechange : "_applyChange" | |
33 }); | |
34 }, | |
35 | |
36 _createShowAllButton : function() { | |
37 var input = this.input, wasOpen = false; | |
38 $("<a>").attr("tabIndex", -1).attr("title", | |
39 "Show All Items").tooltip().appendTo( | |
40 this.wrapper).button({ | |
41 icons : { | |
42 primary : "ui-icon-triangle-1-s" | |
43 }, | |
44 text : false | |
45 }).removeClass("ui-corner-all").addClass( | |
46 "custom-combobox-toggle ui-corner-right") | |
47 .mousedown( | |
48 function() { | |
49 wasOpen = input.autocomplete( | |
50 "widget") | |
51 .is(":visible"); | |
52 }).click(function() { | |
53 input.focus(); | |
54 // Close if already visible | |
55 if (wasOpen) { | |
56 return; | |
57 } | |
58 // Pass empty string as value to search | |
59 // for, displaying all results | |
60 input.autocomplete("search", ""); | |
61 }); | |
62 }, | |
63 _source : function(request, response) { | |
64 var matcher = new RegExp($.ui.autocomplete | |
65 .escapeRegex(request.term), "i"); | |
66 response(this.element.children("option").map( | |
67 function() { | |
68 var text = $(this).text(); | |
69 if (this.value | |
70 && (!request.term || matcher | |
71 .test(text))) | |
72 return { | |
73 label : text, | |
74 value : text, | |
75 option : this | |
76 }; | |
77 })); | |
78 }, | |
79 | |
80 _applyChange : function(event, ui) { | |
81 // Selected an item, nothing to do | |
82 if (ui.item) { | |
83 return; | |
84 } | |
85 // Search for a match (case-insensitive) | |
86 var value = this.input.val(), valueLowerCase = value | |
87 .toLowerCase(), valid = false; | |
88 this.element | |
89 .children("option") | |
90 .each( | |
91 function() { | |
92 if ($(this).text() | |
93 .toLowerCase() === valueLowerCase) { | |
94 this.selected = valid = true; | |
95 return false; | |
96 } | |
97 }); | |
98 // Found a match, nothing to do | |
99 this.element.val(value); | |
100 if (valid) { | |
101 return; | |
102 } | |
103 }, | |
104 _destroy : function() { | |
105 this.wrapper.remove(); | |
106 this.element.show(); | |
107 } | |
108 }); | |
109 })(jQuery); |