Commit | Line | Data |
20198e59 |
1 | var MARGIN=30; |
2 | var svg_root = null; |
3 | var svg_root_element = null; |
4 | var start_element_height = 0; |
5 | var reltypes = {}; |
6 | var readingdata = {}; |
7 | |
20198e59 |
8 | function getTextURL( which ) { |
3f9d7ae5 |
9 | return basepath + textid + '/' + which; |
20198e59 |
10 | } |
11 | |
12 | function getReadingURL( reading_id ) { |
3f9d7ae5 |
13 | return basepath + textid + '/reading/' + reading_id; |
20198e59 |
14 | } |
15 | |
16 | // Make an XML ID into a valid selector |
17 | function jq(myid) { |
18 | return '#' + myid.replace(/(:|\.)/g,'\\$1'); |
19 | } |
20 | |
21 | // Actions for opening the reading panel |
22 | function node_dblclick_listener( evt ) { |
23 | // Open the reading dialogue for the given node. |
24 | // First get the reading info |
25 | var reading_id = $(this).attr('id'); |
26 | var reading_info = readingdata[reading_id]; |
27 | // and then populate the dialog box with it. |
28 | // Set the easy properties first |
29 | $('#reading-form').dialog( 'option', 'title', 'Reading information for "' + reading_info['text'] + '"' ); |
30 | $('#reading_id').val( reading_id ); |
31 | toggle_checkbox( $('#reading_is_nonsense'), reading_info['is_nonsense'] ); |
32 | toggle_checkbox( $('#reading_grammar_invalid'), reading_info['grammar_invalid'] ); |
33 | // Use .text as a backup for .normal_form |
34 | var normal_form = reading_info['normal_form']; |
35 | if( !normal_form ) { |
36 | normal_form = reading_info['text']; |
37 | } |
38 | var nfboxsize = 10; |
39 | if( normal_form.length > 9 ) { |
40 | nfboxsize = normal_form.length + 1; |
41 | } |
42 | $('#reading_normal_form').attr( 'size', nfboxsize ) |
43 | $('#reading_normal_form').val( normal_form ); |
44 | // Now do the morphological properties. |
45 | morphology_form( reading_info['lexemes'] ); |
46 | // and then open the dialog. |
47 | $('#reading-form').dialog("open"); |
48 | } |
49 | |
50 | function toggle_checkbox( box, value ) { |
51 | if( value == null ) { |
52 | value = false; |
53 | } |
54 | box.attr('checked', value ); |
55 | } |
56 | |
57 | function morphology_form ( lexlist ) { |
487674b9 |
58 | if( lexlist.length ) { |
59 | $('#morph_outer').show(); |
60 | $('#morphology').empty(); |
61 | $.each( lexlist, function( idx, lex ) { |
62 | var morphoptions = []; |
63 | if( 'wordform_matchlist' in lex ) { |
64 | $.each( lex['wordform_matchlist'], function( tdx, tag ) { |
65 | var tagstr = stringify_wordform( tag ); |
66 | morphoptions.push( tagstr ); |
67 | }); |
68 | } |
69 | var formtag = 'morphology_' + idx; |
70 | var formstr = ''; |
71 | if( 'form' in lex ) { |
72 | formstr = stringify_wordform( lex['form'] ); |
73 | } |
74 | var form_morph_elements = morph_elements( |
75 | formtag, lex['string'], formstr, morphoptions ); |
76 | $.each( form_morph_elements, function( idx, el ) { |
77 | $('#morphology').append( el ); |
20198e59 |
78 | }); |
20198e59 |
79 | }); |
487674b9 |
80 | } else { |
81 | $('#morph_outer').hide(); |
82 | } |
20198e59 |
83 | } |
84 | |
85 | function stringify_wordform ( tag ) { |
86 | if( tag ) { |
87 | var elements = tag.split(' // '); |
88 | return elements[1] + ' // ' + elements[2]; |
89 | } |
90 | return '' |
91 | } |
92 | |
93 | function morph_elements ( formtag, formtxt, currform, morphoptions ) { |
94 | var clicktag = '(Click to select)'; |
95 | if ( !currform ) { |
96 | currform = clicktag; |
97 | } |
98 | var formlabel = $('<label/>').attr( 'id', 'label_' + formtag ).attr( |
99 | 'for', 'reading_' + formtag ).text( formtxt + ': ' ); |
100 | var forminput = $('<input/>').attr( 'id', 'reading_' + formtag ).attr( |
101 | 'name', 'reading_' + formtag ).attr( 'size', '50' ).attr( |
102 | 'class', 'reading_morphology' ).val( currform ); |
103 | forminput.autocomplete({ source: morphoptions, minLength: 0 }); |
104 | forminput.focus( function() { |
105 | if( $(this).val() == clicktag ) { |
106 | $(this).val(''); |
107 | } |
108 | $(this).autocomplete('search', '') |
109 | }); |
110 | var morphel = [ formlabel, forminput, $('<br/>') ]; |
111 | return morphel; |
112 | } |
113 | |
114 | function color_inactive ( el ) { |
115 | var reading_id = $(el).parent().attr('id'); |
116 | var reading_info = readingdata[reading_id]; |
117 | // If the reading info has any non-disambiguated lexemes, color it yellow; |
118 | // otherwise color it green. |
119 | $(el).attr( {stroke:'green', fill:'#b3f36d'} ); |
120 | if( reading_info ) { |
121 | $.each( reading_info['lexemes'], function ( idx, lex ) { |
122 | if( !lex['is_disambiguated'] || lex['is_disambiguated'] == 0 ) { |
123 | $(el).attr( {stroke:'orange', fill:'#fee233'} ); |
124 | } |
125 | }); |
126 | } |
127 | } |
128 | |
129 | function relemmatize () { |
130 | // Send the reading for a new lemmatization and reopen the form. |
131 | $('#relemmatize_pending').show(); |
132 | var reading_id = $('#reading_id').val() |
133 | ncpath = getReadingURL( reading_id ); |
134 | form_values = { |
135 | 'normal_form': $('#reading_normal_form').val(), |
136 | 'relemmatize': 1 }; |
137 | var jqjson = $.post( ncpath, form_values, function( data ) { |
138 | // Update the form with the return |
139 | if( 'id' in data ) { |
140 | // We got back a good answer. Stash it |
141 | readingdata[reading_id] = data; |
142 | // and regenerate the morphology form. |
143 | morphology_form( data['lexemes'] ); |
144 | } else { |
145 | alert("Could not relemmatize as requested: " + data['error']); |
146 | } |
147 | $('#relemmatize_pending').hide(); |
148 | }); |
149 | } |
150 | |
151 | // Initialize the SVG once it exists |
152 | function svgEnlargementLoaded() { |
153 | //Give some visual evidence that we are working |
154 | $('#loading_overlay').show(); |
155 | lo_height = $("#enlargement_container").outerHeight(); |
156 | lo_width = $("#enlargement_container").outerWidth(); |
157 | $("#loading_overlay").height( lo_height ); |
158 | $("#loading_overlay").width( lo_width ); |
159 | $("#loading_overlay").offset( $("#enlargement_container").offset() ); |
160 | $("#loading_message").offset( |
161 | { 'top': lo_height / 2 - $("#loading_message").height() / 2, |
162 | 'left': lo_width / 2 - $("#loading_message").width() / 2 }); |
163 | //Set viewbox widht and height to widht and height of $('#svgenlargement svg'). |
164 | //This is essential to make sure zooming and panning works properly. |
165 | var rdgpath = getTextURL( 'readings' ); |
166 | $.getJSON( rdgpath, function( data ) { |
167 | readingdata = data; |
168 | $('#svgenlargement ellipse').each( function( i, el ) { color_inactive( el ) }); |
169 | }); |
170 | $('#svgenlargement ellipse').parent().dblclick( node_dblclick_listener ); |
171 | var graph_svg = $('#svgenlargement svg'); |
172 | var svg_g = $('#svgenlargement svg g')[0]; |
173 | if (!svg_g) return; |
174 | svg_root = graph_svg.svg().svg('get').root(); |
175 | |
176 | // Find the real root and ignore any text nodes |
177 | for (i = 0; i < svg_root.childNodes.length; ++i) { |
178 | if (svg_root.childNodes[i].nodeName != '#text') { |
179 | svg_root_element = svg_root.childNodes[i]; |
180 | break; |
181 | } |
182 | } |
183 | |
184 | svg_root.viewBox.baseVal.width = graph_svg.attr( 'width' ); |
185 | svg_root.viewBox.baseVal.height = graph_svg.attr( 'height' ); |
186 | //Now set scale and translate so svg height is about 150px and vertically centered in viewbox. |
187 | //This is just to create a nice starting enlargement. |
188 | var initial_svg_height = 250; |
189 | var scale = initial_svg_height/graph_svg.attr( 'height' ); |
190 | var additional_translate = (graph_svg.attr( 'height' ) - initial_svg_height)/(2*scale); |
191 | var transform = svg_g.getAttribute('transform'); |
192 | var translate = parseFloat( transform.match( /translate\([^\)]*\)/ )[0].split('(')[1].split(' ')[1].split(')')[0] ); |
193 | translate += additional_translate; |
194 | var transform = 'rotate(0) scale(' + scale + ') translate(4 ' + translate + ')'; |
195 | svg_g.setAttribute('transform', transform); |
196 | //used to calculate min and max zoom level: |
197 | start_element_height = $('#__START__').children('ellipse')[0].getBBox().height; |
198 | add_relations( function() { $('#loading_overlay').hide(); }); |
199 | } |
200 | |
201 | function add_relations( callback_fn ) { |
56e3972e |
202 | // Add the relationship types to the keymap list |
203 | $.each( relationship_types, function(index, typedef) { |
204 | var elid = 'list_rel_' + typedef.name; |
205 | $('#keymaplist').append( $('<li>').attr( 'id', elid ).css( "border-color", relation_manager.relation_colors[index] ).text(typedef.name) ); |
206 | }); |
207 | // Now fetch the relationships themselves and add them to the graph |
208 | var rel_types = $.map( relationship_types, function(t) { return t.name }); |
20198e59 |
209 | var textrelpath = getTextURL( 'relationships' ); |
56e3972e |
210 | $.getJSON( textrelpath, function(data) { |
211 | $.each(data, function( index, rel_info ) { |
212 | var type_index = $.inArray(rel_info.type, rel_types); |
213 | var source_found = get_ellipse( rel_info.source ); |
214 | var target_found = get_ellipse( rel_info.target ); |
215 | if( type_index != -1 && source_found.size() && target_found.size() ) { |
216 | var relation = relation_manager.create( rel_info.source, rel_info.target, type_index ); |
217 | relation.data( 'type', rel_info.type ); |
218 | relation.data( 'scope', rel_info.scope ); |
219 | relation.data( 'note', rel_info.note ); |
220 | var node_obj = get_node_obj(rel_info.source); |
221 | node_obj.set_draggable( false ); |
222 | node_obj.ellipse.data( 'node_obj', null ); |
223 | node_obj = get_node_obj(rel_info.target); |
224 | node_obj.set_draggable( false ); |
225 | node_obj.ellipse.data( 'node_obj', null ); |
226 | } |
20198e59 |
227 | }); |
56e3972e |
228 | callback_fn.call(); |
229 | }); |
20198e59 |
230 | } |
231 | |
232 | function get_ellipse( node_id ) { |
233 | return $( jq( node_id ) + ' ellipse'); |
234 | } |
235 | |
236 | function get_node_obj( node_id ) { |
237 | var node_ellipse = get_ellipse( node_id ); |
238 | if( node_ellipse.data( 'node_obj' ) == null ) { |
239 | node_ellipse.data( 'node_obj', new node_obj(node_ellipse) ); |
240 | }; |
241 | return node_ellipse.data( 'node_obj' ); |
242 | } |
243 | |
244 | function node_obj(ellipse) { |
245 | this.ellipse = ellipse; |
246 | var self = this; |
247 | |
248 | this.x = 0; |
249 | this.y = 0; |
250 | this.dx = 0; |
251 | this.dy = 0; |
252 | this.node_elements = node_elements_for(self.ellipse); |
253 | |
254 | this.update_elements = function() { |
255 | self.node_elements = node_elements_for(self.ellipse); |
256 | } |
257 | } |
258 | |
259 | function svgshape( shape_element ) { |
260 | this.shape = shape_element; |
261 | this.move = function(dx,dy) { |
262 | this.shape.attr( "transform", "translate(" + dx + " " + dy + ")" ); |
263 | } |
264 | this.reset = function() { |
265 | this.shape.attr( "transform", "translate( 0, 0 )" ); |
266 | } |
267 | this.grey_out = function(filter) { |
268 | if( this.shape.parent(filter).size() != 0 ) { |
269 | this.shape.attr({'stroke':'#e5e5e5', 'fill':'#e5e5e5'}); |
270 | } |
271 | } |
272 | this.un_grey_out = function(filter) { |
273 | if( this.shape.parent(filter).size() != 0 ) { |
274 | this.shape.attr({'stroke':'#000000', 'fill':'#000000'}); |
275 | } |
276 | } |
277 | } |
278 | |
279 | function svgpath( path_element, svg_element ) { |
280 | this.svg_element = svg_element; |
281 | this.path = path_element; |
282 | this.x = this.path.x; |
283 | this.y = this.path.y; |
284 | this.move = function(dx,dy) { |
285 | this.path.x = this.x + dx; |
286 | this.path.y = this.y + dy; |
287 | } |
288 | this.reset = function() { |
289 | this.path.x = this.x; |
290 | this.path.y = this.y; |
291 | } |
292 | this.grey_out = function(filter) { |
293 | if( this.svg_element.parent(filter).size() != 0 ) { |
294 | this.svg_element.attr('stroke', '#e5e5e5'); |
295 | this.svg_element.siblings('text').attr('fill', '#e5e5e5'); |
296 | this.svg_element.siblings('text').attr('class', 'noselect'); |
297 | } |
298 | } |
299 | this.un_grey_out = function(filter) { |
300 | if( this.svg_element.parent(filter).size() != 0 ) { |
301 | this.svg_element.attr('stroke', '#000000'); |
302 | this.svg_element.siblings('text').attr('fill', '#000000'); |
303 | this.svg_element.siblings('text').attr('class', ''); |
304 | } |
305 | } |
306 | } |
307 | |
308 | function node_elements_for( ellipse ) { |
309 | node_elements = get_edge_elements_for( ellipse ); |
310 | node_elements.push( new svgshape( ellipse.siblings('text') ) ); |
311 | node_elements.push( new svgshape( ellipse ) ); |
312 | return node_elements; |
313 | } |
314 | |
315 | function get_edge_elements_for( ellipse ) { |
316 | edge_elements = new Array(); |
317 | node_id = ellipse.parent().attr('id'); |
318 | edge_in_pattern = new RegExp( node_id + '$' ); |
319 | edge_out_pattern = new RegExp( '^' + node_id ); |
320 | $.each( $('#svgenlargement .edge,#svgenlargement .relation').children('title'), function(index) { |
321 | title = $(this).text(); |
322 | if( edge_in_pattern.test(title) ) { |
323 | polygon = $(this).siblings('polygon'); |
324 | if( polygon.size() > 0 ) { |
325 | edge_elements.push( new svgshape( polygon ) ); |
326 | } |
327 | path_segments = $(this).siblings('path')[0].pathSegList; |
328 | edge_elements.push( new svgpath( path_segments.getItem(path_segments.numberOfItems - 1), $(this).siblings('path') ) ); |
329 | } |
330 | if( edge_out_pattern.test(title) ) { |
331 | path_segments = $(this).siblings('path')[0].pathSegList; |
332 | edge_elements.push( new svgpath( path_segments.getItem(0), $(this).siblings('path') ) ); |
333 | } |
334 | }); |
335 | return edge_elements; |
336 | } |
337 | |
338 | function relation_factory() { |
339 | var self = this; |
340 | this.color_memo = null; |
341 | //TODO: colors hard coded for now |
342 | this.relation_colors = [ "#5CCCCC", "#67E667", "#F9FE72", "#6B90D4", "#FF7673", "#E467B3", "#AA67D5", "#8370D8", "#FFC173" ]; |
343 | |
344 | this.create = function( source_node_id, target_node_id, color_index ) { |
345 | //TODO: Protect from (color_)index out of bound.. |
346 | var relation_color = self.relation_colors[ color_index ]; |
347 | var relation = draw_relation( source_node_id, target_node_id, relation_color ); |
348 | var relation_id = get_relation_id( source_node_id, target_node_id ); |
349 | get_node_obj( source_node_id ).update_elements(); |
350 | get_node_obj( target_node_id ).update_elements(); |
351 | // Set it active by default. May need to restore toggling if having all |
352 | // relationships active is too much of a performance hit. |
353 | var relation_path = relation.children('path'); |
354 | // All relations active in order to allow hover information? |
355 | // Else we will have to deactivate them when they go off-screen. |
356 | relation_path.css( {'cursor':'pointer'} ); |
357 | relation_path.mouseenter( function(event) { |
358 | outerTimer = setTimeout( function() { |
359 | timer = setTimeout( function() { |
360 | var related_nodes = get_related_nodes( relation_id ); |
361 | var source_node_id = related_nodes[0]; |
362 | var target_node_id = related_nodes[1]; |
363 | $('#delete_source_node_id').val( source_node_id ); |
364 | $('#delete_target_node_id').val( target_node_id ); |
365 | self.showinfo(relation); |
366 | }, 500 ) |
367 | }, 1000 ); |
368 | }); |
369 | relation_path.mouseleave( function(event) { |
370 | clearTimeout(outerTimer); |
371 | if( timer != null ) { clearTimeout(timer); } |
372 | }); |
373 | |
374 | return relation; |
375 | } |
376 | |
377 | this.showinfo = function(relation) { |
378 | var htmlstr = 'type: ' + relation.data( 'type' ) + '<br/>scope: ' + relation.data( 'scope' ); |
379 | if( relation.data( 'note' ) ) { |
380 | htmlstr = htmlstr + '<br/>note: ' + relation.data( 'note' ); |
381 | } |
382 | $('#delete-form-text').html( htmlstr ); |
383 | var points = relation.children('path').attr('d').slice(1).replace('C',' ').split(' '); |
384 | var xs = parseFloat( points[0].split(',')[0] ); |
385 | var xe = parseFloat( points[1].split(',')[0] ); |
386 | var ys = parseFloat( points[0].split(',')[1] ); |
387 | var ye = parseFloat( points[3].split(',')[1] ); |
388 | var p = svg_root.createSVGPoint(); |
389 | p.x = xs + ((xe-xs)*1.1); |
390 | p.y = ye - ((ye-ys)/2); |
391 | var ctm = svg_root_element.getScreenCTM(); |
392 | var nx = p.matrixTransform(ctm).x; |
393 | var ny = p.matrixTransform(ctm).y; |
394 | var dialog_aria = $ ("div[aria-labelledby='ui-dialog-title-delete-form']"); |
395 | $('#delete-form').dialog( 'open' ); |
396 | dialog_aria.offset({ left: nx, top: ny }); |
397 | } |
398 | /* Do we need this in readonly mode? |
399 | this.remove = function( relation_id ) { |
400 | var relation = $( jq( relation_id ) ); |
401 | relation.remove(); |
402 | } |
403 | */ |
404 | } |
405 | |
406 | // Utility function to create/return the ID of a relation link between |
407 | // a source and target. |
408 | function get_relation_id( source_id, target_id ) { |
409 | var idlist = [ source_id, target_id ]; |
410 | idlist.sort(); |
411 | return 'relation-' + idlist[0] + '-...-' + idlist[1]; |
412 | } |
413 | |
414 | function get_related_nodes( relation_id ) { |
415 | var srctotarg = relation_id.substr( 9 ); |
416 | return srctotarg.split('-...-'); |
417 | } |
418 | |
419 | function draw_relation( source_id, target_id, relation_color ) { |
420 | var source_ellipse = get_ellipse( source_id ); |
421 | var target_ellipse = get_ellipse( target_id ); |
422 | var relation_id = get_relation_id( source_id, target_id ); |
423 | var svg = $('#svgenlargement').children('svg').svg().svg('get'); |
424 | var path = svg.createPath(); |
425 | var sx = parseInt( source_ellipse.attr('cx') ); |
426 | var rx = parseInt( source_ellipse.attr('rx') ); |
427 | var sy = parseInt( source_ellipse.attr('cy') ); |
428 | var ex = parseInt( target_ellipse.attr('cx') ); |
429 | var ey = parseInt( target_ellipse.attr('cy') ); |
430 | var relation = svg.group( $("#svgenlargement svg g"), |
431 | { 'class':'relation', 'id':relation_id } ); |
432 | svg.title( relation, source_id + '->' + target_id ); |
433 | svg.path( relation, path.move( sx, sy ).curveC( sx + (2*rx), sy, ex + (2*rx), ey, ex, ey ), {fill: 'none', stroke: relation_color, strokeWidth: 4}); |
434 | var relation_element = $('#svgenlargement .relation').filter( ':last' ); |
435 | relation_element.insertBefore( $('#svgenlargement g g').filter(':first') ); |
436 | return relation_element; |
437 | } |
438 | |
439 | $(document).ready(function () { |
440 | |
441 | timer = null; |
442 | relation_manager = new relation_factory(); |
443 | |
444 | $('#enlargement').mousedown(function (event) { |
445 | $(this) |
446 | .data('down', true) |
447 | .data('x', event.clientX) |
448 | .data('y', event.clientY) |
449 | .data('scrollLeft', this.scrollLeft) |
450 | stateTf = svg_root_element.getCTM().inverse(); |
451 | var p = svg_root.createSVGPoint(); |
452 | p.x = event.clientX; |
453 | p.y = event.clientY; |
454 | stateOrigin = p.matrixTransform(stateTf); |
455 | event.returnValue = false; |
456 | event.preventDefault(); |
457 | return false; |
458 | }).mouseup(function (event) { |
459 | $(this).data('down', false); |
460 | }).mousemove(function (event) { |
461 | if( timer != null ) { clearTimeout(timer); } |
462 | if ( ($(this).data('down') == true) ) { |
463 | var p = svg_root.createSVGPoint(); |
464 | p.x = event.clientX; |
465 | p.y = event.clientY; |
466 | p = p.matrixTransform(stateTf); |
467 | var matrix = stateTf.inverse().translate(p.x - stateOrigin.x, p.y - stateOrigin.y); |
468 | var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")"; |
469 | svg_root_element.setAttribute("transform", s); |
470 | } |
471 | event.returnValue = false; |
472 | event.preventDefault(); |
473 | }).mousewheel(function (event, delta) { |
474 | event.returnValue = false; |
475 | event.preventDefault(); |
476 | if (!delta || delta == null || delta == 0) delta = event.originalEvent.wheelDelta; |
477 | if (!delta || delta == null || delta == 0) delta = -1 * event.originalEvent.detail; |
478 | if( delta < -9 ) { delta = -9 }; |
479 | var z = 1 + delta/10; |
480 | z = delta > 0 ? 1 : -1; |
481 | var g = svg_root_element; |
482 | if (g && ((z<1 && (g.getScreenCTM().a * start_element_height) > 4.0) || (z>=1 && (g.getScreenCTM().a * start_element_height) < 100))) { |
483 | var root = svg_root; |
484 | var p = root.createSVGPoint(); |
485 | p.x = event.originalEvent.clientX; |
486 | p.y = event.originalEvent.clientY; |
487 | p = p.matrixTransform(g.getCTM().inverse()); |
488 | var scaleLevel = 1+(z/20); |
489 | var k = root.createSVGMatrix().translate(p.x, p.y).scale(scaleLevel).translate(-p.x, -p.y); |
490 | var matrix = g.getCTM().multiply(k); |
491 | var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")"; |
492 | g.setAttribute("transform", s); |
493 | } |
494 | }).css({ |
495 | 'overflow' : 'hidden', |
496 | 'cursor' : '-moz-grab' |
497 | }); |
498 | |
499 | $( "#delete-form" ).dialog({ |
500 | autoOpen: false, |
501 | height: 135, |
502 | width: 160, |
503 | modal: false, |
504 | buttons: { |
505 | OK: function() { |
506 | $( this ).dialog( "close" ); |
507 | } |
508 | }, |
509 | create: function(event, ui) { |
510 | var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' ); |
511 | buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' ); |
512 | var dialog_aria = $("div[aria-labelledby='ui-dialog-title-delete-form']"); |
513 | dialog_aria.mouseenter( function() { |
514 | if( mouseWait != null ) { clearTimeout(mouseWait) }; |
515 | }) |
516 | dialog_aria.mouseleave( function() { |
517 | mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 ); |
518 | }) |
519 | }, |
520 | open: function() { |
521 | mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 ); |
522 | }, |
523 | close: function() { |
524 | } |
525 | }); |
526 | |
487674b9 |
527 | // function for reading form dialog should go here; |
528 | // just hide the element for now if we don't have morphology |
529 | if( can_morphologize ) { |
530 | $('#reading-form').dialog({ |
531 | autoOpen: false, |
532 | width: 450, |
533 | modal: true, |
534 | buttons: { |
535 | OK: function() { |
536 | $( this ).dialog( "close" ); |
537 | } |
538 | }, |
539 | create: function() { |
540 | // Hide the relemmatize button since it is not allowed |
541 | $('#reading_relemmatize').hide(); |
542 | }, |
543 | open: function() { |
544 | $(".ui-widget-overlay").css("background", "none"); |
545 | $("#dialog_overlay").show(); |
546 | $('#reading_status').empty(); |
547 | $("#dialog_overlay").height( $("#enlargement_container").height() ); |
548 | $("#dialog_overlay").width( $("#enlargement_container").innerWidth() ); |
549 | $("#dialog_overlay").offset( $("#enlargement_container").offset() ); |
550 | }, |
551 | close: function() { |
552 | $("#dialog_overlay").hide(); |
553 | } |
554 | }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) { |
555 | if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1 |
556 | && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { |
557 | var errobj = jQuery.parseJSON( jqXHR.responseText ); |
558 | $('#reading_status').append( '<p class="error">Error: ' + errobj.error + '</p>' ); |
559 | } |
560 | $(event.target).parent().find('.ui-button').button("enable"); |
561 | }); |
562 | } else { |
563 | $('#reading-form').hide(); |
564 | } |
20198e59 |
565 | |
69ac99fc |
566 | // Hide the unused elements |
567 | $('#dialog-form').hide(); |
20198e59 |
568 | $('#update_workspace_button').hide(); |
569 | |
570 | $('.helptag').popupWindow({ |
571 | height:500, |
572 | width:800, |
573 | top:50, |
574 | left:50, |
575 | scrollbars:1 |
576 | }); |
577 | |
578 | |
579 | expandFillPageClients(); |
580 | $(window).resize(function() { |
581 | expandFillPageClients(); |
582 | }); |
583 | |
584 | }); |
585 | |
586 | |
587 | function expandFillPageClients() { |
588 | $('.fillPage').each(function () { |
589 | $(this).height($(window).height() - $(this).offset().top - MARGIN); |
590 | }); |
591 | } |
592 | |
593 | function loadSVG(svgData) { |
594 | var svgElement = $('#svgenlargement'); |
595 | |
596 | $(svgElement).svg('destroy'); |
597 | |
598 | $(svgElement).svg({ |
599 | loadURL: svgData, |
600 | onLoad : svgEnlargementLoaded |
601 | }); |
602 | } |
603 | |
604 | |
605 | /* OS Gadget stuff |
606 | |
607 | function svg_select_callback(topic, data, subscriberData) { |
608 | svgData = data; |
609 | loadSVG(svgData); |
610 | } |
611 | |
612 | function loaded() { |
613 | var prefs = new gadgets.Prefs(); |
614 | var preferredHeight = parseInt(prefs.getString('height')); |
615 | if (gadgets.util.hasFeature('dynamic-height')) gadgets.window.adjustHeight(preferredHeight); |
616 | expandFillPageClients(); |
617 | } |
618 | |
619 | if (gadgets.util.hasFeature('pubsub-2')) { |
620 | gadgets.HubSettings.onConnect = function(hum, suc, err) { |
621 | subId = gadgets.Hub.subscribe("interedition.svg.selected", svg_select_callback); |
622 | loaded(); |
623 | }; |
624 | } |
625 | else gadgets.util.registerOnLoadHandler(loaded); |
626 | */ |