1 // Global state variables
4 var selectedTextEditable;
5 var selectedStemmaID = -1;
8 // Load the names of the appropriate traditions into the directory div.
9 function refreshDirectory () {
10 var lmesg = $('#loading_message').clone();
11 $('#directory').empty().append( lmesg.contents() );
12 $('#directory').load( _get_url(["directory"]),
13 function(response, status, xhr) {
14 if (status == "error") {
15 var msg = "An error occurred: ";
16 $("#directory").html(msg + xhr.status + " " + xhr.statusText);
18 if( textOnLoad != "" ) {
19 // Call the click callback for the relevant text, if it is
21 $('#'+textOnLoad).click();
29 // Load a tradition with its information and stemmata into the tradition
30 // view pane. Calls load_textinfo.
31 function loadTradition( textid, textname, editable ) {
32 selectedTextID = textid;
33 selectedTextEditable = editable;
34 // First insert the placeholder image and register an error handler
35 $('#textinfo_load_status').empty();
36 $('#stemma_graph').empty();
37 $('#textinfo_waitbox').show();
38 $('#textinfo_container').hide().ajaxError(
39 function(event, jqXHR, ajaxSettings, thrownError) {
40 if( ajaxSettings.url.indexOf( 'textinfo' ) > -1 && ajaxSettings.type == 'GET' ) {
41 $('#textinfo_waitbox').hide();
42 $('#textinfo_container').show();
43 display_error( jqXHR, $("#textinfo_load_status") );
47 // Hide the functionality that is irrelevant
49 $('#open_stemma_add').show();
50 $('#open_textinfo_edit').show();
51 $('#relatebutton_label').text('View collation and edit relationships');
53 $('#open_stemma_add').hide();
54 $('#open_stemweb_ui').hide();
55 $('#query_stemweb_ui').hide();
56 $('#open_textinfo_edit').hide();
57 $('#relatebutton_label').text('View collation and relationships');
60 // Then get and load the actual content.
61 // TODO: scale #stemma_graph both horizontally and vertically
62 // TODO: load svgs from SVG.Jquery (to make scaling react in Safari)
63 $.getJSON( _get_url([ "textinfo", textid ]), function (textdata) {
64 // Add the scalar data
65 selectedTextInfo = textdata;
68 stemmata = textdata.stemmata;
69 if( stemmata.length ) {
72 selectedStemmaID = -1;
74 load_stemma( selectedStemmaID );
75 // Set up the relationship mapper button
76 $('#run_relater').attr( 'action', _get_url([ "relation", textid ]) );
77 // Set up the download button
78 $('#dl_tradition').attr( 'href', _get_url([ "download", textid ]) );
79 $('#dl_tradition').attr( 'download', selectedTextInfo.name + '.xml' );
83 // Load the metadata about a tradition into the appropriate div.
84 function load_textinfo() {
85 $('#textinfo_waitbox').hide();
86 $('#textinfo_load_status').empty();
87 $('#textinfo_container').show();
88 $('.texttitle').empty().append( selectedTextInfo.name );
90 $('#witness_num').empty().append( selectedTextInfo.witnesses.size );
91 $('#witness_list').empty().append( selectedTextInfo.witnesses.join( ', ' ) );
93 $('#owner_id').empty().append('no one');
94 if( selectedTextInfo.owner ) {
95 var owneremail = selectedTextInfo.owner;
96 var chop = owneremail.indexOf( '@' );
98 owneremail = owneremail.substr( 0, chop + 1 ) + '...';
100 $('#owner_id').empty().append( owneremail );
102 // Whether or not it is public
103 $('#not_public').empty();
104 if( selectedTextInfo['public'] == false ) {
105 $('#not_public').append('NOT ');
107 // What language setting it has, if any
108 $('#marked_language').empty().append('no language set');
109 if( selectedTextInfo.language && selectedTextInfo.language != 'Default' ) {
110 $('#marked_language').empty().append( selectedTextInfo.language );
114 // Enable / disable the appropriate buttons for paging through the stemma.
115 function show_stemmapager () {
116 $('.pager_left_button').unbind('click').addClass( 'greyed_out' );
117 $('.pager_right_button').unbind('click').addClass( 'greyed_out' );
118 if( selectedStemmaID > 0 ) {
119 $('.pager_left_button').click( function () {
120 load_stemma( selectedStemmaID - 1, selectedTextEditable );
121 }).removeClass( 'greyed_out' );
123 if( selectedStemmaID + 1 < stemmata.length ) {
124 $('.pager_right_button').click( function () {
125 load_stemma( selectedStemmaID + 1, selectedTextEditable );
126 }).removeClass( 'greyed_out' );
130 // Load a given stemma SVG into the stemmagraph box.
131 function load_stemma( idx ) {
132 // Load the stemma at idx
133 selectedStemmaID = idx;
134 show_stemmapager( selectedTextEditable );
135 $('#open_stemma_edit').hide();
136 $('#run_stexaminer').hide();
137 $('#stemma_identifier').empty();
138 // Add the relevant Stemweb functionality
139 if( selectedTextEditable ) {
140 if( selectedTextInfo.stemweb_jobid == 0 ) {
141 $('#open_stemweb_ui').show();
142 $('#query_stemweb_ui').hide();
144 $('#query_stemweb_ui').show();
145 $('#open_stemweb_ui').hide();
149 // Load the stemma and its properties
150 var stemmadata = stemmata[idx];
151 if( selectedTextEditable ) {
152 $('#open_stemma_edit').show();
154 if( stemmadata.directed ) {
155 // Stexaminer submit action
156 var stexpath = _get_url([ "stexaminer", selectedTextID, idx ]);
157 $('#run_stexaminer').attr( 'action', stexpath );
158 $('#run_stexaminer').show();
160 loadSVG( stemmadata.svg );
161 $('#stemma_identifier').text( stemmadata.name );
162 setTimeout( 'start_element_height = $("#stemma_graph .node")[0].getBBox().height;', 500 );
166 function query_stemweb_progress() {
167 var requrl = _get_url([ "stemweb", "query", selectedTextInfo.stemweb_jobid ]);
168 $.getJSON( requrl, function (data) {
169 // Look for a status message, either success, running, or notfound.
170 if( data.status === 'success' ) {
171 // Add the new stemmata to the textinfo and tell the user.
172 selectedTextInfo.stemweb_jobid = 0;
173 if( data.stemmata.length > 0 ) {
174 stemmata = stemmata.concat( data.stemmata );
175 if( selectedStemmaID == -1 ) {
176 // We have a stemma for the first time; load the first one.
177 load_stemma( 0, true );
179 // Move to the index of the first added stemma.
180 var newIdx = stemmata.length - data.stemmata.length;
181 load_stemma( newIdx, true );
183 alert( 'You have one or more new stemmata!' );
185 alert( 'Stemweb run finished with no stemmata...huh?!' );
187 } else if( data.status === 'running' ) {
188 // Just tell the user.
189 alert( 'Your Stemweb query is still running!' );
190 } else if( data.status === 'notfound' ) {
191 // Ask the user to refresh, for now.
192 alert( 'Your Stemweb query probably finished and reported back. Please reload to check.' );
197 // Load the SVG we are given
198 function loadSVG(svgData) {
199 var svgElement = $('#stemma_graph');
201 $(svgElement).svg('destroy');
205 onLoad : function () {
206 var theSVG = svgElement.find('svg');
207 var svgoffset = theSVG.offset();
208 var browseroffset = 1;
209 // Firefox needs a different offset, stupidly enough
210 if( navigator.userAgent.indexOf('Firefox') > -1 ) {
211 browseroffset = 3; // works for tall images
212 // ...but if the SVG is wider than it is tall, Firefox treats
213 // the top as being the top of the graph, loaded into the middle
214 // of the canvas, but then the margin at the top of the canvas
215 // extends upward. So we have to find the actual top of the canvas
216 // and correct for *that* instead.
217 var vbdim = svgElement.svg().svg('get').root().viewBox.baseVal;
218 if( vbdim.height < vbdim.width ) {
219 var vbscale = svgElement.width() / vbdim.width;
220 var vbrealheight = vbdim.height * vbscale;
221 browseroffset = 3 + ( svgElement.height() - vbrealheight ) / 2;
224 var topoffset = theSVG.position().top - svgElement.position().top - browseroffset;
225 theSVG.offset({ top: svgoffset.top - topoffset, left: svgoffset.left });
226 set_stemma_interactive( theSVG );
231 function set_stemma_interactive( svg_element ) {
232 if( selectedTextEditable ) {
233 $( "#root_tree_dialog_button_ok" ).click( function() {
234 var requrl = _get_url([ "stemmaroot", selectedTextID, selectedStemmaID ]);
235 var targetnode = $('#root_tree_dialog').data( 'selectedNode' );
236 $.post( requrl, { root: targetnode }, function (data) {
237 // Reload the new stemma
238 stemmata[selectedStemmaID] = data;
239 load_stemma( selectedStemmaID );
240 // Put away the dialog
241 $('#root_tree_dialog').data( 'selectedNode', null ).hide();
243 } ).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
244 if( ajaxSettings.url.indexOf( 'stemmaroot' ) > -1
245 && ajaxSettings.type == 'POST' ) {
246 display_error( jqXHR, $("#stemma_load_status") );
249 // TODO Clear error at some appropriate point
250 $.each( $( 'ellipse', svg_element ), function(index) {
251 var ellipse = $(this);
252 var g = ellipse.parent( 'g' );
253 g.click( function(evt) {
254 if( typeof root_tree_dialog_timeout !== 'undefined' ) { clearTimeout( root_tree_dialog_timeout ) };
255 g.unbind( 'mouseleave' );
256 var dialog = $( '#root_tree_dialog' );
257 // Note which node triggered the dialog
258 dialog.data( 'selectedNode', g.attr('id') );
259 // Position the dialog
261 dialog.css( 'top', evt.pageY + 3 );
262 dialog.css( 'left', evt.pageX + 3 );
264 root_tree_dialog_timeout = setTimeout( function() {
265 $( '#root_tree_dialog' ).data( 'selectedNode', null ).hide();
266 ellipse.removeClass( 'stemma_node_highlight' );
267 g.mouseleave( function() { ellipse.removeClass( 'stemma_node_highlight' ) } );
270 g.mouseenter( function() {
271 $( 'ellipse.stemma_node_highlight' ).removeClass( 'stemma_node_highlight' );
272 ellipse.addClass( 'stemma_node_highlight' )
274 g.mouseleave( function() { ellipse.removeClass( 'stemma_node_highlight' ) } );
279 // General-purpose error-handling function.
280 // TODO make sure this gets used throughout, where appropriate.
281 function display_error( jqXHR, el ) {
283 if( jqXHR.responseText == "" ) {
284 errmsg = "perhaps the server went down?"
288 errobj = jQuery.parseJSON( jqXHR.responseText );
289 errmsg = errobj.error;
290 } catch ( parse_err ) {
291 errmsg = "something went wrong on the server."
294 var msghtml = $('<span>').attr('class', 'error').text( "An error occurred: " + errmsg );
295 $(el).empty().append( msghtml ).show();
298 // Event to enable the upload button when a file has been selected
299 function file_selected( e ) {
300 if( e.files.length == 1 ) {
301 $('#upload_button').button('enable');
302 $('#new_file_name_container').html( '<span id="new_file_name">' + e.files[0].name + '</span>' );
304 $('#upload_button').button('disable');
305 $('#new_file_name_container').html( '(Use \'pick file\' to select a tradition file to upload.)' );
309 // Implement our own AJAX method that uses the features of XMLHttpRequest2
310 // but try to let it have a similar interface to jquery.post
311 // The data var needs to be a FormData() object.
312 // The callback will be given a single argument, which is the response data
313 // of the given type.
315 function post_xhr2( url, data, cb, type ) {
319 var xhr = new XMLHttpRequest();
320 // Set the expected response type
321 if( type === 'data' ) {
322 xhr.responseType = 'blob';
323 } else if( type === 'xml' ) {
324 xhr.responseType = 'document';
327 // Gin up an AJAX settings object
328 $.ajaxSetup({ url: url, type: 'POST' });
329 xhr.open( 'POST', url, true );
330 // Handle the results
331 xhr.onload = function( e ) {
332 // Get the response and parse it
333 // Call the callback with the response, whatever it was
335 if( xhrs.status > 199 && xhrs.status < 300 ) { // Success
337 if( type === 'json' ) {
338 resp = $.parseJSON( xhrs.responseText );
339 } else if ( type === 'xml' ) {
340 resp = xhrs.responseXML;
341 } else if ( type === 'text' ) {
342 resp = xhrs.responseText;
344 resp = xhrs.response;
348 // Trigger the ajaxError...
349 _trigger_ajaxerror( e );
352 xhr.onerror = _trigger_ajaxerror;
353 xhr.onabort = _trigger_ajaxerror;
357 function _trigger_ajaxerror( e ) {
359 var thrown = xhr.statusText || 'Request error';
360 jQuery.event.trigger( 'ajaxError', [ xhr, $.ajaxSettings, thrown ]);
363 function upload_new () {
364 // Serialize the upload form, get the file and attach it to the request,
365 // POST the lot and handle the response.
366 var newfile = $('#new_file').get(0).files[0];
367 var reader = new FileReader();
368 reader.onload = function( evt ) {
369 var data = new FormData();
370 $.each( $('#new_tradition').serializeArray(), function( i, o ) {
371 data.append( o.name, o.value );
373 data.append( 'file', newfile );
374 var upload_url = _get_url([ 'newtradition' ]);
375 post_xhr2( upload_url, data, function( ret ) {
377 $('#upload-collation-dialog').dialog('close');
379 loadTradition( ret.id, ret.name, 1 );
380 } else if( ret.error ) {
381 $('#upload_status').empty().append(
382 $('<span>').attr('class', 'error').append( ret.error ) );
386 reader.onerror = function( evt ) {
387 var err_resp = 'File read error';
388 if( e.name == 'NotFoundError' ) {
389 err_resp = 'File not found';
390 } else if ( e.name == 'NotReadableError' ) {
391 err_resp == 'File unreadable - is it yours?';
392 } else if ( e.name == 'EncodingError' ) {
393 err_resp == 'File cannot be encoded - is it too long?';
394 } else if ( e.name == 'SecurityError' ) {
395 err_resp == 'File read security error';
397 // Fake a jqXHR object that we can pass to our generic error handler.
398 var jqxhr = { responseText: '{error:"' + err_resp + '"}' };
399 display_error( jqxhr, $('#upload_status') );
400 $('#upload_button').button('disable');
403 reader.readAsBinaryString( newfile );
406 // Utility function to neatly construct an application URL
407 function _get_url( els ) {
408 return basepath + els.join('/');
411 // TODO Attach unified ajaxError handler to document
412 $(document).ready( function() {
413 // See if we have the browser functionality we need
414 // TODO Also think of a test for SVG readiness
415 if( !!window.FileReader && !!window.File ) {
416 $('#compatibility_check').empty();
419 // hide dialog not yet in use
420 $('#root_tree_dialog').hide();
422 // call out to load the directory div
423 $('#textinfo_container').hide();
424 $('#textinfo_waitbox').hide();
427 // Set up the textinfo edit dialog
428 $('#textinfo-edit-dialog').dialog({
434 Save: function (evt) {
435 $("#edit_textinfo_status").empty();
436 $(evt.target).button("disable");
437 var requrl = _get_url([ "textinfo", selectedTextID ]);
438 var reqparam = $('#edit_textinfo').serialize();
439 $.post( requrl, reqparam, function (data) {
440 // Reload the selected text fields
441 selectedTextInfo = data;
443 // Reenable the button and close the form
444 $(evt.target).button("enable");
445 $('#textinfo-edit-dialog').dialog('close');
449 $('#textinfo-edit-dialog').dialog('close');
453 $("#edit_textinfo_status").empty();
454 // Populate the form fields with the current values
455 // edit_(name, language, public, owner)
456 $.each([ 'name', 'language', 'owner' ], function( idx, k ) {
457 var fname = '#edit_' + k;
458 // Special case: language Default is basically language null
459 if( k == 'language' && selectedTextInfo[k] == 'Default' ) {
462 $(fname).val( selectedTextInfo[k] );
465 if( selectedTextInfo['public'] == true ) {
466 $('#edit_public').attr('checked','true');
468 $('#edit_public').removeAttr('checked');
471 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
472 $(event.target).parent().find('.ui-button').button("enable");
473 if( ajaxSettings.url.indexOf( 'textinfo' ) > -1
474 && ajaxSettings.type == 'POST' ) {
475 display_error( jqXHR, $("#edit_textinfo_status") );
480 // Set up the stemma editor dialog
481 $('#stemma-edit-dialog').dialog({
487 Save: function (evt) {
488 $("#edit_stemma_status").empty();
489 $(evt.target).button("disable");
490 var stemmaseq = $('#stemmaseq').val();
491 var requrl = _get_url([ "stemma", selectedTextID, stemmaseq ]);
492 var reqparam = { 'dot': $('#dot_field').val() };
493 // TODO We need to stash the literal SVG string in stemmata
494 // somehow. Implement accept header on server side to decide
495 // whether to send application/json or application/xml?
496 $.post( requrl, reqparam, function (data) {
497 // We received a stemma SVG string in return.
498 // Update the current stemma sequence number
499 selectedStemmaID = data.stemmaid;
500 delete data.stemmaid;
501 // Stash the answer in the appropriate spot in our stemma array
502 stemmata[selectedStemmaID] = data;
503 // Display the new stemma
504 load_stemma( selectedStemmaID, true );
505 // Reenable the button and close the form
506 $(evt.target).button("enable");
507 $('#stemma-edit-dialog').dialog('close');
511 $('#stemma-edit-dialog').dialog('close');
514 open: function(evt) {
515 $("#edit_stemma_status").empty();
516 var stemmaseq = $('#stemmaseq').val();
517 if( stemmaseq == 'n' ) {
518 // If we are creating a new stemma, populate the textarea with a
520 $(evt.target).dialog('option', 'title', 'Add a new stemma')
521 $('#dot_field').val( "digraph \"NAME STEMMA HERE\" {\n\n}" );
523 // If we are editing a stemma, grab its stemmadot and populate the
524 // textarea with that.
525 $(evt.target).dialog('option', 'title', 'Edit selected stemma')
526 $('#dot_field').val( 'Loading, please wait...' );
527 var doturl = _get_url([ "stemmadot", selectedTextID, stemmaseq ]);
528 $.getJSON( doturl, function (data) {
529 // Re-insert the line breaks
530 var dotstring = data.dot.replace(/\|n/gm, "\n");
531 $('#dot_field').val( dotstring );
535 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
536 $(event.target).parent().find('.ui-button').button("enable");
537 if( ajaxSettings.url.indexOf( 'stemma' ) > -1
538 && ajaxSettings.type == 'POST' ) {
539 display_error( jqXHR, $("#edit_stemma_status") );
543 $('#stemweb-ui-dialog').dialog({
549 Run: function (evt) {
550 $("#stemweb_run_status").empty();
551 $(evt.target).button("disable");
552 var requrl = _get_url([ "stemweb", "request" ]);
553 var reqparam = $('#call_stemweb').serialize();
554 // TODO We need to stash the literal SVG string in stemmata
555 // somehow. Implement accept header on server side to decide
556 // whether to send application/json or application/xml?
557 $.getJSON( requrl, reqparam, function (data) {
558 // Job ID is in data.jobid. TODO do something with it.
559 selectedTextInfo.stemweb_jobid = data.jobid;
560 $(evt.target).button("enable");
561 $('#stemweb-ui-dialog').dialog('close');
562 // Reload the current stemma to rejigger the buttons
563 load_stemma( selectedStemmaID, true );
567 $('#stemweb-ui-dialog').dialog('close');
570 create: function(evt) {
571 // Call out to Stemweb to get the algorithm options, with which we
572 // populate the form.
573 var algorithmTypes = {};
574 var algorithmArgs = {};
575 var requrl = _get_url([ "stemweb", "available" ]);
576 $.getJSON( requrl, function( data ) {
577 $.each( data, function( i, o ) {
578 if( o.model === 'algorithms.algorithm' ) {
579 // it's an algorithm.
580 algorithmTypes[ o.pk ] = o.fields;
581 } else if( o.model == 'algorithms.algorithmarg' && o.fields.external ) {
582 // it's an option for an algorithm that we should display.
583 algorithmArgs[ o.pk ] = o.fields;
586 // TODO if it is an empty object, disable Stemweb entirely.
587 if( !jQuery.isEmptyObject( algorithmTypes ) ) {
588 $.each( algorithmTypes, function( pk, fields ) {
589 var algopt = $('<option>').attr( 'value', pk ).append( fields.name );
590 $('#stemweb_algorithm').append( algopt );
592 // Set up the relevant options for whichever algorithm is chosen.
593 // "key" -> form name, option ID "stemweb_$key_opt"
594 // "name" -> form label
595 $('#stemweb_algorithm').change( function() {
596 var pk = $(this).val();
597 $('#stemweb_runtime_options').empty();
598 $.each( algorithmTypes[pk].args, function( i, apk ) {
599 var argInfo = algorithmArgs[apk];
601 // Make the element ID
602 var optId = 'stemweb_' + argInfo.key + '_opt';
604 var optLabel = $('<label>').attr( 'for', optId )
605 .append( argInfo.name + ": " );
607 var argType = argInfo.value;
608 if( argType === 'positive_integer' ) {
609 // Make it an input field of smallish size.
610 optCtrl = $('<input>').attr( 'size', 4 );
611 } else if ( argType === 'boolean' ) {
612 // Make it a checkbox.
613 optCtrl = $('<checkbox>');
615 // Add the name and element ID
616 optCtrl.attr( 'name', argInfo.key ).attr( 'id', optId );
617 // Append the label and the option itself to the form.
618 $('#stemweb_runtime_options').append( optLabel )
619 .append( optCtrl ).append( $('<br>') );
623 $('#stemweb_algorithm').change();
626 // Prime the initial options
628 open: function(evt) {
629 $('#stemweb_run_status').empty();
630 $('#stemweb_tradition').attr('value', selectedTextID );
632 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
633 $(event.target).parent().find('.ui-button').button("enable");
634 if( ajaxSettings.url.indexOf( 'stemweb/request' ) > -1 ) {
635 display_error( jqXHR, $("#stemweb_run_status") );
639 // Set up the download dialog
640 $('#download-dialog').dialog({
646 Download: function (evt) {
647 var dlurl = _get_url([ "download", $('#download_tradition').val(), $('#download_format').val() ]);
648 window.location = dlurl;
649 $('download-dialog').dialog('close');
652 $('#download-dialog').dialog('close');
656 $('#download_tradition').attr('value', selectedTextID );
658 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
659 $(event.target).parent().find('.ui-button').button("enable");
660 if( ajaxSettings.url.indexOf( 'download' ) > -1
661 && ajaxSettings.type == 'POST' ) {
662 display_error( jqXHR, $("#download_status") );
666 $('#upload-collation-dialog').dialog({
676 $('#upload_status').empty();
677 $('#upload_button').button("disable");
683 id: 'pick_file_button',
685 $('#new_file').click();
689 $('#upload-collation-dialog').dialog('close');
693 // Set the upload button to its correct state based on
694 // whether a file is loaded
695 file_selected( $('#new_file').get(0) );
696 $('#upload_status').empty();
698 }).ajaxError( function(event, jqXHR, ajaxSettings, thrownError) {
699 // Reset button state
700 file_selected( $('#new_file').get(0) );
701 // Display error message if applicable
702 if( ajaxSettings.url.indexOf( 'newtradition' ) > -1
703 && ajaxSettings.type == 'POST' ) {
704 display_error( jqXHR, $("#upload_status") );
708 $('#stemma_graph').mousedown( function(evt) {
709 evt.stopPropagation();
710 $('#stemma_graph').data( 'mousedown_xy', [evt.clientX, evt.clientY] );
711 $('body').mousemove( function(evt) {
712 mouse_scale = 1; // for now, was: mouse_scale = svg_root_element.getScreenCTM().a;
713 dx = (evt.clientX - $('#stemma_graph').data( 'mousedown_xy' )[0]) / mouse_scale;
714 dy = (evt.clientY - $('#stemma_graph').data( 'mousedown_xy' )[1]) / mouse_scale;
715 $('#stemma_graph').data( 'mousedown_xy', [evt.clientX, evt.clientY] );
716 var svg_root = $('#stemma_graph svg').svg().svg('get').root();
717 var g = $('g.graph', svg_root).get(0);
718 current_translate = g.getAttribute( 'transform' ).split(/translate\(/)[1].split(')',1)[0].split(' ');
719 new_transform = g.getAttribute( 'transform' ).replace( /translate\([^\)]*\)/, 'translate(' + (parseFloat(current_translate[0]) + dx) + ' ' + (parseFloat(current_translate[1]) + dy) + ')' );
720 g.setAttribute( 'transform', new_transform );
721 evt.returnValue = false;
722 evt.preventDefault();
725 $('body').mouseup( function(evt) {
726 $('body').unbind('mousemove');
727 $('body').unbind('mouseup');
731 $('#stemma_graph').mousewheel(function (event, delta) {
732 event.returnValue = false;
733 event.preventDefault();
734 if (!delta || delta == null || delta == 0) delta = event.originalEvent.wheelDelta;
735 if (!delta || delta == null || delta == 0) delta = -1 * event.originalEvent.detail;
736 if( delta < -9 ) { delta = -9 };
737 var z = 1 + delta/10;
738 z = delta > 0 ? 1 : -1;
739 var svg_root = $('#stemma_graph svg').svg().svg('get').root();
740 var g = $('g.graph', svg_root).get(0);
741 if (g && ((z<1 && (g.getScreenCTM().a * start_element_height) > 4.0) || (z>=1 && (g.getScreenCTM().a * start_element_height) < 1000))) {
742 var scaleLevel = z/10;
743 current_scale = parseFloat( g.getAttribute( 'transform' ).split(/scale\(/)[1].split(')',1)[0].split(' ')[0] );
744 new_transform = g.getAttribute( 'transform' ).replace( /scale\([^\)]*\)/, 'scale(' + (current_scale + scaleLevel) + ')' );
745 g.setAttribute( 'transform', new_transform );