-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
67 lines (59 loc) · 1.84 KB
/
main.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
(function () {
var rootQuestion = data;
var stack = [];
var app = new Ractive({
el: '#root',
template: '#easy-http-status-app',
data: {
currentItem: rootQuestion,
answer: null,
hasPrevious: null,
isIntroduction: true
},
hasNext: function() {
return this.get('currentItem')['yes'] || this.get('currentItem')['no'];
}
});
app.on('start', function (event, current) {
this.set({isIntroduction: false});
});
app.on('answer-yes', function (event, current) {
var next = current['yes'];
if (next['yes']) {
if (app.hasNext()) {
stack.push(this.get('currentItem'));
this.set({hasPrevious: true});
}
this.set({currentItem: current['yes']});
} else if (next['http_status']) {
stack.push(current);
this.set({answer: next['http_status']});
}
});
app.on('answer-no', function (event, current) {
var next = current['no'];
if (next['no']) {
if (app.hasNext()) {
stack.push(this.get('currentItem'));
this.set({hasPrevious: true});
}
this.set({currentItem: current['no']});
} else if (next['http_status']) {
stack.push(current);
this.set({answer: next['http_status']});
}
});
app.on('go-back', function (event, current) {
var item = stack.pop();
if (item) this.set({currentItem: item, answer: null});
if (stack.length == 0) this.set({hasPrevious: null})
});
app.on('restart', function (event) {
stack = [];
this.set({
currentItem: rootQuestion,
answer: null,
hasPrevious: null
});
});
}());