/[bfilter]/trunk/combo2/JSCombo.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/combo2/JSCombo.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 38 - (show annotations)
Wed Nov 17 09:25:10 2004 UTC (19 years, 6 months ago) by dpavlin
File MIME type: application/javascript
File size: 3539 byte(s)
added new combobox implementation by Matko Andjelinic together with example
implementation in php

1 function JSCombo(name, data) {
2
3 this.active = 1;
4
5 this.last_value = null;
6
7 this.debug2_lines = 10;
8
9 this.name = name;
10
11 this.myfilter = new BFilter(data);
12
13 this.myfilter.timeout = 0;
14
15 this.myfilter.parentclass = this;
16
17
18
19 eval("this.myfilter.result = function (arr) { var el = this.element_id('" + this.name + "'+'sel'); el.options[el.options.length] = new Option(arr[1],arr[2]); return true; }");
20
21
22
23 eval("this.myfilter.clear_results = function () { var el = this.element_id('" + this.name + "' + 'sel'); this.parentclass.active = 0; el.style.display = 'none'; el.options.length = 0; el.selectedIndex = -1; return true;}");
24
25
26
27 eval("this.myfilter.show_results = function () { var el_textbox = this.element_id('" + this.name + "textfilter'); var el_dropdown = this.element_id('" + this.name + "sel'); el_dropdown.style.display = ''; this.parentclass.last_value = el_textbox.value; return true;}");
28
29
30
31 var el_textbox = this.myfilter.element_id(this.name + 'textfilter');
32
33
34
35 el_textbox.focus();
36
37 el_textbox.caretPos=1;
38
39 // el_textbox.select();
40
41
42
43 }
44
45
46
47 JSCombo.prototype.debug2 = function (text) {
48
49 var el = this.myfilter.element_id('debug2',1);
50
51 if (! el) return;
52
53 this.debug2_lines++;
54
55 if (this.debug2_lines > 10) {
56
57 el.innerHTML = "...<br>";
58
59 this.debug2_lines = 0;
60
61 }
62
63 if (el) el.innerHTML += this.debug2_lines+": "+text+"<br>";
64
65 return true;
66
67 }
68
69
70
71
72
73 // keypress in dropdown
74
75 JSCombo.prototype.dropdown_keydown = function (event) {
76
77 var d = event.keyCode;
78
79
80
81 this.debug2("dropdown key: "+d);
82
83
84
85 var el_textbox = this.myfilter.element_id(this.name + 'textfilter');
86
87 var el_sel = this.myfilter.element_id(this.name + 'sel');
88
89
90
91 // return to textbox and hide results on
92
93 // enter, backspace, left, right, esc
94
95 if (d == 13 || d == 8 || d == 37 || d == 39 || d == 27) {
96
97 el_textbox.focus();
98
99 this.myfilter.clear_results();
100
101
102
103 // ignore backspace (to prevent back in history)
104
105 if (d == 8) return false;
106
107
108
109 if (d == 27) {
110
111 el_textbox.value = this.last_value;
112
113 }
114
115
116
117 }
118
119
120
121 // up or down on first/last element?
122
123 var sel = el_sel.selectedIndex;
124
125 var max = el_sel.options.length - 1;
126
127 this.debug2("selected: "+sel+" max: "+max);
128
129 if ( (d == 38 && sel == 0) || (d == 40 && sel == max) ) {
130
131 this.myfilter.clear_results();
132
133 el_textbox.value = this.last_value;
134
135 el_textbox.focus();
136
137 this.active = 0;
138
139 }
140
141
142
143 return true;
144
145
146
147 }
148
149
150
151 // keypress in textbox
152
153 JSCombo.prototype.textbox_keydown = function (e) {
154
155 var d = e.keyCode;
156
157 this.debug2("textbox key: "+d);
158
159
160
161 var el = this.myfilter.element_id(this.name + 'sel');
162
163 if (! el) return false;
164
165
166
167 this.active = 0;
168
169
170
171 var el_textbox = this.myfilter.element_id(this.name + 'textfilter');
172
173 var el_sel = this.myfilter.element_id(this.name + 'sel');
174
175 // up, down -- go to dropdown
176
177 if ((d == 40)) {
178
179 // filter if no results
180
181 this.debug2("existing results: "+el_sel.options.length);
182
183 if (el_sel.options.length <= 0) {
184
185 this.myfilter.show_filter(el_textbox.value);
186
187 } else {
188
189 this.myfilter.show_results();
190
191 el_sel.focus();
192
193 }
194
195 return false;
196
197 }
198
199
200
201
202
203 // if not enter, show combo
204
205 if (d != 13) this.active = 1;
206
207
208
209 // if (this.last_value == el_textbox.value) this.active = 0;
210
211
212
213 // left, right -- hide dropdown
214
215 if ((d == 37) || (d == 39)) {
216
217 this.myfilter.clear_results();
218
219 return false;
220
221 }
222
223
224
225 return true;
226
227 }
228
229
230
231
232
233
234
235 JSCombo.prototype.filter = function(value) {
236
237
238
239 this.debug2("combo filter: "+value+" ["+this.active+"]");
240
241 if (! this.active) {
242
243 return null;
244
245 }
246
247
248
249 return this.myfilter.filter(value);
250
251 }
252

  ViewVC Help
Powered by ViewVC 1.1.26