@@ -14,11 +14,11 @@ $(function () { // Same as document.addEventListener("DOMContentLoaded"...
14
14
var dc = { } ;
15
15
16
16
var homeHtmlUrl = "snippets/home-snippet.html" ;
17
- var allCategoriesUrl =
17
+ var allCategoriesUrl =
18
18
"https://davids-restaurant.herokuapp.com/categories.json" ;
19
19
var categoriesTitleHtml = "snippets/categories-title-snippet.html" ;
20
20
var categoryHtml = "snippets/category-snippet.html" ;
21
- var menuItemsUrl =
21
+ var menuItemsUrl =
22
22
"https://davids-restaurant.herokuapp.com/menu_items.json?category=" ;
23
23
var menuItemsTitleHtml = "snippets/menu-items-title.html" ;
24
24
var menuItemHtml = "snippets/menu-item.html" ;
@@ -36,8 +36,8 @@ var showLoading = function (selector) {
36
36
insertHtml ( selector , html ) ;
37
37
} ;
38
38
39
- // Return substitute of '{{propName}}'
40
- // with propValue in given 'string'
39
+ // Return substitute of '{{propName}}'
40
+ // with propValue in given 'string'
41
41
var insertProperty = function ( string , propName , propValue ) {
42
42
var propToReplace = "{{" + propName + "}}" ;
43
43
string = string
@@ -54,19 +54,19 @@ var switchMenuToActive = function () {
54
54
55
55
// Add 'active' to menu button if not already there
56
56
classes = document . querySelector ( "#navMenuButton" ) . className ;
57
- if ( classes . indexOf ( "active" ) == - 1 ) {
57
+ if ( classes . indexOf ( "active" ) === - 1 ) {
58
58
classes += " active" ;
59
59
document . querySelector ( "#navMenuButton" ) . className = classes ;
60
60
}
61
61
} ;
62
62
63
63
// On page load (before images or CSS)
64
64
document . addEventListener ( "DOMContentLoaded" , function ( event ) {
65
-
66
- // TODO: STEP 0: Look over the code from
67
- // *** start ***
68
- // to
69
- // *** finish ***
65
+
66
+ // TODO: STEP 0: Look over the code from
67
+ // *** start ***
68
+ // to
69
+ // *** finish ***
70
70
// below.
71
71
// We changed this code to retrieve all categories from the server instead of
72
72
// simply requesting home HTML snippet. We now also have another function
@@ -75,14 +75,14 @@ document.addEventListener("DOMContentLoaded", function (event) {
75
75
// random category into the home HTML snippet, and then insert that snippet into our
76
76
// main page (index.html).
77
77
//
78
- // TODO: STEP 1: Substitute [...] below with the *value* of the function buildAndShowHomeHTML,
78
+ // TODO: STEP 1: Substitute [...] below with the *value* of the function buildAndShowHomeHTML,
79
79
// so it can be called when server responds with the categories data.
80
80
81
81
// *** start ***
82
82
// On first load, show home view
83
83
showLoading ( "#main-content" ) ;
84
84
$ajaxUtils . sendGetRequest (
85
- allCategoriesUrl ,
85
+ allCategoriesUrl ,
86
86
[ ...] , // ***** <---- TODO: STEP 1: Substitute [...] ******
87
87
true ) ; // Explicitely setting the flag to get JSON from server processed into an object literal
88
88
} ) ;
@@ -92,7 +92,7 @@ $ajaxUtils.sendGetRequest(
92
92
// Builds HTML for the home page based on categories array
93
93
// returned from the server.
94
94
function buildAndShowHomeHTML ( categories ) {
95
-
95
+
96
96
// Load home snippet page
97
97
$ajaxUtils . sendGetRequest (
98
98
homeHtmlUrl ,
@@ -102,7 +102,7 @@ function buildAndShowHomeHTML (categories) {
102
102
// Pay attention to what type of data that function returns vs what the chosenCategoryShortName
103
103
// variable's name implies it expects.
104
104
// var chosenCategoryShortName = ....
105
-
105
+
106
106
107
107
// TODO: STEP 3: Substitute {{randomCategoryShortName}} in the home html snippet with the
108
108
// chosen category from STEP 2. Use existing insertProperty function for that purpose.
@@ -114,15 +114,15 @@ function buildAndShowHomeHTML (categories) {
114
114
// $dc.loadMenuItems('L')
115
115
// Hint: you need to surround the chosen category short name with something before inserting
116
116
// it into the home html snippet.
117
- //
117
+ //
118
118
// var homeHtmlToInsertIntoMainPage = ....
119
-
119
+
120
120
121
121
// TODO: STEP 4: Insert the the produced HTML in STEP 3 into the main page
122
122
// Use the existing insertHtml function for that purpose. Look through this code for an example
123
- // of how to do that.
123
+ // of how to do that.
124
124
// ....
125
-
125
+
126
126
} ,
127
127
false ) ; // False here because we are getting just regular HTML from the server, so no need to process JSON.
128
128
}
@@ -171,8 +171,8 @@ function buildAndShowCategoriesHTML (categories) {
171
171
// Switch CSS class active to menu button
172
172
switchMenuToActive ( ) ;
173
173
174
- var categoriesViewHtml =
175
- buildCategoriesViewHtml ( categories ,
174
+ var categoriesViewHtml =
175
+ buildCategoriesViewHtml ( categories ,
176
176
categoriesTitleHtml ,
177
177
categoryHtml ) ;
178
178
insertHtml ( "#main-content" , categoriesViewHtml ) ;
@@ -185,10 +185,10 @@ function buildAndShowCategoriesHTML (categories) {
185
185
186
186
// Using categories data and snippets html
187
187
// build categories view HTML to be inserted into page
188
- function buildCategoriesViewHtml ( categories ,
188
+ function buildCategoriesViewHtml ( categories ,
189
189
categoriesTitleHtml ,
190
190
categoryHtml ) {
191
-
191
+
192
192
var finalHtml = categoriesTitleHtml ;
193
193
finalHtml += "<section class='row'>" ;
194
194
@@ -198,10 +198,10 @@ function buildCategoriesViewHtml(categories,
198
198
var html = categoryHtml ;
199
199
var name = "" + categories [ i ] . name ;
200
200
var short_name = categories [ i ] . short_name ;
201
- html =
201
+ html =
202
202
insertProperty ( html , "name" , name ) ;
203
- html =
204
- insertProperty ( html ,
203
+ html =
204
+ insertProperty ( html ,
205
205
"short_name" ,
206
206
short_name ) ;
207
207
finalHtml += html ;
@@ -226,9 +226,9 @@ function buildAndShowMenuItemsHTML (categoryMenuItems) {
226
226
function ( menuItemHtml ) {
227
227
// Switch CSS class active to menu button
228
228
switchMenuToActive ( ) ;
229
-
230
- var menuItemsViewHtml =
231
- buildMenuItemsViewHtml ( categoryMenuItems ,
229
+
230
+ var menuItemsViewHtml =
231
+ buildMenuItemsViewHtml ( categoryMenuItems ,
232
232
menuItemsTitleHtml ,
233
233
menuItemHtml ) ;
234
234
insertHtml ( "#main-content" , menuItemsViewHtml ) ;
@@ -241,15 +241,15 @@ function buildAndShowMenuItemsHTML (categoryMenuItems) {
241
241
242
242
// Using category and menu items data and snippets html
243
243
// build menu items view HTML to be inserted into page
244
- function buildMenuItemsViewHtml ( categoryMenuItems ,
244
+ function buildMenuItemsViewHtml ( categoryMenuItems ,
245
245
menuItemsTitleHtml ,
246
246
menuItemHtml ) {
247
-
248
- menuItemsTitleHtml =
247
+
248
+ menuItemsTitleHtml =
249
249
insertProperty ( menuItemsTitleHtml ,
250
250
"name" ,
251
251
categoryMenuItems . category . name ) ;
252
- menuItemsTitleHtml =
252
+ menuItemsTitleHtml =
253
253
insertProperty ( menuItemsTitleHtml ,
254
254
"special_instructions" ,
255
255
categoryMenuItems . category . special_instructions ) ;
@@ -263,40 +263,40 @@ function buildMenuItemsViewHtml(categoryMenuItems,
263
263
for ( var i = 0 ; i < menuItems . length ; i ++ ) {
264
264
// Insert menu item values
265
265
var html = menuItemHtml ;
266
- html =
266
+ html =
267
267
insertProperty ( html , "short_name" , menuItems [ i ] . short_name ) ;
268
- html =
269
- insertProperty ( html ,
268
+ html =
269
+ insertProperty ( html ,
270
270
"catShortName" ,
271
271
catShortName ) ;
272
272
html =
273
273
insertItemPrice ( html ,
274
274
"price_small" ,
275
- menuItems [ i ] . price_small ) ;
275
+ menuItems [ i ] . price_small ) ;
276
276
html =
277
277
insertItemPortionName ( html ,
278
278
"small_portion_name" ,
279
279
menuItems [ i ] . small_portion_name ) ;
280
- html =
280
+ html =
281
281
insertItemPrice ( html ,
282
282
"price_large" ,
283
283
menuItems [ i ] . price_large ) ;
284
284
html =
285
285
insertItemPortionName ( html ,
286
286
"large_portion_name" ,
287
287
menuItems [ i ] . large_portion_name ) ;
288
- html =
289
- insertProperty ( html ,
288
+ html =
289
+ insertProperty ( html ,
290
290
"name" ,
291
291
menuItems [ i ] . name ) ;
292
- html =
293
- insertProperty ( html ,
292
+ html =
293
+ insertProperty ( html ,
294
294
"description" ,
295
295
menuItems [ i ] . description ) ;
296
296
297
297
// Add clearfix after every second menu item
298
298
if ( i % 2 !== 0 ) {
299
- html +=
299
+ html +=
300
300
"<div class='clearfix visible-lg-block visible-md-block'></div>" ;
301
301
}
302
302
@@ -341,4 +341,3 @@ function insertItemPortionName(html,
341
341
global . $dc = dc ;
342
342
343
343
} ) ( window ) ;
344
-
0 commit comments