-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.js
181 lines (150 loc) · 4.98 KB
/
web.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
// web.js
// 2009-05-31
// This is the web browser companion to fulljslint.js.
/*jslint browser: true, evil: true */
/*members checked, clearall, cookie, edition, getElementById, getElementsByName,
getTime, goodparts, indent, indexOf, innerHTML, join, length, onchange,
onclick, parse, predef, push, recommended, report, select, setTime, sort,
split, stringify, substring, toGMTString, value
*/
"use strict";
var JSLINT;
(function () {
var c = document.cookie,
predefined = document.getElementById('predef'),
cluster = {
goodparts: [
'bitwise', 'eqeqeq', 'immed', 'newcap', 'nomen', 'onevar',
'plusplus', 'regexp', 'undef', 'white'
],
clearall: []
},
i, // Loop counter
indent = document.getElementById('indent'),
input = document.getElementById('input'),
jslintstring = document.getElementById('jslintstring'),
n, // A dom node
ns, // An array of dom nodes
nclear,
nclick,
o, // The options object
options = [
'adsafe', 'bitwise', 'browser', 'cap', 'css', 'debug', 'eqeqeq',
'evil', 'forin', 'fragment', 'immed', 'laxbreak', 'newcap',
'nomen', 'on', 'onevar', 'passfail', 'plusplus', 'regexp',
'rhino', 'safe', 'sidebar', 'strict', 'sub', 'undef', 'white',
'widget'
],
output = document.getElementById('output');
function get_check(o) {
var n = document.getElementById(o);
return n && n.checked;
}
function set_check(o, b) {
var n = document.getElementById(o);
if (n) {
n.checked = b;
}
}
function show_jslint_options() {
var a = [], j, oj, s;
for (j = 0; j < options.length; j += 1) {
oj = options[j];
if (get_check(oj)) {
a.push(oj + ': true');
}
}
if (get_check('white') && +indent.value > 0) {
a.push('indent: ' + indent.value);
}
s = '/*jslint ' + a.join(', ') + ' */';
jslintstring.innerHTML = s;
}
function set_cluster(n) {
document.getElementById(n).onclick = function (e) {
var c = cluster[n];
for (i = 0; i < options.length; i += 1) {
set_check(options[i], false);
}
for (i = 0; i < c.length; i += 1) {
set_check(c[i], true);
}
indent.value = '4';
predefined.value = '';
};
// Show the jslintstring options.
show_jslint_options();
}
input.onchange = function (e) {
output.innerHTML = '';
};
// Display the edition.
document.getElementById('edition').innerHTML = 'Edition ' + JSLINT.edition;
// Add click event handlers to the [JSLint] and [clear] buttons.
ns = document.getElementsByName('jslint');
nclick = function (e) {
// Make a JSON cookie of the current options.
var d = new Date(), j, oj, op = {};
for (j = 0; j < options.length; j += 1) {
oj = options[j];
op[oj] = get_check(oj);
}
op.indent = +indent.value || 4;
oj = predefined.value;
if (oj) {
op.predef = oj.split(/\s*,\s*/);
}
d.setTime(d.getTime() + 1e10);
document.cookie = 'jslint=' + JSON.stringify(op) + ';expires=' +
d.toGMTString();
// Call JSLint and obtain the report.
JSLINT(input.value, op);
output.innerHTML = JSLINT.report();
input.select();
return false;
};
nclear = function (e) {
input.value = '';
output.innerHTML = '';
input.select();
return false;
};
for (i = 0; i < ns.length; i += 1) {
n = ns[i];
switch (n.value) {
case 'JSLint':
n.onclick = nclick;
break;
case 'clear':
n.onclick = nclear;
break;
}
}
indent.onchange = predefined.onchange =
document.getElementById('options').onclick = function (e) {
show_jslint_options();
};
// Recover the JSLint options from a JSON cookie.
if (c && c.length > 8) {
i = c.indexOf('jslint={');
if (i >= 0) {
c = c.substring(i + 7);
i = c.indexOf('}');
if (i > 1) {
c = c.substring(0, i + 1);
o = JSON.parse(c);
for (i = 0; i < options.length; i += 1) {
set_check(options[i], o[options[i]]);
}
indent.value = o.indent || 4;
predefined.value = o.predef instanceof Array ?
o.predef.join(',') : '';
}
}
}
// Show the jslintstring options.
show_jslint_options();
set_cluster('goodparts');
set_cluster('clearall');
input.select();
}());