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
181 lines (156 loc) · 6.23 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<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;
}
};
var lastHashtag = new Array();
ss.onError = function(r) {
$('#result').prepend($('<li>').append(r.getStatusCode() + " " + r.getReasonPhrase()));
};
ss.onResponse = function(r) {
$('#result li').each(function(index) {
if (index > 10) {
$(this).remove();
}
});
try {
incompleteMessage.push(r.getData());
if (incompleteMessage.depth == 0) {
var completeMessage = incompleteMessage.message;
incompleteMessage.message = "";
var swaggerResponse = $.parseJSON(completeMessage);
if (swaggerResponse != null) {
var hash = r.getRequest().getPath();
swaggerResponse.statuses.forEach(function(result) {
$('#result').prepend($('<li>').append($('<a>').append(result.text))).highlight(hash);
$('#result').prepend($('<li>').append($('<h3>').append(result.from_user).append('</h3>')));
});
}
}
} 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 stop() {
if (lastHashtag.length > 0 && lastHashtag[0].length != 0) {
lastHashtag.forEach(function(tag) {
swaggerSocket.send(new jQuery.swaggersocket.Request()
.path(tag + '/stop')
.method("GET")
.listener(ss));
});
}
}
function open() {
var request = new jQuery.swaggersocket.Request()
.path(document.location.toString() + 'search/')
.listener(ss);
swaggerSocket.open(request);
}
getElementById('phrase').setAttribute('autocomplete', 'OFF');
getElementById('phrase').onkeyup = function(event) {
// REVISIT need an option for not triggering the search at each keyup event?
// if (kc != 13) {
// return;
// }
stop();
lastHashtag = $.trim(getElementById('phrase').value).split(" ");
if (lastHashtag == '') {
$('#result li').each(function(index) {
$(this).remove();
});
return;
}
lastHashtag.forEach(function(tag) {
swaggerSocket.send(new jQuery.swaggersocket.Request()
.path(tag)
.dataFormat("application/json")
.method("GET")
.listener(ss));
});
return false;
};
getElementById('phrase').onclick = function(event) {
if (getElementById('phrase').value == 'Look up any hashtag....') {
getElementById('phrase').value = '';
}
}
});
</script>
<style type='text/css'>
body {
text-align: center;
}
div {
border: 0px solid black;
}
.highlight {
background-color: yellow
}
.h3 {
background-color: red
}
input#phrase {
width: 20em;
height: 3em;
font-size: 100%;
background-color: #e0f0f0;
}
input#phrase2 {
width: 20em;
height: 3em;
font-size: 100%;
background-color: #e0f0f0;
}
ul {
list-style-type: none;
text-align: left;
}
</style>
</head>
<body>
<h1>Twitter Search using SwaggerSocket</h1>
<h2>Enter hashtag (for multiple, separate using a space); Clear the field to stop</h2>
<h3>You need to configure the Twitter ConsumerKey and ConsumerSecret in web.xml: com.twitter.consumer.key and com.twitter.consumer.secret. Get a key <a href="http://apps.twitter.com">here</a></h3>
<div id='sendMessage'>
<input id='phrase' type='text' value="Look up any hashtag...."/>
</div>
<h2>Results</h2>
<ul id="result"></ul>
</body>
</html>