-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautocomplete.html
More file actions
96 lines (77 loc) · 3.03 KB
/
autocomplete.html
File metadata and controls
96 lines (77 loc) · 3.03 KB
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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery autocomplete with SockJS</title>
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="thrift.js"></script>
<script src="thrift/services_types.js"></script>
<script src="thrift/SuggestionService.js"></script>
<script>
// Maximum Number of suggestions per query
var k = 10;
//var HOST = 'http://metalcon2.physik.uni-mainz.de:8080/completionServer';
var HOST = 'http://metalcon2.physik.uni-mainz.de:8080/server-0.0.1';
//var HOST = 'http://localhost:8000/';
var transport = new Thrift.Transport(HOST);
var protocol = new Thrift.Protocol(transport);
var client = new SuggestionServiceClient(protocol);
sockIsOpen = false;
var sock;
function ACHandler(request, ac_response) {
console.log("AC request:" + request.term);
try {
client.findSuggestionsFor('wikipediaindex', request.term, k, function(results) {
ac_data = $.map(results, function(suggestItem) {
return {
label : suggestItem.suggestion,
payload : JSON.parse(suggestItem.payload)
// payload : JSON.parse(suggestItem.payload)
}
});
ac_response(ac_data);
} );
} catch(ouch){
console.log(ouch);
}
};
$(document).ready(function() {
// Global Variables
input = $("#in");
input.autocomplete({
delay : 0, // no delay
source : function(request, ac_response) {
ACHandler(request, ac_response);
},
select: function(event, row){
if(row.item.payload.href.startsWith("http")){
location.href = row.item.payload.href;
} else {
location.href = "http://"+row.item.payload.href;
}
}
/*
* Set the render engine
*/
}).data("ui-autocomplete")._renderItem = function( ul, item ) {
var innerHTML = '<a><div class = "list_item_container" style="width:500px;"><div style="float:left; width:120px;"><img src="'+item.payload.img+'"></div><div style="float:left; width:300px; margin:8px; padding:8px;">' + item.label + '</div></div><br style="clear:both;"></a>';
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( innerHTML )
.appendTo( ul );
};
});
</script>
</head>
<body>
<h1>SockJs AutoComplete</h1>
<div class="ui-widget">
<form>
<label for="in"> Search: </label> <input id="in" />
</form>
</div>
</body>
</html>