forked from xzilla/phppgadmin
-
Notifications
You must be signed in to change notification settings - Fork 280
/
aciur.js
400 lines (368 loc) · 8.6 KB
/
aciur.js
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
var nkeycode = 0;
var curopt = 0;
var bnsr = false;
var aSuggests = [];
var otxb = null;
var xo = null;
var acv = false;
var fac_c = 1;
var c_fac_c = 1;
var asg = new Array();
var rasg = new Array();
var rasgc = new Array();
var iMoR = false;
var g_c_tb = "";
var g_c_fk = "";
var g_c_sid = "";
var g_c_db = "";
var g_c_v = "";
var g_i_ac = true;
document.body.onclick=function() {deAC();};
function aS(aSuggests) {
if (aSuggests.length > 0) {
tA(aSuggests[curopt]);
}
}
function hKU(oEvent) {
nkeycode = oEvent.keyCode;
var iKeyCode = oEvent.keyCode;
if(iKeyCode!=13) {
if(iKeyCode==40 && (curopt+1)<=(rasg.length-1)) {
curopt++;
bnsr = true;
tA(rasg[curopt]);
htr(document.getElementById('option_tr_'+(curopt+1)));
} else if(iKeyCode==38 && ((curopt-1)<=(rasg.length-1) && (curopt-1)>=0)) {
curopt--;
bnsr = true;
tA(rasg[curopt]);
htr(document.getElementById('option_tr_'+(curopt+1)));
} else {
if ( (iKeyCode!=8 && iKeyCode <= 32) || (iKeyCode >= 33 && iKeyCode <= 46) || (iKeyCode >= 112 && iKeyCode <= 123)) {
} else {
var sTextboxValue = otxb.value.toLowerCase();
SG1(sTextboxValue);
bnsr = false;
}
}
}
else {
if(acv) {
hideAC();
}
return false;
}
}
function initac(tb,fk,sid,db,v) {
g_c_tb = tb;
g_c_fk = fk;
g_c_sid = sid;
g_c_db = db;
}
function sR(p_start,p_len) {
if(!bnsr) {
if (otxb.createTextRange) {
var oRange = otxb.createTextRange();
oRange.moveStart("character", p_start);
oRange.moveEnd("character", p_len - otxb.value.length);
oRange.select();
} else if (otxb.setSelectionRange) {
otxb.setSelectionRange(p_start, p_len);
}
} else {
if (otxb.createTextRange) {
var oRange = otxb.createTextRange();
oRange.moveStart("character",p_len);
oRange.moveEnd("character",p_len);
oRange.select();
} else if (otxb.setSelectionRange) {
otxb.setSelectionRange(p_len,p_len);
}
}
otxb.focus();
}
function tA(p_suggestion) {
if(nkeycode!=8) {
if ((otxb.createTextRange || otxb.setSelectionRange) && p_suggestion) {
var p_len = otxb.value.length;
otxb.value = p_suggestion;
sR(p_len, p_suggestion.length);
}
}
}
function findPosX(obj)
{
if(obj) {
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
}
function findPosY(obj)
{
if(obj) {
var curtop = 0;
var n = 0;
if (obj.y) {
curtop += obj.y;
}
else if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
}
return curtop;
}
}
function hideAC() {
var d = document.getElementById('ac');
d.innerHTML='';
d.style.zIndex=0;
d.style.border=0;
d.style.visibility='hidden';
acv = false;
}
function deAC() {
if(acv) {
hideAC();
}
}
function makenormaltr(id) {
var tr = document.getElementById(id);
tr.style.backgroundColor='white';tr.style.color='black';
}
function fillinval(val) {
var tx = document.getElementById('fac' + c_fac_c);
tx.value=val;
hideAC();
}
function showAC() {
var d = document.getElementById('ac');
d.innerHTML='';
var tb = document.getElementById('fac'+c_fac_c+'_ph');
d.style.top=findPosY(tb)+'px';
d.style.visibility='visible';
acv = true;
d.style.left=findPosX(tb)+'px';
d.style.border='1px solid black';
d.style.position='absolute';
d.style.width=(document.getElementById('aciwp' + c_fac_c).offsetWidth-3) + "px";
d.style.zIndex=20;
d.style.backgroundColor='white';
d.style.margin='0px';
d.style.padding='0px';
d.style.textAlign='left';
document.getElementById("ac_form").onsubmit=function(){return false;};
return d;
}
function aftr() {
for(i=0;i<rasg.length;i++) {
ftr(document.getElementById('option_tr_'+(i+1)));
}
}
function htr(obj) {
aftr();
obj.style.backgroundColor='#3d80df';
obj.style.color='white';
}
function ftr(obj) {
obj.style.backgroundColor='white';
obj.style.color='black';
}
function buildSelectOptions() {
if(rasg.length>0) {
var t = document.createElement('table');
var tb = document.createElement('tbody');
var d = showAC();
t.style.width='100%';
t.style.margin='0px';
t.style.padding='0px';
t.cellPadding='0px';
t.cellSpacing='0px';
t.style.zIndex=6;
t.style.visibility='visible';
for(i=0;i<rasg.length;i++) {
var tr = document.createElement('tr');
var td = document.createElement('td');
var tx = document.createTextNode(rasg[i]);
if(i==0) {
td.style.color='white';
td.id='option_tr_1';
td.style.backgroundColor='#3d80df';
} else {
td.id='option_tr_' + (i+1);
td.style.color='black';
td.style.backgroundColor='white';
}
td.onmouseover=function() { htr(this); this.style.cursor='pointer'; };
td.onmouseout=function() { ftr(this); this.style.cursor='normal'; };
td.onclick=function() { fillinval(this.firstChild.innerHTML); };
td.style.paddingLeft='10px';
td.style.fontSize='9pt';
td.style.fontFamily='Arial';
td.appendChild(tx);
tr.appendChild(td);
tb.appendChild(tr);
}
t.appendChild(tb);
d.appendChild(t);
} else {
hideAC();
}
}
function dF(v) {
g_i_ac = document.getElementById(v).checked;
}
function makeAC(tx,n,tb,fk,sid,db) {
otxb = document.getElementById(tx);
c_fac_c = n;
if(document.getElementById('no_ac').checked) {
if(acv) {
hideAC();
}
otxb = document.getElementById(tx);
v = otxb.value;
curopt = 0;
bnsr = false;
otxb.onkeyup = function (oEvent) {
if (!oEvent) { oEvent = window.event; } hKU(oEvent); };
initac(tb,fk,sid,db,v);
} else {
otxb.onkeyup = function() {};
}
}
function gfacc(s) {
return s.substr(3);
}
function iA(parent, node, referenceNode) {
parent.insertBefore(node, referenceNode.nextSibling);
}
var asg = new Array();
var rasg = new Array();
var rasgc = new Array();
function rS(tx) {
rasg = [];
rasgc = [];
var sTextboxValue = otxb.value.toLowerCase();
if (sTextboxValue.length > 0) {
for (var i=0;i<asg.length;i++) {
var c = asg[i];
if (c.indexOf(sTextboxValue) == 0) {
rasg.push(asg[i]);
}
}
buildSelectOptions();
} else {
hideAC();
}
}
function SG1(s) {
if(!iMoR && s.length>0) {
pr("autocomplete.php","tb="+g_c_tb+"&database="+g_c_db+"&server="+g_c_sid+"&fk="+g_c_fk+"&v="+escapeHTML(s)+"");
} else if(!s.length) {
hideAC();
}
}
function escapeHTML(s) {
s = escape(s);
s = s.replace(/\//g,"%2F");
s = s.replace(/\?/g,"%3F");
s = s.replace(/=/g,"%3D");
s = s.replace(/&/g,"%26");
s = s.replace(/@/g,"%40");
return s;
}
function rEB(v) {
var il = document.getElementsByTagName('input');
for(i in il) {
if(il[i].className=='ac_field' || il[i].className=='normal_field') {
if(v==false) {
il[i].className='normal_field';
il[i].setAttribute("autocomplete",'on');
} else {
il[i].className='ac_field';
il[i].setAttribute("autocomplete",'off');
}
}
}
}
function pgsg(v) {
prgsp(v);
}
function prgsp(v) {
var d = v.split("PPA_EOF;|"); // pondered using RegExp here, but overhead to gain ratio is not convincing
var l = d.length;
asg = [];
for(i=0;i<l;i++) {
asg.push(d[i]);
}
rS(otxb);
aS(rasg);
}
function rS(tx) {
rasg = [];
rasgc = [];
var sTextboxValue = otxb.value.toLowerCase();
if (sTextboxValue.length > 0) {
for (var i=0;i<asg.length;i++) {
var c = asg[i];
if (c.indexOf(sTextboxValue) == 0) {
rasg.push(asg[i]);
}
}
buildSelectOptions();
} else {
hideAC();
}
}
function pr(pg,sr) {
mii();
xo.open("POST",pg,true);
xo.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xo.onreadystatechange=xoc;
xo.send(sr);
}
function mii() {
if(!xo) {
/*@cc_on @*//*@if (@_jscript_version >= 5) try {
xo = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xo = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E) {
xo = false;
}
}
@end @*/if (!xo && typeof XMLHttpRequest!='undefined') {
xo = new XMLHttpRequest();
}
}
}
function xoc(){
iMoR = true;
szr = "";
if (xo.readyState==4) {
if(xo.status==200) {
pgsg(xo.responseText);
iMoR = false;
}
else {
alert("Oops, something unexpected happened, try again");
window.location.reload();
}
}
}