Project

General

Profile

Download (9.9 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 = 1;    // 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 = '#888888';
10
var actb_textColor = '#FFFFFF';
11
var actb_hColor = '#000000';
12
var actb_fFamily = 'Courier';
13
var actb_fSize = '14px';
14
var actb_hStyle = 'text-decoration:underline;font-weight="bold"';
15
/* --- Styles --- */
16

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

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

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

    
44
    for (i=0;i<p;i++){
45
        tobuild += n.substr(i,1);
46
    }
47
    tobuild += ""
48
    for (i=p;i<t.length+p;i++){
49
        tobuild += n.substr(i,1);
50
    }
51
    tobuild += "";
52
    for (i=t.length+p;i<n.length;i++){
53
        tobuild += n.substr(i,1);
54
    }
55
    return tobuild;
56
}
57
function actb_generate(){
58
    if (document.getElementById('tat_frame')) document.body.removeChild(document.getElementById('tat_frame'));
59
    if (document.getElementById('tat_table')) document.body.removeChild(document.getElementById('tat_table'));
60
    frame = document.createElement('iframe');
61
    a = document.createElement('table');
62
    frame.cellSpacing='1px';
63
    frame.cellPadding='2px';
64
    frame.style.zIndex = 3;
65
    frame.style.position='absolute';
66
    frame.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
67
    frame.style.left = curLeft() + "px";
68
    frame.style.backgroundColor=actb_bgColor;
69
    frame.id = 'tat_frame';
70
    a.cellSpacing='1px';
71
    a.cellPadding='2px';
72
    a.style.zIndex = 5;
73
    a.style.position='absolute';
74
    a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
75
    a.style.left = curLeft() + "px";
76
    a.style.backgroundColor=actb_bgColor;
77
    a.id = 'tat_table';
78
    document.body.appendChild(frame);
79
    document.body.appendChild(a);
80
    var i;
81
    var first = true;
82
    var j = 1;
83
    var height = 0;
84
    var counter = 0;
85
    for (i=0;i<actb_keywords.length;i++){
86
        if (actb_bool[i]){
87
            counter++;
88
            r = a.insertRow(-1);
89
            if (first && !actb_tomake){
90
                r.style.backgroundColor = actb_hColor;
91
                first = false;
92
                actb_pos = counter;
93
            }else if(actb_pre == i){
94
                r.style.backgroundColor = actb_hColor;
95
                first = false;
96
                actb_pos = counter;
97
            }else{
98
                r.style.backgroundColor = actb_bgColor;
99
            }
100
            r.id = 'tat_tr'+(j);
101
            c = r.insertCell(-1);
102
            c.style.color = actb_textColor;
103
            c.style.fontFamily = actb_fFamily;
104
            a.style.zIndex = 5;
105
            c.style.fontSize = actb_fSize;
106
            c.innerHTML = actb_parse(actb_keywords[i]);
107
            c.id = 'tat_td'+(j);
108
            height = height + c.offsetHeight;
109
            width = c.offsetWidth;
110
            j++;
111
        }
112
        if (j - 1 == actb_lim && j < actb_total){
113
            r = a.insertRow(-1);
114
            r.style.backgroundColor = actb_bgColor;
115
            c = r.insertCell(-1);
116
            c.style.color = actb_textColor;
117
            a.style.zIndex = 5;
118
            c.style.fontFamily = 'arial narrow';
119
            c.style.fontSize = actb_fSize;
120
            c.align='center';
121
            c.innerHTML = '\\/';
122
            break;
123
        }
124
    }
125
    actb_rangeu = 1;
126
    actb_ranged = j-1;
127
    actb_display = true;
128
    if (actb_pos <= 0) actb_pos = 1;
129
    frame.width=width;
130
    frame.height=height;
131
}
132
function curTop(){
133
    actb_toreturn = 0;
134
    obj = actb_curr;
135
    while(obj){
136
        actb_toreturn += obj.offsetTop;
137
        obj = obj.offsetParent;
138
    }
139
    return actb_toreturn;
140
}
141
function curLeft(){
142
    actb_toreturn = 0;
143
    obj = actb_curr;
144
    while(obj){
145
        actb_toreturn += obj.offsetLeft;
146
        obj = obj.offsetParent;
147
    }
148
    return actb_toreturn;
149
}
150
function actb_remake(){
151
    document.body.removeChild(document.getElementById('tat_table'));
152
    document.body.removeChild(document.getElementById('tat_frame'));
153
    frame = document.createElement('iframe');
154
    frame.cellSpacing='2px';
155
    frame.cellPadding='3px';
156
    frame.style.position='absolute';
157
    frame.style.zIndex = 5;
158
    frame.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
159
    frame.style.left = curLeft() + "px";
160
    frame.style.backgroundColor=actb_bgColor;
161
    frame.id = 'tat_frame';
162

    
163
    a = document.createElement('table');
164
    a.cellSpacing='2px';
165
    a.cellPadding='3px';
166
    a.style.position='absolute';
167
    a.style.zIndex = 5;
168
    a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
169
    a.style.left = curLeft() + "px";
170
    a.style.backgroundColor=actb_bgColor;
171
    a.id = 'tat_table';
172
    document.body.appendChild(frame);
173
    document.body.appendChild(a);
174
    var width = 0;
175
    var height = 0;
176
    var i;
177
    var first = true;
178
    var j = 1;
179
    if (actb_rangeu > 1){
180
        r = a.insertRow(-1);
181
        r.style.backgroundColor = actb_bgColor;
182
        c = r.insertCell(-1);
183
        c.style.color = actb_textColor;
184
        c.style.fontFamily = 'arial narrow';
185
        a.style.zIndex = 5;
186
        c.style.fontSize = actb_fSize;
187
        c.align='center';
188
        c.innerHTML = '/\\';
189
    }
190
    for (i=0;i<actb_keywords.length;i++){
191
        if (actb_bool[i]){
192
            if (j >= actb_rangeu && j <= actb_ranged){
193
                r = a.insertRow(-1);
194
                r.style.backgroundColor = actb_bgColor;
195
                r.id = 'tat_tr'+(j);
196
                c = r.insertCell(-1);
197
                c.style.color = actb_textColor;
198
                c.style.fontFamily = actb_fFamily;
199
                a.style.zIndex = 5;
200
                c.style.fontSize = actb_fSize;
201
                c.innerHTML = actb_parse(actb_keywords[i]);
202
                c.id = 'tat_td'+(j);
203
                j++;
204
            }else{
205
                j++;
206
            }
207
        }
208
        if (j > actb_ranged) break;
209
    }
210
    if (j-1 < actb_total){
211
        r = a.insertRow(-1);
212
        r.style.backgroundColor = actb_bgColor;
213
        c = r.insertCell(-1);
214
        c.style.color = actb_textColor;
215
        c.style.fontFamily = 'arial narrow';
216
        c.style.fontSize = actb_fSize;
217
        c.align='center';
218
        c.innerHTML = '\\/';
219
        height = height + c.height;
220
        width = c.width;
221
    }
222
    alert(height);
223
    frame.width=width
224
    frame.height=height;
225
}
226
function actb_goup(){
227
    if (!actb_display) return;
228
    if (actb_pos == 1) return;
229
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
230
    actb_pos--;
231
    if (actb_pos < actb_rangeu) actb_moveup();
232
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
233
    if (actb_toid) clearTimeout(actb_toid);
234
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
235
}
236
function actb_godown(){
237
    if (!actb_display) return;
238
    if (actb_pos == actb_total) return;
239
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
240
    actb_pos++;
241
    if (actb_pos > actb_ranged) actb_movedown();
242
    document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hColor;
243
    if (actb_toid) clearTimeout(actb_toid);
244
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
245
}
246
function actb_movedown(){
247
    actb_rangeu++;
248
    actb_ranged++;
249
    actb_remake();
250
}
251
function actb_moveup(){
252
    actb_rangeu--;
253
    actb_ranged--;
254
    actb_remake();
255
}
256
function actb_penter(){
257
    if (!actb_display) return;
258
    actb_display = 0;
259
    var word = '';
260
    var c = 0;
261
    for (var i=0;i<=actb_keywords.length;i++){
262
        if (actb_bool[i]) c++;
263
        if (c == actb_pos){
264
            word = actb_keywords[i];
265
            break;
266
        }
267
    }
268
    a = word;//actb_keywords[actb_pos-1];//document.getElementById('tat_td'+actb_pos).;
269
    actb_curr.value = a;
270
    actb_removedisp();
271
}
272
function actb_removedisp(){
273
    actb_display = 0;
274
    if (document.getElementById('tat_frame')) document.body.removeChild(document.getElementById('tat_frame'));
275
    if (document.getElementById('tat_table')) document.body.removeChild(document.getElementById('tat_table'));
276
    if (actb_toid) clearTimeout(actb_toid);
277
}
278
function actb_checkkey(evt, sndr){
279
    a = evt.keyCode;
280
    if (a == 38){ // up key
281
        actb_goup();
282
    }else if(a == 40){ // down key
283
        actb_godown();
284
    }else if(a == 13){
285
        actb_penter();
286
    }
287
}
288
function actb_tocomplete(sndr,evt,arr){
289
    if (arr) actb_keywords = arr;
290
    if (evt.keyCode == 38 || evt.keyCode == 40 || evt.keyCode == 13) return;
291
    var i;
292
    if (actb_display){
293
        var word = 0;
294
        var c = 0;
295
        for (i=0;i<=actb_keywords.length;i++){
296
            if (actb_bool[i]) c++;
297
            if (c == actb_pos){
298
                word = i;
299
                break;
300
            }
301
        }
302
        actb_pre = word;//actb_pos;
303
    }else{ actb_pre = -1};
304

    
305
    if (!sndr) sndr = evt.srcElement;
306
    actb_curr = sndr;
307

    
308
    if (sndr.value == ''){
309
        actb_removedisp();
310
        return;
311
    }
312
    var t = sndr.value;
313
    var re = "";
314
    if (actb_firstText){
315
        re = new RegExp("^" + t, "i");
316
    }else{
317
        re = new RegExp(t, "i");
318
    }
319

    
320
    actb_total = 0;
321
    actb_tomake = false;
322
    for (i=0;i<actb_keywords.length;i++){
323
        actb_bool[i] = false;
324
        if (re.test(actb_keywords[i])){
325
            actb_total++;
326
            actb_bool[i] = true;
327
            if (actb_pre == i) actb_tomake = true;
328
        }
329
    }
330
    if (actb_toid) clearTimeout(actb_toid);
331
    if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
332
    actb_generate(actb_bool);
333
}
(1-1/100)