-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
84 lines (64 loc) · 1.95 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Created with JetBrains WebStorm.
* User: alex
* Date: 6/8/13
* Time: 5:39 PM
* To change this template use File | Settings | File Templates.
*/
var childrenList = [new Children("John", "eat", "apple"),
new Children("Jack", "lick", "brick"),
new Children("Olga", "throw", "TNT") ];
var iceCreamTastes = ['chocolate', 'strawberry', 'vanile'];
var iceCreamShapes = ['cone', 'cream', 'stick'];
var actions = ['bite', 'blow', 'leak', 'crash', 'sell'];
/**
* Show master to change the child
*/
function showDialog(){
debug('Action');
master.show(new Array({name: "Child", data:childrenList},
{name: "Action", data:actions},
{name: 'Shape', data:iceCreamShapes},
{name: 'Taste', data:iceCreamTastes})
, onComplete);
document.getElementById('content').style.display = 'none';
master._container.style.display = 'block';
}
/**
* Callback when finishing the master
*/
function onComplete(data){
debug('dialog completed');
document.getElementById('content').style.display = 'block';
master._container.style.display = 'none';
for(var i=0; i < childrenList.length; i++){
if(childrenList[i] === data[0].data){
var ice = new IceCream(data[2].data, data[3].data);
var child = childrenList[i];
child.actionItem = ice;
child.action = data[1];
}
}
displayChildrens();
}
/**
*
*/
function displayChildrens(){
storyUl = document.getElementById('story');
storyUl.innerHTML = '';
for(var i = 0; i < childrenList.length; i++){
var li = document.createElement("li");
li.appendChild(document.createTextNode(childrenList[i].print()));
storyUl.appendChild(li);
}
}
/**
*
*/
function initStory(){
debug('initStory');
displayChildrens();
master = new ChooseMaster(document.getElementById('dialog'));
}
listen("load", window, initStory);