-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
134 lines (105 loc) · 3.63 KB
/
index.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
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
128
129
130
131
132
133
134
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The HTML5 Herald</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">
<!-- Toffle -->
<script src="toffle.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<input type="button" value="Let's Toffle!" onclick="generateMarkup()">
<div id="container"></div>
<div id="cakeContainer"></div>
<br><div id="TimerBox"></div>
<script id="myInfoTemplate" type="text/toffle-template">
<h1>First Name</h1>
<p> <^ input.fName ^> is my name </p><br>
<h2>Second Name</h2>
<p><^ input.sName ^></p><br>
<h4>Pets:</h4>
<^ each pet in input.pets ^>
<^ plug pettemplate pet false "Waffles and IceCream"^>
<^/^>
<h4>Pets supercute:</h4>
<^ match pet in ??catIsSuperCute input.pets ^>
<^ plug pettemplate pet true input.pets[[0]].name^>
<^/^>
<h3>Age</h3>
<p><^ input.age ^></p><br>
<^ if input.isLoved ^> There is an age! <^/^>
<^ ??isBetween input.age 20 true 40 ^> Between 20 and 40!!! <^/^>
</script>
<script id="pettemplate" type="text/toffle-template" data-params="petInfo|valtest|faveFood">
<hr>
<p>Name: <^ petInfo.name ^> just loves <^ faveFood ^></p>
<p>Cuteness Level: <^ petInfo.cutenessLevel ^></p>
<^ if valtest ^> HELLO! <^/^>
<hr>
</script>
<script>
// Test JSON
var json = {
fName:"Nikolas",
sName:"Howard",
favouritefood:"Egg Custard Tarts",
isLoved: null,
age:25,
pets:[
{
name:"Wilfred",
cutenessLevel: 6
},
{
name:"Scrabbles",
cutenessLevel: 4
},
{
name:"Neighbour Cat",
cutenessLevel: 2
},
{
name:"Kiddles",
cutenessLevel: 10
},
{
name:"Fluffums",
cutenessLevel: 11
}
]
};
var myTemp;
function generateMarkup()
{
// lets see how long it takes do generate our markup using our templates.
var d = new Date();
var startTime = d.getTime();
if(!myTemp)
{
myTemp = toffle.template({
template: document.getElementById('myInfoTemplate'),
helpers: {
isYoungerThan: function(age, targetAge){
return age < targetAge;
},
catIsSuperCute: function(cat){
return cat.cutenessLevel > 4;
},
isBetween: function(age, lower, testbool, upper){
return (age >= lower) && (age <= upper) && testbool
}
}
});
}
var output = myTemp.go({ input: json });
document.getElementById('container').innerHTML = output;
// display the elapsed time
document.getElementById("TimerBox").innerHTML = "Time Taken: " + ((new Date().getTime() - startTime) / 1000) + "ms" ;
}
</script>
</body>
</html>