This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathexample.html
144 lines (124 loc) · 5.31 KB
/
example.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="@stchangg (Stephanie H. Chang)">
<title>Placecomplete: A Select2/jQuery plugin for location autocomplete powered by the Google Maps API</title>
<!-- jQuery, Select2 -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/select2/3.4.1/select2.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/3.4.1/select2.min.css">
<!-- Placecomplete plugin -->
<script src="jquery.placecomplete.js"></script>
<link rel="stylesheet" href="jquery.placecomplete.css">
<!-- The following are not necessary for using Placecomplete -->
<!-- Highlight.js for JSON syntax highlighting -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3/highlight.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3/styles/github.min.css">
<!-- Handlebars.js -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.min.js"></script>
<style>
body {
font-family: "Helvetica Neue";
margin: 0;
padding: 0;
}
.container {
width: 800px;
margin: 0 auto;
padding: 30px;
background: #fff;
}
.wrapper {
margin: 45px 0;
background: #F8F8F8;
border: 2px solid #E9E9E9;
padding: 15px 0 40px 40px;
text-align: center;
}
.user-input {
margin: 0 auto;
display: inline-block;
text-align: left;
}
#example {
width: 300px;
}
.codefont,
code {
font-size: 14px;
font-family: Monaco, Courier, monospace;
}
pre code {
overflow-x: auto;
}
</style>
<script id="response-template" type="text/x-handlebars-template">
<h4>Event type:</h4>
<code>{{eventType}}</code>
{{#if dataTypeHTML}}
<h4>Data type:</h4>
<p class="codefont">{{{dataTypeHTML}}}</p>
<h4>Data value:</h4>
<pre>
<code class="javascript codefont">{{data}}</code>
</pre>
{{/if}}
</script>
</head>
<body>
<div class="container">
<h1>Placecomplete</h1>
<p>A Select2/jQuery plugin for location autocomplete powered by the Google Maps API</p>
<div class="wrapper">
<div class="user-input">
<h3>Choose a location:</h3>
<input type="text" id="example" value="Mountain View, CA"/>
</div>
</div>
<div id="response"></div>
</div>
<script>
$(function() {
var $el = $("#example"),
$responseEl = $("#response");
$el.placecomplete({
width: "element"
});
var tmpl = Handlebars.compile($("#response-template").html());
$el.on({
"placecomplete:selected": function(evt, placeResult) {
var data = JSON.stringify(placeResult, undefined, 2);
var context = {
eventType: evt.type,
dataTypeHTML: "<a href='https://developers.google.com/maps/documentation/javascript/reference#PlaceResult'>Google Maps API PlaceResult</a> augmented with display_text property",
data: data
};
$responseEl.html(tmpl(context));
// Add syntax highlighting via highlight.js
$responseEl.find("pre code").each(function(i, el) {
hljs.highlightBlock(el);
});
},
"placecomplete:cleared": function(evt) {
var context = {
eventType: evt.type
};
$responseEl.html(tmpl(context));
},
"placecomplete:error": function(evt, errorMsg) {
var context = {
eventType: evt.type,
dataTypeHTML: "<a href='https://developers.google.com/maps/documentation/javascript/reference#PlacesServiceStatus'>google.maps.places.PlacesServiceStatus</a>",
data: '"' + errorMsg + '"'
};
$responseEl.html(tmpl(context));
}
});
$el.select2("open", true);
});
</script>
</body>
</html>