Project

General

Profile

Download (11.5 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
/* ---- Variables ---- */
3
var actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
4
var actb_lim = 5;    // Number of elements autocomplete can show (-1: no limit)
5
var actb_firstText = false; // should the auto complete be limited to the beginning of keyword?
6
/* ---- Variables ---- */
7

    
8
/* --- Styles --- */
9
var actb_bgColor = '#FFFFFF';
10
var actb_textColor = '#000000';
11
var actb_hBgColor = '#990000';
12
var actb_htextColor = '#FFFFFF';
13
var actb_fFamily = 'Courier';
14
var actb_fSize = '14px';
15
var actb_hStyle = 'text-decoration:underline;font-weight="bold"';
16
/* --- Styles --- */
17

    
18
/* ---- Constants ---- */
19
var actb_keywords = new Array();
20
var actb_display = true;
21
var actb_pos = 0;
22
var actb_total = 0;
23
var actb_curr = null;
24
var actb_rangeu = 0;
25
var actb_ranged = 0;
26
var actb_bool = new Array();
27
var actb_pre = 0;
28
var actb_toid;
29
var actb_tomake = true;
30
/* ---- Constants ---- */
31

    
32
function actb_parse(n){
33
    var t = escape(actb_curr.value);
34
    var tobuild = '';
35
    var i;
36
    var re = "";
37

    
38
    if (actb_firstText){
39
        re = new RegExp("^" + t, "i");
40
    }else{
41
        re = new RegExp(t, "i");
42
    }
43
    var p = n.search(re);
44

    
45
    for (i=0;i<p;i++){
46
        tobuild += n.substr(i,1);
47
    }
48
    tobuild += ""
49
    for (i=p;i<t.length+p;i++){
50
        tobuild += n.substr(i,1);
51
    }
52
    tobuild += "";
53
    for (i=t.length+p;i<n.length;i++){
54
        tobuild += n.substr(i,1);
55
    }
56
    return tobuild;
57
}
58
function actb_generate(){
59
    if(navigator.appName == "Microsoft Internet Explorer") {
60
        if(actb_keywords.length < 1) return; // if no items setup, do not invoke code.  prevent ie crashing.
61
        if (document.getElementById('tat_frame')) document.body.removeChild(document.getElementById('tat_frame'));
62
    }
63
    if (document.getElementById('tat_table')) document.body.removeChild(document.getElementById('tat_table'));
64
    if(navigator.appName == "Microsoft Internet Explorer") {
65
        frame = document.createElement('iframe');
66
        frame.cellSpacing='1px';
67
        frame.cellPadding='2px';
68
        frame.style.zIndex = 3;
69
        frame.style.position='absolute';
70
        frame.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
71
        frame.style.left = curLeft() + "px";
72
        frame.style.backgroundColor=actb_bgColor;
73
        frame.id = 'tat_frame';
74
    }
75
    a = document.createElement('table');
76
    a.cellSpacing='1px';
77
    a.cellPadding='2px';
78
    a.style.border = '1px solid #990000';
79
    a.style.zIndex = 5;
80
    a.style.position='absolute';
81
    a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
82
    a.style.left = curLeft() + "px";
83
    a.style.backgroundColor=actb_bgColor;
84
    a.id = 'tat_table';
85
    if(navigator.appName == "Microsoft Internet Explorer")
86
        document.body.appendChild(frame);
87
    document.body.appendChild(a);
88
    var i;
89
    var first = true;
90
    var j = 1;
91
    var height = 0;
92
    var counter = 0;
93
    for (i=0;i<actb_keywords.length;i++){
94
        if (actb_bool[i]){
95
            counter++;
96
            r = a.insertRow(-1);
97
            if (first && !actb_tomake){
98
                r.style.backgroundColor = actb_hBgColor;
99
                first = false;
100
                actb_pos = counter;
101
            }else if(actb_pre == i){
102
                r.style.backgroundColor = actb_hBgColor;
103
                first = false;
104
                actb_pos = counter;
105
            }else{
106
                r.style.backgroundColor = actb_bgColor;
107
                r.style.color = actb_bgColor;
108
            }
109
            r.id = 'tat_tr'+(j);
110
            c = r.insertCell(-1);
111
            c.style.color = actb_textColor;
112
            counter = 0;
113
            first = true;
114
            if (first && !actb_tomake){
115
                c.style.color = actb_htextColor;
116
                first = false;
117
                actb_pos = counter;
118
            }else if(actb_pre == i){
119
                c.style.color = actb_htextColor;
120
                first = false;
121
                actb_pos = counter;
122
            }else{
123
                c.style.color = actb_textColor;
124
            }
125
            c.style.fontFamily = actb_fFamily;
126
            a.style.zIndex = 5;
127
            c.style.fontSize = actb_fSize;
128
            c.innerHTML = actb_parse(actb_keywords[i]);
129
            c.id = 'tat_td'+(j);
130
            height = height + c.offsetHeight;
131
            width = c.offsetWidth;
132
            j++;
133
        }
134
        if (j - 1 == actb_lim && j < actb_total){
135
            r = a.insertRow(-1);
136
            r.style.backgroundColor = actb_bgColor;
137
            c = r.insertCell(-1);
138
            c.style.color = actb_textColor;
139
            a.style.zIndex = 5;
140
            c.style.fontFamily = 'arial narrow';
141
            c.style.fontSize = actb_fSize;
142
            c.align='center';
143
            c.innerHTML = '\\/';
144
            break;
145
        }
146
    }
147
    actb_rangeu = 1;
148
    actb_ranged = j-1;
149
    actb_display = true;
150
    if (actb_pos <= 0) actb_pos = 1;
151
    if(navigator.appName == "Microsoft Internet Explorer") {
152
        frame.width=width;
153
        frame.height=height + 5;
154
    }
155
}
156
function curTop(){
157
    actb_toreturn = 0;
158
    obj = actb_curr;
159
    while(obj){
160
        actb_toreturn += obj.offsetTop;
161
        obj = obj.offsetParent;
162
    }
163
    return actb_toreturn;
164
}
165
function curLeft(){
166
    actb_toreturn = 0;
167
    obj = actb_curr;
168
    while(obj){
169
        actb_toreturn += obj.offsetLeft;
170
        obj = obj.offsetParent;
171
    }
172
    return actb_toreturn;
173
}
174
function actb_remake() {
175
    document.body.removeChild(document.getElementById('tat_table'));
176
    if(navigator.appName == "Microsoft Internet Explorer") {
177
        document.body.removeChild(document.getElementById('tat_frame'));
178
        frame = document.createElement('iframe');
179
        frame.cellSpacing='2px';
180
        frame.cellPadding='3px';
181
        frame.style.position='absolute';
182
        frame.style.zIndex = 5;
183
        frame.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
184
        frame.style.left = curLeft() + "px";
185
        frame.style.backgroundColor=actb_bgColor;
186
        frame.id = 'tat_frame';
187
    }
188
    a = document.createElement('table');
189
    a.cellSpacing='2px';
190
    a.cellPadding='3px';
191
    a.style.position='absolute';
192
    a.style.zIndex = 5;
193
    a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
194
    a.style.left = curLeft() + "px";
195
    a.style.backgroundColor=actb_bgColor;
196
    a.id = 'tat_table';
197
    if(navigator.appName == "Microsoft Internet Explorer")
198
        document.body.appendChild(frame);
199
    document.body.appendChild(a);
200
    var width = 0;
201
    var height = 0;
202
    var i;
203
    var first = true;
204
    var j = 1;
205
    if (actb_rangeu > 1){
206
        r = a.insertRow(-1);
207
        r.style.backgroundColor = actb_bgColor;
208
        c = r.insertCell(-1);
209
        c.style.color = actb_textColor;
210
        c.style.fontFamily = 'arial narrow';
211
        a.style.zIndex = 5;
212
        c.style.fontSize = actb_fSize;
213
        c.align='center';
214
        c.innerHTML = '/\\';
215
    }
216
    for (i=0;i<actb_keywords.length;i++){
217
        if (actb_bool[i]){
218
            if (j >= actb_rangeu && j <= actb_ranged){
219
                r = a.insertRow(-1);
220
                r.style.backgroundColor = actb_bgColor;
221
                r.id = 'tat_tr'+(j);
222
                c = r.insertCell(-1);
223
                c.style.color = actb_textColor;
224
                c.style.fontFamily = actb_fFamily;
225
                a.style.zIndex = 5;
226
                c.style.fontSize = actb_fSize;
227
                c.innerHTML = actb_parse(actb_keywords[i]);
228
                c.id = 'tat_td'+(j);
229
                j++;
230
            }else{
231
                j++;
232
            }
233
        }
234
        if (j > actb_ranged) break;
235
    }
236
    if (j-1 < actb_total){
237
        r = a.insertRow(-1);
238
        r.style.backgroundColor = actb_bgColor;
239
        c = r.insertCell(-1);
240
        c.style.color = actb_textColor;
241
        c.style.fontFamily = 'arial narrow';
242
        c.style.fontSize = actb_fSize;
243
        c.align='center';
244
        c.innerHTML = '\\/';
245
        height = height + c.height;
246
        width = c.width;
247
    }
248
    if(navigator.appName == "Microsoft Internet Explorer") {
249
        frame.width=width
250
        frame.height=height;
251
    }
252
}
253
function actb_goup(){
254
    if (!actb_display) return;
255
    if (actb_pos == 1) return;
256
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
257
    document.getElementById('tat_td'+actb_pos).style.color = actb_textColor;
258
    actb_pos--;
259
    if (actb_pos < actb_rangeu) actb_moveup();
260
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hBgColor;
261
    document.getElementById('tat_td'+actb_pos).style.color = actb_htextColor;
262
    if (actb_toid) clearTimeout(actb_toid);
263
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
264
}
265
function actb_godown(){
266
    if (!actb_display) return;
267
    if (actb_pos == actb_total) return;
268
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
269
    document.getElementById('tat_td'+actb_pos).style.color = actb_textColor;
270
    actb_pos++;
271
    if (actb_pos > actb_ranged) actb_movedown();
272
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hBgColor;
273
    document.getElementById('tat_td'+actb_pos).style.color= actb_htextColor;
274
    if (actb_toid) clearTimeout(actb_toid);
275
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
276
}
277
function actb_movedown(){
278
    actb_rangeu++;
279
    actb_ranged++;
280
    actb_remake();
281
}
282
function actb_moveup(){
283
    actb_rangeu--;
284
    actb_ranged--;
285
    actb_remake();
286
}
287
function actb_penter(){
288
    if (!actb_display) return;
289
    actb_display = 0;
290
    var word = '';
291
    var c = 0;
292
    for (var i=0;i<=actb_keywords.length;i++){
293
        if (actb_bool[i]) c++;
294
        if (c == actb_pos){
295
            word = actb_keywords[i];
296
            break;
297
        }
298
    }
299
    a = word;//actb_keywords[actb_pos-1];//document.getElementById('tat_td'+actb_pos).;
300
    actb_curr.value = a;
301
    actb_removedisp();
302
}
303
function actb_removedisp(){
304
    actb_display = 0;
305
    if(navigator.appName == "Microsoft Internet Explorer")
306
        if (document.getElementById('tat_frame')) document.body.removeChild(document.getElementById('tat_frame'));
307
    if (document.getElementById('tat_table')) document.body.removeChild(document.getElementById('tat_table'));
308
    if (actb_toid) clearTimeout(actb_toid);
309
}
310
function actb_checkkey(evt, sndr){
311
    a = evt.keyCode;
312
    if (a == 38){ // up key
313
        actb_goup();
314
    }else if(a == 40){ // down key
315
        actb_godown();
316
    }else if(a == 13){
317
        actb_penter();
318
    }
319
}
320
function actb_tocomplete(sndr,evt,arr){
321
    if (arr) actb_keywords = arr;
322
    if (evt.keyCode == 38 || evt.keyCode == 40 || evt.keyCode == 13) return;
323
    var i;
324
    if (actb_display){
325
        var word = 0;
326
        var c = 0;
327
        for (i=0;i<=actb_keywords.length;i++){
328
            if (actb_bool[i]) c++;
329
            if (c == actb_pos){
330
                word = i;
331
                break;
332
            }
333
        }
334
        actb_pre = word;//actb_pos;
335
    }else{ actb_pre = -1};
336

    
337
    if (!sndr) sndr = evt.srcElement;
338
    actb_curr = sndr;
339

    
340
    if (sndr.value == ''){
341
        actb_removedisp();
342
        return;
343
    }
344
    var t = sndr.value;
345
    var re = "";
346
    if (actb_firstText){
347
        re = new RegExp("^" + t, "i");
348
    }else{
349
        re = new RegExp(t, "i");
350
    }
351

    
352
    actb_total = 0;
353
    actb_tomake = false;
354
    for (i=0;i<actb_keywords.length;i++){
355
        actb_bool[i] = false;
356
        if (re.test(actb_keywords[i])){
357
            actb_total++;
358
            actb_bool[i] = true;
359
            if (actb_pre == i) actb_tomake = true;
360
        }
361
    }
362
    if (actb_toid) clearTimeout(actb_toid);
363
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
364
    actb_generate(actb_bool);
365
}
(1-1/109)