-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·279 lines (249 loc) · 10.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>TouristGopher</title>
<meta name="generator" content="Bootply" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cosmo/bootstrap.min.css">
<link href="styles.css" rel="stylesheet">
<link rel="apple-touch-icon" sizes="57x57" href="/images/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/images/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/images/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/images/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/images/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/images/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/images/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/images/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/images/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/images/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
<link rel="manifest" href="/images/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
</head>
<body>
<!-- nav -->
<nav class="navbar navbar-fixed-top navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img style="height: 26px; width:26px;" src="/images/gopher.png">
</a>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navMain" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">TouristGopher</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="navMain">
<form class="navbar-form" id="serachForm">
<select class="form-control" id="nichepicker">
<option value="restaurants">Restaurants</option>
<option value="bars">Bars</option>
<option value="hotels">Hotels</option>
<option value="nightlife">Nightlife</option>
</select>
<div class="form-group search-container">
<div class="input-group" id="bootstrapSearchContainer">
<input type="text" class="form-control" placeholder="Paris, New York, London..." id="searchInput">
<span class="input-group-addon" id="submit"><span class="glyphicon glyphicon-search"></span> </span>
</div>
</div>
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="https://twitter.com/touristgopher">TouristGopher's Twitter</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<!-- end nav -->
<div class="container-fluid" id="main">
<div class="row">
<div class="col-md-8 col-xs-12" id="left">
<h1><em>This Gopher knows</em></h1>
<p id="pqueryContainer">Search results for <em id="nicheNotifier">restaurants</em> in<em id="resultQueryNotifier"> Paris </em></p>
<img src="/images/loading.gif" id="loading-indicator" style="display:none" />
<!-- item list -->
<div id="revs-container">
<!-- item -->
{{range $i, $a := .Places }}
<div class="col-md-6 col-xs-12">
<div class="panel panel-default">
<div class="panel-body">
<span class="ratingScore"><em>{{ .Rating }}</em></span>
<span class="ratingsSpan"><span class="numRatings">{{ .Number_of_Ratings }}</span> Ratings</span>
<a class="loclink" href="#" dataloc="{{- .Location -}}">{{ .Name }}</a>
</div>
</div>
</div>
{{ end }}
</div>
<!-- End item -->
</div>
<div class="col-md-4 col-xs-12">
<div class="iframe-container">
<div id="map_container"></div>
<div id="map"></div>
</div>
</div>
</div>
<div class='notification' style='display:none'>Map updated</div>
<p>
<a href="http://github.com/octohedron/touristgopher">Source Code</a>
</p>
</div>
<!-- end template -->
<script type="text/javascript">
$(document).ready(function() {
document.querySelector('body').addEventListener('click', function(event) {
if (event.target.attributes.dataloc) {
event.preventDefault();
let lat = event.target.attributes.dataloc.value.split(",")[0];
let long = event.target.attributes.dataloc.value.split(",")[1];
$('.notification').text($(this).data('text')).fadeIn(400).delay(2000).fadeOut(400);
moveToLocation(lat, long);
}
});
/* google maps -----------------------------------------------------*/
google.maps.event.addDomListener(window, 'load', initialize);
var map, infoWindow;
function initialize() {
/* position Amsterdam */
var latlng = new google.maps.LatLng(48.857031, 2.341719);
var mapOptions = {
center: latlng,
zoom: 15
};
// Initialize map
map = new google.maps.Map(document.getElementById("map"), mapOptions);
// Print places
{{range $i, $a := .Places}}
let {{ toJS .Identifier }} = {lat: parseFloat('{{ .Location }}'.split(",")[0]), lng: parseFloat('{{ .Location }}'.split(",")[1])};
var {{toJS .MarkerVar -}} = new google.maps.Marker({
position: {{ toJS .Identifier }},
map: map,
label: '{{ .Name }}',
animation: google.maps.Animation.DROP
});
{{ toJS .MarkerVar -}}.setMap(map);
{{end}}
}; // end initialize
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
/**
* For panning the map
* @param {float} lat The latitude to pan to
* @param {float} lng the longitude to pan to
*/
function moveToLocation(lat, lng){
var center = new google.maps.LatLng(lat, lng);
// using global variable:
map.panTo(center);
}
/* end google maps -----------------------------------------------------*/
// Review template
const Item = ({
Rating, Location, Name, Number_of_Ratings
}) => `
<div class="col-md-6 col-xs-12">
<div class="panel panel-default">
<div class="panel-body">
<span class="ratingScore"><em>${Rating}</em></span>
<span class="ratingsSpan"><span class="numRatings">${Number_of_Ratings}</span> Ratings</span>
<a class="loclink" href="#" dataloc="${Location}">${Name}</a>
</div>
</div>
</div> `;
// reference to the reviews log
var revs = document.getElementById("revs-container");
$('#serachForm').submit((e) => {
e.preventDefault();
search();
})
// search
$('#submit').click((e) => {
e.preventDefault();
search();
});
function search() {
$("#navMain").collapse('hide');
let needle = encodeURIComponent($('#searchInput').val().trim()).split('%20').join('+');
if (needle.length < 3) {
alert("Please enter at least 3 characters")
} else if (needle.length > 50) {
alert("Search query too long")
} else {
let geoURL = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + needle + "&key={{- toJS .GMAPS_KEY -}}";
// clear items first
while (revs.hasChildNodes()) {
revs.removeChild(revs.lastChild);
}
$('#loading-indicator').show();
$('#pqueryContainer').hide();
fetch(geoURL, {
method: 'get'
}).then(function(response) {
response.json().then(function(json) {
if (json["results"] && json["results"].length > 0) {
var lat = json["results"][0]["geometry"]["location"]["lat"];
var long = json["results"][0]["geometry"]["location"]["lng"];
let apiURL = 'http://touristgopher.com/api/4000/' + lat + ',' + long + '/' + $('#nichepicker').val();
fetch(apiURL, {
method: 'get'
}).then(function(response) {
response.json().then(function(json) {
// hide loading indicator
$('#loading-indicator').hide();
moveToLocation(lat, long);
// append new items
json.forEach((i) => {
var item = document.createElement("div");
$(item).html([i].map(Item).join(''));
revs.appendChild(item);
$('#pqueryContainer').show();
$("#nicheNotifier").html($('#nichepicker').val());
$("#resultQueryNotifier").html(" " + needle.split('+').join(' '));
// set new markers
let coords = {lat: parseFloat(i["Location"].split(",")[0]), lng: parseFloat(i["Location"].split(",")[1])};
var marker = new google.maps.Marker({
position: coords,
map: map,
label: i["Name"],
animation: google.maps.Animation.DROP
});
marker.setMap(map);
})
}).catch((e) => console.log(e));
})
} else {
$('#loading-indicator').hide();
$("#resultQueryNotifier").html(needle + " are none");
}
});
}).catch((e) => console.log(e));
}
}
});
</script>
<!-- script references -->
<script src="js/scripts.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?key={{- toJS .GMAPS_KEY -}}&extension=.js&output=embed"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>