-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStep.js
127 lines (100 loc) · 3.98 KB
/
Step.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
class Step{
constructor(number, description, ingredients, time){
this.number = number;
this.description = description;
this.ingredients = ingredients;
this.time = time;
}
static createIngredientsWindow(ingredients){
let ingreds = document.createElement('Ingredients');
let title = document.createElement('IngredientsTitle')
title.innerHTML = "Ingredients";
ingreds.appendChild(title);
let list = document.createElement('ul');
ingredients.forEach(ingredient => {
var currentIngredWindow = document.createElement('li')
currentIngredWindow.innerHTML = ingredient.toString()
list.appendChild(currentIngredWindow);
});
ingreds.appendChild(list);
return ingreds;
}
static ingredientListToString(list, sep){
let out = "";
list.forEach(item => {
out += "-" + item.toString() + sep;
});
return out;
}
replaceIngredient(ingredientFrom, ingredientTo){
for(var i = 0; i < this.ingredients.length; i++){
if(this.ingredients[i].name == ingredientFrom.name){
ingredientTo.scale(this.ingredients[i].amount/ingredientFrom.amount);
this.ingredients[i] = ingredientTo;
this.description = this.description.replace(ingredientFrom.name, ingredientTo.name);
}
}
}
display(window, sound, end){
this.sound = sound;
let stepWindow = document.createElement('Step');
this.id = IdManager.getID();
stepWindow.id = this.id;
let titleWindow = document.createElement('StepTitle');
titleWindow.innerHTML = "Step " + this.number;
let timeToCompleteWindow = document.createElement('StepTimeToComplete');
timeToCompleteWindow.innerHTML = "(Time to complete: " + Timer.secsToTime(this.time) + ")";
let descWindow = document.createElement('StepDescription');
descWindow.innerHTML = this.description;
stepWindow.appendChild(titleWindow);
stepWindow.appendChild(timeToCompleteWindow);
let subwindow = document.createElement('StepInfo');
let stepSeparatorId;
if(this.ingredients.length > 0){
let ingredientsWindow = Step.createIngredientsWindow(this.ingredients);
subwindow.appendChild(ingredientsWindow);
let stepSeparator = document.createElement('StepSeparator');
stepSeparatorId = IdManager.getID()
stepSeparator.id = stepSeparatorId;
subwindow.appendChild(stepSeparator);
}
else{
descWindow.style.borderLeft = "0px";
}
subwindow.appendChild(descWindow);
stepWindow.appendChild(subwindow);
document.getElementById(window).appendChild(stepWindow);
if(this.ingredients.length > 0){
this.animate(stepSeparatorId);
}
this.startbutton = new Button("Start step", window, "StartButton", ()=>(this.start(end)));
this.startbutton.show();
}
animate(id){
document.getElementById(id).style.height = "auto";
var divHeight;
var obj = document.getElementById(id);
if(obj.offsetHeight) {
divHeight=obj.offsetHeight;
} else if(obj.style.pixelHeight) {
divHeight=obj.style.pixelHeight;
}
document.getElementById(id).style.height = "0px";
var containerHeight = document.getElementById(id).parentNode.offsetHeight;
document.getElementById(id).style.height = divHeight + "px";
}
start(endFunction){
this.startbutton.hide();
this.endFunction = endFunction;
this.timer = new Timer(this.time, ()=>(this.end()), "data/timer.mp3");
this.timer.show(this.id, 9);
this.timer.start();
}
delete(){
var elem = document.getElementById(this.id);
elem.parentNode.removeChild(elem);
}
end(){
this.endFunction();
}
}