3 var svg_root_element = null;
4 var start_element_height = 0;
8 function getTextPath() {
9 var currpath = window.location.pathname;
10 // Get rid of trailing slash
11 if( currpath.lastIndexOf('/') == currpath.length - 1 ) {
12 currpath = currpath.slice( 0, currpath.length - 1)
14 // Get rid of query parameters
15 if( currpath.lastIndexOf('?') != -1 ) {
16 currpath = currpath.slice( 0, currpath.lastIndexOf('?') );
18 var path_elements = currpath.split('/');
19 var textid = path_elements.pop();
20 var basepath = path_elements.join( '/' );
21 var path_parts = [ basepath, textid ];
25 function getRelativePath() {
26 var path_parts = getTextPath();
30 function getTextURL( which ) {
31 var path_parts = getTextPath();
32 return path_parts[0] + '/' + path_parts[1] + '/' + which;
35 function getReadingURL( reading_id ) {
36 var path_parts = getTextPath();
37 return path_parts[0] + '/' + path_parts[1] + '/reading/' + reading_id;
40 // Make an XML ID into a valid selector
42 return '#' + myid.replace(/(:|\.)/g,'\\$1');
45 // Actions for opening the reading panel
46 function node_dblclick_listener( evt ) {
47 // Open the reading dialogue for the given node.
48 // First get the reading info
49 var reading_id = $(this).attr('id');
50 var reading_info = readingdata[reading_id];
51 // and then populate the dialog box with it.
52 // Set the easy properties first
53 $('#reading-form').dialog( 'option', 'title', 'Reading information for "' + reading_info['text'] + '"' );
54 $('#reading_id').val( reading_id );
55 toggle_checkbox( $('#reading_is_nonsense'), reading_info['is_nonsense'] );
56 toggle_checkbox( $('#reading_grammar_invalid'), reading_info['grammar_invalid'] );
57 // Use .text as a backup for .normal_form
58 var normal_form = reading_info['normal_form'];
60 normal_form = reading_info['text'];
63 if( normal_form.length > 9 ) {
64 nfboxsize = normal_form.length + 1;
66 $('#reading_normal_form').attr( 'size', nfboxsize )
67 $('#reading_normal_form').val( normal_form );
68 // Now do the morphological properties.
69 morphology_form( reading_info['lexemes'] );
70 // and then open the dialog.
71 $('#reading-form').dialog("open");
74 function toggle_checkbox( box, value ) {
78 box.attr('checked', value );
81 function morphology_form ( lexlist ) {
82 $('#morphology').empty();
83 $.each( lexlist, function( idx, lex ) {
84 var morphoptions = [];
85 if( 'wordform_matchlist' in lex ) {
86 $.each( lex['wordform_matchlist'], function( tdx, tag ) {
87 var tagstr = stringify_wordform( tag );
88 morphoptions.push( tagstr );
91 var formtag = 'morphology_' + idx;
94 formstr = stringify_wordform( lex['form'] );
96 var form_morph_elements = morph_elements(
97 formtag, lex['string'], formstr, morphoptions );
98 $.each( form_morph_elements, function( idx, el ) {
99 $('#morphology').append( el );
104 function stringify_wordform ( tag ) {
106 var elements = tag.split(' // ');
107 return elements[1] + ' // ' + elements[2];
112 function morph_elements ( formtag, formtxt, currform, morphoptions ) {
113 var clicktag = '(Click to select)';
117 var formlabel = $('<label/>').attr( 'id', 'label_' + formtag ).attr(
118 'for', 'reading_' + formtag ).text( formtxt + ': ' );
119 var forminput = $('<input/>').attr( 'id', 'reading_' + formtag ).attr(
120 'name', 'reading_' + formtag ).attr( 'size', '50' ).attr(
121 'class', 'reading_morphology' ).val( currform );
122 forminput.autocomplete({ source: morphoptions, minLength: 0 });
123 forminput.focus( function() {
124 if( $(this).val() == clicktag ) {
127 $(this).autocomplete('search', '')
129 var morphel = [ formlabel, forminput, $('<br/>') ];
133 function color_inactive ( el ) {
134 var reading_id = $(el).parent().attr('id');
135 var reading_info = readingdata[reading_id];
136 // If the reading info has any non-disambiguated lexemes, color it yellow;
137 // otherwise color it green.
138 $(el).attr( {stroke:'green', fill:'#b3f36d'} );
139 $.each( reading_info['lexemes'], function ( idx, lex ) {
140 if( !lex['is_disambiguated'] ) {
141 $(el).attr( {stroke:'orange', fill:'#fee233'} );
146 function relemmatize () {
147 // Send the reading for a new lemmatization and reopen the form.
148 $('#relemmatize_pending').show();
149 var reading_id = $('#reading_id').val()
150 ncpath = getReadingURL( reading_id );
152 'normal_form': $('#reading_normal_form').val(),
154 var jqjson = $.post( ncpath, form_values, function( data ) {
155 // Update the form with the return
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'] );
162 alert("Could not relemmatize as requested: " + data['error']);
164 $('#relemmatize_pending').hide();
168 // Initialize the SVG once it exists
169 function svgEnlargementLoaded() {
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 });
180 //Set viewbox widht and height to widht and height of $('#svgenlargement svg').
181 $('#update_workspace_button').data('locked', false);
182 $('#update_workspace_button').css('background-position', '0px 44px');
183 //This is essential to make sure zooming and panning works properly.
184 var rdgpath = getTextURL( 'readings' );
185 $.getJSON( rdgpath, function( data ) {
187 $('#svgenlargement ellipse').each( function( i, el ) { color_inactive( el ) });
189 $('#svgenlargement ellipse').parent().dblclick( node_dblclick_listener );
190 var graph_svg = $('#svgenlargement svg');
191 var svg_g = $('#svgenlargement svg g')[0];
193 svg_root = graph_svg.svg().svg('get').root();
195 // Find the real root and ignore any text nodes
196 for (i = 0; i < svg_root.childNodes.length; ++i) {
197 if (svg_root.childNodes[i].nodeName != '#text') {
198 svg_root_element = svg_root.childNodes[i];
203 svg_root.viewBox.baseVal.width = graph_svg.attr( 'width' );
204 svg_root.viewBox.baseVal.height = graph_svg.attr( 'height' );
205 //Now set scale and translate so svg height is about 150px and vertically centered in viewbox.
206 //This is just to create a nice starting enlargement.
207 var initial_svg_height = 250;
208 var scale = initial_svg_height/graph_svg.attr( 'height' );
209 var additional_translate = (graph_svg.attr( 'height' ) - initial_svg_height)/(2*scale);
210 var transform = svg_g.getAttribute('transform');
211 var translate = parseFloat( transform.match( /translate\([^\)]*\)/ )[0].split('(')[1].split(' ')[1].split(')')[0] );
212 translate += additional_translate;
213 var transform = 'rotate(0) scale(' + scale + ') translate(4 ' + translate + ')';
214 svg_g.setAttribute('transform', transform);
215 //used to calculate min and max zoom level:
216 start_element_height = $('#__START__').children('ellipse')[0].getBBox().height;
217 add_relations( function() { $('#loading_overlay').hide(); });
220 function add_relations( callback_fn ) {
221 var basepath = getRelativePath();
222 var textrelpath = getTextURL( 'relationships' );
223 $.getJSON( basepath + '/definitions', function(data) {
224 var rel_types = data.types.sort();
225 $.getJSON( textrelpath,
227 $.each(data, function( index, rel_info ) {
228 var type_index = $.inArray(rel_info.type, rel_types);
229 var source_found = get_ellipse( rel_info.source );
230 var target_found = get_ellipse( rel_info.target );
231 if( type_index != -1 && source_found.size() && target_found.size() ) {
232 var relation = relation_manager.create( rel_info.source, rel_info.target, type_index );
233 relation.data( 'type', rel_info.type );
234 relation.data( 'scope', rel_info.scope );
235 relation.data( 'note', rel_info.note );
236 var node_obj = get_node_obj(rel_info.source);
237 node_obj.set_draggable( false );
238 node_obj.ellipse.data( 'node_obj', null );
239 node_obj = get_node_obj(rel_info.target);
240 node_obj.set_draggable( false );
241 node_obj.ellipse.data( 'node_obj', null );
249 function get_ellipse( node_id ) {
250 return $( jq( node_id ) + ' ellipse');
253 function get_node_obj( node_id ) {
254 var node_ellipse = get_ellipse( node_id );
255 if( node_ellipse.data( 'node_obj' ) == null ) {
256 node_ellipse.data( 'node_obj', new node_obj(node_ellipse) );
258 return node_ellipse.data( 'node_obj' );
261 function node_obj(ellipse) {
262 this.ellipse = ellipse;
269 this.node_elements = node_elements_for(self.ellipse);
271 this.get_id = function() {
272 return $(self.ellipse).parent().attr('id')
275 this.set_draggable = function( draggable ) {
277 $(self.ellipse).attr( {stroke:'black', fill:'#fff'} );
278 $(self.ellipse).parent().mousedown( this.mousedown_listener );
279 $(self.ellipse).parent().hover( this.enter_node, this.leave_node );
280 self.ellipse.siblings('text').attr('class', 'noselect draggable');
282 self.ellipse.siblings('text').attr('class', '');
283 $(self.ellipse).parent().unbind( 'mouseenter' ).unbind( 'mouseleave' ).unbind( 'mousedown' );
284 color_inactive( self.ellipse );
288 this.mousedown_listener = function(evt) {
289 evt.stopPropagation();
290 self.x = evt.clientX;
291 self.y = evt.clientY;
292 $('body').mousemove( self.mousemove_listener );
293 $('body').mouseup( self.mouseup_listener );
294 $(self.ellipse).parent().unbind('mouseenter').unbind('mouseleave')
295 self.ellipse.attr( 'fill', '#ff66ff' );
296 first_node_g_element = $("#svgenlargement g .node" ).filter( ":first" );
297 if( first_node_g_element.attr('id') !== self.get_g().attr('id') ) { self.get_g().insertBefore( first_node_g_element ) };
300 this.mousemove_listener = function(evt) {
301 self.dx = (evt.clientX - self.x) / mouse_scale;
302 self.dy = (evt.clientY - self.y) / mouse_scale;
303 self.move_elements();
304 evt.returnValue = false;
305 evt.preventDefault();
309 this.mouseup_listener = function(evt) {
310 if( $('ellipse[fill="#ffccff"]').size() > 0 ) {
311 var source_node_id = $(self.ellipse).parent().attr('id');
312 var source_node_text = self.ellipse.siblings('text').text();
313 var target_node_id = $('ellipse[fill="#ffccff"]').parent().attr('id');
314 var target_node_text = $('ellipse[fill="#ffccff"]').siblings("text").text();
315 $('#source_node_id').val( source_node_id );
316 $('#source_node_text').val( source_node_text );
317 $('#target_node_id').val( target_node_id );
318 $('#target_node_text').val( target_node_text );
319 $('#dialog-form').dialog( 'open' );
321 $('body').unbind('mousemove');
322 $('body').unbind('mouseup');
323 self.ellipse.attr( 'fill', '#fff' );
324 $(self.ellipse).parent().hover( self.enter_node, self.leave_node );
325 self.reset_elements();
328 this.cpos = function() {
329 return { x: self.ellipse.attr('cx'), y: self.ellipse.attr('cy') };
332 this.get_g = function() {
333 return self.ellipse.parent('g');
336 this.enter_node = function(evt) {
337 self.ellipse.attr( 'fill', '#ffccff' );
340 this.leave_node = function(evt) {
341 self.ellipse.attr( 'fill', '#fff' );
344 this.greyout_edges = function() {
345 $.each( self.node_elements, function(index, value) {
346 value.grey_out('.edge');
350 this.ungreyout_edges = function() {
351 $.each( self.node_elements, function(index, value) {
352 value.un_grey_out('.edge');
356 this.move_elements = function() {
357 $.each( self.node_elements, function(index, value) {
358 value.move(self.dx,self.dy);
362 this.reset_elements = function() {
363 $.each( self.node_elements, function(index, value) {
368 this.update_elements = function() {
369 self.node_elements = node_elements_for(self.ellipse);
372 self.set_draggable( true );
375 function svgshape( shape_element ) {
376 this.shape = shape_element;
377 this.move = function(dx,dy) {
378 this.shape.attr( "transform", "translate(" + dx + " " + dy + ")" );
380 this.reset = function() {
381 this.shape.attr( "transform", "translate( 0, 0 )" );
383 this.grey_out = function(filter) {
384 if( this.shape.parent(filter).size() != 0 ) {
385 this.shape.attr({'stroke':'#e5e5e5', 'fill':'#e5e5e5'});
388 this.un_grey_out = function(filter) {
389 if( this.shape.parent(filter).size() != 0 ) {
390 this.shape.attr({'stroke':'#000000', 'fill':'#000000'});
395 function svgpath( path_element, svg_element ) {
396 this.svg_element = svg_element;
397 this.path = path_element;
398 this.x = this.path.x;
399 this.y = this.path.y;
400 this.move = function(dx,dy) {
401 this.path.x = this.x + dx;
402 this.path.y = this.y + dy;
404 this.reset = function() {
405 this.path.x = this.x;
406 this.path.y = this.y;
408 this.grey_out = function(filter) {
409 if( this.svg_element.parent(filter).size() != 0 ) {
410 this.svg_element.attr('stroke', '#e5e5e5');
411 this.svg_element.siblings('text').attr('fill', '#e5e5e5');
412 this.svg_element.siblings('text').attr('class', 'noselect');
415 this.un_grey_out = function(filter) {
416 if( this.svg_element.parent(filter).size() != 0 ) {
417 this.svg_element.attr('stroke', '#000000');
418 this.svg_element.siblings('text').attr('fill', '#000000');
419 this.svg_element.siblings('text').attr('class', '');
424 function node_elements_for( ellipse ) {
425 node_elements = get_edge_elements_for( ellipse );
426 node_elements.push( new svgshape( ellipse.siblings('text') ) );
427 node_elements.push( new svgshape( ellipse ) );
428 return node_elements;
431 function get_edge_elements_for( ellipse ) {
432 edge_elements = new Array();
433 node_id = ellipse.parent().attr('id');
434 edge_in_pattern = new RegExp( node_id + '$' );
435 edge_out_pattern = new RegExp( '^' + node_id );
436 $.each( $('#svgenlargement .edge,#svgenlargement .relation').children('title'), function(index) {
437 title = $(this).text();
438 if( edge_in_pattern.test(title) ) {
439 polygon = $(this).siblings('polygon');
440 if( polygon.size() > 0 ) {
441 edge_elements.push( new svgshape( polygon ) );
443 path_segments = $(this).siblings('path')[0].pathSegList;
444 edge_elements.push( new svgpath( path_segments.getItem(path_segments.numberOfItems - 1), $(this).siblings('path') ) );
446 if( edge_out_pattern.test(title) ) {
447 path_segments = $(this).siblings('path')[0].pathSegList;
448 edge_elements.push( new svgpath( path_segments.getItem(0), $(this).siblings('path') ) );
451 return edge_elements;
454 function relation_factory() {
456 this.color_memo = null;
457 //TODO: colors hard coded for now
458 this.temp_color = '#FFA14F';
459 this.relation_colors = [ "#5CCCCC", "#67E667", "#F9FE72", "#6B90D4", "#FF7673", "#E467B3", "#AA67D5", "#8370D8", "#FFC173" ];
461 this.create_temporary = function( source_node_id, target_node_id ) {
462 var relation_id = get_relation_id( source_node_id, target_node_id );
463 var relation = $( jq( relation_id ) );
464 if( relation.size() == 0 ) {
465 draw_relation( source_node_id, target_node_id, self.temp_color );
467 self.color_memo = relation.children('path').attr( 'stroke' );
468 relation.children('path').attr( 'stroke', self.temp_color );
471 this.remove_temporary = function() {
472 var path_element = $('#svgenlargement .relation').children('path[stroke="' + self.temp_color + '"]');
473 if( self.color_memo != null ) {
474 path_element.attr( 'stroke', self.color_memo );
475 self.color_memo = null;
477 var temporary = path_element.parent('g').remove();
482 this.create = function( source_node_id, target_node_id, color_index ) {
483 //TODO: Protect from (color_)index out of bound..
484 var relation_color = self.relation_colors[ color_index ];
485 var relation = draw_relation( source_node_id, target_node_id, relation_color );
486 get_node_obj( source_node_id ).update_elements();
487 get_node_obj( target_node_id ).update_elements();
490 this.toggle_active = function( relation_id ) {
491 var relation = $( jq( relation_id ) );
492 var relation_path = relation.children('path');
493 if( !relation.data( 'active' ) ) {
494 relation_path.css( {'cursor':'pointer'} );
495 relation_path.mouseenter( function(event) {
496 outerTimer = setTimeout( function() {
497 timer = setTimeout( function() {
498 var related_nodes = get_related_nodes( relation_id );
499 var source_node_id = related_nodes[0];
500 var target_node_id = related_nodes[1];
501 $('#delete_source_node_id').val( source_node_id );
502 $('#delete_target_node_id').val( target_node_id );
503 self.showinfo(relation);
507 relation_path.mouseleave( function(event) {
508 clearTimeout(outerTimer);
509 if( timer != null ) { clearTimeout(timer); }
511 relation.data( 'active', true );
513 relation_path.unbind( 'mouseenter' );
514 relation_path.unbind( 'mouseleave' );
515 relation_path.css( {'cursor':'inherit'} );
516 relation.data( 'active', false );
519 this.showinfo = function(relation) {
520 var htmlstr = 'type: ' + relation.data( 'type' ) + '<br/>scope: ' + relation.data( 'scope' );
521 if( relation.data( 'note' ) ) {
522 htmlstr = htmlstr + '<br/>note: ' + relation.data( 'note' );
524 $('#delete-form-text').html( htmlstr );
525 var points = relation.children('path').attr('d').slice(1).replace('C',' ').split(' ');
526 var xs = parseFloat( points[0].split(',')[0] );
527 var xe = parseFloat( points[1].split(',')[0] );
528 var ys = parseFloat( points[0].split(',')[1] );
529 var ye = parseFloat( points[3].split(',')[1] );
530 var p = svg_root.createSVGPoint();
531 p.x = xs + ((xe-xs)*1.1);
532 p.y = ye - ((ye-ys)/2);
533 var ctm = svg_root_element.getScreenCTM();
534 var nx = p.matrixTransform(ctm).x;
535 var ny = p.matrixTransform(ctm).y;
536 var dialog_aria = $ ("div[aria-labelledby='ui-dialog-title-delete-form']");
537 $('#delete-form').dialog( 'open' );
538 dialog_aria.offset({ left: nx, top: ny });
540 this.remove = function( relation_id ) {
541 var relation = $( jq( relation_id ) );
546 // Utility function to create/return the ID of a relation link between
547 // a source and target.
548 function get_relation_id( source_id, target_id ) {
549 var idlist = [ source_id, target_id ];
551 return 'relation-' + idlist[0] + '-...-' + idlist[1];
554 function get_related_nodes( relation_id ) {
555 var srctotarg = relation_id.substr( 9 );
556 return srctotarg.split('-...-');
559 function draw_relation( source_id, target_id, relation_color ) {
560 var source_ellipse = get_ellipse( source_id );
561 var target_ellipse = get_ellipse( target_id );
562 var relation_id = get_relation_id( source_id, target_id );
563 var svg = $('#svgenlargement').children('svg').svg().svg('get');
564 var path = svg.createPath();
565 var sx = parseInt( source_ellipse.attr('cx') );
566 var rx = parseInt( source_ellipse.attr('rx') );
567 var sy = parseInt( source_ellipse.attr('cy') );
568 var ex = parseInt( target_ellipse.attr('cx') );
569 var ey = parseInt( target_ellipse.attr('cy') );
570 var relation = svg.group( $("#svgenlargement svg g"),
571 { 'class':'relation', 'id':relation_id } );
572 svg.title( relation, source_id + '->' + target_id );
573 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});
574 var relation_element = $('#svgenlargement .relation').filter( ':last' );
575 relation_element.insertBefore( $('#svgenlargement g g').filter(':first') );
576 return relation_element;
580 $(document).ready(function () {
583 relation_manager = new relation_factory();
584 $('#update_workspace_button').data('locked', false);
586 $('#enlargement').mousedown(function (event) {
589 .data('x', event.clientX)
590 .data('y', event.clientY)
591 .data('scrollLeft', this.scrollLeft)
592 stateTf = svg_root_element.getCTM().inverse();
593 var p = svg_root.createSVGPoint();
596 stateOrigin = p.matrixTransform(stateTf);
597 event.returnValue = false;
598 event.preventDefault();
600 }).mouseup(function (event) {
601 $(this).data('down', false);
602 }).mousemove(function (event) {
603 if( timer != null ) { clearTimeout(timer); }
604 if ( ($(this).data('down') == true) && ($('#update_workspace_button').data('locked') == false) ) {
605 var p = svg_root.createSVGPoint();
608 p = p.matrixTransform(stateTf);
609 var matrix = stateTf.inverse().translate(p.x - stateOrigin.x, p.y - stateOrigin.y);
610 var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
611 svg_root_element.setAttribute("transform", s);
613 event.returnValue = false;
614 event.preventDefault();
615 }).mousewheel(function (event, delta) {
616 event.returnValue = false;
617 event.preventDefault();
618 if ( $('#update_workspace_button').data('locked') == false ) {
619 if (!delta || delta == null || delta == 0) delta = event.originalEvent.wheelDelta;
620 if (!delta || delta == null || delta == 0) delta = -1 * event.originalEvent.detail;
621 if( delta < -9 ) { delta = -9 };
622 var z = 1 + delta/10;
623 z = delta > 0 ? 1 : -1;
624 var g = svg_root_element;
625 if (g && ((z<1 && (g.getScreenCTM().a * start_element_height) > 4.0) || (z>=1 && (g.getScreenCTM().a * start_element_height) < 100))) {
627 var p = root.createSVGPoint();
628 p.x = event.originalEvent.clientX;
629 p.y = event.originalEvent.clientY;
630 p = p.matrixTransform(g.getCTM().inverse());
631 var scaleLevel = 1+(z/20);
632 var k = root.createSVGMatrix().translate(p.x, p.y).scale(scaleLevel).translate(-p.x, -p.y);
633 var matrix = g.getCTM().multiply(k);
634 var s = "matrix(" + matrix.a + "," + matrix.b + "," + matrix.c + "," + matrix.d + "," + matrix.e + "," + matrix.f + ")";
635 g.setAttribute("transform", s);
639 'overflow' : 'hidden',
640 'cursor' : '-moz-grab'
644 $( "#dialog-form" ).dialog({
651 $('#status').empty();
652 form_values = $('#collapse_node_form').serialize();
653 ncpath = getTextURL( 'relationships' );
654 $(':button :contains("Ok")').attr("disabled", true);
655 var jqjson = $.post( ncpath, form_values, function(data) {
656 $.each( data, function(item, source_target) {
657 var source_found = get_ellipse( source_target[0] );
658 var target_found = get_ellipse( source_target[1] );
659 if( source_found.size() && target_found.size() ) {
660 var relation = relation_manager.create( source_target[0], source_target[1], $('#rel_type')[0].selectedIndex-1 );
661 relation.data( 'type', $('#rel_type :selected').text() );
662 relation.data( 'scope', $('#scope :selected').text() );
663 relation.data( 'note', $('#note').val() );
664 relation_manager.toggle_active( relation.attr('id') );
667 $( "#dialog-form" ).dialog( "close" );
671 $( this ).dialog( "close" );
674 create: function(event, ui) {
675 $(this).data( 'relation_drawn', false );
676 //TODO? Err handling?
677 var basepath = getRelativePath();
678 var jqjson = $.getJSON( basepath + '/definitions', function(data) {
679 var types = data.types.sort();
680 $.each( types, function(index, value) {
681 $('#rel_type').append( $('<option />').attr( "value", value ).text(value) );
682 $('#keymaplist').append( $('<li>').css( "border-color", relation_manager.relation_colors[index] ).text(value) );
684 var scopes = data.scopes;
685 $.each( scopes, function(index, value) {
686 $('#scope').append( $('<option />').attr( "value", value ).text(value) );
691 relation_manager.create_temporary( $('#source_node_id').val(), $('#target_node_id').val() );
692 $(".ui-widget-overlay").css("background", "none");
693 $("#dialog_overlay").show();
694 $("#dialog_overlay").height( $("#enlargement_container").height() );
695 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
696 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
699 relation_manager.remove_temporary();
700 $( '#status' ).empty();
701 $("#dialog_overlay").hide();
703 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
704 if( ajaxSettings.url == getTextURL('relationships')
705 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
706 var errobj = jQuery.parseJSON( jqXHR.responseText );
707 $('#status').append( '<p class="error">Error: ' + errobj.error + '</br>The relationship cannot be made.</p>' );
711 $( "#delete-form" ).dialog({
718 $( this ).dialog( "close" );
721 form_values = $('#delete_relation_form').serialize();
722 ncpath = getTextURL( 'relationships' );
723 var jqjson = $.ajax({ url: ncpath, data: form_values, success: function(data) {
724 $.each( data, function(item, source_target) {
725 relation_manager.remove( get_relation_id( source_target[0], source_target[1] ) );
727 $( "#delete-form" ).dialog( "close" );
728 }, dataType: 'json', type: 'DELETE' });
731 create: function(event, ui) {
732 var buttonset = $(this).parent().find( '.ui-dialog-buttonset' ).css( 'width', '100%' );
733 buttonset.find( "button:contains('Cancel')" ).css( 'float', 'right' );
734 var dialog_aria = $("div[aria-labelledby='ui-dialog-title-delete-form']");
735 dialog_aria.mouseenter( function() {
736 if( mouseWait != null ) { clearTimeout(mouseWait) };
738 dialog_aria.mouseleave( function() {
739 mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 );
743 mouseWait = setTimeout( function() { $("#delete-form").dialog( "close" ) }, 2000 );
749 // function for reading form dialog should go here; for now hide the element
750 $('#reading-form').dialog({
757 $( this ).dialog( "close" );
759 Update: function( evt ) {
760 // Disable the button
761 $(evt.target).button("disable");
762 $('#reading_status').empty();
763 var reading_id = $('#reading_id').val()
766 'is_nonsense': $('#reading_is_nonsense').is(':checked'),
767 'grammar_invalid': $('#reading_grammar_invalid').is(':checked'),
768 'normal_form': $('#reading_normal_form').val() };
769 // Add the morphology values
770 $('.reading_morphology').each( function() {
771 var rmid = $(this).attr('id');
772 rmid = rmid.substring(8);
773 form_values[rmid] = $(this).val();
775 // Make the JSON call
776 ncpath = getReadingURL( reading_id );
777 var reading_element = readingdata[reading_id];
778 // $(':button :contains("Update")').attr("disabled", true);
779 var jqjson = $.post( ncpath, form_values, function(data) {
780 $.each( data, function(key, value) {
781 reading_element[key] = value;
783 if( $('#update_workspace_button').data('locked') == false ) {
784 color_inactive( get_ellipse( reading_id ) );
786 $(evt.target).button("enable");
787 $( "#reading-form" ).dialog( "close" );
789 // Re-color the node if necessary
796 $(".ui-widget-overlay").css("background", "none");
797 $("#dialog_overlay").show();
798 $('#reading_status').empty();
799 $("#dialog_overlay").height( $("#enlargement_container").height() );
800 $("#dialog_overlay").width( $("#enlargement_container").innerWidth() );
801 $("#dialog_overlay").offset( $("#enlargement_container").offset() );
804 $("#dialog_overlay").hide();
806 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
807 if( ajaxSettings.url.lastIndexOf( getReadingURL('') ) > -1
808 && ajaxSettings.type == 'POST' && jqXHR.status == 403 ) {
809 var errobj = jQuery.parseJSON( jqXHR.responseText );
810 $('#reading_status').append( '<p class="error">Error: ' + errobj.error + '</p>' );
811 $(event.target).parent().find('.ui-button').button("enable");
816 $('#update_workspace_button').click( function() {
817 var svg_enlargement = $('#svgenlargement').svg().svg('get').root();
818 mouse_scale = svg_root_element.getScreenCTM().a;
819 if( $(this).data('locked') == true ) {
820 $('#svgenlargement ellipse' ).each( function( index ) {
821 if( $(this).data( 'node_obj' ) != null ) {
822 $(this).data( 'node_obj' ).ungreyout_edges();
823 $(this).data( 'node_obj' ).set_draggable( false );
824 var node_id = $(this).data( 'node_obj' ).get_id();
825 toggle_relation_active( node_id );
826 $(this).data( 'node_obj', null );
829 $(this).data('locked', false);
830 $(this).css('background-position', '0px 44px');
832 var left = $('#enlargement').offset().left;
833 var right = left + $('#enlargement').width();
834 var tf = svg_root_element.getScreenCTM().inverse();
835 var p = svg_root.createSVGPoint();
838 var cx_min = p.matrixTransform(tf).x;
840 var cx_max = p.matrixTransform(tf).x;
841 $('#svgenlargement ellipse').each( function( index ) {
842 var cx = parseInt( $(this).attr('cx') );
843 if( cx > cx_min && cx < cx_max) {
844 if( $(this).data( 'node_obj' ) == null ) {
845 $(this).data( 'node_obj', new node_obj( $(this) ) );
847 $(this).data( 'node_obj' ).set_draggable( true );
849 $(this).data( 'node_obj' ).greyout_edges();
850 var node_id = $(this).data( 'node_obj' ).get_id();
851 toggle_relation_active( node_id );
854 $(this).css('background-position', '0px 0px');
855 $(this).data('locked', true );
859 $('.helptag').popupWindow({
868 function toggle_relation_active( node_id ) {
869 $('#svgenlargement .relation').find( "title:contains('" + node_id + "')" ).each( function(index) {
870 matchid = new RegExp( "^" + node_id );
871 if( $(this).text().match( matchid ) != null ) {
872 var relation_id = $(this).parent().attr('id');
873 relation_manager.toggle_active( relation_id );
878 expandFillPageClients();
879 $(window).resize(function() {
880 expandFillPageClients();
886 function expandFillPageClients() {
887 $('.fillPage').each(function () {
888 $(this).height($(window).height() - $(this).offset().top - MARGIN);
892 function loadSVG(svgData) {
893 var svgElement = $('#svgenlargement');
895 $(svgElement).svg('destroy');
899 onLoad : svgEnlargementLoaded
906 function svg_select_callback(topic, data, subscriberData) {
912 var prefs = new gadgets.Prefs();
913 var preferredHeight = parseInt(prefs.getString('height'));
914 if (gadgets.util.hasFeature('dynamic-height')) gadgets.window.adjustHeight(preferredHeight);
915 expandFillPageClients();
918 if (gadgets.util.hasFeature('pubsub-2')) {
919 gadgets.HubSettings.onConnect = function(hum, suc, err) {
920 subId = gadgets.Hub.subscribe("interedition.svg.selected", svg_select_callback);
924 else gadgets.util.registerOnLoadHandler(loaded);