-
Notifications
You must be signed in to change notification settings - Fork 1
/
builder.html
94 lines (86 loc) · 2.82 KB
/
builder.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Core Workout Builder</title>
<link rel="stylesheet" href="styles/styles.css">
</head>
<body onload="loadCookie()">
<div id="workout-list" style="display:inline-block"></div>
<div id="add-button" class="noselect" onclick="addStep()" style="display:inline-block">Add Step</div>
<div id="save-button" class="noselect" onclick="saveWorkout()" style="display:inline-block">Save</div>
<div id="reset-button" class="noselect" onclick="resetWorkout()" style="display:inline-block">Reset</div>
<a id="link-button" href="default.html">
<div>← Back to Main Page</div>
</a>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/js.cookie-2.2.0.min.js" type="text/javascript"></script>
<script src="js/workout.js" type="text/javascript"></script>
<script>
function loadCookie() {
try {
var workout = JSON.parse(Cookies.get('customWorkout'));
} catch(e) {
var workout = {
"name":"Custom Workout",
"steps":[]
};
}
var wkElement = document.getElementById("workout-list");
renderWorkout(workout.steps, wkElement, builder=true);
if (workout.steps.length == 0) {
addStep();
}
}
function addStep() {
var newStep = document.createElement("div");
newStep.classList.add("stepContainer");
createDiv("Step Name", "step", newStep, editable=true);
createDiv("Length", "reps", newStep, editable=true);
createDelButton(newStep);
createWorkoutForm(null, newStep);
var wkElement = document.getElementById("workout-list");
wkElement.appendChild(newStep);
}
function saveWorkout() {
var stepList = document.getElementsByClassName("stepContainer");
var workout = {
"name":"Custom Workout",
"steps":[]
}
for (parents of stepList) {
var children = parents.childNodes;
var origText = $(children[1]).text();
var tryInt = parseInt(origText);
switch (getRadioVal(children[3], "workout")) {
case "time":
workout.steps.push({
"name":$(children[0]).text(),
"time":tryInt
});
break;
case "reps":
if (origText == tryInt) {
origText = tryInt;
}
workout.steps.push({
"name":$(children[0]).text(),
"reps":origText
});
}
}
Cookies.set('customWorkout', workout, { expires: 365 });
alert("Custom workout saved with " + workout.steps.length + " exercise steps");
}
function resetWorkout() {
if (confirm("Are you sure you want to reset your custom workout?")) {
Cookies.set('customWorkout', {
"name":"Custom Workout",
"steps":[]
}, { expires: 365 });
location.reload();
}
}
</script>
</body>
</html>