-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtabjax.js
153 lines (149 loc) · 4.32 KB
/
tabjax.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
var tabjax = new function () {
this.str2aa = function (data, rs, fs) {
var fa, i, j, r, ra = data.split(rs), t = [];
for (i in ra) {
r = [];
fa = ra[i].split(fs);
for (j in fa)
r.push(fa[j]);
t.push(r);
}
return t;
}
this.add = function (config) {
var base;
var ncols = (function () {
var i, j, n = 0;
for (i in config.base.show) {
m = config.base.show[i][1];
if (n < m)
n = m;
}
for (j in config.updates) {
for (i in config.updates[j].show) {
m = config.updates[j].show[i][1];
if (n < m)
n = m;
}
}
return n + 1;
})();
function $(id) { return document.getElementById(id); }
function $n(p) { return document.createElement(p); }
function $nt(s) { return document.createTextNode(s); }
function getURL(url, callback) {
var xhr;
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4)
callback(xhr.responseText, xhr.getResponseHeader("Content-Type"));
};
xhr.open('GET', url, true);
xhr.setRequestHeader(
"If-Modified-Since",
"Thu, 01 Jun 1970 00:00:00 GMT");
xhr.send();
}
function reload() {
var i, u;
for (i in config.updates) {
u = config.updates[i];
getURL(u.URL, function (d) {
var j, k, l, r, table, td, tds, trs, uaa, uf, ur;
uaa = u.translate(d);
table = $(config.table_id);
trs = table.childNodes;
for (j in trs) {
if (!trs.hasOwnProperty(j) || j == 0)
continue;
tds = trs[j].childNodes;
r = base[j - 1];
for (k in uaa) {
if (!uaa.hasOwnProperty(k))
continue;
ur = uaa[k];
if (u.match(r, ur)) {
if (u.ofilter)
u.ofilter(r, ur);
for (l in u.show) {
uf = ur[u.show[l][0]];
td = tds[u.show[l][1]];
td.replaceChild($nt(uf), td.firstChild);
}
break;
}
}
}
});
}
setTimeout(reload, config.interval);
}
table = $(config.table_id);
while (table.hasChildNodes())
table.removeChild(table.firstChild);
getURL(
config.base.URL,
function (d) {
var i, j, k, table, td, tr, tb;
base = config.base.translate(d);
table = $(config.table_id);
// filter
tr = $n('tr');
for (j = 0; j < ncols; j++) {
td = $n('td');
tb = $n('input');
tb.type = "text";
tb.onkeyup = function (e) {
var i, j, fss, table, td, tds, trs;
table = $(config.table_id);
trs = table.childNodes;
tds = table.firstChild.childNodes;
fss = [];
for (j in tds)
if (tds[j].firstChild)
fss.push(tds[j].firstChild.value);
for (i in trs) {
if (i == 0)
continue;
// trs[i].hidden = false;
if (trs[i].style)
trs[i].style.display = '';
if (!(tds = trs[i].childNodes))
continue;
for (j in tds) {
if (fss[j] == "")
continue;
if (!(td = tds[j].firstChild))
continue;
if (td.nodeValue.toLowerCase().indexOf(fss[j].toLowerCase())
< 0) {
// trs[i].hidden = true;
if (trs[i].style)
trs[i].style.display = 'none';
}
}
}
};
td.appendChild(tb);
tr.appendChild(td);
}
table.appendChild(tr);
// data
for (i in base) {
tr = $n('tr');
for (j = 0; j < ncols; j++) {
td = $n('td');
for (k in config.base.show)
if (config.base.show[k][1] == j)
td.appendChild($nt(base[i][config.base.show[k][0]]));
if (!td.hasChildNodes())
td.appendChild($nt(''));
tr.appendChild(td);
}
table.appendChild(tr);
}
}
);
reload();
};
};