forked from slaporte/Disambiguity
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
76 lines (67 loc) · 1.93 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
<html>
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
var global_timeout = 5000;
function random_int (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function do_query(url, complete_callback, kwargs) {
var all_kwargs = {
url: url,
type: 'get',
dataType: 'jsonp',
timeout: global_timeout,
success: function(data) {
console.log('successful ajax query to ' + url);
complete_callback(null, data);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('failed query to ' + url);
complete_callback(errorThrown, null);
},
complete: function(jqXHR, textStatus) {
// TODO: error handling (jsonp doesn't get error() calls for a lot of errors)
},
};
for (var key in kwargs) {
if(kwargs.hasOwnProperty(key)) {
all_kwargs[key] = kwargs[key];
}
}
$.ajax(all_kwargs);
}
do_query('http://localhost:8080/fake/', page_setup);
function page_setup(err, data){
var rand_choice = random_int(0, data.dabs.length - 1);
console.log(rand_choice);
var dab = data.dabs[rand_choice];
var choices = dab.options,
page_title = dab.page_title,
dab_title = dab.title,
dab_context = dab.context;
$('#page_title').html(page_title);
$('#phrase').html(dab_title);
$('#context').html(dab_context);
$('span:contains("disambiguation")"').parents('sup').hide();
for(var i = 0; i < choices.length; i++) {
$('#choices').append('<li>' + choices[i].text + '</li>');
}
}
</script>
<style>
.dab-link {
background-color: yellow;
}
</style>
</head>
<body>
<h1>DAB game</h1>
<p>Page: <span id='page_title'></span></p>
<p>Dabblet: <span id='phrase'></span></p>
<h2>context</h2>
<div id='phrase'></div>
<div id='context'></div>
<ul id='choices'></ul>
</body>
</html>