-
Notifications
You must be signed in to change notification settings - Fork 23
/
30c3.js
67 lines (59 loc) · 2.28 KB
/
30c3.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
var problems = [];
var currentProblem = 0;
var guideSlug = 'crew_30c3';
function start(btn) {
$('.download-document').click(function(){
var data = EUCopyright.collectData();
EUCopyright.compile(data, EUCopyright.settings).done(EUCopyright.createDownload);
});
$('input[type=checkbox]').each(function(i, cb) {
if (cb.checked) {
var isDuplicate = false;
for (var j=0; j<problems.length; j++) { // is it already in there?
if (problems2questions[problems[j][0]][0] == problems2questions[cb.value][0]) {
// first question for this problem is equal? TODO this only works in simple cases
isDuplicate = true;
problems[j][1] += '<br />& '+cb.getAttribute('title');
}
}
if (!isDuplicate) problems.push([cb.value, cb.getAttribute('title')]);
}
});
if (problems.length > 0) {
$('.container')[0].className = 'container step-problem'; // switch to next "tab"
$('.download-document').click(function(e){ step() }); // make final button do the right thing
if (typeof guideSlug != 'undefined') {
EUCopyright.loadGuide(guideSlug);
} else {
EUCopyright.loadGuide('30c3');
}
step();
} else { // nothing selected
btn.innerHTML = "Please select a problem above before continuing »";
}
}
function step() {
if (currentProblem < problems.length) { // not at end yet
$('#step-problem h2')[0].innerHTML = problems[currentProblem][1];
// move last q's back to hidden container
var cl = document.getElementById('problem').children.length;
for (var i=0; i<cl; i++) {
$('#questions')[0].appendChild($('#problem')[0].children[0]);
}
// fetch new q's
$(problems2questions[problems[currentProblem][0]]).each(function(i, q) {
$('#problem')[0].appendChild($('.q-'+q)[0]);
});
if (currentProblem == problems.length-1) {
$('#next').hide();
$('.give-name').show();
$('.download-document').show();
}
currentProblem++;
$('#problem').find(':input:first').focus(); // TODO doesn't work?
//$('#problem textarea')[0].focus(); // if there's a textarea, place the cursor inside
} else { // reached end
$('.container')[0].className = 'container step-end';
$('#step-end').find(':input:first')[0].focus(); // TODO doesn't work?
}
}