-
Notifications
You must be signed in to change notification settings - Fork 2
/
display.js
197 lines (162 loc) · 5.57 KB
/
display.js
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
var id, entry;
var filters = ['move_forward', 'filter_tag', 'filter_constituency'];
function setupFilters() {
$.each(filters, function( i, x ) {
var value = $.cookie(x);
if ( $('#' + x).is('[type=checkbox]') )
$('#' + x).attr( 'checked', !!value );
else
$('#' + x).val( value );
$('#' + x).change(function() {
var value = false;
if ( $(this).is('[type=checkbox]') )
value = !!$(this).attr( 'checked' );
else
value = $(this).val();
$.cookie(this.id, value, { date: 365 });
if ( this.id == 'filter_tag' || this.id == 'filter_constituency' )
window.location.reload();
});
})
}
function chooseParseType() {
$('#parse-control li').removeClass('active');
$(this).addClass('active');
var parsetype = $('#parse-control li.active').attr('data-parse_type');
$('#parse-control .dropdown-toggle').text('Parse: ' + (parsetype || 'None'));
maybeLoadTrees();
}
function maybeLoadTrees() {
var parsetype = $('#parse-control li.active').attr('data-parse_type');
if ( !parsetype ) {
$('#parse-container').hide();
return;
}
$('#image, #parse').text('loading...');
$.getJSON('display_ajax.php', {
action: 'display_parse',
entry: entry,
id: id,
type: parsetype
}, function (json) {
$('#image, #parse').text('');
if (json.error) {
return $('<div class="alert-message warning fade in"><a class="close" href="#">×</a><p>No ' + parsetype + ' parse data available.</p></div>')
.prependTo('#container')
.alert();
}
$('#parse-container').show();
$('#image').empty();
$('<img/>')
.attr('src', 'lib/phpsyntaxtree/stgraph.svg?data=' + json.imageData)
.attr('alt', 'Tree: ' + json.imageData)
.appendTo('#image');
$('#parse').text(json.tree);
if ( json.link_parse ) {
var classification = '<h2>' + json.link_parse.constituency + '</h2>';
if ( json.link_parse.error ) {
classification += '<p><strong>Error:</strong> ' + json.link_parse.error + '</p>';
}
if ( json.link_parse.failure_type ) {
classification += '<p><strong>Failure type:</strong> ' + json.link_parse.failure_type;
if ( json.link_parse.missing_node )
classification += ': ' + json.link_parse.missing_node;
classification += '</p>';
}
classification += '<p><strong>Immediately dominating node:</strong> ' + json.link_parse.immediate_node + '</p>';
classification += '<p><strong>Punctuation pass:</strong> ' + ( json.link_parse.punctuation_pass == '1' ? 'yes' : 'no' ) + '</p>';
classification += '<p><strong>Almost:</strong> ' + ( json.link_parse.almost == '1' ? 'yes' : 'no' ) + '</p>';
$('#classification').html(classification);
}
});
}
$(document).ready(function() {
// make sure we can scroll enough to hide next/prev:
$('#container').css('min-height',$(document).height() - 20);
// always hide next/prev immediately.
$(document).scrollTop($('#entry').offset().top - 60);
id = $('input#id').val(),
entry = $('input#entry').val();
var tags_header = $('#tags').siblings('h4');
var toggles = $('.inputs-list label:not(.disabled)');
toggles.find('input').change(function() {
// remove any 'saved tags!' labels
tags_header.find('.label').remove();
});
var labels = ['1','2','3','4','5','6','7','8','9','A','B','D','E','F'];
// add accelerator labels
toggles.slice(0, labels.length).each(function(i) {
$(this).children('span').prepend('<span class="accelerator">(' + labels[i] + ')</span> ');
})
$(document.body).keyup(function onkeyup(e) {
var theChar = String.fromCharCode(e.keyCode);
// Don't do anything if we were in a textarea or something.
var focused = $('input[type=text]:focus, textarea:focus');
if (focused.length)
return;
// Tags
if ( labels.indexOf(theChar) > -1 ) {
var toggle = toggles.eq(labels.indexOf(theChar)).find('input');
toggle.attr('checked', !toggle.attr('checked'));
// remove any 'saved tags!' labels
tags_header.find('.label').remove();
return;
}
if (theChar == 'R')
return window.location = $('#random-link').attr('href');
if (theChar == 'C')
submit('constituent');
if (theChar == 'N')
submit('not_constituent');
if (theChar == 'S')
submit(false);
if( theChar == 'J' )
return window.location = $('#prev').attr('href');
if( theChar == 'K' )
return window.location = $('#next').attr('href');
});
function moveForward() {
if ( $('#move_forward').val() == 'random' )
window.location = $('#random-link').attr('href');
if ( $('#move_forward').val() == 'next' )
window.location = $('#next').attr('href');
}
function submit(constituency) {
if ($('#spinner').is(':visible'))
return;
$('#spinner').show();
// remove 'saved tags!' labels
tags_header.find('.label').remove();
data = { action: 'save', id: id, entry: entry };
if (constituency)
data.constituency = constituency;
tags = {};
$('.tags-list input:not(.disabled)').each(function() {
var input = $(this);
tags[input.attr('data-tag')] = !!input.attr('checked');
})
data.tags = tags;
$.post('display_ajax.php', data, function(json) {
$('#spinner').hide();
if (json.modified) {
$('#last_modified small').text(json.modified);
$('.submit').removeClass('success danger selected');
$('#' + json.constituency).addClass('selected');
}
if (json.tags)
tags_header.append(' <span class="label success fade in" style="margin-left: 5px;">saved tags!</span>');
moveForward();
}, 'json');
}
$('.submit').click(function () {
submit(this.id);
});
// ignore the form
$('form').submit(function(e) {
e.preventDefault();
return false;
});
$('#parse-control li:not(.divider)').click(chooseParseType);
maybeLoadTrees();
setupFilters();
});