Skip to content

Commit 8707f31

Browse files
committed
refactor 6.2: fix jshint issues related to objects on the global scope
1 parent 4de8706 commit 8707f31

File tree

6 files changed

+40
-39
lines changed

6 files changed

+40
-39
lines changed

app/app.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
'use strict';
22

3-
function initialize() {
3+
var map;
4+
5+
window.initialize = function() {
46
var mapDiv = document.getElementById('map-canvas');
5-
map = new MapService(window.google, mapDiv);
7+
map = new window.MapService(window.google, mapDiv);
68

79
var searchControlDiv = document.createElement('div');
810
searchControlDiv.id = 'top';
911
searchControlDiv.className = 'top';
1012

11-
new SearchControl(searchControlDiv);
13+
new window.SearchControl(searchControlDiv);
1214
map.addView(searchControlDiv, 'TOP_LEFT');
1315

1416
var homeControlDiv = document.createElement('div');
1517
homeControlDiv.id = 'bottom_panel';
1618
homeControlDiv.className = 'bottom_panel';
1719

18-
new HomeControl(homeControlDiv);
20+
new window.HomeControl(homeControlDiv);
1921
map.addView(homeControlDiv, 'BOTTOM_CENTER');
20-
}
22+
};

app/home-control.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
function HomeControl(controlDiv, map) {
3+
window.HomeControl = function(controlDiv) {
44
var dashBoard = document.createElement('div');
5-
dashBoard.innerHTML = templates.home();
5+
dashBoard.innerHTML = window.templates.home();
66
dashBoard.id = 'dashboard';
77
dashBoard.className = 'dashboard';
88
controlDiv.appendChild(dashBoard);
9-
}
9+
};

app/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
<body>
1919
<div id="map-canvas"></div>
2020
<script type="text/javascript">
21-
var map;
22-
google.maps.event.addDomListener(window, 'load', initialize);
21+
window.google.maps.event.addDomListener(window, 'load', initialize);
2322
</script>
2423
</body>
2524
</html>

app/location-control.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
'use strict';
22

