123456789101112131415161718192021222324 |
- if(!Array.prototype.indexOf)Array.prototype.indexOf=function(r,n,w){n=+n||0;for(var p=this.length;n<p;n++)if(this[n]===r||w&&this[n]==r)return n;return-1};
- (function(){function r(){w&&n()}var n=function(){k.repaintEverything()},w=true,p=null;$(window).bind("resize",function(){p&&clearTimeout(p);p=setTimeout(r,100)});var o={},x=[],y=[],A=1200,z=function(a,e){$.extend(a,e)},D=function(a,e){for(var b=a.attr("id"),c=o[b],f=0;f<c.length;f++)c[f].paint(b,e)},B=function(a,e){for(var b=o[a],c=0;c<b.length;c++){b[c].canvas.style.display=e;if(b[c].drawEndpoints){b[c].sourceEndpointCanvas.style.display=e;b[c].targetEndpointCanvas.style.display=e}}},C=function(a){var e=
- document.createElement("canvas");document.body.appendChild(e);e.style.position="absolute";if(a)e.className=a;if(/MSIE/.test(navigator.userAgent)&&!window.opera){k.sizeCanvas(e,0,0,A,A);e=G_vmlCanvasManager.initElement(e)}return e},v=function(a){if(a!=null)try{document.body.removeChild(a)}catch(e){}},u=function(a){var e=this;this.x=a.x||0;this.y=a.y||0;this.orientation=a.orientation||[0,0];this.offsets=a.offsets||[0,0];this.compute=function(b,c){return[b[0]+e.x*c[0]+e.offsets[0],b[1]+e.y*c[1]+e.offsets[1]]}},
- k=window.jsPlumb={connectorClass:"_jsPlumb_connector",endpointClass:"_jsPlumb_endpoint",DEFAULT_PAINT_STYLE:{lineWidth:10,strokeStyle:"red"},DEFAULT_ENDPOINT_STYLE:{fillStyle:null},DEFAULT_ENDPOINT_STYLES:[null,null],DEFAULT_DRAG_OPTIONS:{},DEFAULT_CONNECTOR:null,DEFAULT_ENDPOINT:null,DEFAULT_ENDPOINTS:[null,null],Anchors:{TopCenter:new u({x:0.5,y:0,orientation:[0,-1]}),BottomCenter:new u({x:0.5,y:1,orientation:[0,1]}),LeftMiddle:new u({x:0,y:0.5,orientation:[-1,0]}),RightMiddle:new u({x:1,y:0.5,
- orientation:[1,0]}),Center:new u({x:0.5,y:0.5,orientation:[0,0]}),TopRight:new u({x:1,y:0,orientation:[0,-1]}),BottomRight:new u({x:1,y:1,orientation:[0,1]}),TopLeft:new u({x:0,y:0,orientation:[0,-1]}),BottomLeft:new u({x:0,y:1,orientation:[0,1]})},Connectors:{Straight:function(){this.compute=function(a,e,b,c,f){b=Math.abs(a[0]-e[0]);c=Math.abs(a[1]-e[1]);var h=0.45*b,d=0.45*c;b*=1.9;c*=1.9;var g=Math.min(a[0],e[0])-h,i=Math.min(a[1],e[1])-d;if(b<2*f){b=2*f;g=a[0]+(e[0]-a[0])/2-f;h=(b-Math.abs(a[0]-
- e[0]))/2}if(c<2*f){c=2*f;i=a[1]+(e[1]-a[1])/2-f;d=(c-Math.abs(a[1]-e[1]))/2}return[g,i,b,c,a[0]<e[0]?b-h:h,a[1]<e[1]?c-d:d,a[0]<e[0]?h:b-h,a[1]<e[1]?d:c-d]};this.paint=function(a,e){e.beginPath();e.moveTo(a[4],a[5]);e.lineTo(a[6],a[7]);e.stroke()}},Bezier:function(a){var e=this;this.majorAnchor=a||150;this.minorAnchor=10;this._findControlPoint=function(b,c,f,h,d){var g=[],i=e.majorAnchor,m=e.minorAnchor;h.orientation[0]==0?g.push(c[0]<f[0]?b[0]+m:b[0]-m):g.push(b[0]-i*h.orientation[0]);h.orientation[1]==
- 0?g.push(c[1]<f[1]?b[1]+m:b[1]-m):g.push(b[1]+i*d.orientation[1]);return g};this.compute=function(b,c,f,h,d){d=d||0;var g=Math.abs(b[0]-c[0])+d,i=Math.abs(b[1]-c[1])+d,m=Math.min(b[0],c[0])-d/2,j=Math.min(b[1],c[1])-d/2,l=b[0]<c[0]?g-d/2:d/2,s=b[1]<c[1]?i-d/2:d/2,q=b[0]<c[0]?d/2:g-d/2;d=b[1]<c[1]?d/2:i-d/2;var t=e._findControlPoint([l,s],b,c,f,h);b=e._findControlPoint([q,d],c,b,h,f);c=Math.min(Math.min(l,q),Math.min(t[0],b[0]));f=Math.max(Math.max(l,q),Math.max(t[0],b[0]));if(f>g)g=f;if(c<0){m+=c;
- c=Math.abs(c);g+=c;t[0]+=c;l+=c;q+=c;b[0]+=c}c=Math.min(Math.min(s,d),Math.min(t[1],b[1]));f=Math.max(Math.max(s,d),Math.max(t[1],b[1]));if(f>i)i=f;if(c<0){j+=c;c=Math.abs(c);i+=c;t[1]+=c;s+=c;d+=c;b[1]+=c}return[m,j,g,i,l,s,q,d,t[0],t[1],b[0],b[1]]};this.paint=function(b,c){c.beginPath();c.moveTo(b[4],b[5]);c.bezierCurveTo(b[8],b[9],b[10],b[11],b[6],b[7]);c.stroke()}}},Endpoints:{Dot:function(a){a=a||{radius:10};var e=this;this.radius=a.radius;var b=0.5*this.radius,c=this.radius/3,f=function(d){try{return parseInt(d)}catch(g){if(d.substring(d.length-
- 1)=="%")return parseInt(d.substring(0,d-1))}},h=function(d){var g=b,i=c;if(d.offset)g=f(d.offset);if(d.innerRadius)i=f(d.innerRadius);return[g,i]};this.paint=function(d,g,i,m,j){var l=m.radius||e.radius;k.sizeCanvas(i,d[0]-l,d[1]-l,l*2,l*2);d=i.getContext("2d");i={};z(i,m);if(i.fillStyle==null)i.fillStyle=j.strokeStyle;z(d,i);j=/MSIE/.test(navigator.userAgent)&&!window.opera;if(m.gradient&&!j){j=h(m.gradient);g=d.createRadialGradient(l,l,l,l+(g[0]==1?j[0]*-1:j[0]),l+(g[1]==1?j[0]*-1:j[0]),j[1]);for(j=
- 0;j<m.gradient.stops.length;j++)g.addColorStop(m.gradient.stops[j][0],m.gradient.stops[j][1]);d.fillStyle=g}d.beginPath();d.arc(l,l,l,0,Math.PI*2,true);d.closePath();d.fill()}},Rectangle:function(a){a=a||{width:20,height:20};var e=this;this.width=a.width;this.height=a.height;this.paint=function(b,c,f,h,d){var g=h.width||e.width,i=h.height||e.height;k.sizeCanvas(f,b[0]-g/2,b[1]-i/2,g,i);b=f.getContext("2d");f={};z(f,h);if(f.fillStyle==null)f.fillStyle=d.strokeStyle;z(b,f);d=/MSIE/.test(navigator.userAgent)&&
- !window.opera;if(h.gradient&&!d){c=b.createLinearGradient(c[0]==1?g:c[0]==0?g/2:0,c[1]==1?i:c[1]==0?i/2:0,c[0]==-1?g:c[0]==0?i/2:0,c[1]==-1?i:c[1]==0?i/2:0);for(d=0;d<h.gradient.stops.length;d++)c.addColorStop(h.gradient.stops[d][0],h.gradient.stops[d][1]);b.fillStyle=c}b.beginPath();b.rect(0,0,g,i);b.closePath();b.fill()}},Image:function(a){var e=this;this.img=new Image;this.img.onload=function(){e.ready=true};this.img.src=a.url;var b=function(c,f,h,d){f=e.img.width||d.width;d=e.img.height||d.height;
- k.sizeCanvas(h,c[0]-f/2,c[1]-d/2,f,d);h.getContext("2d").drawImage(e.img,0,0)};this.paint=function(c,f,h,d,g){e.ready?b(c,f,h,d,g):window.setTimeout(function(){e.paint(c,f,h,d,g)},200)}}},connect:function(a){a=new E(a);o[a.sourceId+"_"+a.targetId]=a;var e=function(b,c){var f=o[b];if(f==null){f=[];o[b]=f}f.push(c)};e(a.sourceId,a);e(a.targetId,a)},detach:function(a,e){for(var b=o[a],c=-1,f=0;f<b.length;f++)if(b[f].sourceId==a&&b[f].targetId==e||b[f].targetId==a&&b[f].sourceId==e){v(b[f].canvas);if(b[f].drawEndpoints){v(b[f].targetEndpointCanvas);
- v(b[f].sourceEndpointCanvas)}c=f;break}c!=-1&&b.splice(c,1)},detachAll:function(a){for(var e=o[a],b=0;b<e.length;b++){v(e[b].canvas);if(e[b].drawEndpoints){v(e[b].targetEndpointCanvas);v(e[b].sourceEndpointCanvas)}}delete o[a];o[a]=[]},detachEverything:function(){for(var a in o){var e=o[a];if(e.length)try{for(var b=0;b<e.length;b++){v(e[b].canvas);if(e[b].drawEndpoints){v(e[b].targetEndpointCanvas);v(e[b].sourceEndpointCanvas)}}}catch(c){}}delete o;o=[]},getConnections:function(a){return o[a]},hide:function(a){B(a,
- "none")},makeAnchor:function(a,e){var b={};if(arguments.length==1)$.extend(b,a);else{b={x:a,y:e};if(arguments.length>=4)b.orientation=[arguments[2],arguments[3]];if(arguments.length==6)b.offsets=[arguments[4],arguments[5]]}return new u(b)},repaint:function(a){var e=function(f,h){for(var d=o[h],g={absolutePosition:f.offset()},i=0;i<d.length;i++)d[i].paint(h,g,true)},b=function(f){f=typeof f=="string"?$("#"+f):f;var h=f.attr("id");e(f,h)};if(typeof a=="object")for(var c=0;c<a.length;c++)b(a[c]);else b(a)},
- repaintEverything:function(){for(var a in o){var e=o[a];if(e.length)try{for(var b=0;b<e.length;b++)e[b].repaint()}catch(c){}}},setAutomaticRepaint:function(a){w=a},setDefaultNewCanvasSize:function(a){A=a},setRepaintFunction:function(a){n=a},show:function(a){B(a,"block")},sizeCanvas:function(a,e,b,c,f){a.style.height=f+"px";a.height=f;a.style.width=c+"px";a.width=c;a.style.left=e+"px";a.style.top=b+"px"},toggle:function(a){var e=o[a];if(e.length>0)B(a,"none"==e[0].canvas.style.display?"block":"none")},
- unload:function(){delete o;delete x;delete y}},E=function(a){var e=this;this.source=typeof a.source=="string"?$("#"+a.source):a.source;this.target=typeof a.target=="string"?$("#"+a.target):a.target;this.sourceId=$(this.source).attr("id");this.targetId=$(this.target).attr("id");this.drawEndpoints=a.drawEndpoints!=null?a.drawEndpoints:true;this.endpointsOnTop=a.endpointsOnTop!=null?a.endpointsOnTop:true;this.anchors=a.anchors||k.DEFAULT_ANCHORS||[k.Anchors.BottomCenter,k.Anchors.TopCenter];this.connector=
- a.connector||k.DEFAULT_CONNECTOR||new k.Connectors.Bezier;this.paintStyle=a.paintStyle||k.DEFAULT_PAINT_STYLE;this.endpoints=[];if(!a.endpoints)a.endpoints=[null,null];this.endpoints[0]=a.endpoints[0]||a.endpoint||k.DEFAULT_ENDPOINTS[0]||k.DEFAULT_ENDPOINT||new k.Endpoints.Dot;this.endpoints[1]=a.endpoints[1]||a.endpoint||k.DEFAULT_ENDPOINTS[1]||k.DEFAULT_ENDPOINT||new k.Endpoints.Dot;this.endpointStyles=[];if(!a.endpointStyles)a.endpointStyles=[null,null];this.endpointStyles[0]=a.endpointStyles[0]||
- a.endpointStyle||k.DEFAULT_ENDPOINT_STYLES[0]||k.DEFAULT_ENDPOINT_STYLE;this.endpointStyles[1]=a.endpointStyles[1]||a.endpointStyle||k.DEFAULT_ENDPOINT_STYLES[1]||k.DEFAULT_ENDPOINT_STYLE;x[this.sourceId]=this.source.offset();y[this.sourceId]=[this.source.outerWidth(),this.source.outerHeight()];x[this.targetId]=this.target.offset();y[this.targetId]=[this.target.outerWidth(),this.target.outerHeight()];var b=C(k.connectorClass);this.canvas=b;if(this.drawEndpoints){this.sourceEndpointCanvas=C(k.endpointClass);
- this.targetEndpointCanvas=C(k.endpointClass);if(this.endpointsOnTop){$(this.sourceEndpointCanvas).css("zIndex",this.source.css("zIndex")+1);$(this.targetEndpointCanvas).css("zIndex",this.target.css("zIndex")+1)}else{$(this.sourceEndpointCanvas).css("zIndex",this.source.css("zIndex")-1);$(this.targetEndpointCanvas).css("zIndex",this.target.css("zIndex")-1)}}this.paint=function(h,d,g){var i=h!=this.sourceId,m=i?this.sourceId:this.targetId,j=i?0:1,l=i?1:0;if(this.canvas.getContext){if(g){d=$("#"+h);
- g=$("#"+m);y[h]=[d.outerWidth(),d.outerHeight()];y[m]=[g.outerWidth(),g.outerHeight()];x[h]=d.offset();x[m]=g.offset()}else{g=d.absolutePosition||d.offset;d=d!=null?g:$("#"+h).offset();x[h]=d}g=x[h];var s=x[m],q=y[h],t=y[m];d=b.getContext("2d");m=this.anchors[l].compute([g.left,g.top],q,[s.left,s.top],t);h=this.anchors[l].orientation;g=this.anchors[j].compute([s.left,s.top],t,[g.left,g.top],q);s=this.anchors[j].orientation;j=this.connector.compute(m,g,this.anchors[l],this.anchors[j],this.paintStyle.lineWidth);
- k.sizeCanvas(b,j[0],j[1],j[2],j[3]);z(d,this.paintStyle);l=/MSIE/.test(navigator.userAgent)&&!window.opera;if(this.paintStyle.gradient&&!l){l=i?d.createLinearGradient(j[4],j[5],j[6],j[7]):d.createLinearGradient(j[6],j[7],j[4],j[5]);for(q=0;q<this.paintStyle.gradient.stops.length;q++)l.addColorStop(this.paintStyle.gradient.stops[q][0],this.paintStyle.gradient.stops[q][1]);d.strokeStyle=l}this.connector.paint(j,d);if(this.drawEndpoints){j=i?this.sourceEndpointCanvas:this.targetEndpointCanvas;this.endpoints[i?
- 1:0].paint(m,h,i?this.targetEndpointCanvas:this.sourceEndpointCanvas,this.endpointStyles[i?1:0]||this.paintStyle,this.paintStyle);this.endpoints[i?0:1].paint(g,s,j,this.endpointStyles[i?0:1]||this.paintStyle,this.paintStyle)}}};this.repaint=function(){this.paint(this.sourceId,null,true)};if(a.draggable==null?true:a.draggable){var c=a.dragOptions||k.DEFAULT_DRAG_OPTIONS,f=c.drag||function(){};a=function(h,d){var g={};for(var i in c)g[i]=c[i];g.drag=d;h.draggable(g)};a(this.source,function(h,d){D(e.source,
- d);f(h,d)});a(this.target,function(h,d){D(e.target,d);f(h,d)})}this.source.resize&&this.source.resize(function(){k.repaint(e.sourceId)});this.source.offset();this.paint(this.sourceId,{absolutePosition:this.source.offset()})}})();
- (function(r){r.fn.plumb=function(n){n=r.extend({},n);return this.each(function(){var w=r(this),p={};p.source=w;for(var o in n)p[o]=n[o];jsPlumb.connect(p)})};r.fn.detach=function(n){return this.each(function(){var w=r(this).attr("id");if(typeof n=="string")n=[n];for(var p=0;p<n.length;p++)jsPlumb.detach(w,n[p])})};r.fn.detachAll=function(){return this.each(function(){var n=r(this).attr("id");jsPlumb.detachAll(n)})}})(jQuery);
|