forked from alixaxel/ArrestDB
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoc.html
333 lines (315 loc) · 11.1 KB
/
autoc.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="autoComplete/auto-complete.css">
<script type="text/javascript" src="autoComplete/auto-complete.js"></script>
<script>
/*
function updateList(that) {
var lastValue = that.lastValue,
value = that.value,
array = [],
pos = value.indexOf('|'),
start = that.selectionStart,
end = that.selectionEnd,
options;
if (that.options) {
options = that.options;
} else {
options = Object.keys(that.list.options).map(function (option) {
return that.list.options[option].value;
});
that.options = options;
}
if (lastValue !== value) {
that.list.innerHTML = options.filter(function (a) {
return ~a.toLowerCase().indexOf(value.toLowerCase());
}).map(function (a) {
return '<option value="' + value + '|' + a + '">' + a + '</option>';
}).join();
updateInput(that);
that.lastValue = value;
}
}
function updateInput(that) {
var value = that.value,
pos = value.indexOf('|'),
start = that.selectionStart,
end = that.selectionEnd;
if (~pos) {
value = value.slice(pos + 1);
}
that.value = value;
that.setSelectionRange(start, end);
}
(function(funcName, baseObj) {
// The public function name defaults to window.docReady
// but you can pass in your own object and own function name and those will be used
// if you want to put them in a different namespace
funcName = funcName || "docReady";
baseObj = baseObj || window;
var readyList = [];
var readyFired = false;
var readyEventHandlersInstalled = false;
// call this when the document is ready
// this function protects itself against being called more than once
function ready() {
if (!readyFired) {
// this must be set to true before we start calling callbacks
readyFired = true;
for (var i = 0; i < readyList.length; i++) {
// if a callback here happens to add new ready handlers,
// the docReady() function will see that it already fired
// and will schedule the callback to run right after
// this event loop finishes so all handlers will still execute
// in order and no new ones will be added to the readyList
// while we are processing the list
readyList[i].fn.call(window, readyList[i].ctx);
}
// allow any closures held by these functions to free
readyList = [];
}
}
function readyStateChange() {
if ( document.readyState === "complete" ) {
ready();
}
}
// This is the one public interface
// docReady(fn, context);
// the context argument is optional - if present, it will be passed
// as an argument to the callback
baseObj[funcName] = function(callback, context) {
// if ready has already fired, then just schedule the callback
// to fire asynchronously, but right away
if (readyFired) {
setTimeout(function() {callback(context);}, 1);
return;
} else {
// add the function and context to the list
readyList.push({fn: callback, ctx: context});
}
// if document already ready to go, schedule the ready function to run
if (document.readyState === "complete") {
setTimeout(ready, 1);
} else if (!readyEventHandlersInstalled) {
// otherwise if we don't have event handlers installed, install them
if (document.addEventListener) {
// first choice is DOMContentLoaded event
document.addEventListener("DOMContentLoaded", ready, false);
// backup is window load event
window.addEventListener("load", ready, false);
} else {
// must be IE
document.attachEvent("onreadystatechange", readyStateChange);
window.attachEvent("onload", ready);
}
readyEventHandlersInstalled = true;
}
}
})("docReady", window);
*/
/*
docReady(function(){
document.getElementsByTagName('input').browser.addEventListener('keyup',
function (e) {
updateList(this);
});
document.getElementsByTagName('input').browser.addEventListener('input',
function (e) {
updateInput(this);
});
});
*/
/*
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var content = JSON.parse(xhttp.responseText);
var list = document.getElementById("datalist1");
var input = document.getElementById("srch");
list.innerHTML="";
for(var i=0; i< content.length; i++){
var item = content[i];
var option = document.createElement('option');
option.value = item.ContactName;
// option.setAttribute('data-record',item);
list.appendChild(option);
}
input.setAttribute("placeholder", "Contact Name List");
}
};
var myAwsomeplete;
ajax.onload = function() {
myAwsomeplete._list = JSON.parse(ajax.responseText).map(function(i) { return i.ContactName; });
};
(function(funcName, baseObj) {
// The public function name defaults to window.docReady
// but you can pass in your own object and own function name and those will be used
// if you want to put them in a different namespace
funcName = funcName || "docReady";
baseObj = baseObj || window;
var readyList = [];
var readyFired = false;
var readyEventHandlersInstalled = false;
// call this when the document is ready
// this function protects itself against being called more than once
function ready() {
if (!readyFired) {
// this must be set to true before we start calling callbacks
readyFired = true;
for (var i = 0; i < readyList.length; i++) {
// if a callback here happens to add new ready handlers,
// the docReady() function will see that it already fired
// and will schedule the callback to run right after
// this event loop finishes so all handlers will still execute
// in order and no new ones will be added to the readyList
// while we are processing the list
readyList[i].fn.call(window, readyList[i].ctx);
}
// allow any closures held by these functions to free
readyList = [];
}
}
function readyStateChange() {
if ( document.readyState === "complete" ) {
ready();
}
}
// This is the one public interface
// docReady(fn, context);
// the context argument is optional - if present, it will be passed
// as an argument to the callback
baseObj[funcName] = function(callback, context) {
// if ready has already fired, then just schedule the callback
// to fire asynchronously, but right away
if (readyFired) {
setTimeout(function() {callback(context);}, 1);
return;
} else {
// add the function and context to the list
readyList.push({fn: callback, ctx: context});
}
// if document already ready to go, schedule the ready function to run
if (document.readyState === "complete") {
setTimeout(ready, 1);
} else if (!readyEventHandlersInstalled) {
// otherwise if we don't have event handlers installed, install them
if (document.addEventListener) {
// first choice is DOMContentLoaded event
document.addEventListener("DOMContentLoaded", ready, false);
// backup is window load event
window.addEventListener("load", ready, false);
} else {
// must be IE
document.attachEvent("onreadystatechange", readyStateChange);
window.attachEvent("onload", ready);
}
readyEventHandlersInstalled = true;
}
}
})("docReady", window);
docReady(function(){
myAwsomeplete = new Awesomplete(document.querySelector("#srch"),{ list: [{ContactName:"tbd"}] });
});
var ajax;
if (window.XMLHttpRequest) {
ajax = new XMLHttpRequest();
} else {
// code for IE6, IE5
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
function myFunction(event){
var input = event.currentTarget;
input.setAttribute("placeholder","Loading options...");
var value = input.value + String.fromCharCode(event.keyCode);
var uri = "/arrestDB/ArrestDB.php/Customer/ContactName/"+"%25"+value+"%25?limit=20";
ajax.open("GET", uri, true);
ajax.send();
}
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
var content = JSON.parse(ajax.responseText);
var list = document.getElementById("datalist1");
var input = document.getElementById("srch");
list.innerHTML="";
for(var i=0; i< content.length; i++){
var item = content[i];
var option = document.createElement('option');
option.value = input.value+"|"+item.ContactName;
// option.setAttribute('data-record',item);
list.appendChild(option);
}
input.setAttribute("placeholder", "Contact Name List");
}
};
function updateInput(that) {
var value = that.value,
pos = value.indexOf('|'),
start = that.selectionStart,
end = that.selectionEnd;
if (~pos) {
value = value.slice(pos + 1);
}
that.value = value;
that.setSelectionRange(start, end);
}
*/
</script>
</head>
<body>
<input name="q">
<!--
<h2>Database Search Autocomplete datalist</h2>
Customer Contact:
<input type="text" name="srch" id="srch" list="datalist1" placeholder="e.g. datalist" onkeypress="myFunction(event);" oninput="updateInput(this);" >
<datalist id="datalist1">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<input list="browsers" name="browser" id="browser" onkeyup="updateList(this);" oninput="updateInput(this);">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
-->
<script>
'use strict';
var ajax;
if (window.XMLHttpRequest) {
ajax = new XMLHttpRequest();
} else {
// code for IE6, IE5
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
new autoComplete({
selector: 'input[name="q"]',
source: function(term, response){
var uri = "/arrestDB/ArrestDB.php/Customer/ContactName/"+"%25"+term+"%25?limit=20";
ajax.open("GET", uri, false);
ajax.send(null);
var choices=[];
if(ajax.status=== 200){
var records = JSON.parse(ajax.responseText);
for(var i=0; i<records.length; i++){
choices.push(records[i].ContactName);
}
}
response(choices);
}
});
</script>
</body>
</html>