-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag-hinting.js
120 lines (116 loc) · 2.37 KB
/
tag-hinting.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
// JavaScript Document
var last;
var arr = new Array();
function hint(me, e)
{
var key = e.keyCode;
if(key == 38 || key == 40)
{
var firstchild = document.getElementById('hintwords').firstChild;
//alert(firstchild);
//alert(firstchild.nextSibling.nextSibling.nodeValue);
if(key == 40)
{
if(typeof(current) == 'object')
{
current.style.backgroundColor = '#fff';
current = current.nextSibling.nextSibling;
current.style.backgroundColor = '#ccc';
displayhints(current, me);
last = key;
}
else
{
firstchild.style.backgroundColor = '#ccc';
current = firstchild;
displayhints(current, me);
last = key;
}
}
else if(key == 38)
{
if(typeof(current) == 'object')
{
current.style.backgroundColor = '#fff';
current = current.previousSibling.previousSibling;
current.style.backgroundColor = '#ccc';
displayhints(current, me);
last = key;
}
}
}
else if(key == 13)
hidehint();
else
{
current = '';
last = '';
var iter = 0;
var mat = new Array();
var val = me.value.split(",");
var lenval = val.length;
if(lenval == 1)
{
val = me.value.replace(" ","");
}
else
{
val = val[lenval - 1].replace(" ","");
}
var len = val.length;
if(len>0)
{
for(iter=0 ; iter < arr.length; iter++)
{
var patt = new RegExp( val ,'gi');
var result = patt.exec(arr[iter]);
if(result == val)
{
mat.push(arr[iter]);
}
}
var str = '';
for(iter = 0; iter < mat.length ; iter++)
{
if(str == '')
{
str = str + '<span>' + mat[iter] + '</span>';
}
else
{
str = str + '<br>' + '<span>' + mat[iter] + '</span>';
}
}
document.getElementById('hintwords').style.display = 'block';
document.getElementById('hintwords').innerHTML = str;
}
else
{
document.getElementById('hintwords').innerHTML = '';
}
}
}
function displayhints(current, me)
{
val = me.value.split(",");
lenval = val.length;
if(lenval == 1)
me.value = current.innerHTML;
else
{
i =0;
hints = '';
while(i < lenval-1)
{
hints += val[i]+',';
i++;
}
hints += current.innerHTML;
me.value = hints;
}
}
function hidehint()
{
document.getElementById('hintwords').style.display = 'none';
document.getElementById('hintwords').innerHTML = '';
}