-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext1.html
132 lines (108 loc) · 3.82 KB
/
text1.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
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="md/md-icon.css">
<style>
.material-icons.md-13 {
font-size: 13px;
}
.material-icons.md-18 {
font-size: 18px;
}
.material-icons.md-24 {
font-size: 24px;
}
.material-icons.md-36 {
font-size: 36px;
}
.material-icons.md-48 {
font-size: 48px;
}
#search-list {
border: 1px solid #ccc !important;
border-radius: 5px;
width: max-content;
background-color: #eee;
}
#search-list ul {
list-style-type: none;
padding-left: 0;
width: 200px;
}
#search-list li {
padding: 10px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
#search-list li:hover {
background-color: #ccc;
}
</style>
<body>
<p>A function is triggered when the user is pressing a key in the input field.</p>
<p id="result"></p>
<input id="source" type="text">
<div id="search-list">
<ul id="ul-list">
<li>1111</li>
<li>2222</li>
<li>3333</li>
</ul>
</div>
<p id="status">NONE</p>
<script>
var prev = '';
var now = '';
const status = document.getElementById('status');
const source = document.getElementById('source');
const result = document.getElementById('result');
const inputHandler = function (e) {
result.innerHTML = e.target.value;
now = result.innerHTML;
}
source.addEventListener('input', inputHandler);
prev = source.innerText;
function checkChange() {
//now = source.innerText;
if (prev == now) {
status.innerText = prev + "<br/>" + now + "<br/>" + "No Change!";
} else if (prev != now && source.value != "") {
status.innerText = prev + "<br/>" + now + "<br/>" + "Changed!";
// Rest of the task in async
(async () => {
let response = await new Promise(resolve => {
var xhr = new XMLHttpRequest();
// var query = document.getElementById("source");
// var url = "https://nominatim.openstreetmap.org/search.php?q=" + query.innerText + "&format=jsonv2";
var url = "https://nominatim.openstreetmap.org/search.php?q=" + source.value + "&format=jsonv2";
console.log(url);
xhr.open("GET", url, true);
xhr.onload = function (e) {
resolve(xhr.response);
};
xhr.onerror = function () {
resolve(undefined);
console.error("** An error occurred during the XMLHttpRequest");
};
xhr.send();
});
console.log(response);
var data = JSON.parse(response);
var ul_list = document.getElementById("ul-list");
ul_list.innerHTML = "";
if (data.length != 0) {
for (var i = 0; i < data.length; i++) {
ul_list.innerHTML += "<li lat='" + data[i].lat + "' lon='" + data[i].lon + "'>" + "<span class='material-icons md-13'>place</span> " + data[i].display_name + "</li>"
}
} else {
ul_list.innerHTML = "<li><i>No places found!</i></li>"
}
})();
}
prev = now;
status.innerText += " - " + new Date().toLocaleTimeString();
}
setInterval("checkChange(prev)", 3000);
</script>
</body>
</html>