forked from Haline/Arbetsprov
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
89 lines (63 loc) · 2.53 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
<!DOCTYPE html>
<html>
<head class="no-js" dir="ltr" lang="sv">
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Arbetsprov på HM för Jonas Fors Lellky - Claremont AB</title>
<meta name="description" content="Detta är ett arbetsprov av Jonas Fors Lellky för att visa folket på HM att jag duger som frontendutvecklare för hm.com">
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1, initial-scale=1">
<meta name="theme-color" content="">
<meta name="apple-mobile-web-app-title" content="Arbetsprov HM">
</head>
<body>
<h1>Hello World!</h1>
<img src="img/powered-by-google-on-white.png" alt="Google logo"/>
<input id="searchTextField" type="text" size="50" placeholder="Sök svenska städer">
<section id="result"></section>
<!-- Load script without given protocol so that protocol doesnt matter -->
<script src="//maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
var input = document.getElementById('searchTextField');
function initialize(element) {
var input = element;
var options = {
types: ['geocode'],
componentRestrictions: {country: 'se'}
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
prepareBox(autocomplete);
input.value = '';
});
}
function prepareBox(autocomplete) {
if(place === 'undefined')
return;
var place = autocomplete.getPlace();
var val = place.address_components[0].short_name;
addBox(val);
}
function getDateTime() {
/* Stolen from the internet */
var d = new Date();
return (
d.getFullYear() + '-' +
('00' + d.getDate()).slice(-2) + '-' +
('00' + (d.getMonth() + 1)).slice(-2) + ' ' +
('00' + d.getHours()).slice(-2) + ':' +
('00' + d.getMinutes()).slice(-2)
);
}
function addBox(string) {
var $resultContainer = $('#result');
var $newElement = $('<article>');
var date = getDateTime();
$newElement.append('<h1>' + string + '</h1>');
$newElement.append('<p>' + date + '</p>')
$resultContainer.append($newElement);
}
google.maps.event.addDomListener(window, 'load', initialize(input));
</script>
</body>
</html>