/
show.html
executable file
·304 lines (267 loc) · 13 KB
/
show.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
{% extends layout %}
{% load item_tags %}
{% block content %}
{% subclassfields %}
<script type="text/javascript" src="{% media_url "javascripts/highlighting.js" %}"></script>
<script type="text/javascript" src="{% media_url "javascripts/canvas_pointing.js" %}"></script>
<style type="text/css">
.transclude_token:hover {
cursor: pointer;
border-left: 2px solid #f00;
margin-left: -3px;
padding-left: 1px;
background: #ddd;
}
</style>
<script type="text/javascript">
var highlighted_comment_id = null;
var highlighted_transclusion_id = null;
$(document).ready(function () {
DemeCanvasPointing.setup();
var comment_id = {% if highlighted_comment_id %}'{{ highlighted_comment_id }}'{% else %}null{% endif %};
var transclusion_id = {% if highlighted_transclusion_id %}'{{ highlighted_transclusion_id }}'{% else %}null{% endif %};
highlight_comment(comment_id, transclusion_id, true, true);
});
function highlight_comment(comment_id, transclusion_id, scroll_body, scroll_comments) {
// Remove highlighting on previously highlighted comment/transclusion
if (highlighted_comment_id != null) {
$('#right_pane_comment_' + highlighted_comment_id).removeClass('comment_header_highlighted');
}
if (highlighted_transclusion_id != null) {
$('#inline_transclusion_' + highlighted_transclusion_id).removeClass('commentref_highlighted');
}
DemeCanvasPointing.clearLine();
if (comment_id == highlighted_comment_id && transclusion_id == highlighted_transclusion_id) {
// If comment/transclusion is same as before, don't re-highlight
highlighted_comment_id = null;
highlighted_transclusion_id = null;
} else {
if (comment_id != null) {
// Expand the accordion to the comment section
$('#right_accordion').accordion('activate', '#accordion_header_comments');
// Highlight the comment
$('#right_pane_comment_' + comment_id).addClass('comment_header_highlighted');
// Scroll to the proper place in the comment sidebar
if (scroll_comments) {
var y = $('#right_pane_comment_' + comment_id).offset().top - $('#fixed_right_pane').offset().top;
$('#fixed_right_pane').animate({scrollTop:y}, 500);
}
}
if (transclusion_id != null) {
// Show located comments
$('.commentref').show();
$('#hide_located_comments').show();
$('#show_located_comments').hide();
// Highlight the transclusion
$('#inline_transclusion_' + transclusion_id).addClass('commentref_highlighted');
// Scroll to the proper place in the document body
if (scroll_body) {
var y = $('#inline_transclusion_' + transclusion_id).offset().top;
$(document.body).animate({scrollTop:y}, 500);
}
}
// Setup the canvas pointing line between transclusion and comment
if (comment_id != null && transclusion_id != null) {
DemeCanvasPointing.drawLine($('#inline_transclusion_' + transclusion_id), $('#right_pane_comment_' + comment_id));
}
// Store the currently highlighted comment and transclusion
highlighted_comment_id = comment_id;
highlighted_transclusion_id = transclusion_id;
}
}
var is_escaped = {% if is_html %}false{% else %}true{% endif %};
var body_str = "{{ item.body|escapejs }}";
function parse_error(str) {
$('#parse_errors').show();
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
$('#parse_errors')[0].appendChild(div);
}
function located_comment_token_click(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
var tokenWrapper = targ;
var index = tokenWrapper.deme_text_offset;
openLocatedCommentDialog('comment{{ item.pk }}', index);
//var url = '{% url item_type_url viewer="textcomment",action="new" %}?populate_item={{ item.pk }}&populate_item_version_number={{ item.version_number }}&redirect={{ full_path|urlencode }}&populate_item_index=' + index;
//window.location = url;
return false;
}
function openLocatedCommentDialog(name, position)
{
var dialogBox = $('#' + name);
var form = dialogBox.children();
form.replaceWith('<form method="post" action="/viewing/textcomment/accordioncreate?redirect={{ full_path }}&populate_item_index=' + position + '">' + form.html() + '</form>');
dialogBox.dialog({
autoOpen: false,
bgiframe: true,
modal: true,
close: function(event, ui) {dialogBox.dialog('destroy')}
});
dialogBox.dialog('open');
}
function transclusion_token_click(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
var tokenWrapper = targ;
var index = tokenWrapper.deme_text_offset;
var url = '{% url item_type_url viewer="transclusion",action="new" %}?populate_from_item={{ item.pk }}&populate_from_item_version_number={{ item.version_number }}&redirect={{ full_path|urlencode }}&populate_from_item_index=' + index;
window.location = url;
return false;
}
function add_located_comment() {
var docbody = $('#docbody')[0];
var docbody_clone = DemeHighlighting.tokenize(docbody, body_str, is_escaped, parse_error, 'transclude_token', located_comment_token_click);
docbody_clone.setAttribute('id', 'docbody_clone_located_comment');
$(docbody).hide();
docbody.parentNode.insertBefore(docbody_clone, docbody);
$('#add_located_comment_div').hide();
$('#adding_located_comment_div').show();
}
function cancel_add_located_comment() {
$('#docbody').show();
$('#docbody_clone_located_comment').remove();
$('#add_located_comment_div').show();
$('#adding_located_comment_div').hide();
}
function add_transclusion() {
var docbody = $('#docbody')[0];
var docbody_clone = DemeHighlighting.tokenize(docbody, body_str, is_escaped, parse_error, 'transclude_token', transclusion_token_click);
docbody_clone.setAttribute('id', 'docbody_clone_transclusion');
$(docbody).hide();
docbody.parentNode.insertBefore(docbody_clone, docbody);
$('#add_transclusion_div').hide();
$('#adding_transclusion_div').show();
}
function cancel_add_transclusion() {
$('#docbody').show();
$('#docbody_clone_transclusion').remove();
$('#add_transclusion_div').show();
$('#adding_transclusion_div').hide();
}
function start_highlighting() {
$('#docbody').bind('mouseup', add_current_highlight);
$('#add_highlight_div').hide();
$('#adding_highlight_div').show();
}
function cancel_highlighting() {
$('#docbody').unbind('mouseup', add_current_highlight);
$('#add_highlight_div').show();
$('#adding_highlight_div').hide();
}
function add_current_highlight() {
var docbody = $('#docbody')[0];
var selection = DemeHighlighting.get_current_highlight(docbody, body_str);
if (selection) {
var text_excerpt = body_str.substring(selection.start_offset, selection.end_offset);
var length = selection.end_offset - selection.start_offset;
var form_div = document.createElement('div');
form_div.style.border = 'thin solid #aaa';
form_div.style.padding = '5px';
form_div.style.margin = '5px';
var input = document.createElement('input');
input.setAttribute('type', 'hidden');
input.setAttribute('name', 'excerpt');
input.setAttribute('value', '{{ item.pk }} {{ item.version_number }} ' + selection.start_offset + ' ' + length);
form_div.appendChild(input);
var remove_button = document.createElement('button');
remove_button.appendChild(document.createTextNode('Remove'));
remove_button.setAttribute('type', 'button');
remove_button.style.cssFloat = 'right';
remove_button.style.styleFloat = 'right';
remove_button.onclick = function(){$(remove_button.parentNode).remove(); return false;};
form_div.appendChild(remove_button);
form_div.appendChild(selection.contents);
$('#excerpt_form')[0].appendChild(form_div);
//var url = '{% url item_type_url viewer="textdocumentexcerpt",action="new" %}?text_document={{ item.pk }}&text_document_version_number={{ item.version_number }}&redirect={{ full_path|urlencode }}&start_index=' + selection.start_offset + '&length=' + length;
//window.location = url;
}
}
function submit_highlights() {
$('#excerpt_form').submit();
}
</script>
{% ifagentcan 'view TextDocument.body' item %}
<div id="docbody" style="padding: 10px;">{% display_body_with_inline_transclusions item is_html %}</div>
{% endifagentcan %}
<script type="text/javascript">
function expand_comments_reallybig() {
$('#show_comments_link').hide();
$('#hide_comments_link').show();
$('.commentref').show();
show_column_right();
$('#left_table_column').width(.125*PAGE_WIDTH);
$('#center_table_column').width(.375*PAGE_WIDTH);
$('#right_table_column').width(.5*PAGE_WIDTH);
$('#right_accordion').accordion('activate', 1);
show_comments_big();
}
function hide_comments_reallybig() {
$('#show_comments_link').show();
$('#hide_comments_link').hide();
hide_comments_big();
$('.commentref').hide();
$('#left_table_column').width(.125*PAGE_WIDTH);
$('#center_table_column').width(.625*PAGE_WIDTH);
$('#right_table_column').width(.25*PAGE_WIDTH);
decrease_column_right();
}
</script>
{% ifagentcan 'view TextDocument.body' item %}
<div id="show_comments_link">
{% ifagentcan 'comment_on' item %}
<button href="#" onclick="openCommentDialog('comment{{ item.pk }}'); return false;">Add Comment</button>
{% endifagentcan %}
<button href="#" onclick="expand_comments_reallybig(); return false;">Show all comments</button>
</div>
<div id="hide_comments_link" style="display: none;">
{% ifagentcan 'comment_on' item %}
<button href="#" onclick="openCommentDialog('comment{{ item.pk }}'); return false;">Add Comment</button>
{% endifagentcan %}
<button href="#" onclick="hide_comments_reallybig(); return false;">Hide Comments</button>
</div>
<div id="parse_errors" style="display: none;">
</div>
{% ifagentcan 'add_transclusion' item %}
{% ifagentcan 'comment_on' item %}
<div id="add_located_comment_div">
<a href="#" onclick="add_located_comment(); return false;">Add Located Comment</a>
</div>
<div id="adding_located_comment_div" style="display: none;">
Now just select text where you want to comment or
<a href="#" onclick="cancel_add_located_comment(); return false;">Cancel</a>
</div>
{% endifagentcan %}
<div id="add_transclusion_div">
<a href="#" onclick="add_transclusion(); return false;">Add Transclusion</a>
</div>
<div id="adding_transclusion_div" style="display: none;">
Now just select text where you want to add a Transclusion or
<a href="#" onclick="cancel_add_transclusion(); return false;">Cancel</a>
</div>
{% endifagentcan %}
{% ifagentcanglobal 'create TextDocumentExcerpt' %}
{% ifagentcanglobal 'create Collection' %}
<div id="add_highlight_div">
<a href="#" onclick="start_highlighting(); return false;">Add Excerpt</a>
</div>
<div id="adding_highlight_div" style="display: none;">
Now just select text you want to highlight.
When you are done selecting excerpts, <a href="#" onclick="submit_highlights(); return false;">submit them</a> or <a href="#" onclick="cancel_highlighting(); return false;">cancel</a>.
<form id="excerpt_form" method="post" enctype="multipart/form-data" action="{% url item_type_url viewer="textdocumentexcerpt",action="createmultiexcerpt" %}">
</form>
</div>
{% endifagentcanglobal %}
{% endifagentcanglobal %}
<div id="show_located_comments" style="display: none;"><a href="#" onclick="$('.commentref').show(); $('#hide_located_comments').show(); $('#show_located_comments').hide(); return false;">Show Located Comments</a></div>
<div id="hide_located_comments"><a href="#" onclick="$('.commentref').hide(); $('#hide_located_comments').hide(); $('#show_located_comments').show(); DemeCanvasPointing.clearLine(); return false;">Hide Located Comments</a></div>
{% endifagentcan %}
{% endblock content %}