-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
114 lines (102 loc) · 2.82 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Prosperity</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles/reset.css">
<link rel="stylesheet" href="styles/cards.css">
<style type="text/css">
body, html {
width: 100%;
height: 100%;
margin: 0;
border: 0;
padding: 0;
font-family: "Helvetica";
text-align: center;
}
h2 {
font-size: 2em;
margin: 0.2em;
}
.card {
vertical-align: bottom;
margin: 0.5cm;
position: relative;
}
</style>
</head>
<body>
<div id="card-sets"></div>
<script src="lib/handlebars-v4.0.5.js"></script>
<script id="card-template" type="text/x-handlebars-template">
<article class="card">
<div class="location">
<h1 class="title">{{location.title}}</h1>
<p class="ability">{{location.ability}}</p>
<p class="resources">
{{#if location.resources.food}}
<span class="food"></span>
{{/if}}
</p>
</div>
<img src="{{image}}">
<div class="trait">
<h1 class="title">{{trait.title}}</h1>
<p class="ability">{{trait.ability}}</p>
<p class="resources">
{{#if location.resources.food}}
<span class="food"></span>
{{/if}}
</p>
</div>
</article>
</script>
<script>
var card_template_source = document.getElementById("card-template").textContent;
var card_template = Handlebars.compile(card_template_source);
var container = document.getElementById("card-sets");
var render_cards = function(card_sets){
export_only = location.hash.replace(/#/, "");
for(set_name in card_sets){
if(!export_only || export_only == set_name){
var cards_in_set = card_sets[set_name];
var h2 = document.createElement("h2");
h2.textContent = set_name;
container.appendChild(h2);
for(var i = 0; i < cards_in_set.length; i++){
var card = cards_in_set[i];
container.innerHTML += card_template(card).trim();
}
if(export_only){
while(i < 10*7){
container.innerHTML += "<div class='card back'/>";
i += 1;
}
}
}
}
if(!export_only || export_only == "Back"){
container.innerHTML += "<h2>Back</h2>";
container.innerHTML += "<div class='card back'/>";
}
};
var request = new XMLHttpRequest();
request.open('GET', 'cards.json', true);
request.onload = function() {
if (this.response) {
var data = JSON.parse(this.response);
render_cards(data);
} else {
throw new Error("GET cards.json status code " + this.status);
}
};
request.onerror = function() {
// There was a connection error of some sort
throw new Error("Failed to GET cards.json");
};
request.send();
</script>
</body>
</html>