forked from experiandataquality/GlobalIntuitive
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
117 lines (95 loc) · 3.34 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
<!DOCTYPE html>
<html>
<head>
<title>Contact Data Services - sample code</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="dist/css/styles.css">
</head>
<body>
<div id="contact-data-services-container">
<div id="contact-data-services-map"></div>
<div class="cds-filter cds-filter-map"></div>
<div id="contact-data-services-controls">
<div class="cds-filter cds-filter-controls"></div>
<div class="controls-container">
<div class="header">
<h1>Contact Data Services</h1>
</div>
<form>
<div class="loader loader-overlay hidden">
<div class="spinner"></div>
</div>
<label for="country" class="toggle">Country</label>
<select name="country" class="toggle">
<option value="">Please select</option>
<option value="aus">Australia</option>
<option value="fra">France</option>
<option value="nzl">New Zealand</option>
<option value="gbr" selected>United Kingdom</option>
<option value="usa">United States</option>
</select>
<label for="address-input" class="toggle">Address</label>
<input type="text" name="address-input" class="toggle">
</form>
</div>
</div>
<!-- Quick hack to pre-load stamp images -->
<div style="display: none;">
<div class="stamp stamp-gb"></div>
<div class="stamp stamp-us"></div>
</div>
</div>
<script src="dist/js/contact-data-services.js"></script>
<script>
// Set the custom options
var options = {
token: "3002b80a-fc8f-475d-88e0-26f2ad8c36de",
elements: {
input: document.querySelector("input[name='address-input']"),
countryList: document.querySelector("select")
}
};
// Initialise this instance
var address = new ContactDataServices.address(options);
// Show the spinner while we're searching for the formatted address
address.events.on("formatting-search", function(){
document.querySelector(".loader").classList.remove("hidden");
});
// Hide the country and search input when a result is found
address.events.on("formatted-address", function(){
var searchInputs = document.querySelectorAll(".toggle");
for (var i = 0; i < searchInputs.length; ++i) {
searchInputs[i].classList.add("hidden");
}
// Hide the spinner
document.querySelector(".loader").classList.add("hidden");
// After formatting...
setTimeout(function() {
// Add a stamp
var stamp = document.createElement("div");
var envelope = document.querySelector(".formatted-address");
stamp.classList.add("stamp");
envelope.appendChild(stamp);
// Detect country
var addressLines = document.querySelectorAll(".toggle");
var country = addressLines[addressLines.length - 1].textContent;
switch(country) {
case "UNITED KINGDOM":
stamp.classList.add("stamp-gb");
break;
case "UNITED STATES OF AMERICA":
stamp.classList.add("stamp-us");
break;
}
// Add search again link
var retry = document.createElement("a");
retry.setAttribute("href", "#");
retry.classList.add("search-again");
retry.textContent = "Search again";
retry.addEventListener("click", function(){ window.location.reload() }, false);
envelope.appendChild(retry);
}, 100);
});
</script>
</body>
</html>