3-
function showLocation(detail, location) {
3+
window.showLocation = function(detail, location) {
44
return function() {
5-
map.zoomView(location.geo.lat, location.geo.lng);
5+
window.map.zoomView(location.geo.lat, location.geo.lng);
66

77
var locationDiv = document.getElementById('location_detail');
88

99
if (!locationDiv) {
1010
locationDiv = document.createElement('div');
11-
document.getElementById('bottom_panel').appendChild(locationDiv);
11+
document.getElementById('bottom_panel').appendChild(locationDiv);
1212
}
1313

1414
locationDiv.id = 'location_detail';
1515
locationDiv.className = 'location_detail';
1616
locationDiv.style.display = '';
17-
locationDiv.innerHTML = templates.location(location);
17+
locationDiv.innerHTML = window.templates.location(location);
1818

1919
var sateliteViewButton = document.createElement('input');
2020
sateliteViewButton.type = 'button';
@@ -23,10 +23,10 @@ function showLocation(detail, location) {
2323
sateliteViewButton.addEventListener('click', function() {
2424

2525
if (this.value === 'Satelite View') {
26-
map.sateliteView(location.geo.lat, location.geo.lng);
26+
window.map.sateliteView(location.geo.lat, location.geo.lng);
2727
this.value = 'Back to Roadmap';
2828
} else {
29-
map.roadmapView(location.geo.lat, location.geo.lng);
29+
window.map.roadmapView(location.geo.lat, location.geo.lng);
3030
this.value = 'Satelite View';
3131
}
3232

@@ -39,7 +39,7 @@ function showLocation(detail, location) {
3939
streetViewButton.value = 'Street View';
4040

4141
streetViewButton.addEventListener('click', function() {
42-
map.streetView(location.geo.lat, location.geo.lng);
42+
window.map.streetView(location.geo.lat, location.geo.lng);
4343
});
4444

4545
locationDiv.appendChild(streetViewButton);
@@ -49,7 +49,7 @@ function showLocation(detail, location) {
4949
backToFilm.value = 'Back to Film';
5050

5151
backToFilm.addEventListener('click', function() {
52-
map.reset();
52+
window.map.reset();
5353
var locationDetail = document.getElementById('location_detail');
5454
if (locationDetail) {
5555
locationDetail.style.display = 'none';
@@ -59,10 +59,10 @@ function showLocation(detail, location) {
5959
if (filmDetail) {
6060
filmDetail.style.display = '';
6161
}
62-
});
62+
});
6363

6464
locationDiv.appendChild(backToFilm);
6565

6666
document.getElementById('film_detail').style.display = 'none';
6767
};
68-
}
68+
};

app/movie-control.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

3-
function plotLocations(item) {
3+
var plotLocations = function(item) {
44
var xhr = new XMLHttpRequest();
55
xhr.onload = function() {
66
var response = this.response;
77
for (var i = 0; i < response.locations.length; i++) {
8-
map.plotLocation(
8+
window.map.plotLocation(
99
response.locations[i].geo.lat,
1010
response.locations[i].geo.lng,
11-
showLocation(response, response.locations[i]));
11+
window.showLocation(response, response.locations[i]));
1212
}
1313
};
1414
xhr.open('GET', '/movies/locations?title=' +
@@ -17,9 +17,9 @@ function plotLocations(item) {
1717
encodeURIComponent(item.director));
1818
xhr.responseType = 'json';
1919
xhr.send();
20-
}
20+
};
2121

22-
function displayLoadingPanel(response) {
22+
var displayLoadingPanel = function(response) {
2323
var locationDiv = document.getElementById('location_detail');
2424
if (locationDiv) {
2525
locationDiv.style.display = 'none';
@@ -37,36 +37,36 @@ function displayLoadingPanel(response) {
3737
controlText = document.createElement('div');
3838
controlText.id = 'film_detail';
3939
controlText.className = 'film_detail';
40-
controlText.innerHTML = templates.loading(response);
40+
controlText.innerHTML = window.templates.loading(response);
4141

4242
document.getElementById('bottom_panel').appendChild(controlText);
4343

4444
} else {
4545

4646
controlText = document.getElementById('film_detail');
47-
controlText.innerHTML = templates.loading(response);
47+
controlText.innerHTML = window.templates.loading(response);
4848
controlText.style.display = '';
4949

5050
}
51-
}
51+
};
5252

53-
function getMoveDetail(title, director) {
53+
var getMoveDetail = function(title, director) {
5454
var xhr = new XMLHttpRequest();
5555
xhr.onload = function() {
5656
var detail = this.response;
57-
58-
document.getElementById('film_detail').innerHTML = templates.movie(detail);
57+
var template = window.templates.movie(detail);
58+
document.getElementById('film_detail').innerHTML = template;
5959
};
6060
xhr.open('GET', '/movies/content?title=' +
6161
encodeURIComponent(title) +
6262
'&director=' +
6363
encodeURIComponent(director));
6464
xhr.responseType = 'json';
6565
xhr.send();
66-
}
66+
};
6767

68-
function showMovieDetail(item, map) {
68+
window.showMovieDetail = function(item, map) {
6969
displayLoadingPanel(item.title);
7070
getMoveDetail(item.title, item.director);
7171
plotLocations(item, map);
72-
}
72+
};

app/search-control.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

3-
function SearchControl(controlDiv) {
3+
window.SearchControl = function(controlDiv) {
44
var movieClicked = function(item) {
5-
map.clearMarkers();
6-
map.setOptions({ streetViewControl: false, zoomControl: true });
5+
window.map.clearMarkers();
6+
window.map.setOptions({ streetViewControl: false, zoomControl: true });
77
document.getElementById('films_results').innerHTML = '';
88
document.getElementById('q').value = item.title;
9-
showMovieDetail(item);
9+
window.showMovieDetail(item);
1010
};
1111

1212
var searchInput = document.createElement('input');
@@ -29,4 +29,4 @@ function SearchControl(controlDiv) {
2929
var resultsUI = document.createElement('div');
3030
resultsUI.id = 'films_results';
3131
controlDiv.appendChild(resultsUI);
32-
}
32+
};

0 commit comments

Comments
 (0)