This repository has been archived by the owner on Oct 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathindex.html
162 lines (137 loc) · 5.53 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
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
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script type="text/javascript" src="jquery/jquery-2.0.3.js"></script>
<script type="text/javascript" src="jquery/jquery.form.js"></script>
<script type="text/javascript" src="jquery/jquery.list.js"></script>
<script type="text/javascript" src="jquery/jquery.atmosphere.js"></script>
<script type="text/javascript" src="jquery/jquery.swaggersocket.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var ss = new jQuery.swaggersocket.SwaggerSocketListener();
var swaggerSocket = new jQuery.swaggersocket.SwaggerSocket();
//REVISIT move this to somewhere else or find a better way to read incomplete messages
var incompleteMessage = {
depth: 0,
message: "",
push: function(fragment) {
var p = '0';
for (i = 0; i < fragment.length; i++) {
var c = fragment.charAt(i);
if (c == '{' && p != '\\') {
this.depth++;
} else if (c == '}' && p != '\\') {
this.depth--;
}
p = c;
}
this.message += fragment;
}
};
ss.onError = function(errorMsg, r) {
$('#result').prepend($('<li>').append(errorMsg + ":" + r.getStatus() + " " + r.getReasonPhrase()));
};
ss.onResponse = function(r) {
$('#result li').each(function(index) {
$(this).remove();
});
$('#definitions li').each(function(index) {
$(this).remove();
});
try {
incompleteMessage.push(r.getData());
if (incompleteMessage.depth == 0) {
var completeMessage = incompleteMessage.message;
incompleteMessage.message = "";
var swaggerResponse = $.parseJSON(completeMessage);
if (swaggerResponse != null) {
swaggerResponse.examples.forEach(function(example) {
try {
if (example.url != null)
$('#result').prepend($('<li>').append($('<a>').attr('href', example.url).append(example.text))).highlight(getElementById('phrase').value);
else
$('#result').prepend($('<li>').append($('<a>').attr('href', "").append(example.text)));
} catch (e) {
}
});
}
}
} catch (err) {
incompleteMessage.message = "";
}
};
open();
function getKeyCode(ev) {
if (window.event) return window.event.keyCode;
return ev.keyCode;
}
function getElementById() {
return document.getElementById(arguments[0]);
}
function getElementByIdValue() {
return document.getElementById(arguments[0]).value;
}
function open() {
var request = new jQuery.swaggersocket.Request()
.path(document.location.toString() + 'admin/api/word.json')
.listener(ss);
swaggerSocket.open(request);
}
getElementById('phrase').setAttribute('autocomplete', 'OFF');
getElementById('phrase').onkeyup = function(event) {
if (getElementById('phrase').value == '') {
$('#result li').each(function(index) {
$(this).remove();
});
return;
}
var request = new jQuery.swaggersocket.Request()
.path("/" + getElementById('phrase').value + "/examples")
.method("GET")
.listener(ss);
swaggerSocket.send(request);
return false;
};
getElementById('phrase').onclick = function(event) {
if (getElementById('phrase').value == 'Look up any word or phrase...') {
getElementById('phrase').value = '';
}
}
});
</script>
<style type='text/css'>
body {
text-align: center;
}
div {
border: 0px solid black;
}
.highlight {
background-color: yellow
}
input#phrase {
width: 20em;
height: 3em;
font-size: 100%;
background-color: #e0f0f0;
}
ul {
list-style-type: none;
text-align: left;
}
</style>
</head>
<body>
<h1>Searching <a href="http://wordnik.com"/>Wordnik.com</a> ... in REAL TIME!</h1>
<h2>You need to configure the Swagger key in web.xml: com.wordnik.swagger.key. Get a key <a href="http://developer.wordnik.com">here</a></h2>
<br/><br/><br/><br/>
<image src="/w.png"/>
<br/>
<div id='sendMessage'>
<input id='phrase' type='text' value="Look up any word or phrase..."/>
<br>
</div>
<br/>
<ul id='definitions'></ul>
<ul id="result"></ul>
</body>
</html>