-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
339 lines (265 loc) · 6.43 KB
/
Copy pathscript.js
File metadata and controls
339 lines (265 loc) · 6.43 KB
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
"use strict";
/*
* We want to disable the "enter" key from submitting the form when
* participants are entering strategy mixtures.
* This is to force them to press the rows instead of just using easy
* keyboard input.
*/
function disableEnter(e)
{
var keycode;
e = e || window.event;
keycode = e.which || e.keyCode;
if (keycode != 13)
return(true);
if (e.preventDefault)
e.preventDefault();
else
e.returnValue = false;
if (e.stopPropagation)
e.stopPropagation();
else
e.cancelBubble = true;
return(false);
}
function onNavUp()
{
var nav = document.getElementById('nav');
var btn = document.getElementById('navButton');
if ( ! ('' == nav.style.maxHeight || nav.style.maxHeight == '0px')) {
nav.style.maxHeight = '0px';
btn.style.textShadow = 'none';
}
}
function onNav(event)
{
var nav = document.getElementById('nav');
var btn = document.getElementById('navButton');
if ('' == nav.style.maxHeight || nav.style.maxHeight == '0px') {
nav.style.maxHeight = '100em';
btn.style.textShadow = '1px 1px #fff';
} else {
nav.style.maxHeight = '0px';
btn.style.textShadow = 'none';
}
if (event.stopPropagation)
event.stopPropagation();
else
event.cancelBubble = true;
return false;
}
function timerCountdown(donefunc, e, value)
{
var now;
now = Math.floor(new Date().getTime() / 1000);
if (now >= value) {
if (null !== donefunc) {
donefunc();
}
return;
}
doClearNode(e);
formatCountdown(value - now, e);
setTimeout(timerCountdown, 1000, donefunc, e, value);
}
function doHideNode(e)
{
if (null !== e && ! e.classList.contains('noshow'))
e.classList.add('noshow');
return(e);
}
function doHide(name)
{
return(doHideNode(document.getElementById(name)));
}
function doUnhideNode(e)
{
if (null !== e)
e.classList.remove('noshow');
return(e);
}
function doUnhide(name)
{
return(doUnhideNode(document.getElementById(name)));
}
function doClearNode(e)
{
if (null === e)
return(null);
while (e.firstChild)
e.removeChild(e.firstChild);
return(e);
}
function doValue(name, value)
{
var e;
if (null !== (e = document.getElementById(name)))
e.value = value;
}
function doClear(name)
{
return(doClearNode(document.getElementById(name)));
}
function doClearReplaceMarkup(name, str)
{
var e;
if (null !== (e = doClearNode(document.getElementById(name))))
e.innerHTML = str;
return(e);
}
function doClearReplaceNode(node, str)
{
var e;
if (null !== (e = doClearNode(node)))
e.appendChild(document.createTextNode(str));
return(e);
}
function doClearReplace(name, str)
{
return(doClearReplaceNode(document.getElementById(name), str));
}
function doValueClass(cls, str)
{
var e, i, sz;
e = document.getElementsByClassName(cls);
for (i = 0, sz = e.length; i < sz; i++)
e[i].value = str;
}
function parseJson(resp)
{
var p;
try {
p = JSON.parse(resp);
} catch (error) {
console.log('JSON parse fail: ' + error);
return(null);
}
return(p);
}
function doClearReplaceClass(cls, str)
{
var e, i, sz;
e = document.getElementsByClassName(cls);
for (i = 0, sz = e.length; i < sz; i++) {
doClearNode(e[i]);
e[i].appendChild(document.createTextNode(str));
}
}
/*
* Give a number of seconds "v", format the time as a human-readable
* string (e.g., 1d4h3m).
* Make sure that v is non-negative.
*/
function formatCountdown(v, e)
{
var p, span, showseconds;
/* Clamp time. */
if (v < 0)
v = 0;
showseconds = v < 60;
span = document.createElement('span');
if (v >= 24 * 60 * 60) {
p = Math.floor(v / (24 * 60 * 60));
span.appendChild(document.createTextNode(p));
span.appendChild(document.createTextNode('d'));
v -= p * (24 * 60 * 60);
}
e.appendChild(span);
span = document.createElement('span');
if (v >= 60 * 60) {
p = Math.floor(v / (60 * 60));
span.appendChild(document.createTextNode(p));
span.appendChild(document.createTextNode('h'));
v -= p * (60 * 60);
}
e.appendChild(span);
span = document.createElement('span');
if (v >= 60) {
p = Math.floor(v / 60);
span.appendChild(document.createTextNode(p));
span.appendChild(document.createTextNode('m'));
v -= p * (60);
}
e.appendChild(span);
if (showseconds) {
span = document.createElement('span');
span.setAttribute('class', 'seconds');
p = Math.floor(v);
span.appendChild(document.createTextNode(p));
span.appendChild(document.createTextNode('s'));
e.appendChild(span);
}
}
function getQueryVariable(variable)
{
var query, vars, i, pair;
query = window.location.search.substring(1);
vars = query.split("&");
for (i = 0; i < vars.length; i++) {
pair = vars[i].split("=");
if(pair[0] == variable)
return(pair[1]);
}
return(null);
}
function sendQuery(url, setup, success, error)
{
var xmlhttp = new XMLHttpRequest();
if (null !== setup)
setup();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200 && null !== success)
success(xmlhttp.responseText);
else if (xmlhttp.readyState == 4 && null !== error)
error(xmlhttp.status);
};
xmlhttp.open('GET', url, true);
xmlhttp.send(null);
}
function sendFormData(oFormElement, formdata, setup, error, success)
{
var xmlhttp = new XMLHttpRequest();
if (null !== setup)
setup();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200 && null !== success)
success(xmlhttp.responseText);
else if (xmlhttp.readyState == 4 && null !== error)
error(xmlhttp.status);
};
xmlhttp.open(oFormElement.method, oFormElement.action, true);
xmlhttp.send(formdata);
return(false);
}
function sendForm(oFormElement, setup, error, success)
{
return(sendFormData(oFormElement,
new FormData(oFormElement), setup, error, success));
}
/*
* Check our URL to see if we have a session identifier and/or session
* cookie in our query string.
* This happens if we're invoked from a cookie-less place.
*/
function getURL(base)
{
var sessid, sesscookie, url;
url = base;
if (null !== (sessid = getQueryVariable('sessid')) &&
null !== (sesscookie = getQueryVariable('sesscookie')))
url += '?sessid=' + sessid + '&sesscookie=' + sesscookie;
return(url);
}
/*
* If we're calling from a cookie-less place (e.g., Mechanical Turk
* external window), then append our session information to the form.
*/
function augmentForm(e)
{
var sessid, sesscookie;
if (null !== (sessid = getQueryVariable('sessid')) &&
null !== (sesscookie = getQueryVariable('sesscookie'))) {
e.append('sessid', sessid);
e.append('sesscookie', sesscookie);
}
}