[hg] galaxy 2476: IE compatibility fixes in workflow editor java...
details: http://www.bx.psu.edu/hg/galaxy/rev/14fd033f08eb changeset: 2476:14fd033f08eb user: James Taylor <james@jamestaylor.org> date: Fri Jul 10 16:21:19 2009 -0400 description: IE compatibility fixes in workflow editor javascript (groan) 2 file(s) affected in this change: static/scripts/galaxy.workflow_editor.canvas.js static/scripts/packed/galaxy.workflow_editor.canvas.js diffs (474 lines): diff -r 0b5d64cde142 -r 14fd033f08eb static/scripts/galaxy.workflow_editor.canvas.js --- a/static/scripts/galaxy.workflow_editor.canvas.js Fri Jul 10 16:15:32 2009 -0400 +++ b/static/scripts/galaxy.workflow_editor.canvas.js Fri Jul 10 16:21:19 2009 -0400 @@ -2,7 +2,7 @@ this.element = element; this.connectors = []; } -Terminal.prototype = { +$.extend( Terminal.prototype, { connect: function ( connector ) { this.connectors.push( connector ); if ( this.node ) { @@ -25,26 +25,26 @@ c.destroy(); }); } -} +}); function OutputTerminal( element, datatype ) { Terminal.call( this, element ); this.datatype = datatype; } -OutputTerminal.prototype = new Terminal; +OutputTerminal.prototype = new Terminal(); function InputTerminal( element, datatypes ) { Terminal.call( this, element ); this.datatypes = datatypes; } -InputTerminal.prototype = new Terminal; +InputTerminal.prototype = new Terminal(); $.extend( InputTerminal.prototype, { can_accept: function ( other ) { if ( this.connectors.length < 1 ) { - for ( t in this.datatypes ) { + for ( var t in this.datatypes ) { // FIXME: No idea what to do about this case if ( other.datatype == "input" ) { return true; } if ( issubtype( other.datatype, this.datatypes[t] ) ) { @@ -60,7 +60,7 @@ this.canvas = null; this.dragging = false; this.inner_color = "#FFFFFF"; - this.outer_color = "#D8B365" + this.outer_color = "#D8B365"; if ( handle1 && handle2 ) { this.connect( handle1, handle2 ); } @@ -90,10 +90,16 @@ G_vmlCanvasManager.initElement( this.canvas ); } canvas_container.append( $(this.canvas) ); - if ( this.dragging ) { this.canvas.style.zIndex = "300" } + if ( this.dragging ) { + this.canvas.style.zIndex = "300"; + } } - var relativeLeft = function( e ) { return $(e).offset().left - canvas_container.offset().left } - var relativeTop = function( e ) { return $(e).offset().top - canvas_container.offset().top } + var relativeLeft = function( e ) { + return $(e).offset().left - canvas_container.offset().left; + }; + var relativeTop = function( e ) { + return $(e).offset().top - canvas_container.offset().top; + }; // Find the position of each handle var start_x = relativeLeft( this.handle1.element ) + 5; var start_y = relativeTop( this.handle1.element ) + 5; @@ -157,7 +163,7 @@ }).bind( "dropend", function ( e ) { e.dragProxy.terminal.connectors[0].inner_color = "#FFFFFF"; }).bind( "drop", function( e ) { - new Connector( e.dragTarget.terminal, e.dropTarget.terminal ).redraw(); + ( new Connector( e.dragTarget.terminal, e.dropTarget.terminal ) ).redraw(); }).bind( "hover", function() { // If connected, create a popup to allow disconnection if ( terminal.connectors.length > 0 ) { @@ -168,22 +174,24 @@ .append( $("<div class='buttons'></div>").append( $("<img src='../images/delete_icon.png' />").click( function() { - $.each( terminal.connectors, function( _, x ) { x.destroy() } ); + $.each( terminal.connectors, function( _, x ) { + x.destroy(); + }); t.remove(); }))) .bind( "mouseleave", function() { $(this).remove(); }); // Position it and show - t.css( { + t.css({ top: $(this).offset().top - 2, left: $(this).offset().left - t.width(), - 'padding-right': $(this).width() } - ).show(); + 'padding-right': $(this).width() + }).show(); } }); node.input_terminals[name] = terminal; - }) + }); }, enable_output_terminal : function( elements, name, type ) { var node = this; @@ -213,7 +221,7 @@ e.dragProxy.terminal.redraw(); // FIXME: global canvas_manager.update_viewport_overlay(); - } + }; onmove(); $("#canvas-container").get(0).scroll_panel.test( e, onmove ); }).bind( "dragend", function ( e ) { @@ -226,8 +234,12 @@ }); }, redraw : function () { - $.each( this.input_terminals, function( _, t ) { t.redraw() } ); - $.each( this.output_terminals, function( _, t ) { t.redraw() } ); + $.each( this.input_terminals, function( _, t ) { + t.redraw(); + }); + $.each( this.output_terminals, function( _, t ) { + t.redraw(); + }); }, destroy : function () { $.each( this.input_terminals, function( k, t ) { @@ -246,7 +258,7 @@ // Keep inactive nodes stacked from most to least recently active // by moving element to the end of parent's node list var element = this.element.get(0); - (function(p) { p.removeChild( element ); p.appendChild( element ) })(element.parentNode); + (function(p) { p.removeChild( element ); p.appendChild( element ); })(element.parentNode); // Remove active class $(element).removeClass( "toolForm-active" ); }, @@ -279,7 +291,7 @@ $.each( data.data_outputs, function( i, output ) { var t = $( "<div class='terminal output-terminal'></div>" ); node.enable_output_terminal( t, output.name, output.extension ); - var label = output.name + var label = output.name; if ( output.extension != 'input' ) { label = label + " (" + output.extension + ")"; } @@ -301,7 +313,7 @@ // Update input rows var old_body = el.find( "div.inputs" ); var new_body = $("<div class='inputs'></div>"); - var old = old_body.find( "div.input-data-row") + var old = old_body.find( "div.input-data-row"); $.each( data.data_inputs, function( i, input ) { var t = $("<div class='terminal input-terminal'></div>"); node.enable_input_terminal( t, input.name, input.extensions ); @@ -323,7 +335,7 @@ // Cleanup any leftover terminals old_body.find( "div.input-data-row > .terminal" ).each( function() { this.terminal.destroy(); - }) + }); // If active, reactivate with new form_html this.changed(); this.redraw(); @@ -344,7 +356,7 @@ function Workflow( canvas_container ) { this.canvas_container = canvas_container; this.id_counter = 0; - this.nodes = {} + this.nodes = {}; this.name = null; this.has_changes = false; } @@ -372,9 +384,9 @@ }); }, to_simple : function () { - var nodes = {} + var nodes = {}; $.each( this.nodes, function ( i, node ) { - var input_connections = {} + var input_connections = {}; $.each( node.input_terminals, function ( k, t ) { input_connections[ t.name ] = null; // There should only be 0 or 1 connectors, so this is @@ -391,10 +403,10 @@ tool_errors : node.tool_errors, input_connections : input_connections, position : $(node.element).position() - } + }; nodes[ node.id ] = node_data; - }) - return { steps: nodes } + }); + return { steps: nodes }; }, from_simple : function ( data ) { wf = this; @@ -409,7 +421,7 @@ } node.id = step.id; wf.nodes[ node.id ] = node; - max_id = Math.max( max_id, parseInt( id ) ) + max_id = Math.max( max_id, parseInt( id ) ); }); wf.id_counter = max_id + 1; // Second pass, connections @@ -423,7 +435,7 @@ node.input_terminals[ k ] ); c.redraw(); } - }) + }); }); }, clear_active_node : function() { @@ -471,31 +483,32 @@ }); }); // Assemble order, tracking levels - node_ids_by_level = [] + node_ids_by_level = []; while ( true ) { // Everything without a predecessor - level_parents = [] - $.each( n_pred, function( k, v ) { - if ( v == 0 ) { - level_parents.push( k ); + level_parents = []; + for ( var pred_k in n_pred ) { + if ( n_pred[ pred_k ] == 0 ) { + level_parents.push( pred_k ); } - }); + } if ( level_parents.length == 0 ) { break; } - node_ids_by_level.push( level_parents ) + node_ids_by_level.push( level_parents ); // Remove the parents from this level, and decrement the number // of predecessors for each successor - $.each( level_parents, function( k, v ) { + for ( var k in level_parents ) { + var v = level_parents[k]; delete n_pred[v]; - $.each( successors[v], function( sk, sv ) { - n_pred[sv] -= 1; - }); - }); + for ( var sk in successors[v] ) { + n_pred[ sucessors[v][sk] ] -= 1; + } + } } if ( n_pred.length ) { // ERROR: CYCLE! Currently we do nothing - return + return; } // Layout each level var all_nodes = this.nodes; @@ -505,7 +518,7 @@ // We keep nodes in the same order in a level to give the user // some control over ordering ids.sort( function( a, b ) { - return $(all_nodes[a].element).position().top - $(all_nodes[b].element).position().top + return $(all_nodes[a].element).position().top - $(all_nodes[b].element).position().top; }); // Position each node var max_width = 0; @@ -520,7 +533,7 @@ left += max_width + h_pad; }); // Need to redraw all connectors - $.each( all_nodes, function( _, node ) { node.redraw() } ); + $.each( all_nodes, function( _, node ) { node.redraw(); } ); }, bounds_for_all_nodes: function() { var xmin = Infinity, xmax = -Infinity, @@ -528,7 +541,7 @@ p; $.each( this.nodes, function( id, node ) { e = $(node.element); - p = e.position() + p = e.position(); xmin = Math.min( xmin, p.left ); xmax = Math.max( xmax, p.left + e.width() ); ymin = Math.min( ymin, p.top ); @@ -559,11 +572,11 @@ left: left, top: top, width: width, - height: height, + height: height }); // Move elements back if needed this.canvas_container.children().each( function() { - var p = $(this).position() + var p = $(this).position(); $(this).css( "left", p.left + xmin_delta ); $(this).css( "top", p.top + ymin_delta ); }); @@ -585,26 +598,26 @@ function prebuild_node( type, title_text, tool_id ) { var f = $("<div class='toolForm toolFormInCanvas'></div>"); var node = new Node( f ); - node.type = type + node.type = type; if ( type == 'tool' ) { node.tool_id = tool_id; } - var title = $("<div class='toolFormTitle unselectable'>" + title_text + "</div>" ) + var title = $("<div class='toolFormTitle unselectable'>" + title_text + "</div>" ); f.append( title ); f.css( "left", $(window).scrollLeft() + 20 ); f.css( "top", $(window).scrollTop() + 20 ); - var b = $("<div class='toolFormBody'></div>") + var b = $("<div class='toolFormBody'></div>"); var tmp = "<div><img height='16' align='middle' src='../images/loading_small_white_bg.gif'/> loading tool info...</div>"; b.append( tmp ); node.form_html = tmp; - f.append( b ) + f.append( b ); // Fix width to computed width // Now add floats var buttons = $("<div class='buttons' style='float: right;'></div>"); buttons.append( $("<img src='../images/delete_icon.png' />").click( function( e ) { node.destroy(); } ).hover( - function() { $(this).attr( 'src', "../images/delete_icon_dark.png" ) }, - function() { $(this).attr( 'src', "../images/delete_icon.png" ) } + function() { $(this).attr( 'src', "../images/delete_icon_dark.png" ); }, + function() { $(this).attr( 'src', "../images/delete_icon.png" ); } ) ); // Place inside container f.appendTo( "#canvas-container" ); @@ -647,12 +660,12 @@ child = ext_to_type[child]; parent = ext_to_type[parent]; return ( type_to_type[child] ) && ( parent in type_to_type[child] ); -}; +} function populate_datatype_info( data ) { ext_to_type = data.ext_to_class_name; type_to_type = data.class_to_classes; -}; +} // FIXME: merge scroll panel into CanvasManager, clean up hardcoded stuff. @@ -663,14 +676,14 @@ test: function( e, onmove ) { clearTimeout( this.timeout ); var x = e.pageX, - y = e.pageY; + y = e.pageY, // Panel size and position panel = $(this.panel), panel_pos = panel.position(), panel_w = panel.width(), - panel_h = panel.height() + panel_h = panel.height(), // Viewport size and offset - viewport = panel.parent(); + viewport = panel.parent(), viewport_w = viewport.width(), viewport_h = viewport.height(), viewport_offset = viewport.offset(), @@ -747,7 +760,7 @@ top: y }); self.update_viewport_overlay(); - } + }; // Dragging within canvas background this.cc.each( function() { this.scroll_panel = new ScrollPanel( this ); @@ -766,13 +779,13 @@ }); // Dragging for overview pane this.ov.bind( "drag", function( e ) { - var in_w = self.cc.width(); - var in_h = self.cc.height() - var o_w = self.oc.width(); - var o_h = self.oc.height(); - var p = $(this).offsetParent().offset(); - var new_x_offset = e.offsetX - p.left; - var new_y_offset = e.offsetY - p.top; + var in_w = self.cc.width(), + in_h = self.cc.height(), + o_w = self.oc.width(), + o_h = self.oc.height(), + p = $(this).offsetParent().offset(), + new_x_offset = e.offsetX - p.left, + new_y_offset = e.offsetY - p.top; move( - ( new_x_offset / o_w * in_w ), - ( new_y_offset / o_h * in_h ) ); }).bind( "dragend", function() { @@ -794,15 +807,15 @@ }, update_viewport_overlay: function() { - var cc = this.cc; - var cv = this.cv; - var oc = this.oc; - var ov = this.ov; - var in_w = cc.width(); - var in_h = cc.height() - var o_w = oc.width(); - var o_h = oc.height(); - var cc_pos = cc.position() + var cc = this.cc, + cv = this.cv, + oc = this.oc, + ov = this.ov, + in_w = cc.width(), + in_h = cc.height(), + o_w = oc.width(), + o_h = oc.height(), + cc_pos = cc.position(); ov.css( { left: - ( cc_pos.left / in_w * o_w ), top: - ( cc_pos.top / in_h * o_h ), @@ -812,11 +825,11 @@ }); }, draw_overview: function() { - var canvas_el = $("#overview-canvas"); - var size = canvas_el.parent().parent().width() - var c = canvas_el.get(0).getContext("2d"); - var in_w = $("#canvas-container").width(); - var in_h = $("#canvas-container").height() + var canvas_el = $("#overview-canvas"), + size = canvas_el.parent().parent().width(), + c = canvas_el.get(0).getContext("2d"), + in_w = $("#canvas-container").width(), + in_h = $("#canvas-container").height(); var o_h, shift_h, o_w, shift_w; // Fit canvas into overview area var cv_w = this.cv.width(); @@ -853,7 +866,7 @@ c.strokeStyle = "#D8B365"; c.lineWidth = 1; $.each( workflow.nodes, function( id, node ) { - var node_element = $(node.element); + var node_element = $(node.element), position = node_element.position(), x = position.left / in_w * o_w, y = position.top / in_h * o_h, @@ -864,4 +877,4 @@ }); this.update_viewport_overlay(); } -}) \ No newline at end of file +}); \ No newline at end of file diff -r 0b5d64cde142 -r 14fd033f08eb static/scripts/packed/galaxy.workflow_editor.canvas.js --- a/static/scripts/packed/galaxy.workflow_editor.canvas.js Fri Jul 10 16:15:32 2009 -0400 +++ b/static/scripts/packed/galaxy.workflow_editor.canvas.js Fri Jul 10 16:21:19 2009 -0400 @@ -1,1 +1,1 @@ -function Terminal(a){this.element=a;this.connectors=[]}Terminal.prototype={connect:function(a){this.connectors.push(a);if(this.node){this.node.changed()}},disconnect:function(a){this.connectors.splice($.inArray(a,this.connectors),1);if(this.node){this.node.changed()}},redraw:function(){$.each(this.connectors,function(a,b){b.redraw()})},destroy:function(){$.each(this.connectors.slice(),function(a,b){b.destroy()})}};function OutputTerminal(a,b){Terminal.call(this,a);this.datatype=b}OutputTerminal.prototype=new Terminal;function InputTerminal(a,b){Terminal.call(this,a);this.datatypes=b}InputTerminal.prototype=new Terminal;$.extend(InputTerminal.prototype,{can_accept:function(a){if(this.connectors.length<1){for(t in this.datatypes){if(a.datatype=="input"){return true}if(issubtype(a.datatype,this.datatypes[t])){return true}}}return false}});function Connector(b,a){this.canvas=null;this.dragging=false;this.inner_color="#FFFFFF";this.outer_color="#D8B365";if(b&&a){this.connect(b,a) }}$.extend(Connector.prototype,{connect:function(b,a){this.handle1=b;this.handle1.connect(this);this.handle2=a;this.handle2.connect(this)},destroy:function(){if(this.handle1){this.handle1.disconnect(this)}if(this.handle2){this.handle2.disconnect(this)}$(this.canvas).remove()},redraw:function(){var d=$("#canvas-container");if(!this.canvas){this.canvas=document.createElement("canvas");if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(this.canvas)}d.append($(this.canvas));if(this.dragging){this.canvas.style.zIndex="300"}}var o=function(c){return $(c).offset().left-d.offset().left};var j=function(c){return $(c).offset().top-d.offset().top};var i=o(this.handle1.element)+5;var g=j(this.handle1.element)+5;var q=o(this.handle2.element)+5;var n=j(this.handle2.element)+5;var f=100;var l=Math.min(i,q);var a=Math.max(i,q);var k=Math.min(g,n);var v=Math.max(g,n);var b=Math.min(Math.max(Math.abs(v-k)/2,100),300);var p=l-f;var u=k-f;var r=a-l+2*f;var m=v-k+2*f;this.canvas.style. left=p+"px";this.canvas.style.top=u+"px";this.canvas.setAttribute("width",r);this.canvas.setAttribute("height",m);i-=p;g-=u;q-=p;n-=u;var s=this.canvas.getContext("2d");s.lineCap="round";s.strokeStyle=this.outer_color;s.lineWidth=7;s.beginPath();s.moveTo(i,g);s.bezierCurveTo(i+b,g,q-b,n,q,n);s.stroke();s.strokeStyle=this.inner_color;s.lineWidth=5;s.beginPath();s.moveTo(i,g);s.bezierCurveTo(i+b,g,q-b,n,q,n);s.stroke()}});function Node(a){this.element=a;this.input_terminals={};this.output_terminals={};this.tool_errors={}}$.extend(Node.prototype,{enable_input_terminal:function(d,a,b){var c=this;$(d).each(function(){var f=this.terminal=new InputTerminal(this,b);f.node=c;f.name=a;$(this).bind("dropstart",function(g){g.dragProxy.terminal.connectors[0].inner_color="#BBFFBB"}).bind("dropend",function(g){g.dragProxy.terminal.connectors[0].inner_color="#FFFFFF"}).bind("drop",function(g){new Connector(g.dragTarget.terminal,g.dropTarget.terminal).redraw()}).bind("hover",function(){if(f. connectors.length>0){var g=$("<div class='callout'></div>").css({display:"none"}).appendTo("body").append($("<div class='buttons'></div>").append($("<img src='../images/delete_icon.png' />").click(function(){$.each(f.connectors,function(j,i){i.destroy()});g.remove()}))).bind("mouseleave",function(){$(this).remove()});g.css({top:$(this).offset().top-2,left:$(this).offset().left-g.width(),"padding-right":$(this).width()}).show()}});c.input_terminals[a]=f})},enable_output_terminal:function(d,a,b){var c=this;$(d).each(function(){var g=this;var f=this.terminal=new OutputTerminal(this,b);f.node=c;f.name=a;$(this).bind("dragstart",function(j){var i=$('<div class="drag-terminal" style="position: absolute;"></div>').appendTo("#canvas-container").get(0);i.terminal=new OutputTerminal(i);var k=new Connector();k.dragging=true;k.connect(this.terminal,i.terminal);$.dropManage({filter:function(l){return this.terminal.can_accept(f)}}).addClass("input-terminal-active");return i}).bind("drag", function(j){var i=function(){var l=$(j.dragProxy).offsetParent().offset(),k=j.offsetX-l.left,m=j.offsetY-l.top;$(j.dragProxy).css({left:k,top:m});j.dragProxy.terminal.redraw();canvas_manager.update_viewport_overlay()};i();$("#canvas-container").get(0).scroll_panel.test(j,i)}).bind("dragend",function(i){i.dragProxy.terminal.connectors[0].destroy();$(i.dragProxy).remove();$.dropManage().removeClass("input-terminal-active");$("#canvas-container").get(0).scroll_panel.stop()});c.output_terminals[a]=f})},redraw:function(){$.each(this.input_terminals,function(a,b){b.redraw()});$.each(this.output_terminals,function(a,b){b.redraw()})},destroy:function(){$.each(this.input_terminals,function(a,b){b.destroy()});$.each(this.output_terminals,function(a,b){b.destroy()});workflow.remove_node(this);$(this.element).remove()},make_active:function(){$(this.element).addClass("toolForm-active")},make_inactive:function(){var a=this.element.get(0);(function(b){b.removeChild(a);b.appendChild(a)})(a. parentNode);$(a).removeClass("toolForm-active")},init_field_data:function(g){var d=this.element;if(g.type){this.type=g.type}this.name=g.name;this.form_html=g.form_html;this.tool_state=g.tool_state;this.tool_errors=g.tool_errors;if(this.tool_errors){d.addClass("tool-node-error")}else{d.removeClass("tool-node-error")}var c=this;var a=d.find(".toolFormBody");a.find("div").remove();var i=$("<div class='inputs'></div>").appendTo(a);$.each(g.data_inputs,function(j,b){var f=$("<div class='terminal input-terminal'></div>");c.enable_input_terminal(f,b.name,b.extensions);i.append($("<div class='form-row dataRow input-data-row' name='"+b.name+"'>"+b.label+"</div>").prepend(f))});if((g.data_inputs.length>0)&&(g.data_outputs.length>0)){a.append($("<div class='rule'></div>"))}$.each(g.data_outputs,function(k,b){var j=$("<div class='terminal output-terminal'></div>");c.enable_output_terminal(j,b.name,b.extension);var f=b.name;if(b.extension!="input"){f=f+" ("+b.extension+")"}a.append($("<d iv class='form-row dataRow'>"+f+"</div>").append(j))});workflow.node_changed(this)},update_field_data:function(f){var c=$(this.element),d=this;this.tool_state=f.tool_state;this.form_html=f.form_html;this.tool_errors=f.tool_errors;if(this.tool_errors){c.addClass("tool-node-error")}else{c.removeClass("tool-node-error")}var g=c.find("div.inputs");var b=$("<div class='inputs'></div>");var a=g.find("div.input-data-row");$.each(f.data_inputs,function(l,j){var k=$("<div class='terminal input-terminal'></div>");d.enable_input_terminal(k,j.name,j.extensions);g.find("div[name="+j.name+"]").each(function(){$(this).find(".input-terminal").each(function(){var i=this.terminal.connectors[0];if(i){k[0].terminal.connectors[0]=i;i.handle2=k[0].terminal}});$(this).remove()});b.append($("<div class='form-row dataRow input-data-row' name='"+j.name+"'>"+j.label+"</div>").prepend(k))});g.replaceWith(b);g.find("div.input-data-row > .terminal").each(function(){this.terminal.destroy()});this.changed( );this.redraw()},error:function(d){var a=$(this.element).find(".toolFormBody");a.find("div").remove();var c="<div style='color: red; text-style: italic;'>"+d+"</div>";this.form_html=c;a.html(c);workflow.node_changed(this)},changed:function(){workflow.node_changed(this)}});function Workflow(a){this.canvas_container=a;this.id_counter=0;this.nodes={};this.name=null;this.has_changes=false}$.extend(Workflow.prototype,{add_node:function(a){a.id=this.id_counter;a.element.attr("id","wf-node-step-"+a.id);this.id_counter++;this.nodes[a.id]=a;this.has_changes=true;a.workflow=this},remove_node:function(a){if(this.active_node==a){this.clear_active_node()}delete this.nodes[a.id];this.has_changes=true},remove_all:function(){wf=this;$.each(this.nodes,function(b,a){a.destroy();wf.remove_node(a)})},to_simple:function(){var a={};$.each(this.nodes,function(b,d){var f={};$.each(d.input_terminals,function(g,i){f[i.name]=null;$.each(i.connectors,function(j,k){f[i.name]={id:k.handle1.node.id,output _name:k.handle1.name}})});var c={id:d.id,type:d.type,tool_id:d.tool_id,tool_state:d.tool_state,tool_errors:d.tool_errors,input_connections:f,position:$(d.element).position()};a[d.id]=c});return{steps:a}},from_simple:function(a){wf=this;var b=0;wf.name=a.name;$.each(a.steps,function(f,d){var c=prebuild_node("tool",d.name,d.tool_id);c.init_field_data(d);if(d.position){c.element.css({top:d.position.top,left:d.position.left})}c.id=d.id;wf.nodes[c.id]=c;b=Math.max(b,parseInt(f))});wf.id_counter=b+1;$.each(a.steps,function(f,d){var c=wf.nodes[f];$.each(d.input_connections,function(i,g){if(g){var j=wf.nodes[g.id];var l=new Connector();l.connect(j.output_terminals[g.output_name],c.input_terminals[i]);l.redraw()}})})},clear_active_node:function(){if(this.active_node){this.active_node.make_inactive();this.active_node=null}parent.show_form_for_tool("<div>No node selected</div>")},activate_node:function(a){if(this.active_node!=a){this.clear_active_node();parent.show_form_for_tool(a.form _html,a);a.make_active();this.active_node=a}},node_changed:function(a){this.has_changes=true;if(this.active_node==a){parent.show_form_for_tool(a.form_html,a)}},layout:function(){var a={};var b={};$.each(this.nodes,function(i,g){if(a[i]===undefined){a[i]=0}if(b[i]===undefined){b[i]=[]}});$.each(this.nodes,function(i,g){$.each(g.input_terminals,function(k,l){$.each(l.connectors,function(m,n){var j=n.handle1.node;a[g.id]+=1;b[j.id].push(g.id)})})});node_ids_by_level=[];while(true){level_parents=[];$.each(a,function(i,g){if(g==0){level_parents.push(i)}});if(level_parents.length==0){break}node_ids_by_level.push(level_parents);$.each(level_parents,function(i,g){delete a[g];$.each(b[g],function(k,j){a[j]-=1})})}if(a.length){return}var d=this.nodes;var c=80;v_pad=30;var f=c;$.each(node_ids_by_level,function(g,j){j.sort(function(m,i){return $(d[m].element).position().top-$(d[i].element).position().top});var k=0;var l=v_pad;$.each(j,function(i,o){var n=d[o];var m=$(n.element);$(m).css ({top:l,left:f});k=Math.max(k,$(m).width());l+=$(m).height()+v_pad});f+=k+c});$.each(d,function(g,i){i.redraw()})},bounds_for_all_nodes:function(){var d=Infinity,b=-Infinity,c=Infinity,a=-Infinity,f;$.each(this.nodes,function(i,g){e=$(g.element);f=e.position();d=Math.min(d,f.left);b=Math.max(b,f.left+e.width());c=Math.min(c,f.top);a=Math.max(a,f.top+e.width())});return{xmin:d,xmax:b,ymin:c,ymax:a}},fit_canvas_to_nodes:function(){var a=this.bounds_for_all_nodes();var f=this.canvas_container.position();var j=this.canvas_container.parent();var d=fix_delta(a.xmin,100);var i=fix_delta(a.ymin,100);d=Math.max(d,f.left);i=Math.max(i,f.top);var c=f.left-d;var g=f.top-i;var b=round_up(a.xmax+100,100)+d;var k=round_up(a.ymax+100,100)+i;b=Math.max(b,-c+j.width());k=Math.max(k,-g+j.height());this.canvas_container.css({left:c,top:g,width:b,height:k,});this.canvas_container.children().each(function(){var l=$(this).position();$(this).css("left",l.left+d);$(this).css("top",l.top+i)})}});func tion fix_delta(a,b){if(a<b||a>3*b){new_pos=(Math.ceil(((a%b))/b)+1)*b;return(-(a-new_pos))}return 0}function round_up(a,b){return Math.ceil(a/b)*b}function prebuild_node(m,k,s){var j=$("<div class='toolForm toolFormInCanvas'></div>");var g=new Node(j);g.type=m;if(m=="tool"){g.tool_id=s}var q=$("<div class='toolFormTitle unselectable'>"+k+"</div>");j.append(q);j.css("left",$(window).scrollLeft()+20);j.css("top",$(window).scrollTop()+20);var n=$("<div class='toolFormBody'></div>");var i="<div><img height='16' align='middle' src='../images/loading_small_white_bg.gif'/> loading tool info...</div>";n.append(i);g.form_html=i;j.append(n);var l=$("<div class='buttons' style='float: right;'></div>");l.append($("<img src='../images/delete_icon.png' />").click(function(b){g.destroy()}).hover(function(){$(this).attr("src","../images/delete_icon_dark.png")},function(){$(this).attr("src","../images/delete_icon.png")}));j.appendTo("#canvas-container");var d=$("#canvas-container").position( );var c=$("#canvas-container").parent();var a=j.width();var r=j.height();j.css({left:(-d.left)+(c.width()/2)-(a/2),top:(-d.top)+(c.height()/2)-(r/2)});l.prependTo(q);a+=(l.width()+10);j.css("width",a);$(j).bind("dragstart",function(){workflow.activate_node(g)}).bind("dragend",function(){workflow.node_changed(this);workflow.fit_canvas_to_nodes();canvas_manager.draw_overview()}).bind("dragclickonly",function(){workflow.activate_node(g)}).bind("drag",function(o){var f=$(this).offsetParent().offset(),b=o.offsetX-f.left,p=o.offsetY-f.top;$(this).css({left:b,top:p});$(this).find(".terminal").each(function(){this.terminal.redraw()})});return g}var ext_to_type=null;var type_to_type=null;function issubtype(b,a){b=ext_to_type[b];a=ext_to_type[a];return(type_to_type[b])&&(a in type_to_type[b])}function populate_datatype_info(a){ext_to_type=a.ext_to_class_name;type_to_type=a.class_to_classes}function ScrollPanel(a){this.panel=a}$.extend(ScrollPanel.prototype,{test:function(f,c){clearTim eout(this.timeout);var a=f.pageX,g=f.pageY;b=$(this.panel),panel_pos=b.position(),panel_w=b.width(),panel_h=b.height();viewport=b.parent();viewport_w=viewport.width(),viewport_h=viewport.height(),viewport_offset=viewport.offset(),min_x=viewport_offset.left,min_y=viewport_offset.top,max_x=min_x+viewport.width(),max_y=min_y+viewport.height(),p_min_x=-(panel_w-(viewport_w/2)),p_min_y=-(panel_h-(viewport_h/2)),p_max_x=(viewport_w/2),p_max_y=(viewport_h/2),moved=false,close_dist=5,nudge=23;if(a-close_dist<min_x){if(panel_pos.left<p_max_x){var d=Math.min(nudge,p_max_x-panel_pos.left);b.css("left",panel_pos.left+d);moved=true}}else{if(a+close_dist>max_x){if(panel_pos.left>p_min_x){var d=Math.min(nudge,panel_pos.left-p_min_x);b.css("left",panel_pos.left-d);moved=true}}else{if(g-close_dist<min_y){if(panel_pos.top<p_max_y){var d=Math.min(nudge,p_max_y-panel_pos.top);b.css("top",panel_pos.top+d);moved=true}}else{if(g+close_dist>max_y){if(panel_pos.top>p_min_y){var d=Math.min(nudge,pane l_pos.top-p_min_x);b.css("top",(panel_pos.top-d)+"px");moved=true}}}}}if(moved){c();var b=this;this.timeout=setTimeout(function(){b.test(f,c)},50)}},stop:function(b,a){clearTimeout(this.timeout)}});function CanvasManager(b,a){this.cv=b;this.cc=this.cv.find("#canvas-container");this.oc=a.find("#overview-canvas");this.ov=a.find("#overview-viewport");this.init_drag()}$.extend(CanvasManager.prototype,{init_drag:function(){var b=this;var a=function(f,g){f=Math.min(f,b.cv.width()/2);f=Math.max(f,-b.cc.width()+b.cv.width()/2);g=Math.min(g,b.cv.height()/2);g=Math.max(g,-b.cc.height()+b.cv.height()/2);b.cc.css({left:f,top:g});b.update_viewport_overlay()};this.cc.each(function(){this.scroll_panel=new ScrollPanel(this)});var d,c;this.cv.bind("dragstart",function(g){var i=$(this).offset();var f=b.cc.position();c=f.top-i.top;d=f.left-i.left}).bind("drag",function(f){a(f.offsetX+d,f.offsetY+c)}).bind("dragend",function(){workflow.fit_canvas_to_nodes();b.draw_overview()});this.ov.bind("dra g",function(l){var k=b.cc.width();var g=b.cc.height();var f=b.oc.width();var i=b.oc.height();var j=$(this).offsetParent().offset();var n=l.offsetX-j.left;var m=l.offsetY-j.top;a(-(n/f*k),-(m/i*g))}).bind("dragend",function(){workflow.fit_canvas_to_nodes();b.draw_overview()});$("#overview-border").bind("drag",function(g){var j=$(this).offsetParent();var i=j.offset();var f=Math.max(j.width()-(g.offsetX-i.left),j.height()-(g.offsetY-i.top));$(this).css({width:f,height:f});b.draw_overview()})},update_viewport_overlay:function(){var b=this.cc;var f=this.cv;var a=this.oc;var c=this.ov;var d=b.width();var k=b.height();var j=a.width();var g=a.height();var i=b.position();c.css({left:-(i.left/d*j),top:-(i.top/k*g),width:(f.width()/d*j)-2,height:(f.height()/k*g)-2})},draw_overview:function(){var k=$("#overview-canvas");var n=k.parent().parent().width();var j=k.get(0).getContext("2d");var d=$("#canvas-container").width();var m=$("#canvas-container").height();var g,a,l,f;var i=this.cv.wi dth();var b=this.cv.height();if(d<i&&m<b){l=d/i*n;f=(n-l)/2;g=m/b*n;a=(n-g)/2}else{if(d<m){a=0;g=n;l=Math.ceil(g*d/m);f=(n-l)/2}else{l=n;f=0;g=Math.ceil(l*m/d);a=(n-g)/2}}k.parent().css({left:f,top:a,width:l,height:g});k.attr("width",l);k.attr("height",g);j.fillStyle="#D2C099";j.strokeStyle="#D8B365";j.lineWidth=1;$.each(workflow.nodes,function(p,c){var o=$(c.element);position=o.position(),x=position.left/d*l,y=position.top/m*g,w=o.width()/d*l,h=o.height()/m*g;j.fillRect(x,y,w,h);j.strokeRect(x,y,w,h)});this.update_viewport_overlay()}}); \ No newline at end of file +function Terminal(a){this.element=a;this.connectors=[]}$.extend(Terminal.prototype,{connect:function(a){this.connectors.push(a);if(this.node){this.node.changed()}},disconnect:function(a){this.connectors.splice($.inArray(a,this.connectors),1);if(this.node){this.node.changed()}},redraw:function(){$.each(this.connectors,function(a,b){b.redraw()})},destroy:function(){$.each(this.connectors.slice(),function(a,b){b.destroy()})}});function OutputTerminal(a,b){Terminal.call(this,a);this.datatype=b}OutputTerminal.prototype=new Terminal();function InputTerminal(a,b){Terminal.call(this,a);this.datatypes=b}InputTerminal.prototype=new Terminal();$.extend(InputTerminal.prototype,{can_accept:function(a){if(this.connectors.length<1){for(var b in this.datatypes){if(a.datatype=="input"){return true}if(issubtype(a.datatype,this.datatypes[b])){return true}}}return false}});function Connector(b,a){this.canvas=null;this.dragging=false;this.inner_color="#FFFFFF";this.outer_color="#D8B365";if(b&&a) {this.connect(b,a)}}$.extend(Connector.prototype,{connect:function(b,a){this.handle1=b;this.handle1.connect(this);this.handle2=a;this.handle2.connect(this)},destroy:function(){if(this.handle1){this.handle1.disconnect(this)}if(this.handle2){this.handle2.disconnect(this)}$(this.canvas).remove()},redraw:function(){var d=$("#canvas-container");if(!this.canvas){this.canvas=document.createElement("canvas");if(window.G_vmlCanvasManager){G_vmlCanvasManager.initElement(this.canvas)}d.append($(this.canvas));if(this.dragging){this.canvas.style.zIndex="300"}}var n=function(c){return $(c).offset().left-d.offset().left};var i=function(c){return $(c).offset().top-d.offset().top};var h=n(this.handle1.element)+5;var g=i(this.handle1.element)+5;var p=n(this.handle2.element)+5;var m=i(this.handle2.element)+5;var f=100;var k=Math.min(h,p);var a=Math.max(h,p);var j=Math.min(g,m);var t=Math.max(g,m);var b=Math.min(Math.max(Math.abs(t-j)/2,100),300);var o=k-f;var s=j-f;var q=a-k+2*f;var l=t-j+2*f; this.canvas.style.left=o+"px";this.canvas.style.top=s+"px";this.canvas.setAttribute("width",q);this.canvas.setAttribute("height",l);h-=o;g-=s;p-=o;m-=s;var r=this.canvas.getContext("2d");r.lineCap="round";r.strokeStyle=this.outer_color;r.lineWidth=7;r.beginPath();r.moveTo(h,g);r.bezierCurveTo(h+b,g,p-b,m,p,m);r.stroke();r.strokeStyle=this.inner_color;r.lineWidth=5;r.beginPath();r.moveTo(h,g);r.bezierCurveTo(h+b,g,p-b,m,p,m);r.stroke()}});function Node(a){this.element=a;this.input_terminals={};this.output_terminals={};this.tool_errors={}}$.extend(Node.prototype,{enable_input_terminal:function(d,a,b){var c=this;$(d).each(function(){var f=this.terminal=new InputTerminal(this,b);f.node=c;f.name=a;$(this).bind("dropstart",function(g){g.dragProxy.terminal.connectors[0].inner_color="#BBFFBB"}).bind("dropend",function(g){g.dragProxy.terminal.connectors[0].inner_color="#FFFFFF"}).bind("drop",function(g){(new Connector(g.dragTarget.terminal,g.dropTarget.terminal)).redraw()}).bind("hov er",function(){if(f.connectors.length>0){var g=$("<div class='callout'></div>").css({display:"none"}).appendTo("body").append($("<div class='buttons'></div>").append($("<img src='../images/delete_icon.png' />").click(function(){$.each(f.connectors,function(i,h){h.destroy()});g.remove()}))).bind("mouseleave",function(){$(this).remove()});g.css({top:$(this).offset().top-2,left:$(this).offset().left-g.width(),"padding-right":$(this).width()}).show()}});c.input_terminals[a]=f})},enable_output_terminal:function(d,a,b){var c=this;$(d).each(function(){var g=this;var f=this.terminal=new OutputTerminal(this,b);f.node=c;f.name=a;$(this).bind("dragstart",function(j){var i=$('<div class="drag-terminal" style="position: absolute;"></div>').appendTo("#canvas-container").get(0);i.terminal=new OutputTerminal(i);var k=new Connector();k.dragging=true;k.connect(this.terminal,i.terminal);$.dropManage({filter:function(h){return this.terminal.can_accept(f)}}).addClass("input-terminal-active");ret urn i}).bind("drag",function(i){var h=function(){var k=$(i.dragProxy).offsetParent().offset(),j=i.offsetX-k.left,l=i.offsetY-k.top;$(i.dragProxy).css({left:j,top:l});i.dragProxy.terminal.redraw();canvas_manager.update_viewport_overlay()};h();$("#canvas-container").get(0).scroll_panel.test(i,h)}).bind("dragend",function(h){h.dragProxy.terminal.connectors[0].destroy();$(h.dragProxy).remove();$.dropManage().removeClass("input-terminal-active");$("#canvas-container").get(0).scroll_panel.stop()});c.output_terminals[a]=f})},redraw:function(){$.each(this.input_terminals,function(a,b){b.redraw()});$.each(this.output_terminals,function(a,b){b.redraw()})},destroy:function(){$.each(this.input_terminals,function(a,b){b.destroy()});$.each(this.output_terminals,function(a,b){b.destroy()});workflow.remove_node(this);$(this.element).remove()},make_active:function(){$(this.element).addClass("toolForm-active")},make_inactive:function(){var a=this.element.get(0);(function(b){b.removeChild(a);b .appendChild(a)})(a.parentNode);$(a).removeClass("toolForm-active")},init_field_data:function(g){var d=this.element;if(g.type){this.type=g.type}this.name=g.name;this.form_html=g.form_html;this.tool_state=g.tool_state;this.tool_errors=g.tool_errors;if(this.tool_errors){d.addClass("tool-node-error")}else{d.removeClass("tool-node-error")}var c=this;var a=d.find(".toolFormBody");a.find("div").remove();var h=$("<div class='inputs'></div>").appendTo(a);$.each(g.data_inputs,function(j,b){var f=$("<div class='terminal input-terminal'></div>");c.enable_input_terminal(f,b.name,b.extensions);h.append($("<div class='form-row dataRow input-data-row' name='"+b.name+"'>"+b.label+"</div>").prepend(f))});if((g.data_inputs.length>0)&&(g.data_outputs.length>0)){a.append($("<div class='rule'></div>"))}$.each(g.data_outputs,function(k,b){var j=$("<div class='terminal output-terminal'></div>");c.enable_output_terminal(j,b.name,b.extension);var f=b.name;if(b.extension!="input"){f=f+" ("+b.extensio n+")"}a.append($("<div class='form-row dataRow'>"+f+"</div>").append(j))});workflow.node_changed(this)},update_field_data:function(f){var c=$(this.element),d=this;this.tool_state=f.tool_state;this.form_html=f.form_html;this.tool_errors=f.tool_errors;if(this.tool_errors){c.addClass("tool-node-error")}else{c.removeClass("tool-node-error")}var g=c.find("div.inputs");var b=$("<div class='inputs'></div>");var a=g.find("div.input-data-row");$.each(f.data_inputs,function(k,h){var j=$("<div class='terminal input-terminal'></div>");d.enable_input_terminal(j,h.name,h.extensions);g.find("div[name="+h.name+"]").each(function(){$(this).find(".input-terminal").each(function(){var i=this.terminal.connectors[0];if(i){j[0].terminal.connectors[0]=i;i.handle2=j[0].terminal}});$(this).remove()});b.append($("<div class='form-row dataRow input-data-row' name='"+h.name+"'>"+h.label+"</div>").prepend(j))});g.replaceWith(b);g.find("div.input-data-row > .terminal").each(function(){this.terminal.destr oy()});this.changed();this.redraw()},error:function(d){var a=$(this.element).find(".toolFormBody");a.find("div").remove();var c="<div style='color: red; text-style: italic;'>"+d+"</div>";this.form_html=c;a.html(c);workflow.node_changed(this)},changed:function(){workflow.node_changed(this)}});function Workflow(a){this.canvas_container=a;this.id_counter=0;this.nodes={};this.name=null;this.has_changes=false}$.extend(Workflow.prototype,{add_node:function(a){a.id=this.id_counter;a.element.attr("id","wf-node-step-"+a.id);this.id_counter++;this.nodes[a.id]=a;this.has_changes=true;a.workflow=this},remove_node:function(a){if(this.active_node==a){this.clear_active_node()}delete this.nodes[a.id];this.has_changes=true},remove_all:function(){wf=this;$.each(this.nodes,function(b,a){a.destroy();wf.remove_node(a)})},to_simple:function(){var a={};$.each(this.nodes,function(b,d){var f={};$.each(d.input_terminals,function(g,h){f[h.name]=null;$.each(h.connectors,function(j,k){f[h.name]={id:k.ha ndle1.node.id,output_name:k.handle1.name}})});var c={id:d.id,type:d.type,tool_id:d.tool_id,tool_state:d.tool_state,tool_errors:d.tool_errors,input_connections:f,position:$(d.element).position()};a[d.id]=c});return{steps:a}},from_simple:function(a){wf=this;var b=0;wf.name=a.name;$.each(a.steps,function(f,d){var c=prebuild_node("tool",d.name,d.tool_id);c.init_field_data(d);if(d.position){c.element.css({top:d.position.top,left:d.position.left})}c.id=d.id;wf.nodes[c.id]=c;b=Math.max(b,parseInt(f))});wf.id_counter=b+1;$.each(a.steps,function(f,d){var c=wf.nodes[f];$.each(d.input_connections,function(h,g){if(g){var i=wf.nodes[g.id];var j=new Connector();j.connect(i.output_terminals[g.output_name],c.input_terminals[h]);j.redraw()}})})},clear_active_node:function(){if(this.active_node){this.active_node.make_inactive();this.active_node=null}parent.show_form_for_tool("<div>No node selected</div>")},activate_node:function(a){if(this.active_node!=a){this.clear_active_node();parent.show_ form_for_tool(a.form_html,a);a.make_active();this.active_node=a}},node_changed:function(a){this.has_changes=true;if(this.active_node==a){parent.show_form_for_tool(a.form_html,a)}},layout:function(){var i={};var b={};$.each(this.nodes,function(l,k){if(i[l]===undefined){i[l]=0}if(b[l]===undefined){b[l]=[]}});$.each(this.nodes,function(l,k){$.each(k.input_terminals,function(m,n){$.each(n.connectors,function(p,q){var o=q.handle1.node;i[k.id]+=1;b[o.id].push(k.id)})})});node_ids_by_level=[];while(true){level_parents=[];for(var a in i){if(i[a]==0){level_parents.push(a)}}if(level_parents.length==0){break}node_ids_by_level.push(level_parents);for(var f in level_parents){var j=level_parents[f];delete i[j];for(var g in b[j]){i[sucessors[j][g]]-=1}}}if(i.length){return}var d=this.nodes;var h=80;v_pad=30;var c=h;$.each(node_ids_by_level,function(k,l){l.sort(function(p,o){return $(d[p].element).position().top-$(d[o].element).position().top});var m=0;var n=v_pad;$.each(l,function(o,r){var q=d[r];var p=$(q.element);$(p).css({top:n,left:c});m=Math.max(m,$(p).width());n+=$(p).height()+v_pad});c+=m+h});$.each(d,function(k,l){l.redraw()})},bounds_for_all_nodes:function(){var d=Infinity,b=-Infinity,c=Infinity,a=-Infinity,f;$.each(this.nodes,function(h,g){e=$(g.element);f=e.position();d=Math.min(d,f.left);b=Math.max(b,f.left+e.width());c=Math.min(c,f.top);a=Math.max(a,f.top+e.width())});return{xmin:d,xmax:b,ymin:c,ymax:a}},fit_canvas_to_nodes:function(){var a=this.bounds_for_all_nodes();var f=this.canvas_container.position();var i=this.canvas_container.parent();var d=fix_delta(a.xmin,100);var h=fix_delta(a.ymin,100);d=Math.max(d,f.left);h=Math.max(h,f.top);var c=f.left-d;var g=f.top-h;var b=round_up(a.xmax+100,100)+d;var j=round_up(a.ymax+100,100)+h;b=Math.max(b,-c+i.width());j=Math.max(j,-g+i.height());this.canvas_container.css({left:c,top:g,width:b,height:j});this.canvas_container.children().each(function(){var k=$(this).position();$(this).css("left",k.left+d);$( this).css("top",k.top+h)})}});function fix_delta(a,b){if(a<b||a>3*b){new_pos=(Math.ceil(((a%b))/b)+1)*b;return(-(a-new_pos))}return 0}function round_up(a,b){return Math.ceil(a/b)*b}function prebuild_node(l,j,r){var i=$("<div class='toolForm toolFormInCanvas'></div>");var g=new Node(i);g.type=l;if(l=="tool"){g.tool_id=r}var n=$("<div class='toolFormTitle unselectable'>"+j+"</div>");i.append(n);i.css("left",$(window).scrollLeft()+20);i.css("top",$(window).scrollTop()+20);var m=$("<div class='toolFormBody'></div>");var h="<div><img height='16' align='middle' src='../images/loading_small_white_bg.gif'/> loading tool info...</div>";m.append(h);g.form_html=h;i.append(m);var k=$("<div class='buttons' style='float: right;'></div>");k.append($("<img src='../images/delete_icon.png' />").click(function(b){g.destroy()}).hover(function(){$(this).attr("src","../images/delete_icon_dark.png")},function(){$(this).attr("src","../images/delete_icon.png")}));i.appendTo("#canvas-container");var d=$("#canvas-container").position();var c=$("#canvas-container").parent();var a=i.width();var q=i.height();i.css({left:(-d.left)+(c.width()/2)-(a/2),top:(-d.top)+(c.height()/2)-(q/2)});k.prependTo(n);a+=(k.width()+10);i.css("width",a);$(i).bind("dragstart",function(){workflow.activate_node(g)}).bind("dragend",function(){workflow.node_changed(this);workflow.fit_canvas_to_nodes();canvas_manager.draw_overview()}).bind("dragclickonly",function(){workflow.activate_node(g)}).bind("drag",function(o){var f=$(this).offsetParent().offset(),b=o.offsetX-f.left,p=o.offsetY-f.top;$(this).css({left:b,top:p});$(this).find(".terminal").each(function(){this.terminal.redraw()})});return g}var ext_to_type=null;var type_to_type=null;function issubtype(b,a){b=ext_to_type[b];a=ext_to_type[a];return(type_to_type[b])&&(a in type_to_type[b])}function populate_datatype_info(a){ext_to_type=a.ext_to_class_name;type_to_type=a.class_to_classes}function ScrollPanel(a){this.panel=a}$.extend(ScrollPanel.prot otype,{test:function(v,d){clearTimeout(this.timeout);var k=v.pageX,j=v.pageY,l=$(this.panel),c=l.position(),b=l.width(),i=l.height(),w=l.parent(),s=w.width(),a=w.height(),r=w.offset(),p=r.left,m=r.top,A=p+w.width(),u=m+w.height(),B=-(b-(s/2)),z=-(i-(a/2)),g=(s/2),f=(a/2),h=false,q=5,o=23;if(k-q<p){if(c.left<g){var n=Math.min(o,g-c.left);l.css("left",c.left+n);h=true}}else{if(k+q>A){if(c.left>B){var n=Math.min(o,c.left-B);l.css("left",c.left-n);h=true}}else{if(j-q<m){if(c.top<f){var n=Math.min(o,f-c.top);l.css("top",c.top+n);h=true}}else{if(j+q>u){if(c.top>z){var n=Math.min(o,c.top-B);l.css("top",(c.top-n)+"px");h=true}}}}}if(h){d();var l=this;this.timeout=setTimeout(function(){l.test(v,d)},50)}},stop:function(b,a){clearTimeout(this.timeout)}});function CanvasManager(b,a){this.cv=b;this.cc=this.cv.find("#canvas-container");this.oc=a.find("#overview-canvas");this.ov=a.find("#overview-viewport");this.init_drag()}$.extend(CanvasManager.prototype,{init_drag:function(){var b=this; var a=function(f,g){f=Math.min(f,b.cv.width()/2);f=Math.max(f,-b.cc.width()+b.cv.width()/2);g=Math.min(g,b.cv.height()/2);g=Math.max(g,-b.cc.height()+b.cv.height()/2);b.cc.css({left:f,top:g});b.update_viewport_overlay()};this.cc.each(function(){this.scroll_panel=new ScrollPanel(this)});var d,c;this.cv.bind("dragstart",function(g){var h=$(this).offset();var f=b.cc.position();c=f.top-h.top;d=f.left-h.left}).bind("drag",function(f){a(f.offsetX+d,f.offsetY+c)}).bind("dragend",function(){workflow.fit_canvas_to_nodes();b.draw_overview()});this.ov.bind("drag",function(k){var j=b.cc.width(),g=b.cc.height(),f=b.oc.width(),h=b.oc.height(),i=$(this).offsetParent().offset(),m=k.offsetX-i.left,l=k.offsetY-i.top;a(-(m/f*j),-(l/h*g))}).bind("dragend",function(){workflow.fit_canvas_to_nodes();b.draw_overview()});$("#overview-border").bind("drag",function(g){var i=$(this).offsetParent();var h=i.offset();var f=Math.max(i.width()-(g.offsetX-h.left),i.height()-(g.offsetY-h.top));$(this).css({wi dth:f,height:f});b.draw_overview()})},update_viewport_overlay:function(){var b=this.cc,f=this.cv,a=this.oc,c=this.ov,d=b.width(),j=b.height(),i=a.width(),g=a.height(),h=b.position();c.css({left:-(h.left/d*i),top:-(h.top/j*g),width:(f.width()/d*i)-2,height:(f.height()/j*g)-2})},draw_overview:function(){var j=$("#overview-canvas"),m=j.parent().parent().width(),i=j.get(0).getContext("2d"),d=$("#canvas-container").width(),l=$("#canvas-container").height();var g,a,k,f;var h=this.cv.width();var b=this.cv.height();if(d<h&&l<b){k=d/h*m;f=(m-k)/2;g=l/b*m;a=(m-g)/2}else{if(d<l){a=0;g=m;k=Math.ceil(g*d/l);f=(m-k)/2}else{k=m;f=0;g=Math.ceil(k*l/d);a=(m-g)/2}}j.parent().css({left:f,top:a,width:k,height:g});j.attr("width",k);j.attr("height",g);i.fillStyle="#D2C099";i.strokeStyle="#D8B365";i.lineWidth=1;$.each(workflow.nodes,function(t,q){var s=$(q.element),n=s.position(),c=n.left/d*k,r=n.top/l*g,o=s.width()/d*k,p=s.height()/l*g;i.fillRect(c,r,o,p);i.strokeRect(c,r,o,p)});this.update_viewp ort_overlay()}}); \ No newline at end of file
participants (1)
-
Greg Von Kuster