3 var svg_root_element = null;
4 var start_element_height = 0;
8 jQuery.removeFromArray = function(value, arr) {
9 return jQuery.grep(arr, function(elem, index) {
10 return elem !== value;
14 function 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) {
25 function getTextURL( which ) {
26 return basepath + textid + '/' + which;
29 function getReadingURL( reading_id ) {
30 return basepath + textid + '/reading/' + reading_id;
33 // Make an XML ID into a valid selector
35 return '#' + myid.replace(/(:|\.)/g,'\\$1');
38 // Actions for opening the reading panel
39 function 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 );
48 toggle_checkbox( $('#reading_is_nonsense'), reading_info['is_nonsense'] );
49 toggle_checkbox( $('#reading_grammar_invalid'), reading_info['grammar_invalid'] );
50 // Use .text as a backup for .normal_form
51 var normal_form = reading_info['normal_form'];
53 normal_form = reading_info['text'];
56 if( normal_form.length > 9 ) {
57 nfboxsize = normal_form.length + 1;
59 $('#reading_normal_form').attr( 'size', nfboxsize )
60 $('#reading_normal_form').val( normal_form );
62 // Fill in the witnesses for the de-collation box.
63 $('#reading_decollate_witnesses').empty();
64 $.each( reading_info['witnesses'], function( idx, wit ) {
65 $('#reading_decollate_witnesses').append( $('<option/>').attr(
66 'value', wit ).text( wit ) );
69 // Now do the morphological properties.
70 morphology_form( reading_info['lexemes'] );
71 // and then open the dialog.
72 $('#reading-form').dialog("open");
75 function toggle_checkbox( box, value ) {
79 box.attr('checked', value );
82 function morphology_form ( lexlist ) {
83 if( lexlist.length ) {
84 $('#morph_outer').show();
85 $('#morphology').empty();
86 $.each( lexlist, function( idx, lex ) {
87 var morphoptions = [];
88 if( 'wordform_matchlist' in lex ) {
89 $.each( lex['wordform_matchlist'], function( tdx, tag ) {
90 var tagstr = stringify_wordform( tag );
91 morphoptions.push( tagstr );
94 var formtag = 'morphology_' + idx;
97 formstr = stringify_wordform( lex['form'] );
99 var form_morph_elements = morph_elements(
100 formtag, lex['string'], formstr, morphoptions );
101 $.each( form_morph_elements, function( idx, el ) {
102 $('#morphology').append( el );
106 $('#morph_outer').hide();
110 function stringify_wordform ( tag ) {
112 var elements = tag.split(' // ');
113 return elements[1] + ' // ' + elements[2];
118 function morph_elements ( formtag, formtxt, currform, morphoptions ) {
119 var clicktag = '(Click to select)';
123 var formlabel = $('<label/>').attr( 'id', 'label_' + formtag ).attr(
124 'for', 'reading_' + formtag ).text( formtxt + ': ' );
125 var forminput = $('<input/>').attr( 'id', 'reading_' + formtag ).attr(
126 'name', 'reading_' + formtag ).attr( 'size', '50' ).attr(
127 'class', 'reading_morphology' ).val( currform );
128 forminput.autocomplete({ source: morphoptions, minLength: 0 });
129 forminput.focus( function() {
130 if( $(this).val() == clicktag ) {
133 $(this).autocomplete('search', '')
135 var morphel = [ formlabel, forminput, $('<br/>') ];
139 function color_inactive ( el ) {
140 var reading_id = $(el).parent().attr('id');
141 var reading_info = readingdata[reading_id];
142 // If the reading info has any non-disambiguated lexemes, color it yellow;
143 // otherwise color it green.
144 $(el).attr( {stroke:'green', fill:'#b3f36d'} );
146 $.each( reading_info['lexemes'], function ( idx, lex ) {
147 if( !lex['is_disambiguated'] || lex['is_disambiguated'] == 0 ) {
148 $(el).attr( {stroke:'orange', fill:'#fee233'} );
154 function relemmatize () {
155 // Send the reading for a new lemmatization and reopen the form.
156 $('#relemmatize_pending').show();
157 var reading_id = $('#reading_id').val()
158 ncpath = getReadingURL( reading_id );
160 'normal_form': $('#reading_normal_form').val(),
162 var jqjson = $.post( ncpath, form_values, function( data ) {
163 // Update the form with the return
165 // We got back a good answer. Stash it
166 readingdata[reading_id] = data;
167 // and regenerate the morphology form.
168 morphology_form( data['lexemes'] );
170 alert("Could not relemmatize as requested: " + data['error']);
172 $('#relemmatize_pending').hide();
176 // Initialize the SVG once it exists
177 function svgEnlargementLoaded() {
178 //Give some visual evidence that we are working
179 $('#loading_overlay').show();
180 lo_height = $("#enlargement_container").outerHeight();
181 lo_width = $("#enlargement_container").outerWidth();
182 $("#loading_overlay").height( lo_height );
183 $("#loading_overlay").width( lo_width );
184 $("#loading_overlay").offset( $("#enlargement_container").offset() );
185 $("#loading_message").offset(
186 { 'top': lo_height / 2 - $("#loading_message").height() / 2,
187 'left': lo_width / 2 - $("#loading_message").width() / 2 });
189 // Show the update toggle button.
190 $('#update_workspace_button').data('locked', false);
191 $('#update_workspace_button').css('background-position', '0px 44px');
193 $('#svgenlargement ellipse').parent().dblclick( node_dblclick_listener );
194 var graph_svg = $('#svgenlargement svg');
195 var svg_g = $('#svgenlargement svg g')[0];
197 svg_root = graph_svg.svg().svg('get').root();
199 // Find the real root and ignore any text nodes
200 for (i = 0; i < svg_root.childNodes.length; ++i) {
201 if (svg_root.childNodes[i].nodeName != '#text') {
202 svg_root_element = svg_root.childNodes[i];
207 //Set viewbox width and height to width and height of $('#svgenlargement svg').
208 //This is essential to make sure zooming and panning works properly.
209 svg_root.viewBox.baseVal.width = graph_svg.attr( 'width' );
210 svg_root.viewBox.baseVal.height = graph_svg.attr( 'height' );
211 //Now set scale and translate so svg height is about 150px and vertically centered in viewbox.
212 //This is just to create a nice starting enlargement.
213 var initial_svg_height = 250;
214 var scale = initial_svg_height/graph_svg.attr( 'height' );
215 var additional_translate = (graph_svg.attr( 'height' ) - initial_svg_height)/(2*scale);
216 var transform = svg_g.getAttribute('transform');
217 var translate = parseFloat( transform.match( /translate\([^\)]*\)/ )[0].split('(')[1].split(' ')[1].split(')')[0] );
218 translate += additional_translate;
219 var transform = 'rotate(0) scale(' + scale + ') translate(4 ' + translate + ')';
220 svg_g.setAttribute('transform', transform);
221 //used to calculate min and max zoom level:
222 start_element_height = $('#__START__').children('ellipse')[0].getBBox().height;
223 //some use of call backs to ensure succesive execution
224 add_relations( function() {
225 var rdgpath = getTextURL( 'readings' );
226 $.getJSON( rdgpath, function( data ) {
228 $('#svgenlargement ellipse').each( function( i, el ) { color_inactive( el ) });
229 $('#loading_overlay').hide();
234 marquee = new Marquee();
238 function add_relations( callback_fn ) {
239 // Add the relationship types to the keymap list
240 $.each( relationship_types, function(index, typedef) {
241 li_elm = $('<li class="key">').css( "border-color",
242 relation_manager.relation_colors[index] ).text(typedef.name);
243 li_elm.append( $('<div>').attr('class', 'key_tip_container').append(
244 $('<div>').attr('class', 'key_tip').text(typedef.description) ) );
245 $('#keymaplist').append( li_elm );
247 // Now fetch the relationships themselves and add them to the graph
248 var rel_types = $.map( relationship_types, function(t) { return t.name });
249 // Save this list of names to the outer element data so that the relationship
250 // factory can access it
251 $('#keymap').data('relations', rel_types);
252 var textrelpath = getTextURL( 'relationships' );
253 $.getJSON( textrelpath, function(data) {
254 $.each(data, function( index, rel_info ) {
255 var type_index = $.inArray(rel_info.type, rel_types);
256 var source_found = get_ellipse( rel_info.source );
257 var target_found = get_ellipse( rel_info.target );
258 if( type_index != -1 && source_found.size() && target_found.size() ) {
259 var relation = relation_manager.create( rel_info.source, rel_info.target, type_index );
260 relation.data( 'type', rel_info.type );
261 relation.data( 'scope', rel_info.scope );
262 relation.data( 'note', rel_info.note );
264 var node_obj = get_node_obj(rel_info.source);
265 node_obj.set_selectable( false );
266 node_obj.ellipse.data( 'node_obj', null );
267 node_obj = get_node_obj(rel_info.target);
268 node_obj.set_selectable( false );
269 node_obj.ellipse.data( 'node_obj', null );
277 function get_ellipse( node_id ) {
278 return $( jq( node_id ) + ' ellipse');
281 function get_node_obj( node_id ) {
282 var node_ellipse = get_ellipse( node_id );
283 if( node_ellipse.data( 'node_obj' ) == null ) {
284 node_ellipse.data( 'node_obj', new node_obj(node_ellipse) );
286 return node_ellipse.data( 'node_obj' );
289 function node_obj(ellipse) {
290 this.ellipse = ellipse;
297 this.node_elements = node_elements_for(self.ellipse);
299 this.get_id = function() {
300 return $(self.ellipse).parent().attr('id')
303 this.set_selectable = function( clickable ) {
304 if( clickable && editable ) {
305 $(self.ellipse).attr( {stroke:'black', fill:'#fff'} );
306 $(self.ellipse).parent().hover( this.enter_node, this.leave_node );
307 $(self.ellipse).parent().mousedown( function(evt) { evt.stopPropagation() } );
308 $(self.ellipse).parent().click( function(evt) {
309 evt.stopPropagation();
310 if( $('ellipse[fill="#9999ff"]').size() > 0 ) {
311 $('ellipse[fill="#9999ff"]').each( function() {
312 $(this).data( 'node_obj' ).set_draggable( false );
315 self.set_draggable( true )
318 $(self.ellipse).attr( {stroke:'black', fill:'#fff'} );
319 self.ellipse.siblings('text').attr('class', '');
320 $(self.ellipse).parent().unbind();
321 $('body').unbind('mousemove');
322 $('body').unbind('mouseup');
326 this.set_draggable = function( draggable ) {
327 if( draggable && editable ) {
328 $(self.ellipse).attr( {stroke:'black', fill:'#9999ff'} );
329 $(self.ellipse).parent().mousedown( this.mousedown_listener );
330 $(self.ellipse).parent().unbind( 'mouseenter' ).unbind( 'mouseleave' );
331 self.ellipse.siblings('text').attr('class', 'noselect draggable');
333 $(self.ellipse).attr( {stroke:'black', fill:'#fff'} );
334 self.ellipse.siblings('text').attr('class', '');
335 $(self.ellipse).parent().unbind( 'mousedown ');
336 $(self.ellipse).parent().mousedown( function(evt) { evt.stopPropagation() } );
337 $(self.ellipse).parent().hover( this.enter_node, this.leave_node );
341 this.mousedown_listener = function(evt) {
342 evt.stopPropagation();
343 self.x = evt.clientX;
344 self.y = evt.clientY;
345 $('body').mousemove( self.mousemove_listener );
346 $('body').mouseup( self.mouseup_listener );
347 $(self.ellipse).parent().unbind('mouseenter').unbind('mouseleave')
348 self.ellipse.attr( 'fill', '#6b6bb2' );
349 first_node_g_element = $("#svgenlargement g .node" ).filter( ":first" );
350 if( first_node_g_element.attr('id') !== self.get_g().attr('id') ) { self.get_g().insertBefore( first_node_g_element ) };
353 this.mousemove_listener = function(evt) {
354 self.dx = (evt.clientX - self.x) / mouse_scale;
355 self.dy = (evt.clientY - self.y) / mouse_scale;
356 self.move_elements();
357 evt.returnValue = false;
358 evt.preventDefault();
362 this.mouseup_listener = function(evt) {
363 if( $('ellipse[fill="#ffccff"]').size() > 0 ) {
364 var source_node_id = $(self.ellipse).parent().attr('id');
365 var source_node_text = self.ellipse.siblings('text').text();
366 var target_node_id = $('ellipse[fill="#ffccff"]').parent().attr('id');
367 var target_node_text = $('ellipse[fill="#ffccff"]').siblings("text").text();
368 $('#source_node_id').val( source_node_id );
369 $('#source_node_text').val( source_node_text );
370 $('#target_node_id').val( target_node_id );
371 $('#target_node_text').val( target_node_text );
372 $('#dialog-form').dialog( 'open' );
374 $('body').unbind('mousemove');
375 $('body').unbind('mouseup');
376 self.ellipse.attr( 'fill', '#9999ff' );
377 self.reset_elements();
380 this.cpos = function() {
381 return { x: self.ellipse.attr('cx'), y: self.ellipse.attr('cy') };
384 this.get_g = function() {
385 return self.ellipse.parent('g');
388 this.enter_node = function(evt) {
389 self.ellipse.attr( 'fill', '#ffccff' );
392 this.leave_node = function(evt) {
393 self.ellipse.attr( 'fill', '#fff' );
396 this.greyout_edges = function() {
397 $.each( self.node_elements, function(index, value) {
398 value.grey_out('.edge');
402 this.ungreyout_edges = function() {
403 $.each( self.node_elements, function(index, value) {
404 value.un_grey_out('.edge');
408 this.reposition = function( dx, dy ) {
409 $.each( self.node_elements, function(index, value) {
410 value.reposition( dx, dy );
414 this.move_elements = function() {
415 $.each( self.node_elements, function(index, value) {
416 value.move( self.dx, self.dy );
420 this.reset_elements = function() {
421 $.each( self.node_elements, function(index, value) {
426 this.update_elements = function() {
427 self.node_elements = node_elements_for(self.ellipse);
430 this.get_witnesses = function() {
431 return readingdata[self.get_id()].witnesses
434 self.set_selectable( true );
437 function svgshape( shape_element ) {
438 this.shape = shape_element;
441 this.repositioned = this.shape.parent().data( 'repositioned' );
442 if( this.repositioned != null ) {
443 this.reposx = this.repositioned[0];
444 this.reposy = this.repositioned[1];
446 this.reposition = function (dx, dy) {
448 this.reposx = this.reposx + dx;
449 this.reposy = this.reposy + dy;
450 this.shape.parent().data( 'repositioned', [this.reposx,this.reposy] );
452 this.move = function(dx,dy) {
453 this.shape.attr( "transform", "translate( " + (this.reposx + dx) + " " + (this.reposy + dy) + " )" );
455 this.reset = function() {
456 this.shape.attr( "transform", "translate( " + this.reposx + " " + this.reposy + " )" );
458 this.grey_out = function(filter) {
459 if( this.shape.parent(filter).size() != 0 ) {
460 this.shape.attr({'stroke':'#e5e5e5', 'fill':'#e5e5e5'});
463 this.un_grey_out = function(filter) {
464 if( this.shape.parent(filter).size() != 0 ) {
465 this.shape.attr({'stroke':'#000000', 'fill':'#000000'});
470 function svgpath( path_element, svg_element ) {
471 this.svg_element = svg_element;
472 this.path = path_element;
473 this.x = this.path.x;
474 this.y = this.path.y;
476 this.reposition = function (dx, dy) {
477 this.x = this.x + dx;
478 this.y = this.y + dy;
479 this.path.x = this.x;
480 this.path.y = this.y;
483 this.move = function(dx,dy) {
484 this.path.x = this.x + dx;
485 this.path.y = this.y + dy;
488 this.reset = function() {
489 this.path.x = this.x;
490 this.path.y = this.y;
493 this.grey_out = function(filter) {
494 if( this.svg_element.parent(filter).size() != 0 ) {
495 this.svg_element.attr('stroke', '#e5e5e5');
496 this.svg_element.siblings('text').attr('fill', '#e5e5e5');
497 this.svg_element.siblings('text').attr('class', 'noselect');
500 this.un_grey_out = function(filter) {
501 if( this.svg_element.parent(filter).size() != 0 ) {
502 this.svg_element.attr('stroke', '#000000');
503 this.svg_element.siblings('text').attr('fill', '#000000');
504 this.svg_element.siblings('text').attr('class', '');
509 function node_elements_for( ellipse ) {
510 node_elements = get_edge_elements_for( ellipse );
511 node_elements.push( new svgshape( ellipse.siblings('text') ) );
512 node_elements.push( new svgshape( ellipse ) );
513 return node_elements;
516 function get_edge_elements_for( ellipse ) {
517 edge_elements = new Array();
518 node_id = ellipse.parent().attr('id');
519 edge_in_pattern = new RegExp( node_id + '$' );
520 edge_out_pattern = new RegExp( '^' + node_id + '-' );
521 $.each( $('#svgenlargement .edge,#svgenlargement .relation').children('title'), function(index) {
522 title = $(this).text();
523 if( edge_in_pattern.test(title) ) {
524 polygon = $(this).siblings('polygon');
525 if( polygon.size() > 0 ) {
526 edge_elements.push( new svgshape( polygon ) );
528 path_segments = $(this).siblings('path')[0].pathSegList;
529 edge_elements.push( new svgpath( path_segments.getItem(path_segments.numberOfItems - 1), $(this).siblings('path') ) );
531 if( edge_out_pattern.test(title) ) {
532 path_segments = $(this).siblings('path')[0].pathSegList;
533 edge_elements.push( new svgpath( path_segments.getItem(0), $(this).siblings('path') ) );
536 return edge_elements;
539 function relation_factory() {
541 this.color_memo = null;
542 //TODO: colors hard coded for now
543 this.temp_color = '#FFA14F';
544 this.relation_colors = [ "#5CCCCC", "#67E667", "#F9FE72", "#6B90D4", "#FF7673", "#E467B3", "#AA67D5", "#8370D8", "#FFC173" ];
546 this.create_temporary = function( source_node_id, target_node_id ) {
547 var relation_id = get_relation_id( source_node_id, target_node_id );
548 var relation = $( jq( relation_id ) );
549 if( relation.size() == 0 ) {
550 draw_relation( source_node_id, target_node_id, self.temp_color );
552 self.color_memo = relation.children('path').attr( 'stroke' );
553 relation.children('path').attr( 'stroke', self.temp_color );
556 this.remove_temporary = function() {
557 var path_element = $('#svgenlargement .relation').children('path[stroke="' + self.temp_color + '"]');
558 if( self.color_memo != null ) {
559 path_element.attr( 'stroke', self.color_memo );
560 self.color_memo = null;
562 var temporary = path_element.parent('g').remove();
567 this.create = function( source_node_id, target_node_id, color_index ) {
568 //TODO: Protect from (color_)index out of bound..
569 var relation_color = self.relation_colors[ color_index ];
570 var relation = draw_relation( source_node_id, target_node_id, relation_color );
571 get_node_obj( source_node_id ).update_elements();
572 get_node_obj( target_node_id ).update_elements();
575 this.toggle_active = function( relation_id ) {
576 var relation = $( jq( relation_id ) );
577 var relation_path = relation.children('path');
578 if( !relation.data( 'active' ) ) {
579 relation_path.css( {'cursor':'pointer'} );
580 relation_path.mouseenter( function(event) {
581 outerTimer = setTimeout( function() {
582 timer = setTimeout( function() {
583 var related_nodes = get_related_nodes( relation_id );
584 var source_node_id = related_nodes[0];
585 var target_node_id = related_nodes[1];
586 $('#delete_source_node_id').val( source_node_id );
587 $('#delete_target_node_id').val( target_node_id );
588 self.showinfo(relation);
592 relation_path.mouseleave( function(event) {
593 clearTimeout(outerTimer);
594 if( timer != null ) { clearTimeout(timer); }
596 relation.data( 'active', true );
598 relation_path.unbind( 'mouseenter' );
599 relation_path.unbind( 'mouseleave' );
600 relation_path.css( {'cursor':'inherit'} );
601 relation.data( 'active', false );
604 this.showinfo = function(relation) {
605 $('#delete_relation_type').text( relation.data('type') );
606 $('#delete_relation_scope').text( relation.data('scope') );
607 if( relation.data( 'note' ) ) {
608 $('#delete_relation_note').text('note: ' + relation.data( 'note' ) );
610 var points = relation.children('path').attr('d').slice(1).replace('C',' ').split(' ');
611 var xs = parseFloat( points[0].split(',')[0] );
612 var xe = parseFloat( points[1].split(',')[0] );
613 var ys = parseFloat( points[0].split(',')[1] );
614 var ye = parseFloat( points[3].split(',')[1] );
615 var p = svg_root.createSVGPoint();
616 p.x = xs + ((xe-xs)*1.1);
617 p.y = ye - ((ye-ys)/2);
618 var ctm = svg_root_element.getScreenCTM();
619 var nx = p.matrixTransform(ctm).x;
620 var ny = p.matrixTransform(ctm).y;
621 var dialog_aria = $ ("div[aria-labelledby='ui-dialog-title-delete-form']");
622 $('#delete-form').dialog( 'open' );
623 dialog_aria.offset({ left: nx, top: ny });
625 this.remove = function( relation_id ) {
629 var relation = $( jq( relation_id ) );
634 // Utility function to create/return the ID of a relation link between
635 // a source and target.
636 function get_relation_id( source_id, target_id ) {
637 var idlist = [ source_id, target_id ];
639 return 'relation-' + idlist[0] + '-...-' + idlist[1];
642 function get_related_nodes( relation_id ) {
643 var srctotarg = relation_id.substr( 9 );
644 return srctotarg.split('-...-');
647 function draw_relation( source_id, target_id, relation_color ) {
648 var source_ellipse = get_ellipse( source_id );
649 var target_ellipse = get_ellipse( target_id );
650 var relation_id = get_relation_id( source_id, target_id );
651 var svg = $('#svgenlargement').children('svg').svg().svg('get');
652 var path = svg.createPath();
653 var sx = parseInt( source_ellipse.attr('cx') );
654 var rx = parseInt( source_ellipse.attr('rx') );
655 var sy = parseInt( source_ellipse.attr('cy') );
656 var ex = parseInt( target_ellipse.attr('cx') );
657 var ey = parseInt( target_ellipse.attr('cy') );
658 var relation = svg.group( $("#svgenlargement svg g"), { 'class':'relation', 'id':relation_id } );
659 svg.title( relation, source_id + '->' + target_id );
660 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});
661 var relation_element = $('#svgenlargement .relation').filter( ':last' );
662 relation_element.insertBefore( $('#svgenlargement g g').filter(':first') );
663 return relation_element;
666 function detach_node( readings ) {
667 // separate out the deleted relationships, discard for now
668 delete readings['DELETED'];
670 $.extend( readingdata, readings );
671 // remove from existing readings the witnesses for the new nodes/readings
672 $.each( readings, function( node_id, reading ) {
673 $.each( reading.witnesses, function( index, witness ) {
674 var witnesses = readingdata[ reading.orig_rdg ].witnesses;
675 readingdata[ reading.orig_rdg ].witnesses = $.removeFromArray( witness, witnesses );
681 // here we detach witnesses from the existing edges accoring to what's being relayed by readings
682 $.each( readings, function( node_id, reading ) {
683 var edges = edges_of( get_ellipse( reading.orig_rdg ) );
684 incoming_remaining = [];
685 outgoing_remaining = [];
686 $.each( reading.witnesses, function( index, witness ) {
687 incoming_remaining.push( witness );
688 outgoing_remaining.push( witness );
690 $.each( edges, function( index, edge ) {
691 detached_edge = edge.detach_witnesses( reading.witnesses );
692 if( detached_edge != null ) {
693 detached_edges.push( detached_edge );
694 $.each( detached_edge.witnesses, function( index, witness ) {
695 if( detached_edge.is_incoming == true ) {
696 incoming_remaining = $.removeFromArray( witness, incoming_remaining );
698 outgoing_remaining = $.removeFromArray( witness, outgoing_remaining );
704 // After detaching we still need to check if for *all* readings
705 // an edge was detached. It may be that a witness was not
706 // explicitly named on an edge but was part of a 'majority' edge
707 // in which case we need to duplicate and name that edge after those
708 // remaining witnesses.
709 if( outgoing_remaining.length > 0 ) {
710 $.each( edges, function( index, edge ) {
711 if( edge.get_label() == 'majority' && !edge.is_incoming ) {
712 detached_edges.push( edge.clone_for( outgoing_remaining ) );
716 if( incoming_remaining.length > 0 ) {
717 $.each( edges, function( index, edge ) {
718 if( edge.get_label() == 'majority' && edge.is_incoming ) {
719 detached_edges.push( edge.clone_for( incoming_remaining ) );
724 // Finally multiple selected nodes may share edges
726 $.each( detached_edges, function( index, edge ) {
728 $.each( copy_array, function( index, copy_edge ) {
729 if( copy_edge.g_elem.attr( 'id' ) == edge.g_elem.attr( 'id' ) ) { do_copy = false }
731 if( do_copy == true ) {
732 copy_array.push( edge );
735 detached_edges = copy_array;
737 // Lots of unabstracted knowledge down here :/
738 // Clone original node/reading, rename/id it..
739 duplicate_node = get_ellipse( reading.orig_rdg ).parent().clone();
740 duplicate_node.attr( 'id', node_id );
741 duplicate_node.children( 'title' ).text( node_id );
743 // This needs somehow to move to node or even to shapes! #repositioned
744 duplicate_node_data = get_ellipse( reading.orig_rdg ).parent().data( 'repositioned' );
745 if( duplicate_node_data != null ) {
746 duplicate_node.children( 'ellipse' ).parent().data( 'repositioned', duplicate_node_data );
749 // Add the node and all new edges into the graph
750 var graph_root = $('#svgenlargement svg g.graph');
751 graph_root.append( duplicate_node );
752 $.each( detached_edges, function( index, edge ) {
753 id_suffix = node_id.slice( node_id.indexOf( '_' ) );
754 edge.g_elem.attr( 'id', ( edge.g_elem.attr( 'id' ) + id_suffix ) );
755 edge_title = edge.g_elem.children( 'title' ).text();
756 edge_weight = 0.8 + ( 0.2 * edge.witnesses.length );
757 edge_title = edge_title.replace( reading.orig_rdg, node_id );
758 edge.g_elem.children( 'title' ).text( edge_title );
759 edge.g_elem.children( 'path').attr( 'stroke-width', edge_weight );
760 // Reg unabstracted knowledge: isn't it more elegant to make
761 // it edge.append_to( graph_root )?
762 graph_root.append( edge.g_elem );
765 // Make the detached node a real node_obj
766 var ellipse_elem = get_ellipse( node_id );
767 var new_node = new node_obj( ellipse_elem );
768 ellipse_elem.data( 'node_obj', new_node );
770 // Move the node somewhat up for 'dramatic effect' :-p
771 new_node.reposition( 0, -70 );
777 function merge_nodes( source_node_id, target_node_id, consequences ) {
778 if( consequences.status != null && consequences.status == 'ok' ) {
779 merge_node( source_node_id, target_node_id );
780 if( consequences.checkalign != null ) {
781 $.each( consequences.checkalign, function( index, node_ids ) {
782 temp_relation = draw_relation( node_ids[0], node_ids[1], "#89a02c" );
783 var sy = parseInt( temp_relation.children('path').attr('d').split('C')[0].split(',')[1] );
784 var ey = parseInt( temp_relation.children('path').attr('d').split(' ')[2].split(',')[1] );
785 var yC = ey + (( sy - ey )/2);
786 // TODO: compute xC to be always the same distance to the amplitude of the curve
787 var xC = parseInt( temp_relation.children('path').attr('d').split(' ')[1].split(',')[0] );
788 var svg = $('#svgenlargement').children('svg').svg('get');
789 parent_g = svg.group( $('#svgenlargement svg g') );
790 var ids_text = node_ids[0] + '-' + node_ids[1];
791 var merge_id = 'merge-' + ids_text;
792 svg.image( parent_g, xC, (yC-8), 16, 16, '/images/tick_circle_frame.png', { id: merge_id } );
793 svg.image( parent_g, (xC+20), (yC-8), 16, 16, '/images/no_entry.png', { id: 'no' + merge_id } );
794 $( '#' + merge_id ).hover( function(){ $(this).addClass( 'draggable' ) }, function(){ $(this).removeClass( 'draggable' ) } );
795 $( '#no' + merge_id ).hover( function(){ $(this).addClass( 'draggable' ) }, function(){ $(this).removeClass( 'draggable' ) } );
796 $( '#' + merge_id ).click( function( evt ){
797 merge_node( node_ids[0], node_ids[1] );
798 temp_relation.remove();
799 $( '#' + merge_id ).parent().remove();
801 var ncpath = getTextURL( 'merge' );
802 var form_values = "source_id=" + source_node_id + "&target_id=" + target_node_id + "&single=true";
803 $.post( ncpath, form_values );
805 $( '#no' + merge_id ).click( function( evt ) {
806 temp_relation.remove();
807 $( '#' + merge_id ).parent().remove();
814 function merge_node( source_node_id, target_node_id ) {
815 $.each( edges_of( get_ellipse( source_node_id ) ), function( index, edge ) {
816 if( edge.is_incoming == true ) {
817 edge.attach_endpoint( target_node_id );
819 edge.attach_startpoint( target_node_id );
822 $( jq( source_node_id ) ).remove();
833 this.enlargementOffset = $('#svgenlargement').offset();
834 this.svg_rect = $('#svgenlargement svg').svg('get');
836 this.show = function( event ) {
837 self.x = event.clientX;
838 self.y = event.clientY;
839 p = svg_root.createSVGPoint();
840 p.x = event.clientX - self.enlargementOffset.left;
841 p.y = event.clientY - self.enlargementOffset.top;
842 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' } );
845 this.expand = function( event ) {
846 self.dx = (event.clientX - self.x);
847 self.dy = (event.clientY - self.y);
848 var rect = $('#marquee');
849 if( rect.length != 0 ) {
850 var rect_w = Math.abs( self.dx );
851 var rect_h = Math.abs( self.dy );
852 var rect_x = self.x - self.enlargementOffset.left;
853 var rect_y = self.y - self.enlargementOffset.top;
854 if( self.dx < 0 ) { rect_x = rect_x - rect_w }
855 if( self.dy < 0 ) { rect_y = rect_y - rect_h }
856 rect.attr("x", rect_x).attr("y", rect_y).attr("width", rect_w).attr("height", rect_h);
860 this.select = function() {
861 var rect = $('#marquee');
862 if( rect.length != 0 ) {
863 //unselect any possible selected first
864 //TODO: unless SHIFT?
865 if( $('ellipse[fill="#9999ff"]').size() > 0 ) {
866 $('ellipse[fill="#9999ff"]').each( function() {
867 $(this).data( 'node_obj' ).set_draggable( false );
870 //compute dimension of marquee
871 var left = $('#marquee').offset().left;
872 var top = $('#marquee').offset().top;
873 var right = left + parseInt( $('#marquee').attr( 'width' ) );
874 var bottom = top + parseInt( $('#marquee').attr( 'height' ) );
875 var tf = svg_root_element.getScreenCTM().inverse();
876 var p = svg_root.createSVGPoint();
879 var cx_min = p.matrixTransform(tf).x;
880 var cy_min = p.matrixTransform(tf).y;
883 var cx_max = p.matrixTransform(tf).x;
884 var cy_max = p.matrixTransform(tf).y;
885 //select any node with its center inside the marquee
887 //also merge witness sets from nodes
889 $('#svgenlargement ellipse').each( function( index ) {
890 var cx = parseInt( $(this).attr('cx') );
891 var cy = parseInt( $(this).attr('cy') );
893 // This needs somehow to move to node or even to shapes! #repositioned
894 // We should ask something more aling the lines of: nodes.each { |item| node.selected? }
895 var org_translate = $(this).parent().data( 'repositioned' );
896 if( org_translate != null ) {
897 cx = cx + org_translate[0];
898 cy = cy + org_translate[1];
901 if( cx > cx_min && cx < cx_max) {
902 if( cy > cy_min && cy < cy_max) {
903 // we actually heve no real 'selected' state for nodes, except coloring
904 $(this).attr( 'fill', '#9999ff' );
905 // Take note of the selected reading(s) and applicable witness(es)
906 // so we can populate the multipleselect-form
907 readings.push( $(this).parent().attr('id') );
908 var this_witnesses = $(this).data( 'node_obj' ).get_witnesses();
909 witnesses = arrayUnique( witnesses.concat( this_witnesses ) );
913 if( $('ellipse[fill="#9999ff"]').size() > 0 ) {
914 //add intersection of witnesses sets to the multi select form and open it
915 $('#detach_collated_form').empty();
916 $.each( readings, function( index, value ) {
917 $('#detach_collated_form').append( $('<input>').attr(
918 "type", "hidden").attr("name", "readings[]").attr(
921 $.each( witnesses, function( index, value ) {
922 $('#detach_collated_form').append(
923 '<input type="checkbox" name="witnesses[]" value="' + value
924 + '">' + value + '<br>' );
926 $('#multiple_selected_readings').attr('value', readings.join(',') );
927 $('#multipleselect-form').dialog( 'open' );
929 self.svg_rect.remove( $('#marquee') );
933 this.unselect = function() {
934 $('ellipse[fill="#9999ff"]').attr( 'fill', '#fff' );
939 function readings_equivalent( source, target ) {
940 var sourcetext = readingdata[source].text;
941 var targettext = readingdata[target].text;
942 if( sourcetext === targettext ) {
945 // Lowercase and strip punctuation from both and compare again
946 var stlc = sourcetext.toLowerCase().replace(/[^\w\s]|_/g, "");
947 var ttlc = targettext.toLowerCase().replace(/[^\w\s]|_/g, "");
948 if( stlc === ttlc ) {
955 $(document).ready(function () {
958 relation_manager = new relation_factory();
960 $('#update_workspace_button').data('locked', false);
962 // Set up the mouse events on the SVG enlargement
963 $('#enlargement').mousedown(function (event) {
966 .data('x', event.clientX)
967 .data('y', event.clientY)
968 .data('scrollLeft', this.scrollLeft)
969 stateTf = svg_root_element.getCTM().inverse();
970 var p = svg_root.createSVGPoint();
973 stateOrigin = p.matrixTransform(stateTf);
975 // Activate marquee if in interaction mode
976 if( $('#update_workspace_button').data('locked') == true ) { marquee.show( event ) };
978 event.returnValue = false;
979 event.preventDefault();
981 }).mouseup(function (event) {
983 $(this).data('down', false);
984 }).mousemove(function (event) {
985 if( timer != null ) { clearTimeout(timer); }
986 if ( ($(this).data('down') == true) && ($('#update_workspace_button').data('locked') == false) ) {
987 var p = svg_root.createSVGPoint();
990 p = p.matrixTransform(stateTf);
991 var matrix = stateTf.inverse().translate(p.x - stateOrigin.x, p.y - stateOrigin.y);
992 var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
993 svg_root_element.setAttribute("transform", s);
995 marquee.expand( event );
996 event.returnValue = false;
997 event.preventDefault();
998 }).mousewheel(function (event, delta) {
999 event.returnValue = false;
1000 event.preventDefault();
1001 if ( $('#update_workspace_button').data('locked') == false ) {
1002 if (!delta || delta == null || delta == 0) delta = event.originalEvent.wheelDelta;
1003 if (!delta || delta == null || delta == 0) delta = -1 * event.originalEvent.detail;
1004 if( delta < -9 ) { delta = -9 };
1005 var z = 1 + delta/10;
1006 z = delta > 0 ? 1 : -1;
1007 var g = svg_root_element;
1008 if (g && ((z<1 && (g.getScreenCTM().a * start_element_height) > 4.0) || (z>=1 && (g.getScreenCTM().a * start_element_height) < 100))) {
1009 var root = svg_root;
1010 var p = root.createSVGPoint();
1011 p.x = event.originalEvent.clientX;
1012 p.y = event.originalEvent.clientY;
1013 p = p.matrixTransform(g.getCTM().inverse());
1014 var scaleLevel = 1+(z/20);
1015 var k = root.createSVGMatrix().translate(p.x, p.y).scale(scaleLevel).translate(-p.x, -p.y);
1016 var matrix = g.getCTM().multiply(k);
1017 var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
1018 g.setAttribute("transform", s);
1022 'overflow' : 'hidden',
1023 'cursor' : '-moz-grab'
1027 // Set up the relationship creation dialog. This also functions as the reading
1028 // merge dialog where appropriate.
1031 $( '#dialog-form' ).dialog( {
1037 'Merge readings': function( evt ) {
1038 $( evt.target ).button( 'disable' );
1039 $( '#status' ).empty();
1040 form_values = $( '#collapse_node_form' ).serialize();
1041 ncpath = getTextURL( 'merge' );
1042 var jqjson = $.post( ncpath, form_values, function( data ) {
1043 merge_nodes( $( '#source_node_id' ).val(), $( '#target_node_id' ).val(), data );
1044 $( '#dialog-form' ).dialog( 'close' );
1047 OK: function( evt ) {
1048 $( evt.target ).button( 'disable' );
1049 $( '#status' ).empty();
1050 form_values = $( '#collapse_node_form' ).serialize();
1051 ncpath = getTextURL( 'relationships' );
1052 var jqjson = $.post( ncpath, form_values, function( data ) {
1053 $.each( data, function( item, source_target ) {
1054 var source_found = get_ellipse( source_target[0] );
1055 var target_found = get_ellipse( source_target[1] );
1056 var relation_found = $.inArray( source_target[2], $( '#keymap' ).data( 'relations' ) );
1057 if( source_found.size() && target_found.size() && relation_found > -1 ) {
1058 var relation = relation_manager.create( source_target[0], source_target[1], relation_found );
1059 relation.data( 'type', source_target[2] );
1060 relation.data( 'scope', $('#scope :selected').text() );
1061 relation.data( 'note', $('#note').val() );
1062 relation_manager.toggle_active( relation.attr('id') );
1064 $(evt.target).button( 'enable' );
1066 $( '#dialog-form' ).dialog( 'close' );
1069 Cancel: function() {
1070 $( this ).dialog( 'close' );
1073 create: function(event, ui) {
1074 $(this).data( 'relation_drawn', false );
1075 $('#rel_type').data( 'changed_after_open', false );
1076 $.each( relationship_types, function(index, typedef) {
1077 $('#rel_type').append( $('<option />').attr( "value", typedef.name ).text(typedef.name) );
1079 $.each( relationship_scopes, function(index, value) {
1080 $('#scope').append( $('<option />').attr( "value", value ).text(value) );
1082 // Handler to clear the annotation field, the first time the relationship is
1083 // changed after opening the form.
1084 $('#rel_type').change( function () {
1085 if( !$(this).data( 'changed_after_open' ) ) {
1088 $(this).data( 'changed_after_open', true );
1092 relation_manager.create_temporary(
1093 $('#source_node_id').val(), $('#target_node_id').val() );
1094 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' )
1095 if( readings_equivalent( $('#source_node_id').val(),
1096 $('#target_node_id').val() ) ) {
1097 buttonset.find( "button:contains('Merge readings')" ).show();
1099 buttonset.find( "button:contains('Merge readings')" ).hide();
1101 $(".ui-widget-overlay").css("background", "none");
1102 $("#dialog_overlay").show();
1103 $("#dialog_overlay").height( $("#enlargement_container").height() );
1104 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
1105 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
1106 $('#rel_type').data( 'changed_after_open', false );
1109 relation_manager.remove_temporary();
1110 $( '#status' ).empty();
1111 $("#dialog_overlay").hide();
1113 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
1114 if( ajaxSettings.url == getTextURL('relationships')
1115 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
1117 if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) {
1118 error = 'You are not authorized to modify this tradition. (Try logging in again?)';
1121 var errobj = jQuery.parseJSON( jqXHR.responseText );
1122 error = errobj.error + '</br>The relationship cannot be made.</p>';
1124 error = jqXHR.responseText;
1127 $('#status').append( '<p class="error">Error: ' + error );
1129 $(event.target).parent().find('.ui-button').button("enable");
1133 // Set up the relationship info display and deletion dialog.
1134 $( "#delete-form" ).dialog({
1140 OK: function() { $( this ).dialog( "close" ); },
1141 "Delete all": function () { delete_relation( true ); },
1142 Delete: function() { delete_relation( false ); }
1144 create: function(event, ui) {
1145 // TODO What is this logic doing?
1146 // This scales the buttons in the dialog and makes it look proper
1147 // Not sure how essential it is, does anything break if it's not here?
1148 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' );
1149 buttonset.find( "button:contains('OK')" ).css( 'float', 'right' );
1150 // A: This makes sure that the pop up delete relation dialogue for a hovered over
1151 // relation auto closes if the user doesn't engage (mouseover) with it.
1152 var dialog_aria = $("div[aria-labelledby='ui-dialog-title-delete-form']");
1153 dialog_aria.mouseenter( function() {
1154 if( mouseWait != null ) { clearTimeout(mouseWait) };
1156 dialog_aria.mouseleave( function() {
1157 mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 );
1161 // Show the appropriate buttons...
1162 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' )
1163 // If the user can't edit, show only the OK button
1165 buttonset.find( "button:contains('Delete')" ).hide();
1166 // If the relationship scope is local, show only OK and Delete
1167 } else if( $('#delete_relation_scope').text() === 'local' ) {
1168 $( this ).dialog( "option", "width", 160 );
1169 buttonset.find( "button:contains('Delete')" ).show();
1170 buttonset.find( "button:contains('Delete all')" ).hide();
1171 // Otherwise, show all three
1173 $( this ).dialog( "option", "width", 200 );
1174 buttonset.find( "button:contains('Delete')" ).show();
1176 mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 );
1178 close: function() {}
1181 $( "#multipleselect-form" ).dialog({
1187 Cancel: function() { $( this ).dialog( "close" ); },
1188 Detach: function ( evt ) {
1190 $( evt.target ).button( "disable" );
1191 var form_values = $('#detach_collated_form').serialize();
1192 ncpath = getTextURL( 'duplicate' );
1193 var jqjson = $.post( ncpath, form_values, function(data) {
1194 detach_node( data );
1195 $(evt.target).button("enable");
1196 self.dialog( "close" );
1200 create: function(event, ui) {
1201 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' );
1202 buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' );
1205 $( this ).dialog( "option", "width", 200 );
1206 $(".ui-widget-overlay").css("background", "none");
1207 $('#multipleselect-form-status').empty();
1208 $("#dialog_overlay").show();
1209 $("#dialog_overlay").height( $("#enlargement_container").height() );
1210 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
1211 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
1215 $("#dialog_overlay").hide();
1217 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
1218 if( ajaxSettings.url == getTextURL('duplicate')
1219 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
1221 if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) {
1222 error = 'You are not authorized to modify this tradition. (Try logging in again?)';
1225 var errobj = jQuery.parseJSON( jqXHR.responseText );
1226 error = errobj.error + '</br>The relationship cannot be made.</p>';
1228 error = jqXHR.responseText;
1231 $('#multipleselect-form-status').append( '<p class="error">Error: ' + error );
1233 $(event.target).parent().find('.ui-button').button("enable");
1237 // Helpers for relationship deletion
1239 function delete_relation( scopewide ) {
1240 form_values = $('#delete_relation_form').serialize();
1242 form_values += "&scopewide=true";
1244 ncpath = getTextURL( 'relationships' );
1245 var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) {
1246 $.each( data, function(item, source_target) {
1247 relation_manager.remove( get_relation_id( source_target[0], source_target[1] ) );
1249 $( "#delete-form" ).dialog( "close" );
1250 }, dataType: 'json', type: 'DELETE' });
1253 function toggle_relation_active( node_id ) {
1254 $('#svgenlargement .relation').find( "title:contains('" + node_id + "')" ).each( function(index) {
1255 matchid = new RegExp( "^" + node_id );
1256 if( $(this).text().match( matchid ) != null ) {
1257 var relation_id = $(this).parent().attr('id');
1258 relation_manager.toggle_active( relation_id );
1263 // function for reading form dialog should go here;
1264 // just hide the element for now if we don't have morphology
1265 if( can_morphologize ) {
1267 $('#reading_decollate_witnesses').multiselect();
1269 $('#decollation').hide();
1271 $('#reading-form').dialog({
1277 Cancel: function() {
1278 $( this ).dialog( "close" );
1280 Update: function( evt ) {
1281 // Disable the button
1282 $(evt.target).button("disable");
1283 $('#reading_status').empty();
1284 var reading_id = $('#reading_id').val()
1287 'is_nonsense': $('#reading_is_nonsense').is(':checked'),
1288 'grammar_invalid': $('#reading_grammar_invalid').is(':checked'),
1289 'normal_form': $('#reading_normal_form').val() };
1290 // Add the morphology values
1291 $('.reading_morphology').each( function() {
1292 if( $(this).val() != '(Click to select)' ) {
1293 var rmid = $(this).attr('id');
1294 rmid = rmid.substring(8);
1295 form_values[rmid] = $(this).val();
1298 // Make the JSON call
1299 ncpath = getReadingURL( reading_id );
1300 var reading_element = readingdata[reading_id];
1301 // $(':button :contains("Update")').attr("disabled", true);
1302 var jqjson = $.post( ncpath, form_values, function(data) {
1303 $.each( data, function(key, value) {
1304 reading_element[key] = value;
1306 if( $('#update_workspace_button').data('locked') == false ) {
1307 color_inactive( get_ellipse( reading_id ) );
1309 $(evt.target).button("enable");
1310 $( "#reading-form" ).dialog( "close" );
1312 // Re-color the node if necessary
1316 create: function() {
1318 // Get rid of the disallowed editing UI bits
1319 $( this ).dialog( "option", "buttons",
1320 [{ text: "OK", click: function() { $( this ).dialog( "close" ); }}] );
1321 $('#reading_relemmatize').hide();
1325 $(".ui-widget-overlay").css("background", "none");
1326 $('#reading_decollate_witnesses').multiselect("refresh");
1327 $('#reading_decollate_witnesses').multiselect("uncheckAll");
1328 $("#dialog_overlay").show();
1329 $('#reading_status').empty();
1330 $("#dialog_overlay").height( $("#enlargement_container").height() );
1331 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
1332 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
1333 $("#reading-form").parent().find('.ui-button').button("enable");
1336 $("#dialog_overlay").hide();
1338 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
1339 if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1
1340 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
1342 if( jqXHR.responseText.indexOf('do not have permission to modify') > -1 ) {
1343 error = 'You are not authorized to modify this tradition. (Try logging in again?)';
1346 var errobj = jQuery.parseJSON( jqXHR.responseText );
1347 error = errobj.error + '</br>The relationship cannot be made.</p>';
1349 error = jqXHR.responseText;
1352 $('#status').append( '<p class="error">Error: ' + error );
1354 $(event.target).parent().find('.ui-button').button("enable");
1357 $('#reading-form').hide();
1361 $('#update_workspace_button').click( function() {
1365 var svg_enlargement = $('#svgenlargement').svg().svg('get').root();
1366 mouse_scale = svg_root_element.getScreenCTM().a;
1367 if( $(this).data('locked') == true ) {
1368 $('#svgenlargement ellipse' ).each( function( index ) {
1369 if( $(this).data( 'node_obj' ) != null ) {
1370 $(this).data( 'node_obj' ).ungreyout_edges();
1371 $(this).data( 'node_obj' ).set_selectable( false );
1372 color_inactive( $(this) );
1373 var node_id = $(this).data( 'node_obj' ).get_id();
1374 toggle_relation_active( node_id );
1375 $(this).data( 'node_obj', null );
1378 $(this).data('locked', false);
1379 $(this).css('background-position', '0px 44px');
1381 var left = $('#enlargement').offset().left;
1382 var right = left + $('#enlargement').width();
1383 var tf = svg_root_element.getScreenCTM().inverse();
1384 var p = svg_root.createSVGPoint();
1387 var cx_min = p.matrixTransform(tf).x;
1389 var cx_max = p.matrixTransform(tf).x;
1390 $('#svgenlargement ellipse').each( function( index ) {
1391 var cx = parseInt( $(this).attr('cx') );
1392 if( cx > cx_min && cx < cx_max) {
1393 if( $(this).data( 'node_obj' ) == null ) {
1394 $(this).data( 'node_obj', new node_obj( $(this) ) );
1396 $(this).data( 'node_obj' ).set_selectable( true );
1398 $(this).data( 'node_obj' ).greyout_edges();
1399 var node_id = $(this).data( 'node_obj' ).get_id();
1400 toggle_relation_active( node_id );
1403 $(this).css('background-position', '0px 0px');
1404 $(this).data('locked', true );
1409 // Hide the unused elements
1410 $('#dialog-form').hide();
1411 $('#update_workspace_button').hide();
1415 $('.helptag').popupWindow({
1423 expandFillPageClients();
1424 $(window).resize(function() {
1425 expandFillPageClients();
1431 function expandFillPageClients() {
1432 $('.fillPage').each(function () {
1433 $(this).height($(window).height() - $(this).offset().top - MARGIN);
1437 function loadSVG(svgData) {
1438 var svgElement = $('#svgenlargement');
1440 $(svgElement).svg('destroy');
1444 onLoad : svgEnlargementLoaded
1452 function svg_select_callback(topic, data, subscriberData) {
1458 var prefs = new gadgets.Prefs();
1459 var preferredHeight = parseInt(prefs.getString('height'));
1460 if (gadgets.util.hasFeature('dynamic-height')) gadgets.window.adjustHeight(preferredHeight);
1461 expandFillPageClients();
1464 if (gadgets.util.hasFeature('pubsub-2')) {
1465 gadgets.HubSettings.onConnect = function(hum, suc, err) {
1466 subId = gadgets.Hub.subscribe("interedition.svg.selected", svg_select_callback);
1470 else gadgets.util.registerOnLoadHandler(loaded);