Align the svg properly for BI/RL text
[scpubgit/stemmaweb.git] / root / js / relationship.js
CommitLineData
76f05423 1var MARGIN=30;
2var svg_root = null;
3var svg_root_element = null;
4var start_element_height = 0;
5var reltypes = {};
5f15640c 6var readingdata = {};
76f05423 7
a471cb0f 8jQuery.removeFromArray = function(value, arr) {
9 return jQuery.grep(arr, function(elem, index) {
10 return elem !== value;
11 });
12};
13
a84ca4de 14function arrayUnique(array) {
15 var a = array.concat();
16 for(var i=0; i<a.length; ++i) {
17 for(var j=i+1; j<a.length; ++j) {
18 if(a[i] === a[j])
19 a.splice(j--, 1);
20 }
21 }
22 return a;
23};
24
5f15640c 25function getTextURL( which ) {
3f9d7ae5 26 return basepath + textid + '/' + which;
5f15640c 27}
28
29function getReadingURL( reading_id ) {
3f9d7ae5 30 return basepath + textid + '/reading/' + reading_id;
b28e606e 31}
32
45ee3b96 33// Make an XML ID into a valid selector
34function jq(myid) {
35 return '#' + myid.replace(/(:|\.)/g,'\\$1');
36}
37
065c7cf2 38// Actions for opening the reading panel
39function node_dblclick_listener( evt ) {
40 // Open the reading dialogue for the given node.
41 // First get the reading info
42 var reading_id = $(this).attr('id');
43 var reading_info = readingdata[reading_id];
44 // and then populate the dialog box with it.
45 // Set the easy properties first
46 $('#reading-form').dialog( 'option', 'title', 'Reading information for "' + reading_info['text'] + '"' );
47 $('#reading_id').val( reading_id );
798fa939 48 toggle_checkbox( $('#reading_is_nonsense'), reading_info['is_nonsense'] );
49 toggle_checkbox( $('#reading_grammar_invalid'), reading_info['grammar_invalid'] );
065c7cf2 50 // Use .text as a backup for .normal_form
51 var normal_form = reading_info['normal_form'];
52 if( !normal_form ) {
53 normal_form = reading_info['text'];
54 }
55 var nfboxsize = 10;
56 if( normal_form.length > 9 ) {
57 nfboxsize = normal_form.length + 1;
58 }
59 $('#reading_normal_form').attr( 'size', nfboxsize )
60 $('#reading_normal_form').val( normal_form );
61 // Now do the morphological properties.
0dcdd5ec 62 morphology_form( reading_info['lexemes'] );
065c7cf2 63 // and then open the dialog.
0dcdd5ec 64 $('#reading-form').dialog("open");
65}
66
798fa939 67function toggle_checkbox( box, value ) {
68 if( value == null ) {
69 value = false;
70 }
71 box.attr('checked', value );
72}
73
0dcdd5ec 74function morphology_form ( lexlist ) {
487674b9 75 if( lexlist.length ) {
76 $('#morph_outer').show();
77 $('#morphology').empty();
78 $.each( lexlist, function( idx, lex ) {
79 var morphoptions = [];
80 if( 'wordform_matchlist' in lex ) {
81 $.each( lex['wordform_matchlist'], function( tdx, tag ) {
82 var tagstr = stringify_wordform( tag );
83 morphoptions.push( tagstr );
84 });
85 }
86 var formtag = 'morphology_' + idx;
87 var formstr = '';
88 if( 'form' in lex ) {
89 formstr = stringify_wordform( lex['form'] );
90 }
91 var form_morph_elements = morph_elements(
92 formtag, lex['string'], formstr, morphoptions );
93 $.each( form_morph_elements, function( idx, el ) {
94 $('#morphology').append( el );
08f8443a 95 });
065c7cf2 96 });
487674b9 97 } else {
98 $('#morph_outer').hide();
99 }
065c7cf2 100}
101
102function stringify_wordform ( tag ) {
08f8443a 103 if( tag ) {
104 var elements = tag.split(' // ');
105 return elements[1] + ' // ' + elements[2];
106 }
107 return ''
065c7cf2 108}
109
d1132306 110function morph_elements ( formtag, formtxt, currform, morphoptions ) {
111 var clicktag = '(Click to select)';
112 if ( !currform ) {
113 currform = clicktag;
114 }
065c7cf2 115 var formlabel = $('<label/>').attr( 'id', 'label_' + formtag ).attr(
d1132306 116 'for', 'reading_' + formtag ).text( formtxt + ': ' );
065c7cf2 117 var forminput = $('<input/>').attr( 'id', 'reading_' + formtag ).attr(
0dcdd5ec 118 'name', 'reading_' + formtag ).attr( 'size', '50' ).attr(
119 'class', 'reading_morphology' ).val( currform );
d1132306 120 forminput.autocomplete({ source: morphoptions, minLength: 0 });
121 forminput.focus( function() {
122 if( $(this).val() == clicktag ) {
123 $(this).val('');
124 }
125 $(this).autocomplete('search', '')
126 });
065c7cf2 127 var morphel = [ formlabel, forminput, $('<br/>') ];
128 return morphel;
129}
130
4c41c02c 131function color_inactive ( el ) {
132 var reading_id = $(el).parent().attr('id');
133 var reading_info = readingdata[reading_id];
134 // If the reading info has any non-disambiguated lexemes, color it yellow;
135 // otherwise color it green.
136 $(el).attr( {stroke:'green', fill:'#b3f36d'} );
bb3230b1 137 if( reading_info ) {
138 $.each( reading_info['lexemes'], function ( idx, lex ) {
139 if( !lex['is_disambiguated'] || lex['is_disambiguated'] == 0 ) {
140 $(el).attr( {stroke:'orange', fill:'#fee233'} );
141 }
142 });
143 }
4c41c02c 144}
145
997ebe92 146function relemmatize () {
147 // Send the reading for a new lemmatization and reopen the form.
a0a66634 148 $('#relemmatize_pending').show();
997ebe92 149 var reading_id = $('#reading_id').val()
150 ncpath = getReadingURL( reading_id );
151 form_values = {
152 'normal_form': $('#reading_normal_form').val(),
153 'relemmatize': 1 };
154 var jqjson = $.post( ncpath, form_values, function( data ) {
155 // Update the form with the return
156 if( 'id' in data ) {
157 // We got back a good answer. Stash it
158 readingdata[reading_id] = data;
159 // and regenerate the morphology form.
160 morphology_form( data['lexemes'] );
161 } else {
162 alert("Could not relemmatize as requested: " + data['error']);
163 }
a0a66634 164 $('#relemmatize_pending').hide();
997ebe92 165 });
166}
167
065c7cf2 168// Initialize the SVG once it exists
b28e606e 169function svgEnlargementLoaded() {
fc018906 170 //Give some visual evidence that we are working
171 $('#loading_overlay').show();
172 lo_height = $("#enlargement_container").outerHeight();
173 lo_width = $("#enlargement_container").outerWidth();
174 $("#loading_overlay").height( lo_height );
175 $("#loading_overlay").width( lo_width );
176 $("#loading_overlay").offset( $("#enlargement_container").offset() );
177 $("#loading_message").offset(
178 { 'top': lo_height / 2 - $("#loading_message").height() / 2,
179 'left': lo_width / 2 - $("#loading_message").width() / 2 });
30d0ba1e 180 if( editable ) {
181 // Show the update toggle button.
182 $('#update_workspace_button').data('locked', false);
183 $('#update_workspace_button').css('background-position', '0px 44px');
184 }
065c7cf2 185 $('#svgenlargement ellipse').parent().dblclick( node_dblclick_listener );
9529f69c 186 var graph_svg = $('#svgenlargement svg');
187 var svg_g = $('#svgenlargement svg g')[0];
76f05423 188 if (!svg_g) return;
9529f69c 189 svg_root = graph_svg.svg().svg('get').root();
76f05423 190
191 // Find the real root and ignore any text nodes
192 for (i = 0; i < svg_root.childNodes.length; ++i) {
193 if (svg_root.childNodes[i].nodeName != '#text') {
194 svg_root_element = svg_root.childNodes[i];
195 break;
196 }
197 }
198
30d0ba1e 199 //Set viewbox width and height to width and height of $('#svgenlargement svg').
200 //This is essential to make sure zooming and panning works properly.
9529f69c 201 svg_root.viewBox.baseVal.width = graph_svg.attr( 'width' );
202 svg_root.viewBox.baseVal.height = graph_svg.attr( 'height' );
c1241fc8 203
9529f69c 204 //Now set scale and translate so svg height is about 150px and vertically centered in viewbox.
205 //This is just to create a nice starting enlargement.
206 var initial_svg_height = 250;
207 var scale = initial_svg_height/graph_svg.attr( 'height' );
208 var additional_translate = (graph_svg.attr( 'height' ) - initial_svg_height)/(2*scale);
209 var transform = svg_g.getAttribute('transform');
c1241fc8 210
211 var x = 4;
212
213 var y = parseFloat( transform.match( /translate\([^\)]*\)/ )[0].split('(')[1].split(' ')[1].split(')')[0] );
214 y += additional_translate;
215
216 var transform = 'rotate(0) scale(' + scale + ')';
217 svg_g.setAttribute('transform', transform);
218
219 var keymap = document.getElementById("keymap");
220
221 var keymap_right = keymap.getBoundingClientRect().right;
222 keymap_right = svg_root.viewBox.baseVal.width - keymap_right;
223
224 var keymap_left = keymap.getBoundingClientRect().width;
225
226 if (text_direction == 'RL') {
227 // Edge of screen minus the width of the svg minus the width of the
228 // keymap minus the margin
229
230 x = (scrollToEnd() - keymap_right - keymap_left - 40) / scale;
231 }
232 else if (text_direction == 'BI') {
233 x = placeMiddle() / scale;
234 y = (svg_g.getBoundingClientRect().height + 50) / scale;
235 }
236
237 svg_g.setAttribute('transform', transform + ' translate(' + x + ' ' + y + ')');
238
9529f69c 239 //used to calculate min and max zoom level:
4c41c02c 240 start_element_height = $('#__START__').children('ellipse')[0].getBBox().height;
e538eccb 241 //some use of call backs to ensure succesive execution
242 add_relations( function() {
243 var rdgpath = getTextURL( 'readings' );
244 $.getJSON( rdgpath, function( data ) {
245 readingdata = data;
246 $('#svgenlargement ellipse').each( function( i, el ) { color_inactive( el ) });
9231663d 247 $('#loading_overlay').hide();
e538eccb 248 });
e538eccb 249 });
c1add777 250
251 //initialize marquee
252 marquee = new Marquee();
6afcd813 253}
254
fc018906 255function add_relations( callback_fn ) {
56e3972e 256 // Add the relationship types to the keymap list
56e3972e 257 $.each( relationship_types, function(index, typedef) {
671c04b1 258 li_elm = $('<li class="key">').css( "border-color",
259 relation_manager.relation_colors[index] ).text(typedef.name);
260 li_elm.append( $('<div>').attr('class', 'key_tip_container').append(
261 $('<div>').attr('class', 'key_tip').text(typedef.description) ) );
cfefd283 262 $('#keymaplist').append( li_elm );
56e3972e 263 });
264 // Now fetch the relationships themselves and add them to the graph
265 var rel_types = $.map( relationship_types, function(t) { return t.name });
266 // Save this list of names to the outer element data so that the relationship
267 // factory can access it
268 $('#keymap').data('relations', rel_types);
5f15640c 269 var textrelpath = getTextURL( 'relationships' );
56e3972e 270 $.getJSON( textrelpath, function(data) {
271 $.each(data, function( index, rel_info ) {
272 var type_index = $.inArray(rel_info.type, rel_types);
51ca18ee 273 var source_found = get_ellipse( rel_info.source_id );
274 var target_found = get_ellipse( rel_info.target_id );
cfa6ff76 275 var emphasis = rel_info.is_significant;
56e3972e 276 if( type_index != -1 && source_found.size() && target_found.size() ) {
48a371e5 277 var relation = relation_manager.create( rel_info.source_id, rel_info.target_id, type_index, emphasis );
51ca18ee 278 // Save the relationship data too.
279 $.each( rel_info, function( k, v ) {
280 relation.data( k, v );
281 });
30d0ba1e 282 if( editable ) {
51ca18ee 283 var node_obj = get_node_obj(rel_info.source_id);
e538eccb 284 node_obj.set_selectable( false );
30d0ba1e 285 node_obj.ellipse.data( 'node_obj', null );
51ca18ee 286 node_obj = get_node_obj(rel_info.target_id);
e538eccb 287 node_obj.set_selectable( false );
30d0ba1e 288 node_obj.ellipse.data( 'node_obj', null );
289 }
56e3972e 290 }
291 });
292 callback_fn.call();
293 });
b28e606e 294}
295
296function get_ellipse( node_id ) {
45ee3b96 297 return $( jq( node_id ) + ' ellipse');
b28e606e 298}
299
300function get_node_obj( node_id ) {
9529f69c 301 var node_ellipse = get_ellipse( node_id );
302 if( node_ellipse.data( 'node_obj' ) == null ) {
303 node_ellipse.data( 'node_obj', new node_obj(node_ellipse) );
304 };
305 return node_ellipse.data( 'node_obj' );
b28e606e 306}
307
b28e606e 308function node_obj(ellipse) {
309 this.ellipse = ellipse;
310 var self = this;
311
312 this.x = 0;
313 this.y = 0;
314 this.dx = 0;
315 this.dy = 0;
316 this.node_elements = node_elements_for(self.ellipse);
22a70299 317
b28e606e 318 this.get_id = function() {
45ee3b96 319 return $(self.ellipse).parent().attr('id')
b28e606e 320 }
321
e538eccb 322 this.set_selectable = function( clickable ) {
323 if( clickable && editable ) {
324 $(self.ellipse).attr( {stroke:'black', fill:'#fff'} );
325 $(self.ellipse).parent().hover( this.enter_node, this.leave_node );
326 $(self.ellipse).parent().mousedown( function(evt) { evt.stopPropagation() } );
327 $(self.ellipse).parent().click( function(evt) {
328 evt.stopPropagation();
329 if( $('ellipse[fill="#9999ff"]').size() > 0 ) {
330 $('ellipse[fill="#9999ff"]').each( function() {
331 $(this).data( 'node_obj' ).set_draggable( false );
332 } );
333 }
334 self.set_draggable( true )
335 });
336 } else {
337 $(self.ellipse).attr( {stroke:'black', fill:'#fff'} );
338 self.ellipse.siblings('text').attr('class', '');
339 $(self.ellipse).parent().unbind();
340 $('body').unbind('mousemove');
341 $('body').unbind('mouseup');
342 }
343 }
344
b28e606e 345 this.set_draggable = function( draggable ) {
30d0ba1e 346 if( draggable && editable ) {
e538eccb 347 $(self.ellipse).attr( {stroke:'black', fill:'#9999ff'} );
05485bfd 348 $(self.ellipse).parent().mousedown( this.mousedown_listener );
e538eccb 349 $(self.ellipse).parent().unbind( 'mouseenter' ).unbind( 'mouseleave' );
05485bfd 350 self.ellipse.siblings('text').attr('class', 'noselect draggable');
b28e606e 351 } else {
e538eccb 352 $(self.ellipse).attr( {stroke:'black', fill:'#fff'} );
05485bfd 353 self.ellipse.siblings('text').attr('class', '');
e538eccb 354 $(self.ellipse).parent().unbind( 'mousedown ');
355 $(self.ellipse).parent().mousedown( function(evt) { evt.stopPropagation() } );
356 $(self.ellipse).parent().hover( this.enter_node, this.leave_node );
b28e606e 357 }
358 }
359
360 this.mousedown_listener = function(evt) {
361 evt.stopPropagation();
362 self.x = evt.clientX;
363 self.y = evt.clientY;
364 $('body').mousemove( self.mousemove_listener );
365 $('body').mouseup( self.mouseup_listener );
05485bfd 366 $(self.ellipse).parent().unbind('mouseenter').unbind('mouseleave')
e538eccb 367 self.ellipse.attr( 'fill', '#6b6bb2' );
b28e606e 368 first_node_g_element = $("#svgenlargement g .node" ).filter( ":first" );
369 if( first_node_g_element.attr('id') !== self.get_g().attr('id') ) { self.get_g().insertBefore( first_node_g_element ) };
370 }
371
372 this.mousemove_listener = function(evt) {
9529f69c 373 self.dx = (evt.clientX - self.x) / mouse_scale;
374 self.dy = (evt.clientY - self.y) / mouse_scale;
b28e606e 375 self.move_elements();
05485bfd 376 evt.returnValue = false;
377 evt.preventDefault();
378 return false;
b28e606e 379 }
380
381 this.mouseup_listener = function(evt) {
382 if( $('ellipse[fill="#ffccff"]').size() > 0 ) {
45ee3b96 383 var source_node_id = $(self.ellipse).parent().attr('id');
05485bfd 384 var source_node_text = self.ellipse.siblings('text').text();
45ee3b96 385 var target_node_id = $('ellipse[fill="#ffccff"]').parent().attr('id');
05485bfd 386 var target_node_text = $('ellipse[fill="#ffccff"]').siblings("text").text();
b28e606e 387 $('#source_node_id').val( source_node_id );
05485bfd 388 $('#source_node_text').val( source_node_text );
51ca18ee 389 $('.rel_rdg_a').text( "'" + source_node_text + "'" );
b28e606e 390 $('#target_node_id').val( target_node_id );
05485bfd 391 $('#target_node_text').val( target_node_text );
51ca18ee 392 $('.rel_rdg_b').text( "'" + target_node_text + "'" );
b28e606e 393 $('#dialog-form').dialog( 'open' );
394 };
395 $('body').unbind('mousemove');
396 $('body').unbind('mouseup');
e538eccb 397 self.ellipse.attr( 'fill', '#9999ff' );
9529f69c 398 self.reset_elements();
b28e606e 399 }
f2fb96fc 400
b28e606e 401 this.cpos = function() {
402 return { x: self.ellipse.attr('cx'), y: self.ellipse.attr('cy') };
403 }
404
405 this.get_g = function() {
406 return self.ellipse.parent('g');
407 }
408
409 this.enter_node = function(evt) {
410 self.ellipse.attr( 'fill', '#ffccff' );
411 }
412
413 this.leave_node = function(evt) {
414 self.ellipse.attr( 'fill', '#fff' );
415 }
416
417 this.greyout_edges = function() {
418 $.each( self.node_elements, function(index, value) {
419 value.grey_out('.edge');
420 });
421 }
422
423 this.ungreyout_edges = function() {
424 $.each( self.node_elements, function(index, value) {
425 value.un_grey_out('.edge');
426 });
427 }
428
6c8d1880 429 this.reposition = function( dx, dy ) {
430 $.each( self.node_elements, function(index, value) {
431 value.reposition( dx, dy );
432 } );
433 }
434
b28e606e 435 this.move_elements = function() {
436 $.each( self.node_elements, function(index, value) {
6c8d1880 437 value.move( self.dx, self.dy );
22a70299 438 } );
b28e606e 439 }
440
441 this.reset_elements = function() {
442 $.each( self.node_elements, function(index, value) {
6c8d1880 443 value.reset();
22a70299 444 } );
b28e606e 445 }
446
447 this.update_elements = function() {
448 self.node_elements = node_elements_for(self.ellipse);
449 }
450
a84ca4de 451 this.get_witnesses = function() {
452 return readingdata[self.get_id()].witnesses
453 }
6c8d1880 454
e538eccb 455 self.set_selectable( true );
b28e606e 456}
457
458function svgshape( shape_element ) {
459 this.shape = shape_element;
6c8d1880 460 this.reposx = 0;
461 this.reposy = 0;
462 this.repositioned = this.shape.parent().data( 'repositioned' );
463 if( this.repositioned != null ) {
464 this.reposx = this.repositioned[0];
465 this.reposy = this.repositioned[1];
466 }
467 this.reposition = function (dx, dy) {
468 this.move( dx, dy );
469 this.reposx = this.reposx + dx;
470 this.reposy = this.reposy + dy;
471 this.shape.parent().data( 'repositioned', [this.reposx,this.reposy] );
472 }
b28e606e 473 this.move = function(dx,dy) {
6c8d1880 474 this.shape.attr( "transform", "translate( " + (this.reposx + dx) + " " + (this.reposy + dy) + " )" );
b28e606e 475 }
476 this.reset = function() {
6c8d1880 477 this.shape.attr( "transform", "translate( " + this.reposx + " " + this.reposy + " )" );
b28e606e 478 }
479 this.grey_out = function(filter) {
480 if( this.shape.parent(filter).size() != 0 ) {
481 this.shape.attr({'stroke':'#e5e5e5', 'fill':'#e5e5e5'});
482 }
483 }
484 this.un_grey_out = function(filter) {
485 if( this.shape.parent(filter).size() != 0 ) {
486 this.shape.attr({'stroke':'#000000', 'fill':'#000000'});
487 }
488 }
489}
490
491function svgpath( path_element, svg_element ) {
492 this.svg_element = svg_element;
493 this.path = path_element;
494 this.x = this.path.x;
495 this.y = this.path.y;
6c8d1880 496
497 this.reposition = function (dx, dy) {
498 this.x = this.x + dx;
499 this.y = this.y + dy;
500 this.path.x = this.x;
501 this.path.y = this.y;
502 }
503
b28e606e 504 this.move = function(dx,dy) {
505 this.path.x = this.x + dx;
506 this.path.y = this.y + dy;
507 }
6c8d1880 508
b28e606e 509 this.reset = function() {
510 this.path.x = this.x;
511 this.path.y = this.y;
512 }
6c8d1880 513
b28e606e 514 this.grey_out = function(filter) {
515 if( this.svg_element.parent(filter).size() != 0 ) {
516 this.svg_element.attr('stroke', '#e5e5e5');
517 this.svg_element.siblings('text').attr('fill', '#e5e5e5');
05485bfd 518 this.svg_element.siblings('text').attr('class', 'noselect');
b28e606e 519 }
520 }
521 this.un_grey_out = function(filter) {
522 if( this.svg_element.parent(filter).size() != 0 ) {
523 this.svg_element.attr('stroke', '#000000');
524 this.svg_element.siblings('text').attr('fill', '#000000');
05485bfd 525 this.svg_element.siblings('text').attr('class', '');
b28e606e 526 }
527 }
528}
529
530function node_elements_for( ellipse ) {
531 node_elements = get_edge_elements_for( ellipse );
532 node_elements.push( new svgshape( ellipse.siblings('text') ) );
533 node_elements.push( new svgshape( ellipse ) );
534 return node_elements;
535}
536
537function get_edge_elements_for( ellipse ) {
538 edge_elements = new Array();
45ee3b96 539 node_id = ellipse.parent().attr('id');
b28e606e 540 edge_in_pattern = new RegExp( node_id + '$' );
22a70299 541 edge_out_pattern = new RegExp( '^' + node_id + '-' );
b28e606e 542 $.each( $('#svgenlargement .edge,#svgenlargement .relation').children('title'), function(index) {
543 title = $(this).text();
544 if( edge_in_pattern.test(title) ) {
545 polygon = $(this).siblings('polygon');
546 if( polygon.size() > 0 ) {
547 edge_elements.push( new svgshape( polygon ) );
548 }
549 path_segments = $(this).siblings('path')[0].pathSegList;
550 edge_elements.push( new svgpath( path_segments.getItem(path_segments.numberOfItems - 1), $(this).siblings('path') ) );
551 }
552 if( edge_out_pattern.test(title) ) {
553 path_segments = $(this).siblings('path')[0].pathSegList;
554 edge_elements.push( new svgpath( path_segments.getItem(0), $(this).siblings('path') ) );
555 }
556 });
557 return edge_elements;
558}
559
560function relation_factory() {
561 var self = this;
562 this.color_memo = null;
563 //TODO: colors hard coded for now
564 this.temp_color = '#FFA14F';
565 this.relation_colors = [ "#5CCCCC", "#67E667", "#F9FE72", "#6B90D4", "#FF7673", "#E467B3", "#AA67D5", "#8370D8", "#FFC173" ];
566
567 this.create_temporary = function( source_node_id, target_node_id ) {
45ee3b96 568 var relation_id = get_relation_id( source_node_id, target_node_id );
569 var relation = $( jq( relation_id ) );
9529f69c 570 if( relation.size() == 0 ) {
b28e606e 571 draw_relation( source_node_id, target_node_id, self.temp_color );
572 } else {
573 self.color_memo = relation.children('path').attr( 'stroke' );
574 relation.children('path').attr( 'stroke', self.temp_color );
575 }
576 }
577 this.remove_temporary = function() {
578 var path_element = $('#svgenlargement .relation').children('path[stroke="' + self.temp_color + '"]');
579 if( self.color_memo != null ) {
580 path_element.attr( 'stroke', self.color_memo );
581 self.color_memo = null;
582 } else {
9529f69c 583 var temporary = path_element.parent('g').remove();
584 temporary.empty();
585 temporary = null;
b28e606e 586 }
587 }
48a371e5 588 this.create = function( source_node_id, target_node_id, color_index, emphasis ) {
b28e606e 589 //TODO: Protect from (color_)index out of bound..
590 var relation_color = self.relation_colors[ color_index ];
48a371e5 591 var relation = draw_relation( source_node_id, target_node_id, relation_color, emphasis );
9529f69c 592 get_node_obj( source_node_id ).update_elements();
593 get_node_obj( target_node_id ).update_elements();
594 return relation;
b28e606e 595 }
9529f69c 596 this.toggle_active = function( relation_id ) {
45ee3b96 597 var relation = $( jq( relation_id ) );
9529f69c 598 var relation_path = relation.children('path');
599 if( !relation.data( 'active' ) ) {
600 relation_path.css( {'cursor':'pointer'} );
601 relation_path.mouseenter( function(event) {
602 outerTimer = setTimeout( function() {
603 timer = setTimeout( function() {
45ee3b96 604 var related_nodes = get_related_nodes( relation_id );
605 var source_node_id = related_nodes[0];
606 var target_node_id = related_nodes[1];
9529f69c 607 $('#delete_source_node_id').val( source_node_id );
608 $('#delete_target_node_id').val( target_node_id );
609 self.showinfo(relation);
610 }, 500 )
611 }, 1000 );
612 });
613 relation_path.mouseleave( function(event) {
614 clearTimeout(outerTimer);
615 if( timer != null ) { clearTimeout(timer); }
616 });
617 relation.data( 'active', true );
618 } else {
619 relation_path.unbind( 'mouseenter' );
620 relation_path.unbind( 'mouseleave' );
621 relation_path.css( {'cursor':'inherit'} );
622 relation.data( 'active', false );
623 }
624 }
625 this.showinfo = function(relation) {
088a14af 626 $('#delete_relation_type').text( relation.data('type') );
627 $('#delete_relation_scope').text( relation.data('scope') );
51ca18ee 628 $('#delete_relation_attributes').empty();
e4bdf660 629 var significance = ' is not ';
630 if( relation.data( 'is_significant' ) === 'yes') {
631 significance = ' is ';
632 } else if ( relation.data( 'is_significant' ) === 'maybe' ) {
633 significance = ' might be ';
634 }
635 $('#delete_relation_attributes').append(
636 "This relationship" + significance + "stemmatically significant<br/>");
51ca18ee 637 if( relation.data( 'a_derivable_from_b' ) ) {
638 $('#delete_relation_attributes').append(
639 "'" + relation.data('source_text') + "' derivable from '" + relation.data('target_text') + "'<br/>");
640 }
641 if( relation.data( 'b_derivable_from_a' ) ) {
642 $('#delete_relation_attributes').append(
643 "'" + relation.data('target_text') + "' derivable from '" + relation.data('source_text') + "'<br/>");
644 }
645 if( relation.data( 'non_independent' ) ) {
646 $('#delete_relation_attributes').append(
647 "Variance unlikely to arise coincidentally<br/>");
648 }
69a19c91 649 if( relation.data( 'note' ) ) {
088a14af 650 $('#delete_relation_note').text('note: ' + relation.data( 'note' ) );
69a19c91 651 }
9529f69c 652 var points = relation.children('path').attr('d').slice(1).replace('C',' ').split(' ');
653 var xs = parseFloat( points[0].split(',')[0] );
654 var xe = parseFloat( points[1].split(',')[0] );
655 var ys = parseFloat( points[0].split(',')[1] );
656 var ye = parseFloat( points[3].split(',')[1] );
657 var p = svg_root.createSVGPoint();
658 p.x = xs + ((xe-xs)*1.1);
659 p.y = ye - ((ye-ys)/2);
76f05423 660 var ctm = svg_root_element.getScreenCTM();
9529f69c 661 var nx = p.matrixTransform(ctm).x;
662 var ny = p.matrixTransform(ctm).y;
663 var dialog_aria = $ ("div[aria-labelledby='ui-dialog-title-delete-form']");
664 $('#delete-form').dialog( 'open' );
665 dialog_aria.offset({ left: nx, top: ny });
666 }
667 this.remove = function( relation_id ) {
30d0ba1e 668 if( !editable ) {
669 return;
670 }
45ee3b96 671 var relation = $( jq( relation_id ) );
9529f69c 672 relation.remove();
b28e606e 673 }
674}
675
45ee3b96 676// Utility function to create/return the ID of a relation link between
677// a source and target.
678function get_relation_id( source_id, target_id ) {
679 var idlist = [ source_id, target_id ];
680 idlist.sort();
681 return 'relation-' + idlist[0] + '-...-' + idlist[1];
682}
683
684function get_related_nodes( relation_id ) {
685 var srctotarg = relation_id.substr( 9 );
686 return srctotarg.split('-...-');
687}
688
48a371e5 689function draw_relation( source_id, target_id, relation_color, emphasis ) {
9529f69c 690 var source_ellipse = get_ellipse( source_id );
691 var target_ellipse = get_ellipse( target_id );
45ee3b96 692 var relation_id = get_relation_id( source_id, target_id );
9529f69c 693 var svg = $('#svgenlargement').children('svg').svg().svg('get');
694 var path = svg.createPath();
695 var sx = parseInt( source_ellipse.attr('cx') );
696 var rx = parseInt( source_ellipse.attr('rx') );
697 var sy = parseInt( source_ellipse.attr('cy') );
698 var ex = parseInt( target_ellipse.attr('cx') );
699 var ey = parseInt( target_ellipse.attr('cy') );
9231663d 700 var relation = svg.group( $("#svgenlargement svg g"), { 'class':'relation', 'id':relation_id } );
9529f69c 701 svg.title( relation, source_id + '->' + target_id );
cfa6ff76 702 var stroke_width = emphasis === "yes" ? 6 : emphasis === "maybe" ? 4 : 2;
48a371e5 703 svg.path( relation, path.move( sx, sy ).curveC( sx + (2*rx), sy, ex + (2*rx), ey, ex, ey ), {fill: 'none', stroke: relation_color, strokeWidth: stroke_width });
b28e606e 704 var relation_element = $('#svgenlargement .relation').filter( ':last' );
705 relation_element.insertBefore( $('#svgenlargement g g').filter(':first') );
9529f69c 706 return relation_element;
b28e606e 707}
708
5fe117bc 709function detach_node( readings ) {
217f5e64 710 // separate out the deleted relationships, discard for now
b6f3476b 711 if( 'DELETED' in readings ) {
712 // Remove each of the deleted relationship links.
713 $.each( readings['DELETED'], function( idx, pair ) {
714 var relation_id = get_relation_id( pair[0], pair[1] );
715 var relation = $( jq( relation_id ) );
716 if( relation.size() == 0 ) {
717 relation_id = get_relation_id( pair[1], pair[0] );
718 }
719 relation_manager.remove( relation_id );
720 });
721 delete readings['DELETED'];
722 }
a471cb0f 723 // add new node(s)
724 $.extend( readingdata, readings );
725 // remove from existing readings the witnesses for the new nodes/readings
726 $.each( readings, function( node_id, reading ) {
727 $.each( reading.witnesses, function( index, witness ) {
728 var witnesses = readingdata[ reading.orig_rdg ].witnesses;
729 readingdata[ reading.orig_rdg ].witnesses = $.removeFromArray( witness, witnesses );
730 } );
731 } );
732
a471cb0f 733 detached_edges = [];
8cd2e785 734
735 // here we detach witnesses from the existing edges accoring to what's being relayed by readings
a471cb0f 736 $.each( readings, function( node_id, reading ) {
737 var edges = edges_of( get_ellipse( reading.orig_rdg ) );
738 incoming_remaining = [];
739 outgoing_remaining = [];
740 $.each( reading.witnesses, function( index, witness ) {
741 incoming_remaining.push( witness );
742 outgoing_remaining.push( witness );
743 } );
744 $.each( edges, function( index, edge ) {
745 detached_edge = edge.detach_witnesses( reading.witnesses );
746 if( detached_edge != null ) {
747 detached_edges.push( detached_edge );
748 $.each( detached_edge.witnesses, function( index, witness ) {
749 if( detached_edge.is_incoming == true ) {
750 incoming_remaining = $.removeFromArray( witness, incoming_remaining );
751 } else {
752 outgoing_remaining = $.removeFromArray( witness, outgoing_remaining );
753 }
754 } );
755 }
756 } );
8cd2e785 757
60c66cd2 758 // After detaching we still need to check if for *all* readings
8cd2e785 759 // an edge was detached. It may be that a witness was not
760 // explicitly named on an edge but was part of a 'majority' edge
761 // in which case we need to duplicate and name that edge after those
762 // remaining witnesses.
a471cb0f 763 if( outgoing_remaining.length > 0 ) {
a471cb0f 764 $.each( edges, function( index, edge ) {
a471cb0f 765 if( edge.get_label() == 'majority' && !edge.is_incoming ) {
766 detached_edges.push( edge.clone_for( outgoing_remaining ) );
767 }
768 } );
769 }
770 if( incoming_remaining.length > 0 ) {
a471cb0f 771 $.each( edges, function( index, edge ) {
772 if( edge.get_label() == 'majority' && edge.is_incoming ) {
dc8a13bd 773 detached_edges.push( edge.clone_for( incoming_remaining ) );
a471cb0f 774 }
775 } );
776 }
60c66cd2 777
22a70299 778 // Finally multiple selected nodes may share edges
779 var copy_array = [];
780 $.each( detached_edges, function( index, edge ) {
781 var do_copy = true;
782 $.each( copy_array, function( index, copy_edge ) {
783 if( copy_edge.g_elem.attr( 'id' ) == edge.g_elem.attr( 'id' ) ) { do_copy = false }
784 } );
785 if( do_copy == true ) {
786 copy_array.push( edge );
787 }
788 } );
789 detached_edges = copy_array;
790
60c66cd2 791 // Lots of unabstracted knowledge down here :/
792 // Clone original node/reading, rename/id it..
793 duplicate_node = get_ellipse( reading.orig_rdg ).parent().clone();
794 duplicate_node.attr( 'id', node_id );
795 duplicate_node.children( 'title' ).text( node_id );
6c8d1880 796
797 // This needs somehow to move to node or even to shapes! #repositioned
798 duplicate_node_data = get_ellipse( reading.orig_rdg ).parent().data( 'repositioned' );
22a70299 799 if( duplicate_node_data != null ) {
6c8d1880 800 duplicate_node.children( 'ellipse' ).parent().data( 'repositioned', duplicate_node_data );
22a70299 801 }
60c66cd2 802
803 // Add the node and all new edges into the graph
931ed236 804 var graph_root = $('#svgenlargement svg g.graph');
60c66cd2 805 graph_root.append( duplicate_node );
806 $.each( detached_edges, function( index, edge ) {
dc8a13bd 807 id_suffix = node_id.slice( node_id.indexOf( '_' ) );
808 edge.g_elem.attr( 'id', ( edge.g_elem.attr( 'id' ) + id_suffix ) );
60c66cd2 809 edge_title = edge.g_elem.children( 'title' ).text();
22a70299 810 edge_weight = 0.8 + ( 0.2 * edge.witnesses.length );
60c66cd2 811 edge_title = edge_title.replace( reading.orig_rdg, node_id );
812 edge.g_elem.children( 'title' ).text( edge_title );
22a70299 813 edge.g_elem.children( 'path').attr( 'stroke-width', edge_weight );
60c66cd2 814 // Reg unabstracted knowledge: isn't it more elegant to make
815 // it edge.append_to( graph_root )?
816 graph_root.append( edge.g_elem );
817 } );
22a70299 818
819 // Make the detached node a real node_obj
820 var ellipse_elem = get_ellipse( node_id );
821 var new_node = new node_obj( ellipse_elem );
822 ellipse_elem.data( 'node_obj', new_node );
823
60c66cd2 824 // Move the node somewhat up for 'dramatic effect' :-p
9231663d 825 new_node.reposition( 0, -70 );
60c66cd2 826
a471cb0f 827 } );
60c66cd2 828
9231663d 829}
a471cb0f 830
9231663d 831function merge_nodes( source_node_id, target_node_id, consequences ) {
832 if( consequences.status != null && consequences.status == 'ok' ) {
833 merge_node( source_node_id, target_node_id );
834 if( consequences.checkalign != null ) {
835 $.each( consequences.checkalign, function( index, node_ids ) {
0c4354f6 836 var temp_relation = draw_relation( node_ids[0], node_ids[1], "#89a02c" );
9231663d 837 var sy = parseInt( temp_relation.children('path').attr('d').split('C')[0].split(',')[1] );
838 var ey = parseInt( temp_relation.children('path').attr('d').split(' ')[2].split(',')[1] );
839 var yC = ey + (( sy - ey )/2);
840 // TODO: compute xC to be always the same distance to the amplitude of the curve
841 var xC = parseInt( temp_relation.children('path').attr('d').split(' ')[1].split(',')[0] );
842 var svg = $('#svgenlargement').children('svg').svg('get');
843 parent_g = svg.group( $('#svgenlargement svg g') );
844 var ids_text = node_ids[0] + '-' + node_ids[1];
845 var merge_id = 'merge-' + ids_text;
5a80f535 846 var yes = svg.image( parent_g, xC, (yC-8), 16, 16, merge_button_yes, { id: merge_id } );
847 var no = svg.image( parent_g, (xC+20), (yC-8), 16, 16, merge_button_no, { id: 'no' + merge_id } );
848 $(yes).hover( function(){ $(this).addClass( 'draggable' ) }, function(){ $(this).removeClass( 'draggable' ) } );
849 $(no).hover( function(){ $(this).addClass( 'draggable' ) }, function(){ $(this).removeClass( 'draggable' ) } );
850 $(yes).click( function( evt ){
9231663d 851 merge_node( node_ids[0], node_ids[1] );
852 temp_relation.remove();
5a80f535 853 $(evt.target).parent().remove();
759f1868 854 //notify backend
855 var ncpath = getTextURL( 'merge' );
aaf27b2e 856 var form_values = "source_id=" + node_ids[0] + "&target_id=" + node_ids[1] + "&single=true";
759f1868 857 $.post( ncpath, form_values );
9231663d 858 } );
5a80f535 859 $(no).click( function( evt ) {
9231663d 860 temp_relation.remove();
5a80f535 861 $(evt.target).parent().remove();
9231663d 862 } );
863 } );
864 }
865 }
866}
867
868function merge_node( source_node_id, target_node_id ) {
869 $.each( edges_of( get_ellipse( source_node_id ) ), function( index, edge ) {
870 if( edge.is_incoming == true ) {
871 edge.attach_endpoint( target_node_id );
872 } else {
873 edge.attach_startpoint( target_node_id );
874 }
875 } );
876 $( jq( source_node_id ) ).remove();
a471cb0f 877}
878
a51e34c5 879function compress_nodes(readings) {
880 //add text of other readings to 1st reading
a51e34c5 881
2d34519e 882 var first = get_ellipse(readings[0]);
883 var first_title = first.parent().find('text')[0];
884
885 for (var i = 1; i < readings.length; i++) {
886 var cur = get_ellipse(readings[i]);
a51e34c5 887 var cur_title = cur.parent().find('text')[0];
888
889 first_title.textContent += " " + cur_title.textContent;
890 };
891
892 //delete all others
893 for (var i = 1; i < readings.length; i++) {
894 var node = get_ellipse(readings[i]);
895 var rid = readings[i-1] + '->' + readings[i];
896
897 //[].slice.call(s.getElementsByTagName('title')).find(function(elem){return elem.textContent=='r64.2->r66.2'}).parentNode.remove()
898
2a65f5c9 899 var titles = svg_root.getElementsByTagName('title');
900 var titlesArray = [].slice.call(titles);
a51e34c5 901
2a65f5c9 902 if (titlesArray.length > 0) {
903 var title = titlesArray.find(function(elem){
904 return elem.textContent === rid;
905 });
906
907 if (title && title.parentNode) {
908 title.parentNode.remove();
909 }
910 }
a51e34c5 911
2a65f5c9 912 var x = parseInt(first[0].getAttribute('cx'), 10);
913
914 first[0].setAttribute('rx', 4.5 * first_title.textContent.length);
915
916 if (text_direction !== "BI") {
917 first[0].setAttribute('cx', x + first_title.textContent.length + 20);
918 first_title.setAttribute('x', first[0].getAttribute('cx'));
919 }
a51e34c5 920
2a65f5c9 921 merge_node(readings[i], readings[0]);
922 //node.parent().remove();
a51e34c5 923 }
924}
925
c1add777 926function Marquee() {
927
928 var self = this;
929
f6516f22 930 this.x = 0;
931 this.y = 0;
932 this.dx = 0;
933 this.dy = 0;
c1add777 934 this.enlargementOffset = $('#svgenlargement').offset();
935 this.svg_rect = $('#svgenlargement svg').svg('get');
936
937 this.show = function( event ) {
f6516f22 938 self.x = event.clientX;
939 self.y = event.clientY;
c1add777 940 p = svg_root.createSVGPoint();
941 p.x = event.clientX - self.enlargementOffset.left;
942 p.y = event.clientY - self.enlargementOffset.top;
c1add777 943 self.svg_rect.rect( p.x, p.y, 0, 0, { fill: 'black', 'fill-opacity': '0.1', stroke: 'black', 'stroke-dasharray': '4,2', strokeWidth: '0.02em', id: 'marquee' } );
944 };
945
946 this.expand = function( event ) {
f6516f22 947 self.dx = (event.clientX - self.x);
948 self.dy = (event.clientY - self.y);
c1add777 949 var rect = $('#marquee');
f6516f22 950 if( rect.length != 0 ) {
951 var rect_w = Math.abs( self.dx );
952 var rect_h = Math.abs( self.dy );
953 var rect_x = self.x - self.enlargementOffset.left;
954 var rect_y = self.y - self.enlargementOffset.top;
955 if( self.dx < 0 ) { rect_x = rect_x - rect_w }
956 if( self.dy < 0 ) { rect_y = rect_y - rect_h }
957 rect.attr("x", rect_x).attr("y", rect_y).attr("width", rect_w).attr("height", rect_h);
c1add777 958 }
959 };
960
a84ca4de 961 this.select = function() {
c1add777 962 var rect = $('#marquee');
963 if( rect.length != 0 ) {
e538eccb 964 //unselect any possible selected first
22a70299 965 //TODO: unless SHIFT?
e538eccb 966 if( $('ellipse[fill="#9999ff"]').size() > 0 ) {
967 $('ellipse[fill="#9999ff"]').each( function() {
968 $(this).data( 'node_obj' ).set_draggable( false );
969 } );
970 }
971 //compute dimension of marquee
c1add777 972 var left = $('#marquee').offset().left;
973 var top = $('#marquee').offset().top;
974 var right = left + parseInt( $('#marquee').attr( 'width' ) );
975 var bottom = top + parseInt( $('#marquee').attr( 'height' ) );
976 var tf = svg_root_element.getScreenCTM().inverse();
977 var p = svg_root.createSVGPoint();
978 p.x=left;
979 p.y=top;
980 var cx_min = p.matrixTransform(tf).x;
981 var cy_min = p.matrixTransform(tf).y;
982 p.x=right;
983 p.y=bottom;
984 var cx_max = p.matrixTransform(tf).x;
985 var cy_max = p.matrixTransform(tf).y;
e538eccb 986 //select any node with its center inside the marquee
5fe117bc 987 var readings = [];
e538eccb 988 //also merge witness sets from nodes
a84ca4de 989 var witnesses = [];
c1add777 990 $('#svgenlargement ellipse').each( function( index ) {
991 var cx = parseInt( $(this).attr('cx') );
992 var cy = parseInt( $(this).attr('cy') );
6c8d1880 993
994 // This needs somehow to move to node or even to shapes! #repositioned
995 // We should ask something more aling the lines of: nodes.each { |item| node.selected? }
996 var org_translate = $(this).parent().data( 'repositioned' );
22a70299 997 if( org_translate != null ) {
998 cx = cx + org_translate[0];
999 cy = cy + org_translate[1];
1000 }
6c8d1880 1001
c1add777 1002 if( cx > cx_min && cx < cx_max) {
1003 if( cy > cy_min && cy < cy_max) {
1004 // we actually heve no real 'selected' state for nodes, except coloring
e538eccb 1005 $(this).attr( 'fill', '#9999ff' );
5fe117bc 1006 // Take note of the selected reading(s) and applicable witness(es)
1007 // so we can populate the multipleselect-form
1008 readings.push( $(this).parent().attr('id') );
a84ca4de 1009 var this_witnesses = $(this).data( 'node_obj' ).get_witnesses();
1010 witnesses = arrayUnique( witnesses.concat( this_witnesses ) );
c1add777 1011 }
1012 }
1013 });
e538eccb 1014 if( $('ellipse[fill="#9999ff"]').size() > 0 ) {
5fe117bc 1015 //add intersection of witnesses sets to the multi select form and open it
1016 $('#detach_collated_form').empty();
a51e34c5 1017
5fe117bc 1018 $.each( readings, function( index, value ) {
1019 $('#detach_collated_form').append( $('<input>').attr(
1020 "type", "hidden").attr("name", "readings[]").attr(
1021 "value", value ) );
a51e34c5 1022 });
1023 $.each( witnesses, function( index, value ) {
5fe117bc 1024 $('#detach_collated_form').append(
1025 '<input type="checkbox" name="witnesses[]" value="' + value
1026 + '">' + value + '<br>' );
a84ca4de 1027 });
5fe117bc 1028 $('#multiple_selected_readings').attr('value', readings.join(',') );
a51e34c5 1029
1030 if ($('#action-merge')[0].checked) {
1031 $('#detach_collated_form').hide();
1032 $('#multipleselect-form-text').hide();
1033
1034 $('#detach_btn').hide();
1035 $('#merge_btn').show();
1036 } else {
1037 $('#detach_collated_form').show();
1038 $('#multipleselect-form-text').show();
1039
1040 $('#detach_btn').show();
1041 $('#merge_btn').hide();
1042 }
1043
1044 $('#action-detach').change(function() {
1045 if ($('#action-detach')[0].checked) {
1046 $('#detach_collated_form').show();
2d34519e 1047 $('#multipleselect-form-text').show();
a51e34c5 1048
1049 $('#detach_btn').show();
1050 $('#merge_btn').hide();
1051 }
1052 });
1053
1054 $('#action-merge').change(function() {
1055 if ($('#action-merge')[0].checked) {
1056 $('#detach_collated_form').hide();
2d34519e 1057 $('#multipleselect-form-text').hide();
a51e34c5 1058
1059 $('#detach_btn').hide();
1060 $('#merge_btn').show();
1061 }
1062 });
1063
a84ca4de 1064 $('#multipleselect-form').dialog( 'open' );
1065 }
c1add777 1066 self.svg_rect.remove( $('#marquee') );
1067 }
1068 };
1069
f6516f22 1070 this.unselect = function() {
e538eccb 1071 $('ellipse[fill="#9999ff"]').attr( 'fill', '#fff' );
f6516f22 1072 }
1073
c1add777 1074}
1075
b001c73d 1076function readings_equivalent( source, target ) {
1077 var sourcetext = readingdata[source].text;
1078 var targettext = readingdata[target].text;
1079 if( sourcetext === targettext ) {
1080 return true;
1081 }
1082 // Lowercase and strip punctuation from both and compare again
f069bb5c 1083 var nonwc = XRegExp('[^\\p{L}\\s]|_');
1084 var stlc = XRegExp.replace( sourcetext.toLocaleLowerCase(), nonwc, "", 'all' );
1085 var ttlc = XRegExp.replace( targettext.toLocaleLowerCase(), nonwc, "", 'all' );
b001c73d 1086 if( stlc === ttlc ) {
1087 return true;
1088 }
1089 return false;
1090}
1091
89aae3ee 1092function scrollToEnd() {
1093 var stateTf = svg_root_element.getCTM().inverse();
1094
c1241fc8 1095 var elem_width = Math.floor(svg_root_element.getBoundingClientRect().width);
1096 var vbdim = svg_root.viewBox.baseVal;
1097
1098 var x = vbdim.width - elem_width;
1099
1100 return x;
1101}
1102
1103function placeMiddle() {
1104 var stateTf = svg_root_element.getCTM().inverse();
1105
1106 var elem_width = Math.floor(svg_root_element.getBoundingClientRect().width);
89aae3ee 1107 var vbdim = svg_root.viewBox.baseVal;
89aae3ee 1108
c1241fc8 1109 var x = Math.floor((vbdim.width - elem_width) /2);
89aae3ee 1110
c1241fc8 1111 return x;
89aae3ee 1112}
9529f69c 1113
c1241fc8 1114
b28e606e 1115$(document).ready(function () {
9529f69c 1116
1117 timer = null;
b28e606e 1118 relation_manager = new relation_factory();
1119
c1add777 1120 $('#update_workspace_button').data('locked', false);
b001c73d 1121
1122 // Set up the mouse events on the SVG enlargement
9529f69c 1123 $('#enlargement').mousedown(function (event) {
b28e606e 1124 $(this)
9529f69c 1125 .data('down', true)
1126 .data('x', event.clientX)
1127 .data('y', event.clientY)
1128 .data('scrollLeft', this.scrollLeft)
c1add777 1129 stateTf = svg_root_element.getCTM().inverse();
1130 var p = svg_root.createSVGPoint();
1131 p.x = event.clientX;
1132 p.y = event.clientY;
1133 stateOrigin = p.matrixTransform(stateTf);
1134
1135 // Activate marquee if in interaction mode
1136 if( $('#update_workspace_button').data('locked') == true ) { marquee.show( event ) };
1137
1138 event.returnValue = false;
1139 event.preventDefault();
1140 return false;
b28e606e 1141 }).mouseup(function (event) {
a84ca4de 1142 marquee.select();
c1add777 1143 $(this).data('down', false);
b28e606e 1144 }).mousemove(function (event) {
9529f69c 1145 if( timer != null ) { clearTimeout(timer); }
1146 if ( ($(this).data('down') == true) && ($('#update_workspace_button').data('locked') == false) ) {
1147 var p = svg_root.createSVGPoint();
1148 p.x = event.clientX;
1149 p.y = event.clientY;
1150 p = p.matrixTransform(stateTf);
1151 var matrix = stateTf.inverse().translate(p.x - stateOrigin.x, p.y - stateOrigin.y);
1152 var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
76f05423 1153 svg_root_element.setAttribute("transform", s);
b28e606e 1154 }
c1add777 1155 marquee.expand( event );
76f05423 1156 event.returnValue = false;
1157 event.preventDefault();
b28e606e 1158 }).mousewheel(function (event, delta) {
9529f69c 1159 event.returnValue = false;
1160 event.preventDefault();
1161 if ( $('#update_workspace_button').data('locked') == false ) {
76f05423 1162 if (!delta || delta == null || delta == 0) delta = event.originalEvent.wheelDelta;
1163 if (!delta || delta == null || delta == 0) delta = -1 * event.originalEvent.detail;
9529f69c 1164 if( delta < -9 ) { delta = -9 };
1165 var z = 1 + delta/10;
76f05423 1166 z = delta > 0 ? 1 : -1;
1167 var g = svg_root_element;
1168 if (g && ((z<1 && (g.getScreenCTM().a * start_element_height) > 4.0) || (z>=1 && (g.getScreenCTM().a * start_element_height) < 100))) {
9529f69c 1169 var root = svg_root;
1170 var p = root.createSVGPoint();
76f05423 1171 p.x = event.originalEvent.clientX;
1172 p.y = event.originalEvent.clientY;
9529f69c 1173 p = p.matrixTransform(g.getCTM().inverse());
76f05423 1174 var scaleLevel = 1+(z/20);
1175 var k = root.createSVGMatrix().translate(p.x, p.y).scale(scaleLevel).translate(-p.x, -p.y);
9529f69c 1176 var matrix = g.getCTM().multiply(k);
1177 var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
1178 g.setAttribute("transform", s);
1179 }
1180 }
b28e606e 1181 }).css({
1182 'overflow' : 'hidden',
1183 'cursor' : '-moz-grab'
1184 });
1185
c1add777 1186
b001c73d 1187 // Set up the relationship creation dialog. This also functions as the reading
1188 // merge dialog where appropriate.
b001c73d 1189
30d0ba1e 1190 if( editable ) {
9231663d 1191 $( '#dialog-form' ).dialog( {
30d0ba1e 1192 autoOpen: false,
e4bdf660 1193 height: 350,
cfa6ff76 1194 width: 340,
30d0ba1e 1195 modal: true,
1196 buttons: {
9231663d 1197 'Merge readings': function( evt ) {
932277e1 1198 var mybuttons = $(evt.target).closest('button').parent().find('button');
1199 mybuttons.button( 'disable' );
9231663d 1200 $( '#status' ).empty();
1201 form_values = $( '#collapse_node_form' ).serialize();
b001c73d 1202 ncpath = getTextURL( 'merge' );
9231663d 1203 var jqjson = $.post( ncpath, form_values, function( data ) {
1204 merge_nodes( $( '#source_node_id' ).val(), $( '#target_node_id' ).val(), data );
932277e1 1205 mybuttons.button( 'enable' );
9231663d 1206 $( '#dialog-form' ).dialog( 'close' );
1207 } );
b001c73d 1208 },
1209 OK: function( evt ) {
932277e1 1210 var mybuttons = $(evt.target).closest('button').parent().find('button');
1211 mybuttons.button( 'disable' );
9231663d 1212 $( '#status' ).empty();
1213 form_values = $( '#collapse_node_form' ).serialize();
30d0ba1e 1214 ncpath = getTextURL( 'relationships' );
9231663d 1215 var jqjson = $.post( ncpath, form_values, function( data ) {
1216 $.each( data, function( item, source_target ) {
30d0ba1e 1217 var source_found = get_ellipse( source_target[0] );
1218 var target_found = get_ellipse( source_target[1] );
9231663d 1219 var relation_found = $.inArray( source_target[2], $( '#keymap' ).data( 'relations' ) );
30d0ba1e 1220 if( source_found.size() && target_found.size() && relation_found > -1 ) {
cfa6ff76 1221 var emphasis = $('#is_significant option:selected').attr('value');
48a371e5 1222 var relation = relation_manager.create( source_target[0], source_target[1], relation_found, emphasis );
45ee3b96 1223 relation_manager.toggle_active( relation.attr('id') );
51ca18ee 1224 $.each( $('#collapse_node_form').serializeArray(), function( i, k ) {
1225 relation.data( k.name, k.value );
1226 });
7b54e481 1227 }
932277e1 1228 mybuttons.button( 'enable' );
30d0ba1e 1229 });
9231663d 1230 $( '#dialog-form' ).dialog( 'close' );
30d0ba1e 1231 }, 'json' );
1232 },
1233 Cancel: function() {
9231663d 1234 $( this ).dialog( 'close' );
30d0ba1e 1235 }
1236 },
1237 create: function(event, ui) {
1238 $(this).data( 'relation_drawn', false );
a166dca8 1239 $('#rel_type').data( 'changed_after_open', false );
56e3972e 1240 $.each( relationship_types, function(index, typedef) {
1241 $('#rel_type').append( $('<option />').attr( "value", typedef.name ).text(typedef.name) );
1242 });
1243 $.each( relationship_scopes, function(index, value) {
1244 $('#scope').append( $('<option />').attr( "value", value ).text(value) );
a166dca8 1245 });
e4bdf660 1246 $.each( ternary_values, function( index, value ) {
1247 $('#is_significant').append( $('<option />').attr( "value", value ).text(value) );
1248 });
1249 // Handler to reset fields to default, the first time the relationship
1250 // is changed after opening the form.
a166dca8 1251 $('#rel_type').change( function () {
1252 if( !$(this).data( 'changed_after_open' ) ) {
1253 $('#note').val('');
e4bdf660 1254 $(this).find(':checked').removeAttr('checked');
a166dca8 1255 }
1256 $(this).data( 'changed_after_open', true );
1257 });
30d0ba1e 1258 },
1259 open: function() {
b001c73d 1260 relation_manager.create_temporary(
1261 $('#source_node_id').val(), $('#target_node_id').val() );
1262 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' )
1263 if( readings_equivalent( $('#source_node_id').val(),
1264 $('#target_node_id').val() ) ) {
1265 buttonset.find( "button:contains('Merge readings')" ).show();
1266 } else {
1267 buttonset.find( "button:contains('Merge readings')" ).hide();
1268 }
30d0ba1e 1269 $(".ui-widget-overlay").css("background", "none");
1270 $("#dialog_overlay").show();
1271 $("#dialog_overlay").height( $("#enlargement_container").height() );
1272 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
1273 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
a166dca8 1274 $('#rel_type').data( 'changed_after_open', false );
30d0ba1e 1275 },
1276 close: function() {
1277 relation_manager.remove_temporary();
1278 $( '#status' ).empty();
1279 $("#dialog_overlay").hide();
1280 }
1281 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
e4bdf660 1282 if( ( ajaxSettings.url == getTextURL('relationships')
1283 || ajaxSettings.url == getTextURL('merge') )
21e6ebc7 1284 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
1285 var error;
1286 if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) {
1287 error = 'You are not authorized to modify this tradition. (Try logging in again?)';
1288 } else {
1289 try {
1290 var errobj = jQuery.parseJSON( jqXHR.responseText );
1291 error = errobj.error + '</br>The relationship cannot be made.</p>';
1292 } catch(e) {
1293 error = jqXHR.responseText;
1294 }
1295 }
1296 $('#status').append( '<p class="error">Error: ' + error );
1297 }
1298 $(event.target).parent().find('.ui-button').button("enable");
30d0ba1e 1299 } );
1300 }
b28e606e 1301
b001c73d 1302 // Set up the relationship info display and deletion dialog.
9529f69c 1303 $( "#delete-form" ).dialog({
1304 autoOpen: false,
69a19c91 1305 height: 135,
d5b3c010 1306 width: 300,
9529f69c 1307 modal: false,
b001c73d 1308 buttons: {
1309 OK: function() { $( this ).dialog( "close" ); },
1310 "Delete all": function () { delete_relation( true ); },
1311 Delete: function() { delete_relation( false ); }
1312 },
9529f69c 1313 create: function(event, ui) {
30d0ba1e 1314 // TODO What is this logic doing?
a84ca4de 1315 // This scales the buttons in the dialog and makes it look proper
1316 // Not sure how essential it is, does anything break if it's not here?
9529f69c 1317 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' );
b001c73d 1318 buttonset.find( "button:contains('OK')" ).css( 'float', 'right' );
a84ca4de 1319 // A: This makes sure that the pop up delete relation dialogue for a hovered over
1320 // relation auto closes if the user doesn't engage (mouseover) with it.
9529f69c 1321 var dialog_aria = $("div[aria-labelledby='ui-dialog-title-delete-form']");
1322 dialog_aria.mouseenter( function() {
1323 if( mouseWait != null ) { clearTimeout(mouseWait) };
1324 })
1325 dialog_aria.mouseleave( function() {
1326 mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 );
1327 })
1328 },
1329 open: function() {
b001c73d 1330 // Show the appropriate buttons...
1331 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' )
1332 // If the user can't edit, show only the OK button
088a14af 1333 if( !editable ) {
b001c73d 1334 buttonset.find( "button:contains('Delete')" ).hide();
1335 // If the relationship scope is local, show only OK and Delete
088a14af 1336 } else if( $('#delete_relation_scope').text() === 'local' ) {
1337 $( this ).dialog( "option", "width", 160 );
b001c73d 1338 buttonset.find( "button:contains('Delete')" ).show();
1339 buttonset.find( "button:contains('Delete all')" ).hide();
1340 // Otherwise, show all three
088a14af 1341 } else {
1342 $( this ).dialog( "option", "width", 200 );
b001c73d 1343 buttonset.find( "button:contains('Delete')" ).show();
088a14af 1344 }
9529f69c 1345 mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 );
1346 },
088a14af 1347 close: function() {}
9529f69c 1348 });
1349
a84ca4de 1350 $( "#multipleselect-form" ).dialog({
1351 autoOpen: false,
1352 height: 150,
1353 width: 250,
1354 modal: true,
5fe117bc 1355 buttons: {
32f13891 1356 Cancel: function() {
1357 document.getElementById('duplicate-merge-error').innerHTML = "";
1358 $( this ).dialog( "close" );
1359 },
a51e34c5 1360 Detach: function ( evt ) {
1361 evt.target.id = 'detach_btn';
1362
22a70299 1363 var self = $(this);
a51e34c5 1364 var mybuttons = $(evt.target).closest('button').parent().find('button');
1365 mybuttons.button( 'disable' );
22a70299 1366 var form_values = $('#detach_collated_form').serialize();
1367 ncpath = getTextURL( 'duplicate' );
1368 var jqjson = $.post( ncpath, form_values, function(data) {
1369 detach_node( data );
932277e1 1370 mybuttons.button("enable");
22a70299 1371 self.dialog( "close" );
1372 } );
a51e34c5 1373 },
1374 Merge: function (evt) {
1375 evt.target.id = 'merge_btn';
1376
1377 var self = $(this);
1378 var mybuttons = $(evt.target).closest('button').parent().find('button');
1379 mybuttons.button('disable');
1380
1381 var ncpath = getTextURL('compress');
1382 var form_values = $('#detach_collated_form').serialize();
1383
1384 var jqjson = $.post(ncpath, form_values, function(data) {
2d34519e 1385 if (data.success) {
32f13891 1386 document.getElementById('duplicate-merge-error').innerHTML = "";
1387
2d34519e 1388 if (data.nodes) {
1389 compress_nodes(data.nodes);
1390 }
1391
1392 mybuttons.button('enable');
1393 self.dialog('close');
1394 } else if (data.error_msg) {
1395 document.getElementById('duplicate-merge-error').innerHTML = data.error_msg;
1396 mybuttons.button('enable');
a51e34c5 1397
2d34519e 1398 }
a51e34c5 1399 });
22a70299 1400 }
7ef4a584 1401 },
1402 create: function(event, ui) {
a84ca4de 1403 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' );
1404 buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' );
1405 },
1406 open: function() {
1407 $( this ).dialog( "option", "width", 200 );
e538eccb 1408 $(".ui-widget-overlay").css("background", "none");
5fe117bc 1409 $('#multipleselect-form-status').empty();
e538eccb 1410 $("#dialog_overlay").show();
1411 $("#dialog_overlay").height( $("#enlargement_container").height() );
1412 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
1413 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
a51e34c5 1414
1415 var mybuttons = $(this).parent().find('button');
1416
1417 mybuttons[1].id = 'detach_btn';
1418 mybuttons[2].id = 'merge_btn';
8f6a0901 1419
1420 if ($('#action-merge')[0].checked) {
1421 $('#detach_collated_form').hide();
1422 $('#multipleselect-form-text').hide();
1423
1424 $('#detach_btn').hide();
1425 $('#merge_btn').show();
1426 } else {
1427 $('#detach_collated_form').show();
1428 $('#multipleselect-form-text').show();
1429
1430 $('#detach_btn').show();
1431 $('#merge_btn').hide();
1432 }
a84ca4de 1433 },
e538eccb 1434 close: function() {
1435 marquee.unselect();
1436 $("#dialog_overlay").hide();
1437 }
5fe117bc 1438 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
1439 if( ajaxSettings.url == getTextURL('duplicate')
1440 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
1441 var error;
1442 if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) {
1443 error = 'You are not authorized to modify this tradition. (Try logging in again?)';
1444 } else {
1445 try {
1446 var errobj = jQuery.parseJSON( jqXHR.responseText );
1447 error = errobj.error + '</br>The relationship cannot be made.</p>';
1448 } catch(e) {
1449 error = jqXHR.responseText;
1450 }
1451 }
1452 $('#multipleselect-form-status').append( '<p class="error">Error: ' + error );
1453 }
1454 $(event.target).parent().find('.ui-button').button("enable");
1455 });
1456
a84ca4de 1457
088a14af 1458 // Helpers for relationship deletion
1459
1460 function delete_relation( scopewide ) {
1461 form_values = $('#delete_relation_form').serialize();
1462 if( scopewide ) {
1463 form_values += "&scopewide=true";
1464 }
1465 ncpath = getTextURL( 'relationships' );
1466 var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) {
1467 $.each( data, function(item, source_target) {
1468 relation_manager.remove( get_relation_id( source_target[0], source_target[1] ) );
1469 });
1470 $( "#delete-form" ).dialog( "close" );
1471 }, dataType: 'json', type: 'DELETE' });
1472 }
1473
1474 function toggle_relation_active( node_id ) {
1475 $('#svgenlargement .relation').find( "title:contains('" + node_id + "')" ).each( function(index) {
1476 matchid = new RegExp( "^" + node_id );
1477 if( $(this).text().match( matchid ) != null ) {
1478 var relation_id = $(this).parent().attr('id');
1479 relation_manager.toggle_active( relation_id );
1480 };
1481 });
1482 }
1483
487674b9 1484 // function for reading form dialog should go here;
1485 // just hide the element for now if we don't have morphology
1486 if( can_morphologize ) {
1487 $('#reading-form').dialog({
1488 autoOpen: false,
1489 // height: 400,
1490 width: 450,
1491 modal: true,
1492 buttons: {
1493 Cancel: function() {
1494 $( this ).dialog( "close" );
1495 },
1496 Update: function( evt ) {
1497 // Disable the button
932277e1 1498 var mybuttons = $(evt.target).closest('button').parent().find('button');
1499 mybuttons.button( 'disable' );
487674b9 1500 $('#reading_status').empty();
1501 var reading_id = $('#reading_id').val()
1502 form_values = {
1503 'id' : reading_id,
1504 'is_nonsense': $('#reading_is_nonsense').is(':checked'),
1505 'grammar_invalid': $('#reading_grammar_invalid').is(':checked'),
1506 'normal_form': $('#reading_normal_form').val() };
1507 // Add the morphology values
1508 $('.reading_morphology').each( function() {
1509 if( $(this).val() != '(Click to select)' ) {
1510 var rmid = $(this).attr('id');
1511 rmid = rmid.substring(8);
1512 form_values[rmid] = $(this).val();
1513 }
45ee3b96 1514 });
487674b9 1515 // Make the JSON call
1516 ncpath = getReadingURL( reading_id );
1517 var reading_element = readingdata[reading_id];
1518 // $(':button :contains("Update")').attr("disabled", true);
1519 var jqjson = $.post( ncpath, form_values, function(data) {
1520 $.each( data, function(key, value) {
1521 reading_element[key] = value;
1522 });
1523 if( $('#update_workspace_button').data('locked') == false ) {
1524 color_inactive( get_ellipse( reading_id ) );
1525 }
932277e1 1526 mybuttons.button("enable");
487674b9 1527 $( "#reading-form" ).dialog( "close" );
1528 });
1529 // Re-color the node if necessary
1530 return false;
1531 }
1532 },
1533 create: function() {
30d0ba1e 1534 if( !editable ) {
1535 // Get rid of the disallowed editing UI bits
1536 $( this ).dialog( "option", "buttons",
1537 [{ text: "OK", click: function() { $( this ).dialog( "close" ); }}] );
1538 $('#reading_relemmatize').hide();
1539 }
487674b9 1540 },
1541 open: function() {
1542 $(".ui-widget-overlay").css("background", "none");
1543 $("#dialog_overlay").show();
1544 $('#reading_status').empty();
1545 $("#dialog_overlay").height( $("#enlargement_container").height() );
1546 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
1547 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
1548 $("#reading-form").parent().find('.ui-button').button("enable");
1549 },
1550 close: function() {
1551 $("#dialog_overlay").hide();
1552 }
1553 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
21e6ebc7 1554 if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1
487674b9 1555 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
21e6ebc7 1556 var error;
1557 if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) {
1558 error = 'You are not authorized to modify this tradition. (Try logging in again?)';
1559 } else {
1560 try {
1561 var errobj = jQuery.parseJSON( jqXHR.responseText );
1562 error = errobj.error + '</br>The relationship cannot be made.</p>';
1563 } catch(e) {
1564 error = jqXHR.responseText;
1565 }
1566 }
1567 $('#status').append( '<p class="error">Error: ' + error );
1568 }
1569 $(event.target).parent().find('.ui-button').button("enable");
487674b9 1570 });
1571 } else {
1572 $('#reading-form').hide();
45ee3b96 1573 }
4c41c02c 1574
76f05423 1575
b28e606e 1576 $('#update_workspace_button').click( function() {
30d0ba1e 1577 if( !editable ) {
1578 return;
1579 }
b28e606e 1580 var svg_enlargement = $('#svgenlargement').svg().svg('get').root();
76f05423 1581 mouse_scale = svg_root_element.getScreenCTM().a;
9529f69c 1582 if( $(this).data('locked') == true ) {
1583 $('#svgenlargement ellipse' ).each( function( index ) {
1584 if( $(this).data( 'node_obj' ) != null ) {
1585 $(this).data( 'node_obj' ).ungreyout_edges();
e538eccb 1586 $(this).data( 'node_obj' ).set_selectable( false );
1587 color_inactive( $(this) );
9529f69c 1588 var node_id = $(this).data( 'node_obj' ).get_id();
1589 toggle_relation_active( node_id );
1590 $(this).data( 'node_obj', null );
1591 }
b28e606e 1592 })
b28e606e 1593 $(this).data('locked', false);
9529f69c 1594 $(this).css('background-position', '0px 44px');
b28e606e 1595 } else {
9529f69c 1596 var left = $('#enlargement').offset().left;
1597 var right = left + $('#enlargement').width();
76f05423 1598 var tf = svg_root_element.getScreenCTM().inverse();
9529f69c 1599 var p = svg_root.createSVGPoint();
1600 p.x=left;
1601 p.y=100;
1602 var cx_min = p.matrixTransform(tf).x;
1603 p.x=right;
1604 var cx_max = p.matrixTransform(tf).x;
1605 $('#svgenlargement ellipse').each( function( index ) {
1606 var cx = parseInt( $(this).attr('cx') );
1607 if( cx > cx_min && cx < cx_max) {
1608 if( $(this).data( 'node_obj' ) == null ) {
1609 $(this).data( 'node_obj', new node_obj( $(this) ) );
1610 } else {
e538eccb 1611 $(this).data( 'node_obj' ).set_selectable( true );
9529f69c 1612 }
1613 $(this).data( 'node_obj' ).greyout_edges();
1614 var node_id = $(this).data( 'node_obj' ).get_id();
1615 toggle_relation_active( node_id );
b28e606e 1616 }
9529f69c 1617 });
1618 $(this).css('background-position', '0px 0px');
b28e606e 1619 $(this).data('locked', true );
b28e606e 1620 }
1621 });
30d0ba1e 1622
1623 if( !editable ) {
1624 // Hide the unused elements
1625 $('#dialog-form').hide();
1626 $('#update_workspace_button').hide();
1627 }
1628
b28e606e 1629
e847b186 1630 $('.helptag').popupWindow({
1631 height:500,
1632 width:800,
1633 top:50,
1634 left:50,
1635 scrollbars:1
1636 });
1637
76f05423 1638 expandFillPageClients();
1639 $(window).resize(function() {
1640 expandFillPageClients();
1641 });
1642
9529f69c 1643});
b28e606e 1644
1645
76f05423 1646function expandFillPageClients() {
1647 $('.fillPage').each(function () {
1648 $(this).height($(window).height() - $(this).offset().top - MARGIN);
1649 });
1650}
1651
aeb47ed3 1652function loadSVG(svgData) {
76f05423 1653 var svgElement = $('#svgenlargement');
1654
1655 $(svgElement).svg('destroy');
1656
1657 $(svgElement).svg({
1658 loadURL: svgData,
1659 onLoad : svgEnlargementLoaded
1660 });
1661}
1662
1663
c1add777 1664
76f05423 1665/* OS Gadget stuff
1666
1667function svg_select_callback(topic, data, subscriberData) {
1668 svgData = data;
1669 loadSVG(svgData);
1670}
1671
1672function loaded() {
1673 var prefs = new gadgets.Prefs();
1674 var preferredHeight = parseInt(prefs.getString('height'));
1675 if (gadgets.util.hasFeature('dynamic-height')) gadgets.window.adjustHeight(preferredHeight);
1676 expandFillPageClients();
1677}
1678
1679if (gadgets.util.hasFeature('pubsub-2')) {
1680 gadgets.HubSettings.onConnect = function(hum, suc, err) {
1681 subId = gadgets.Hub.subscribe("interedition.svg.selected", svg_select_callback);
1682 loaded();
1683 };
1684}
1685else gadgets.util.registerOnLoadHandler(loaded);
1686*/