|
39 | 39 |
|
40 | 40 | google.maps.event.addDomListener(window, 'load', initialize); |
41 | 41 |
|
| 42 | + /* |
| 43 | + * Search Panel |
| 44 | + */ |
42 | 45 | function SearchControl(controlDiv, map) { |
| 46 | + var movieClicked = function(item) { |
| 47 | + map.clearMarkers(); |
| 48 | + map.setOptions({ streetViewControl: false, zoomControl: true }); |
| 49 | + document.getElementById('films_results').innerHTML = ''; |
| 50 | + document.getElementById('q').value = item.title; |
| 51 | + showMovieDetail(item); |
| 52 | + }; |
43 | 53 |
|
44 | 54 | var searchInput = document.createElement('input'); |
45 | 55 | searchInput.type = 'search'; |
|
54 | 64 | label: 'title', |
55 | 65 | value: 'releaseYear', |
56 | 66 | select: function(item) { |
57 | | - clicked(item); |
| 67 | + movieClicked(item); |
58 | 68 | } |
59 | 69 | }); |
60 | 70 |
|
|
63 | 73 | controlDiv.appendChild(resultsUI); |
64 | 74 | } |
65 | 75 |
|
66 | | - function clicked(item) { |
67 | | - |
68 | | - map.clearMarkers(); |
69 | | - map.setOptions({ streetViewControl: false, zoomControl: true }); |
70 | | - |
71 | | - document.getElementById('films_results').innerHTML = ''; |
72 | | - |
73 | | - detailPanel(item.title); |
74 | | - |
75 | | - document.getElementById('q').value = item.title; |
76 | | - |
77 | | - setMoveDetail(item.title, item.director); |
78 | | - |
79 | | - var xhr = new XMLHttpRequest(); |
80 | | - xhr.onload = function() { |
81 | | - var response = this.response; |
82 | | - for (var i = 0; i < response.locations.length; i++) { |
83 | | - map.plotLocation( |
84 | | - response.locations[i].geo.lat, |
85 | | - response.locations[i].geo.lng, |
86 | | - zoom(response, response.locations[i])); |
87 | | - }; |
88 | | - } |
89 | | - xhr.open("GET", "/movies/locations?title=" + encodeURIComponent(item.title) + '&director=' + encodeURIComponent(item.director)); |
90 | | - xhr.responseType = "json"; |
91 | | - xhr.send(); |
92 | | - } |
93 | | - |
94 | | - function detailPanel(response) { |
95 | | - var locationDiv = document.getElementById('location_detail'); |
96 | | - if (locationDiv) { |
97 | | - locationDiv.style.display = 'none'; |
98 | | - } |
99 | | - |
100 | | - var dashboard = document.getElementById('dashboard'); |
101 | | - if (dashboard) { |
102 | | - dashboard.style.display = 'none'; |
103 | | - } |
104 | | - |
105 | | - if (!document.getElementById('film_detail')) { |
106 | | - |
107 | | - // Set CSS for the control interior. |
108 | | - var controlText = document.createElement('div'); |
109 | | - controlText.id = 'film_detail'; |
110 | | - controlText.className = 'film_detail'; |
111 | | - controlText.innerHTML = templates.loading(response); |
112 | | - |
113 | | - document.getElementById('bottom_panel').appendChild(controlText); |
114 | | - |
115 | | - } else { |
116 | | - |
117 | | - var controlText = document.getElementById('film_detail'); |
118 | | - controlText.innerHTML = templates.loading(response);; |
119 | | - controlText.style.display = ''; |
120 | | - |
121 | | - } |
122 | | - } |
123 | | - |
124 | | - function setMoveDetail(title, director) { |
125 | | - |
126 | | - var xhr = new XMLHttpRequest(); |
127 | | - xhr.onload = function() { |
128 | | - var detail = this.response; |
129 | | - |
130 | | - document.getElementById('film_detail').innerHTML = templates.movie(detail); |
131 | | - } |
132 | | - xhr.open("GET", "/movies/content?title=" + encodeURIComponent(title) + '&director=' + encodeURIComponent(director)); |
133 | | - xhr.responseType = "json"; |
134 | | - xhr.send(); |
135 | | - } |
136 | | - |
137 | | - function zoom(detail, location) { |
| 76 | + /* |
| 77 | + * Movie Detail |
| 78 | + */ |
| 79 | + function showLocation(detail, location) { |
138 | 80 | return function() { |
139 | 81 | map.zoomView(location.geo.lat, location.geo.lng); |
140 | 82 |
|
|
201 | 143 | } |
202 | 144 | } |
203 | 145 |
|
| 146 | + /* |
| 147 | + * Movie Detail |
| 148 | + */ |
| 149 | + function showMovieDetail(item) { |
| 150 | + displayLoadingPanel(item.title); |
| 151 | + getMoveDetail(item.title, item.director); |
| 152 | + plotLocations(item); |
| 153 | + } |
| 154 | + |
| 155 | + function plotLocations(item) { |
| 156 | + var xhr = new XMLHttpRequest(); |
| 157 | + xhr.onload = function() { |
| 158 | + var response = this.response; |
| 159 | + for (var i = 0; i < response.locations.length; i++) { |
| 160 | + map.plotLocation( |
| 161 | + response.locations[i].geo.lat, |
| 162 | + response.locations[i].geo.lng, |
| 163 | + showLocation(response, response.locations[i])); |
| 164 | + }; |
| 165 | + } |
| 166 | + xhr.open("GET", "/movies/locations?title=" + encodeURIComponent(item.title) + '&director=' + encodeURIComponent(item.director)); |
| 167 | + xhr.responseType = "json"; |
| 168 | + xhr.send(); |
| 169 | + } |
| 170 | + |
| 171 | + function displayLoadingPanel(response) { |
| 172 | + var locationDiv = document.getElementById('location_detail'); |
| 173 | + if (locationDiv) { |
| 174 | + locationDiv.style.display = 'none'; |
| 175 | + } |
| 176 | + |
| 177 | + var dashboard = document.getElementById('dashboard'); |
| 178 | + if (dashboard) { |
| 179 | + dashboard.style.display = 'none'; |
| 180 | + } |
| 181 | + |
| 182 | + if (!document.getElementById('film_detail')) { |
| 183 | + |
| 184 | + // Set CSS for the control interior. |
| 185 | + var controlText = document.createElement('div'); |
| 186 | + controlText.id = 'film_detail'; |
| 187 | + controlText.className = 'film_detail'; |
| 188 | + controlText.innerHTML = templates.loading(response); |
| 189 | + |
| 190 | + document.getElementById('bottom_panel').appendChild(controlText); |
| 191 | + |
| 192 | + } else { |
| 193 | + |
| 194 | + var controlText = document.getElementById('film_detail'); |
| 195 | + controlText.innerHTML = templates.loading(response);; |
| 196 | + controlText.style.display = ''; |
| 197 | + |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + function getMoveDetail(title, director) { |
| 202 | + var xhr = new XMLHttpRequest(); |
| 203 | + xhr.onload = function() { |
| 204 | + var detail = this.response; |
| 205 | + |
| 206 | + document.getElementById('film_detail').innerHTML = templates.movie(detail); |
| 207 | + } |
| 208 | + xhr.open("GET", "/movies/content?title=" + encodeURIComponent(title) + '&director=' + encodeURIComponent(director)); |
| 209 | + xhr.responseType = "json"; |
| 210 | + xhr.send(); |
| 211 | + } |
| 212 | + |
| 213 | + /* |
| 214 | + * Homepage Panel |
| 215 | + */ |
204 | 216 | function HomeControl(controlDiv, map) { |
205 | 217 | var dashBoard = document.createElement('div'); |
206 | 218 | dashBoard.innerHTML = templates.home(); |
|
0 commit comments