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) { |
671c04b1 |
204 | li_elm = $('<li class="key">').css( "border-color", |
205 | relation_manager.relation_colors[index] ).text(typedef.name); |
206 | li_elm.append( $('<div>').attr('class', 'key_tip_container').append( |
207 | $('<div>').attr('class', 'key_tip').text(typedef.description) ) ); |
208 | $('#keymaplist').append( li_elm ); |
56e3972e |
209 | }); |
210 | // Now fetch the relationships themselves and add them to the graph |
211 | var rel_types = $.map( relationship_types, function(t) { return t.name }); |
20198e59 |
212 | var textrelpath = getTextURL( 'relationships' ); |
56e3972e |
213 | $.getJSON( textrelpath, function(data) { |
214 | $.each(data, function( index, rel_info ) { |
215 | var type_index = $.inArray(rel_info.type, rel_types); |
216 | var source_found = get_ellipse( rel_info.source ); |
217 | var target_found = get_ellipse( rel_info.target ); |
218 | if( type_index != -1 && source_found.size() && target_found.size() ) { |
219 | var relation = relation_manager.create( rel_info.source, rel_info.target, type_index ); |
220 | relation.data( 'type', rel_info.type ); |
221 | relation.data( 'scope', rel_info.scope ); |
222 | relation.data( 'note', rel_info.note ); |
223 | var node_obj = get_node_obj(rel_info.source); |
224 | node_obj.set_draggable( false ); |
225 | node_obj.ellipse.data( 'node_obj', null ); |
226 | node_obj = get_node_obj(rel_info.target); |
227 | node_obj.set_draggable( false ); |
228 | node_obj.ellipse.data( 'node_obj', null ); |
229 | } |
20198e59 |
230 | }); |
56e3972e |
231 | callback_fn.call(); |
232 | }); |
20198e59 |
233 | } |
234 | |
235 | function get_ellipse( node_id ) { |
236 | return $( jq( node_id ) + ' ellipse'); |
237 | } |
238 | |
239 | function get_node_obj( node_id ) { |
240 | var node_ellipse = get_ellipse( node_id ); |
241 | if( node_ellipse.data( 'node_obj' ) == null ) { |
242 | node_ellipse.data( 'node_obj', new node_obj(node_ellipse) ); |
243 | }; |
244 | return node_ellipse.data( 'node_obj' ); |
245 | } |
246 | |
247 | function node_obj(ellipse) { |
248 | this.ellipse = ellipse; |
249 | var self = this; |
250 | |
251 | this.x = 0; |
252 | this.y = 0; |
253 | this.dx = 0; |
254 | this.dy = 0; |
255 | this.node_elements = node_elements_for(self.ellipse); |
256 | |
257 | this.update_elements = function() { |
258 | self.node_elements = node_elements_for(self.ellipse); |
259 | } |
260 | } |
261 | |
262 | function svgshape( shape_element ) { |
263 | this.shape = shape_element; |
264 | this.move = function(dx,dy) { |
265 | this.shape.attr( "transform", "translate(" + dx + " " + dy + ")" ); |
266 | } |
267 | this.reset = function() { |
268 | this.shape.attr( "transform", "translate( 0, 0 )" ); |
269 | } |
270 | this.grey_out = function(filter) { |
271 | if( this.shape.parent(filter).size() != 0 ) { |
272 | this.shape.attr({'stroke':'#e5e5e5', 'fill':'#e5e5e5'}); |
273 | } |
274 | } |
275 | this.un_grey_out = function(filter) { |
276 | if( this.shape.parent(filter).size() != 0 ) { |
277 | this.shape.attr({'stroke':'#000000', 'fill':'#000000'}); |
278 | } |
279 | } |
280 | } |
281 | |
282 | function svgpath( path_element, svg_element ) { |
283 | this.svg_element = svg_element; |
284 | this.path = path_element; |
285 | this.x = this.path.x; |
286 | this.y = this.path.y; |
287 | this.move = function(dx,dy) { |
288 | this.path.x = this.x + dx; |
289 | this.path.y = this.y + dy; |
290 | } |
291 | this.reset = function() { |
292 | this.path.x = this.x; |
293 | this.path.y = this.y; |
294 | } |
295 | this.grey_out = function(filter) { |
296 | if( this.svg_element.parent(filter).size() != 0 ) { |
297 | this.svg_element.attr('stroke', '#e5e5e5'); |
298 | this.svg_element.siblings('text').attr('fill', '#e5e5e5'); |
299 | this.svg_element.siblings('text').attr('class', 'noselect'); |
300 | } |
301 | } |
302 | this.un_grey_out = function(filter) { |
303 | if( this.svg_element.parent(filter).size() != 0 ) { |
304 | this.svg_element.attr('stroke', '#000000'); |
305 | this.svg_element.siblings('text').attr('fill', '#000000'); |
306 | this.svg_element.siblings('text').attr('class', ''); |
307 | } |
308 | } |
309 | } |
310 | |
311 | function node_elements_for( ellipse ) { |
312 | node_elements = get_edge_elements_for( ellipse ); |
313 | node_elements.push( new svgshape( ellipse.siblings('text') ) ); |
314 | node_elements.push( new svgshape( ellipse ) ); |
315 | return node_elements; |
316 | } |
317 | |
318 | function get_edge_elements_for( ellipse ) { |
319 | edge_elements = new Array(); |
320 | node_id = ellipse.parent().attr('id'); |
321 | edge_in_pattern = new RegExp( node_id + '$' ); |
322 | edge_out_pattern = new RegExp( '^' + node_id ); |
323 | $.each( $('#svgenlargement .edge,#svgenlargement .relation').children('title'), function(index) { |
324 | title = $(this).text(); |
325 | if( edge_in_pattern.test(title) ) { |
326 | polygon = $(this).siblings('polygon'); |
327 | if( polygon.size() > 0 ) { |
328 | edge_elements.push( new svgshape( polygon ) ); |
329 | } |
330 | path_segments = $(this).siblings('path')[0].pathSegList; |
331 | edge_elements.push( new svgpath( path_segments.getItem(path_segments.numberOfItems - 1), $(this).siblings('path') ) ); |
332 | } |
333 | if( edge_out_pattern.test(title) ) { |
334 | path_segments = $(this).siblings('path')[0].pathSegList; |
335 | edge_elements.push( new svgpath( path_segments.getItem(0), $(this).siblings('path') ) ); |
336 | } |
337 | }); |
338 | return edge_elements; |
339 | } |
340 | |
341 | function relation_factory() { |
342 | var self = this; |
343 | this.color_memo = null; |
344 | //TODO: colors hard coded for now |
345 | this.relation_colors = [ "#5CCCCC", "#67E667", "#F9FE72", "#6B90D4", "#FF7673", "#E467B3", "#AA67D5", "#8370D8", "#FFC173" ]; |
346 | |
347 | this.create = function( source_node_id, target_node_id, color_index ) { |
348 | //TODO: Protect from (color_)index out of bound.. |
349 | var relation_color = self.relation_colors[ color_index ]; |
350 | var relation = draw_relation( source_node_id, target_node_id, relation_color ); |
351 | var relation_id = get_relation_id( source_node_id, target_node_id ); |
352 | get_node_obj( source_node_id ).update_elements(); |
353 | get_node_obj( target_node_id ).update_elements(); |
354 | // Set it active by default. May need to restore toggling if having all |
355 | // relationships active is too much of a performance hit. |
356 | var relation_path = relation.children('path'); |
357 | // All relations active in order to allow hover information? |
358 | // Else we will have to deactivate them when they go off-screen. |
359 | relation_path.css( {'cursor':'pointer'} ); |
360 | relation_path.mouseenter( function(event) { |
361 | outerTimer = setTimeout( function() { |
362 | timer = setTimeout( function() { |
363 | var related_nodes = get_related_nodes( relation_id ); |
364 | var source_node_id = related_nodes[0]; |
365 | var target_node_id = related_nodes[1]; |
366 | $('#delete_source_node_id').val( source_node_id ); |
367 | $('#delete_target_node_id').val( target_node_id ); |
368 | self.showinfo(relation); |
369 | }, 500 ) |
370 | }, 1000 ); |
371 | }); |
372 | relation_path.mouseleave( function(event) { |
373 | clearTimeout(outerTimer); |
374 | if( timer != null ) { clearTimeout(timer); } |
375 | }); |
376 | |
377 | return relation; |
378 | } |
379 | |
380 | this.showinfo = function(relation) { |
381 | var htmlstr = 'type: ' + relation.data( 'type' ) + '<br/>scope: ' + relation.data( 'scope' ); |
382 | if( relation.data( 'note' ) ) { |
383 | htmlstr = htmlstr + '<br/>note: ' + relation.data( 'note' ); |
384 | } |
385 | $('#delete-form-text').html( htmlstr ); |
386 | var points = relation.children('path').attr('d').slice(1).replace('C',' ').split(' '); |
387 | var xs = parseFloat( points[0].split(',')[0] ); |
388 | var xe = parseFloat( points[1].split(',')[0] ); |
389 | var ys = parseFloat( points[0].split(',')[1] ); |
390 | var ye = parseFloat( points[3].split(',')[1] ); |
391 | var p = svg_root.createSVGPoint(); |
392 | p.x = xs + ((xe-xs)*1.1); |
393 | p.y = ye - ((ye-ys)/2); |
394 | var ctm = svg_root_element.getScreenCTM(); |
395 | var nx = p.matrixTransform(ctm).x; |
396 | var ny = p.matrixTransform(ctm).y; |
397 | var dialog_aria = $ ("div[aria-labelledby='ui-dialog-title-delete-form']"); |
398 | $('#delete-form').dialog( 'open' ); |
399 | dialog_aria.offset({ left: nx, top: ny }); |
400 | } |
401 | /* Do we need this in readonly mode? |
402 | this.remove = function( relation_id ) { |
403 | var relation = $( jq( relation_id ) ); |
404 | relation.remove(); |
405 | } |
406 | */ |
407 | } |
408 | |
409 | // Utility function to create/return the ID of a relation link between |
410 | // a source and target. |
411 | function get_relation_id( source_id, target_id ) { |
412 | var idlist = [ source_id, target_id ]; |
413 | idlist.sort(); |
414 | return 'relation-' + idlist[0] + '-...-' + idlist[1]; |
415 | } |
416 | |
417 | function get_related_nodes( relation_id ) { |
418 | var srctotarg = relation_id.substr( 9 ); |
419 | return srctotarg.split('-...-'); |
420 | } |
421 | |
422 | function draw_relation( source_id, target_id, relation_color ) { |
423 | var source_ellipse = get_ellipse( source_id ); |
424 | var target_ellipse = get_ellipse( target_id ); |
425 | var relation_id = get_relation_id( source_id, target_id ); |
426 | var svg = $('#svgenlargement').children('svg').svg().svg('get'); |
427 | var path = svg.createPath(); |
428 | var sx = parseInt( source_ellipse.attr('cx') ); |
429 | var rx = parseInt( source_ellipse.attr('rx') ); |
430 | var sy = parseInt( source_ellipse.attr('cy') ); |
431 | var ex = parseInt( target_ellipse.attr('cx') ); |
432 | var ey = parseInt( target_ellipse.attr('cy') ); |
433 | var relation = svg.group( $("#svgenlargement svg g"), |
434 | { 'class':'relation', 'id':relation_id } ); |
435 | svg.title( relation, source_id + '->' + target_id ); |
436 | 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}); |
437 | var relation_element = $('#svgenlargement .relation').filter( ':last' ); |
438 | relation_element.insertBefore( $('#svgenlargement g g').filter(':first') ); |
439 | return relation_element; |
440 | } |
441 | |
442 | $(document).ready(function () { |
443 | |
444 | timer = null; |
445 | relation_manager = new relation_factory(); |
446 | |
447 | $('#enlargement').mousedown(function (event) { |
448 | $(this) |
449 | .data('down', true) |
450 | .data('x', event.clientX) |
451 | .data('y', event.clientY) |
452 | .data('scrollLeft', this.scrollLeft) |
453 | stateTf = svg_root_element.getCTM().inverse(); |
454 | var p = svg_root.createSVGPoint(); |
455 | p.x = event.clientX; |
456 | p.y = event.clientY; |
457 | stateOrigin = p.matrixTransform(stateTf); |
458 | event.returnValue = false; |
459 | event.preventDefault(); |
460 | return false; |
461 | }).mouseup(function (event) { |
462 | $(this).data('down', false); |
463 | }).mousemove(function (event) { |
464 | if( timer != null ) { clearTimeout(timer); } |
465 | if ( ($(this).data('down') == true) ) { |
466 | var p = svg_root.createSVGPoint(); |
467 | p.x = event.clientX; |
468 | p.y = event.clientY; |
469 | p = p.matrixTransform(stateTf); |
470 | var matrix = stateTf.inverse().translate(p.x - stateOrigin.x, p.y - stateOrigin.y); |
471 | var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")"; |
472 | svg_root_element.setAttribute("transform", s); |
473 | } |
474 | event.returnValue = false; |
475 | event.preventDefault(); |
476 | }).mousewheel(function (event, delta) { |
477 | event.returnValue = false; |
478 | event.preventDefault(); |
479 | if (!delta || delta == null || delta == 0) delta = event.originalEvent.wheelDelta; |
480 | if (!delta || delta == null || delta == 0) delta = -1 * event.originalEvent.detail; |
481 | if( delta < -9 ) { delta = -9 }; |
482 | var z = 1 + delta/10; |
483 | z = delta > 0 ? 1 : -1; |
484 | var g = svg_root_element; |
485 | if (g && ((z<1 && (g.getScreenCTM().a * start_element_height) > 4.0) || (z>=1 && (g.getScreenCTM().a * start_element_height) < 100))) { |
486 | var root = svg_root; |
487 | var p = root.createSVGPoint(); |
488 | p.x = event.originalEvent.clientX; |
489 | p.y = event.originalEvent.clientY; |
490 | p = p.matrixTransform(g.getCTM().inverse()); |
491 | var scaleLevel = 1+(z/20); |
492 | var k = root.createSVGMatrix().translate(p.x, p.y).scale(scaleLevel).translate(-p.x, -p.y); |
493 | var matrix = g.getCTM().multiply(k); |
494 | var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")"; |
495 | g.setAttribute("transform", s); |
496 | } |
497 | }).css({ |
498 | 'overflow' : 'hidden', |
499 | 'cursor' : '-moz-grab' |
500 | }); |
501 | |
502 | $( "#delete-form" ).dialog({ |
503 | autoOpen: false, |
504 | height: 135, |
505 | width: 160, |
506 | modal: false, |
507 | buttons: { |
508 | OK: function() { |
509 | $( this ).dialog( "close" ); |
510 | } |
511 | }, |
512 | create: function(event, ui) { |
513 | var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' ); |
514 | buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' ); |
515 | var dialog_aria = $("div[aria-labelledby='ui-dialog-title-delete-form']"); |
516 | dialog_aria.mouseenter( function() { |
517 | if( mouseWait != null ) { clearTimeout(mouseWait) }; |
518 | }) |
519 | dialog_aria.mouseleave( function() { |
520 | mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 ); |
521 | }) |
522 | }, |
523 | open: function() { |
524 | mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 ); |
525 | }, |
526 | close: function() { |
527 | } |
528 | }); |
529 | |
487674b9 |
530 | // function for reading form dialog should go here; |
531 | // just hide the element for now if we don't have morphology |
532 | if( can_morphologize ) { |
533 | $('#reading-form').dialog({ |
534 | autoOpen: false, |
535 | width: 450, |
536 | modal: true, |
537 | buttons: { |
538 | OK: function() { |
539 | $( this ).dialog( "close" ); |
540 | } |
541 | }, |
542 | create: function() { |
543 | // Hide the relemmatize button since it is not allowed |
544 | $('#reading_relemmatize').hide(); |
545 | }, |
546 | open: function() { |
547 | $(".ui-widget-overlay").css("background", "none"); |
548 | $("#dialog_overlay").show(); |
549 | $('#reading_status').empty(); |
550 | $("#dialog_overlay").height( $("#enlargement_container").height() ); |
551 | $("#dialog_overlay").width( $("#enlargement_container").innerWidth() ); |
552 | $("#dialog_overlay").offset( $("#enlargement_container").offset() ); |
553 | }, |
554 | close: function() { |
555 | $("#dialog_overlay").hide(); |
556 | } |
557 | }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) { |
558 | if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1 |
559 | && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) { |
560 | var errobj = jQuery.parseJSON( jqXHR.responseText ); |
561 | $('#reading_status').append( '<p class="error">Error: ' + errobj.error + '</p>' ); |
562 | } |
563 | $(event.target).parent().find('.ui-button').button("enable"); |
564 | }); |
565 | } else { |
566 | $('#reading-form').hide(); |
567 | } |
20198e59 |
568 | |
69ac99fc |
569 | // Hide the unused elements |
570 | $('#dialog-form').hide(); |
20198e59 |
571 | $('#update_workspace_button').hide(); |
572 | |
573 | $('.helptag').popupWindow({ |
574 | height:500, |
575 | width:800, |
576 | top:50, |
577 | left:50, |
578 | scrollbars:1 |
579 | }); |
580 | |
581 | |
582 | expandFillPageClients(); |
583 | $(window).resize(function() { |
584 | expandFillPageClients(); |
585 | }); |
586 | |
587 | }); |
588 | |
589 | |
590 | function expandFillPageClients() { |
591 | $('.fillPage').each(function () { |
592 | $(this).height($(window).height() - $(this).offset().top - MARGIN); |
593 | }); |
594 | } |
595 | |
596 | function loadSVG(svgData) { |
597 | var svgElement = $('#svgenlargement'); |
598 | |
599 | $(svgElement).svg('destroy'); |
600 | |
601 | $(svgElement).svg({ |
602 | loadURL: svgData, |
603 | onLoad : svgEnlargementLoaded |
604 | }); |
605 | } |
606 | |
607 | |
608 | /* OS Gadget stuff |
609 | |
610 | function svg_select_callback(topic, data, subscriberData) { |
611 | svgData = data; |
612 | loadSVG(svgData); |
613 | } |
614 | |
615 | function loaded() { |
616 | var prefs = new gadgets.Prefs(); |
617 | var preferredHeight = parseInt(prefs.getString('height')); |
618 | if (gadgets.util.hasFeature('dynamic-height')) gadgets.window.adjustHeight(preferredHeight); |
619 | expandFillPageClients(); |
620 | } |
621 | |
622 | if (gadgets.util.hasFeature('pubsub-2')) { |
623 | gadgets.HubSettings.onConnect = function(hum, suc, err) { |
624 | subId = gadgets.Hub.subscribe("interedition.svg.selected", svg_select_callback); |
625 | loaded(); |
626 | }; |
627 | } |
628 | else gadgets.util.registerOnLoadHandler(loaded); |
629 | */ |