-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathindex.html
342 lines (319 loc) · 19.7 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html>
<html lang="en" ng-app="turtleFacts">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Turtle Facts and Quiz</title>
<!-- Bootstrap css and my own css -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7"
crossorigin="anonymous">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Turtle Facts Quiz</h1>
<h3>
Learn about all the turtles below before you decide to take on the
<strong>TURTLE QUIZ</strong>
</h3>
</div>
<!-- Hook on the controller for this view and specify when to show it using ng-hide -->
<div ng-controller="listCtrl as list" ng-hide="list.quizMetrics.quizActive || list.quizMetrics.resultsActive">
<!-- top search bar with start quiz button using bootstrap -->
<form class="form-inline well well-sm clearfix">
<span class="glyphicon glyphicon-search"></span>
<input
type="text"
placeholder="Search..."
class="form-control"
ng-model="list.search">
<button class="btn btn-warning pull-right"
ng-click="list.activateQuiz()">
<strong>Start Quiz</strong>
</button>
</form>
<!-- row to contain the list of turtles -->
<div class="row">
<!-- ng-repeat allows areas of markup to be repeated for a set number of times using model data -->
<!-- in this case it is a property on the view model called data which is being filtered using the search -->
<!-- property on the model -->
<div class="col-sm-6" ng-repeat="turtle in list.data | filter:list.search">
<!-- using a bootstrap well to style -->
<div class="well well-sm">
<div class="row">
<div class="col-md-6">
<!-- ng-src instead of src to allow correct functionality with angular -->
<img ng-src="{{turtle.image_url}}"
class="img-rounded img-responsive well-image">
</div>
<div class="col-md-6">
<!-- ng-src instead of src to allow correct functionality with angular -->
<h4>{{turtle.type}}</h4>
<!-- more angular data binding -->
<p><strong>Locations: </strong>{{turtle.locations}}</p>
<p><strong>Size: </strong>{{turtle.size}}</p>
<p><strong>Average Lifespan: </strong>{{turtle.lifespan}}</p>
<p><strong>Diet: </strong>{{turtle.diet}}</p>
<!-- ng-click is an angular directive to allow click events within angular -->
<!-- data-toggle and data-target are bootstrap attributes to trigger the popup modal -->
<button class="btn btn-primary pull-right"
data-toggle="modal"
data-target="#turtle-info"
ng-click="list.changeActiveTurtle(turtle)">Learn More</button>
</div>
</div><!-- row -->
</div><!-- well -->
</div><!-- col-xs-6 -->
</div>
<!-- the markup for the modal -->
<div class="modal" id="turtle-info">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<!-- more usage of angular data binding -->
<h2>{{list.activeTurtle.type}}</h2>
</div>
<div class="modal-body">
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<!-- ng-src used again instead of src -->
<img ng-src="{{list.activeTurtle.image_url}}" class="img-rounded img-responsive">
</div>
</div>
<div class="row top-buffer">
<div class="col-md-6">
<!-- angular data binding -->
<p><strong>Locations: </strong>{{list.activeTurtle.locations}}</p>
<p><strong>Size: </strong>{{list.activeTurtle.size}}</p>
<p><strong>Average Lifespan: </strong>{{list.activeTurtle.lifespan}}</p>
<p><strong>Diet: </strong>{{list.activeTurtle.diet}}</p>
</div>
<div class="col-xs-12 top-buffer">
<!-- angular data binding and data-dismiss for bootstrap -->
<p>{{list.activeTurtle.description}}</p>
<button class="btn btn-danger pull-right"
data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!-- List Controller -->
<!-- Attach the quizCtrl to the view and ng-show when the quizActive flag is set -->
<div ng-controller="quizCtrl as quiz" ng-show="quiz.quizMetrics.quizActive">
<div class="row">
<div class="col-xs-8">
<h2>Progress:</h2>
<div class="btn-toolbar">
<!-- ng-repeat to loop throuh all questions and display the button markup for each -->
<!-- ng-class conditionally displaying bootstrap classes when a question has been answered or not -->
<!-- ng-click to call method setActiveQuestion to move to selected question -->
<!-- the $index argument is an angular variable that contains the index of the current ng-repeat iteration -->
<button class="btn"
ng-repeat="question in quiz.dataService.quizQuestions"
ng-class="{'btn-info': question.selected !== null, 'btn-danger': question.selected === null}"
ng-click="quiz.setActiveQuestion($index)">
<!-- display glyphicons -->
<!-- ng-class to style glypicons -->
<span class="glyphicon"
ng-class="{'glyphicon-pencil': question.selected !== null, 'glyphicon-question-sign': question.selected === null}"></span>
</button>
</div>
</div>
<div class="col-xs-4">
<div class="row">
<h4>Legend:</h4>
<div class="col-sm-4">
<button class="btn btn-info">
<span class="glyphicon glyphicon-pencil"></span>
</button>
<p>Answered</p>
</div>
<div class="col-sm-4">
<button class="btn btn-danger">
<span class="glyphicon glyphicon-question-sign"></span>
</button>
<p>Unanswered</p>
</div>
</div>
</div>
</div><!-- progress area -->
<div class="row">
<div class="alert alert-danger"
ng-show="quiz.error">
Error! You have not answered all of the questions!
<button class="close" ng-click="quiz.error = false">×</button>
</div>
<h3>Question:</h3>
<div class="well well-sm" ng-hide="quiz.finalise">
<div class="row">
<div class="col-xs-12">
<!-- angular {{}} notation for expressions to be evaluated -->
<!-- adds 1 to activeQuestion as it is zero index. Then displays the question -->
<!-- will be in the form of "3. this is the third question" -->
<!-- where the 3. is the incremented activeQuestion -->
<h4>{{quiz.activeQuestion+1 + ". " + quiz.dataService.quizQuestions[quiz.activeQuestion].text}}</h4>
<!-- ng-if will only render the below markup when true. Unlike ng-show or ng-hide which -->
<!-- simply doesnt show the markup, but it is still rendered in the source. -->
<!-- ng-if will not even render the markup -->
<!-- this is done in the below two sections to aviod a url being displayed as a question -->
<!-- or text being entered as an image url and causing issues -->
<div class="row"
ng-if="quiz.dataService.quizQuestions[quiz.activeQuestion].type === 'text'">
<div class="col-sm-6" ng-repeat="answer in quiz.dataService.quizQuestions[quiz.activeQuestion].possibilities">
<h4 class="answer"
ng-class="{'bg-info': $index === quiz.dataService.quizQuestions[quiz.activeQuestion].selected}"
ng-click="quiz.selectAnswer($index)">
{{answer.answer}}
</h4>
</div>
</div>
<!-- notice the ng-if being used again -->
<!-- only the below section or the above section will display, never both -->
<!-- this will depend on if the current question is set to image or text -->
<div class="row"
ng-if="quiz.dataService.quizQuestions[quiz.activeQuestion].type === 'image'">
<!-- more bootstrap and another ng-repeat, this time looping through the possible answers -->
<div class="col-sm-6" ng-repeat="answer in quiz.dataService.quizQuestions[quiz.activeQuestion].possibilities">
<div class="image-answer"
ng-class="{'image-selected': $index === quiz.dataService.quizQuestions[quiz.activeQuestion].selected}"
ng-click="quiz.selectAnswer($index)">
<img ng-src="{{answer.answer}}">
</div>
</div>
</div>
</div>
</div>
<!-- ng-click will call the questionAnswered method on the controller -->
<button class="btn btn-warning" ng-click="quiz.questionAnswered()">Continue</button>
</div>
<!-- this section is the prompt to be show when the user finishes the quiz to ensure they want to continue -->
<!-- it only shows when the finalise flag is true -->
<!-- clicking yes will call the finaliseAnswers method which will send the user to the results page -->
<!-- clicking no will remove the finalise flag and this put the user back into the quiz interface -->
<div class="well well-sm" ng-show="quiz.finalise">
<div class="row">
<div class="col-xs-12">
<h3>Are you sure you want to submit your answers?</h3>
<button class="btn btn-success" ng-click="quiz.finaliseAnswers()">Yes</button>
<button class="btn btn-danger" ng-click="quiz.finalise = false">No</button>
</div>
</div>
</div>
</div><!-- question row -->
</div><!-- quiz controller -->
<!-- letting angular know which controller to use for this view and when to show the view using ng-show -->
<div ng-controller="resultsCtrl as results" ng-show="results.quizMetrics.resultsActive">
<div class="row">
<div class="col-xs-8">
<h2>Results:</h2>
<div class="btn-toolbar">
<!-- ng-repeat used again to loop through the possible answers to thequestions which are stored on -->
<!-- the controller. The controller got that data from the quiz factory in js/factory/quiz.js -->
<!-- ng-class is another angular directive. This directive will add a class to the element based -->
<!-- on the conditional it is provided. In this case it will add btn-sucess class if question.correct -->
<!-- is true and will add btn-danger class if question.correct is false -->
<!-- ng-click is again used to trigger a method on the controller called setActiveQuestion -->
<!-- the method is passed the $index as an argument. $index is built into angular and holds -->
<!-- the current index of the ng-repeat loop -->
<button class="btn"
ng-repeat="question in results.dataService.quizQuestions"
ng-class="{'btn-success': question.correct, 'btn-danger': !question.correct}"
ng-click="results.setActiveQuestion($index)">
<!-- display glyphicons -->
<!-- ng-class is utilsed again to style the glyphicons conditionally -->
<span class="glyphicon"
ng-class="{'glyphicon-ok': question.correct, 'glyphicon-remove': !question.correct}"></span>
</button>
</div>
</div>
<div class="col-xs-4">
<div class="row">
<h4>Legend:</h4>
<div class="col-sm-4">
<button class="btn btn-success">
<span class="glyphicon glyphicon-ok"></span>
</button>
<p>Correct</p>
</div>
<div class="col-sm-4">
<button class="btn btn-danger">
<span class="glyphicon glyphicon-remove"></span>
</button>
<p>Incorrect</p>
</div>
</div>
</div>
</div><!-- row -->
<!-- display the score and percentage to the user -->
<div class="row">
<div class="col-xs-12 top-buffer">
<!-- the score is displayed using simple angular expressions -->
<h2>You Scored {{results.quizMetrics.numCorrect}} / {{results.dataService.quizQuestions.length}}</h2>
<!-- the percentage is calculated using a method which is then filtered using the number filter -->
<!-- which ensures only 2 decimal places will be shown -->
<h2><strong>{{results.calculatePerc() | number:2}}%</strong></h2>
</div>
</div>
<div class="row">
<h3>Questions:</h3>
<div class="well well-sm">
<div class="row">
<div class="col-xs-12">
<!-- the below may look strange. -->
<!-- the angular expression will add 1 to the active question, because it is 0 index -->
<!-- it then displays it with a . after it followed by the question. -->
<!-- something like this "3. This is the third question:" -->
<h4>{{results.activeQuestion+1 +". "+results.dataService.quizQuestions[results.activeQuestion].text}}</h4>
<div class="row"
ng-if="results.dataService.quizQuestions[results.activeQuestion].type === 'text'">
<!-- ng-repeat being utilised again -->
<div class="col-sm-6" ng-repeat="answer in results.dataService.quizQuestions[results.activeQuestion].possibilities">
<h4 class="answer"
ng-class="results.getAnswerClass($index)">
{{answer.answer}}
<!-- more usage of the ng-show directive to selectively show the elements on condition -->
<p class="pull-right"
ng-show="$index !== results.quizMetrics.correctAnswers[results.activeQuestion] && $index === results.dataService.quizQuestions[results.activeQuestion].selected">Your Answer</p>
<p class="pull-right"
ng-show="$index === results.quizMetrics.correctAnswers[results.activeQuestion]">Correct Answer</p>
</h4>
</div>
</div><!-- row -->
<!-- more ng-if -->
<div class="row"
ng-if="results.dataService.quizQuestions[results.activeQuestion].type === 'image'">
<!-- more ng-repeat -->
<div class="col-sm-6" ng-repeat="answer in results.dataService.quizQuestions[results.activeQuestion].possibilities">
<!-- ng-class and ng-src -->
<div class="image-answer"
ng-class="results.getAnswerClass($index)">
<img ng-src="{{answer.answer}}">
</div>
</div>
</div>
</div>
</div>
</div><!-- well -->
<!-- ng-click calling the reset method on the controller -->
<button class="btn btn-primary btn-lg" ng-click="results.reset()">Go Back To Facts</button>
</div>
</div>
</div>
<!-- third party js -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.2/angular.min.js"></script>
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<!-- Our application scripts -->
<script src="js/app.js"></script>
<script src="js/controllers/list.js"></script>
<script src="js/controllers/quiz.js"></script>
<script src="js/controllers/results.js"></script>
<script src="js/factories/quizMetrics.js"></script>
<script src="js/factories/dataservice.js"></script>
</body>
</html>