It can be used with either jQuery or MooTools (or another library of your choice if you feel like implementing a plugin for it). Required versions are as follows:
For Canvas support in IE you also need to include Google's ExplorerCanvas script.
jsPlumb 1.2.1 has been tested on the following browsers:
Several new concepts have been introduced since version 1.2, and a few convenience methods have been added. The major changes are:
This other stuff has been done too:
<script type="text/javascript" src="http://explorercanvas.googlecode.com/svn/trunk/excanvas.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script> <script type="text/javascript" src="PATH_TO/jquery.jsPlumb-1.2.1-all-min.js "></script>
<script type="text/javascript" src="http://explorercanvas.googlecode.com/svn/trunk/excanvas.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js"></script> <script type="text/javascript" src="PATH_TO_MOO_TOOLS_MORE_1_2_4_4"></script> <script type="text/javascript" src="PATH_TO/mootools.jsPlumb-1.2.1-all-min.js "></script>
jsPlumb.connect({source:'element1', target:'element2'});
$("#element1").plumb({target:'element2'});
var endpointOptions = { isSource:true, isTarget:true };
var endpoint = jsPlumb.addEndpoint('elementId', endpointOptions);
var exampleGreyEndpointOptions = {
endpoint:new jsPlumb.Endpoints.Rectangle(),
style:{ width:25, height:21, fillStyle:'#666' },
isSource:true,
connectorStyle : { strokeStyle:"#666" },
isTarget:true
};
jsPlumb.addEndpoint('element1', jsPlumb.extend({anchor:jsPlumb.Anchors.BottomCenter}, exampleGreyEndpointOptions));
jsPlumb.addEndpoint('element2', jsPlumb.extend({anchor:jsPlumb.Anchors.TopCenter}, exampleGreyEndpointOptions));
At the time of writing, jsPlumb supports jQuery and MooTools, and each of those libraries uses different terminology. In addition, jQuery's API is more fully featured, providing easy support for setting the zIndex and opacity of elements being dragged, as well as the 'scope' for a drag/drop (allowing you to specify more than one type of drag/drop pair), and hover classes for when a draggable is on the move or over a droppable. If you're using jQuery you can of course just supply these values on the dragOptions; to make it easier, jsPlumb's MooTools adapter recognizes these options and adds appropriate callbacks for you.
Given that the options here are library-specific, and both jQuery and MooTools are well-documented, we're going to discuss just the three drag options that behave the same way in both (see below for hoverClass):
For more information about drag options, take a look at the jQuery or MooTools docs.
There are two jQuery droppable options that jsPlumb treats as shortcuts in MooTools:
For more information about drop options when using jQuery, see here.
var exampleGreyEndpointOptions = {
endpoint:new jsPlumb.Endpoints.Rectangle(),
style:{ width:25, height:21, fillStyle:'#666' },
isSource:true,
connectionStyle : { strokeStyle:"#666" },
isTarget:true,
scope:'exampleGreyConnection'
};
jsPlumb.getDefaultScope();
jsPlumb.setDefaultScope("mySpecialDefaultScope");
var exampleGreyEndpointOptions = {
endpoint:new jsPlumb.Endpoints.Rectangle(),
style:{ width:25, height:21, fillStyle:'#666' },
isSource:true,
connectionStyle : { strokeStyle:"#666" },
isTarget:true,
dragOptions:{scope:'dragScope'},
dropOptions:{scope:'dropScope'}
};
var firstInstance = jsPlumb.getInstance();
firstInstance.Defaults.Connector = new jsPlumb.Connectors.Bezier(150);
firstInstance.Defaults.Container = "container1";
firstInstance.Defaults.Anchors = [jsPlumb.Anchors.TopCenter, jsPlumb.Anchors.BottomCenter];
firstInstance.connect({source:'element1', target:'element2', scope:'someScope'});
var secondInstance = jsPlumb.getInstance({
PaintStyle:{lineWidth:3, strokeStyle:color3},
Connector:new jsPlumb.Connectors.Bezier(30),
Endpoint:new jsPlumb.Endpoints.Dot({radius:5}),
EndpointStyle : { fillStyle: color3 },
Anchor : jsPlumb.makeAnchor(0.5,0.5,1,1),
Container:"container2"
});
secondInstance.connect({source:'element4', target:'element3', scope:'someScope'});
jsPlumb.setAutomaticRepaint(false);
var repaint = function() {
// do some things, perhaps, and then...
jsPlumb.repaintEverything();
};
jsPlumb.setRepaintFunction(repaint);
Another example"
var repaint = function() {
// completely start over
jsPlumb.detachEverything();
// paint all your connections
};
jsPlumb.setRepaintFunction(repaint);
<body onunload="jsPlumb.unload();"> ... </body>
These are the options you can specify on a call to the connect/plumb method:
This is a required argument only when using 'connect' (when using 'plumb' the source element is the one on which the plumb method was called). It identifies the source element for the plumb.
This is a required argument. It identifies the target element for the plumb.
Optional; if not supplied jsPlumb uses the values defined in jsPlumb.Defaults.PaintStyle (see Defaults). This object allows you to specify five attributes of the connector (note that all of these except 'gradient' are just passed through to the Canvas element's paint context):
The arguments to the strokeStyle parameter can be anything that is a valid argument for the strokeStyle parameter of HTML Canvas element, which are CSS colors, patterns or gradients.
This is the working group's page for the Canvas element, where you can find information on painting in Canvas.
Mozilla also has some good documentation here.
Optional; if not supplied jsPlumb uses a Bezier connector (see Defaults)
Valid values for this are:
You can also supply your own Connector implementation; for details on how to write a Connector see the Connectors section below.
Optional; if not supplied jsPlumb uses [ jsPlumb.Anchors.BottomCenter, jsPlumb.Anchors.TopCenter ] (see defaults)
If you supply this, it must be in the form of a list with two elements - the first element is the anchor type for the source element (the one on which you are calling the 'plumb' method), and the second is the anchor type for the target element.
Valid values for this are any Anchor you have created yourself (see the anchors section below), or one of these default anchors provided by jsPlumb:
The locations of these are hopefully self-explanatory. You can supply your own Anchor implementations, or use jsPlumb's 'makeAnchor' function to create an Anchor in a custom location, if you need to - see the section on Anchors.
Optional; if not supplied jsPlumb uses jsPlumb.Endpoints.Dot, with the default size of 10 (see Defaults).
Valid values for this are:
Similar to Connectors and Anchors, you can provide your own Endpoint implementation; see the Endpoints section.
Optional; this is similar to endpoint but should be used when you want to specify a different Endpoint for each end of the Connector.
This should be supplied as a list, for example:
endpoints:[ ..endpoint1.. , ..endpoint2.. ]
Optional; if not supplied jsPlumb uses the values defined in jsPlumb.Defaults.EndpointStyle (see defaults).
This Javascript object allows you to specify the following arguments for the Endpoint:
Optional; this is similar to endpointStyle but should be used when you want to specify a different style for each of the two Endpoints.
This should be supplied as a list, for example:
endpointStyles:[ { ..style1.. }, { ..style2.. } ]
This is a boolean value that defaults to true.
You can provide your own set of dragOptions to pass through to the underlying library's drag API if you need to. jsPlumb will wrap any event methods you provide, since it needs to be aware of drag activity, but everything else is passed through as you specify it. You can do this either on each call you make:
jsPlumb.connect({source:'someWindow', target:"otherWindow", dragOptions:{cursor: 'crosshair'}});
jsPlumb.Defaults.DragOptions = { .. your drag options here. };
PaintStyle : { lineWidth : 10, strokeStyle : "red" }
DragOptions : { }
EndpointStyle : { fillStyle : null; }
EndpointStyles : [ null, null ]
Anchors : [ jsPlumb.Anchors.BottomCenter, jsPlumb.Anchors.TopCenter ]
Connector : jsPlumb.Connectors.Bezier;
Endpoint : jsPlumb.Endpoints.Dot;
Endpoints : [jsPlumb.Endpoints.Dot, jsPlumb.Endpoints.Dot];
Note that in EndpointStyle, the default fillStyle is 'null'. This instructs jsPlumb to use the strokeStyle from the attached connector to fill the endpoint.
Note also that you can specify either or both (or neither) of 'EndpointStyle' and 'EndpointStyles'. This allows you to specify a different end point for each end of a connection. 'Endpoint' and 'Endpoints' use the same concept. jsPlumb will look first in the individual endpoint/endpoint style arrays, and then fall back to the single default version.
you can override these defaults by including this in a script somewhere:
jsPlumb.Defaults.PaintStyle = {
lineWidth:13,
strokeStyle: 'rgba(200,0,0,100)'
}
jsPlumb.Defaults.DragOptions = { cursor: 'crosshair' };
jsPlumb.Default.Endpoints = [ new jsPlumb.Endpoints.Dot(7), new jsPlumb.Endpoints.Dot(11) ]
jsPlumb.Defaults.EndpointStyles = [{ fillStyle:'#225588' }, { fillStyle:'#558822' }];
An Anchor models the notion of where on an element a plumb line should connect. jsPlumb has nine default anchor locations you can use to specify where the plumb lines connect to elements: these are the four corners of an element, the center of the element, and the midpoint of each edge of the element.
You can provide your own anchor locations if you need to. jsPlumb supports two ways of doing this:
This function creates a basic Anchor of the type that jsPlumb uses internally, which is a statically located anchor whose position is specified by providing a fractional distance for both x and y. For instance, the TopCenter anchor in jsPlumb is situated at [0, 0.5].
A call to jsPlumb.makeAnchor should look something like this:var myAnchor = jsPlumb.makeAnchor( 0.333, 0.5, 0, 1 );
Here we have specified an anchor that will be located at a point which is one-third of the width of the element, and half its height. The orientation array indicates that the natural flow of connectors from this element is unspecified for the x direction, but straight down the page in the y direction.
The arguments are:For most cases, the jsPlumb.makeAnchor function will probably suffice. But the method signature of the compute function of an anchor takes the location of both elements, meaning it is possible to write an anchor whose position takes into account where the current element is in relation to the one it is plumbed to. jsPlumb does not natively do this but it seems like something that might be useful.
An anchors function consists of two parts - a function that computes the location of the anchor, given the current xy and width/height of the source element and target element, plus an 'orientation' array, which gives jsPlumb hints about which way plumb lines should flow into and out of the anchor point. Not every Connector implementation will use this orientation array - the Straight Connector, for instance, ignores it completely, because it just directly connects the two anchor points.
To provide your own anchor location you can either set it in amongst the defaults:
jsPlumb.Anchors.MyAnchor = {
compute : function(xy, wh, txy, twh) { // do some maths and return an [x,y] location }
orientation : [ox, oy] // each value can be one of -1, 0 or 1. 0 means dont care,
// 1 or -1 means go in this direction in this plane.
};
var myAnchor = {
compute : function(xy, wh, txy, twh) { // do some maths and return an [x,y] location }
orientation : [ox, oy] // each value can be one of -1, 0 or 1. 0 means dont care,
// 1 or -1 means go in this direction in this plane.
};
$("someWindow").plumb({target:'otherWindow', anchors:[myAnchor, myAnchor]});
The compute function should return an array of two elements - the [x,y] on screen where the anchor is located.
Examples of the orientation array can be found in the Javascript source. It is simply a hint to jsPlumb of what direction a plumb line leaving the given anchor should _initially_ head in. So, for example, the TopCenter anchor point defines its orientation as [0,-1], meaning "i don't care about x, but i want you to head towards the top of the screen as you leave this point". Take another example - BottomRight. This is the bottom right corner of an element. It declares its orientation to be [1,1], meaning go down and to the right as you leave this element.
jsPlumb attaches the CSS class _jsPlumb_connector to Connectors that it generates.
The Bezier Connector provides a Bezier path between the two endpoints. You construct one like this:
var myConnector = new jsPlumb.Connectors.Bezier(curviness);
curviness, which is optional (and defaults to 150), defines the distance in pixels that
the Bezier's control points are situated from the anchor points. This does not mean that your
connector will pass through a point at this distance from your curve. It is a hint to how you want the
curve to travel. Rather than discuss Bezier curves at length here, because they are a very complex topic,
we refer you to Wikipedia.
The Straight Connector draws a straight line between the two endpoints. You construct one like this:
var myConnector = new jsPlumb.Connectors.Straight();
this.compute = function(sourcePos, targetPos, sourceAnchor, targetAnchor, lineWidth) {
...
return dimensions;
}
The next four elements must be the coordinates of the two endpoints of the line you are going to draw.
The remainder of the items in the returned list are arbitrary, and will vary between Connector implementations; this list is passed in to a Connector's paint function, so each implementation will put into the list whatever it needs to paint itself. For instance, the straight line connector only needs the [x,y] location of each end of the line it will paint, and that is one of the required entries, so it does not have to do anything extra, whereas the Bezier connector adds the location of the two control points. Other types of Connectors will do whatever is appropriate for their particular situation.
This is the method signature for the paint function:this.paint = function(dimensions, ctx) { .. }
jsPlumb.connect({source:'someWindow', target:'otherWindow', connector:new jsPlumb.Connectors.Straight()});
An Endpoint is the UI component that marks the location of an Anchor, ie. the place where a Connector joins an element. jsPlumb comes with three Endpoint implementations - Dot, Rectangle and Image.
This draws a dot. Example constructor:
var myDot = new jsPlumb.Endpoints.Dot({radius:34});
In the endpointStyle option of a plumb call, you can set two values that this will pick up:
Draws a rectangle. Example constructor:
var myRect = new jsPlumb.Endpoints.Rectangle({width:34, height:10});
In the endpointStyle you can set the following for this:
Draws an image from a given URL. Example constructor:
var myImage = new jsPlumb.Endpoints.Image({url:"http://myserver.com/images/endpoint.png"});
To create your own Endpoint implementation, you need to implement a single method:
paint : function(anchorPoint, orientation, canvas, endpointStyle, connectorPaintStyle) { ... }It is your responsibility to size and locate the canvas to suit your needs. jsPlumb provides the following helper method to assist you:
jsPlumb.sizeCanvas(canvas, x, y, width, height);
There are two types of gradients available in Canvas - a 'linear' gradient, which consists of colored lines all going in one direction, and a 'radial' gradient, which consists of colored circles emanating from one circle to another. Because of their basic shape, jsPlumb supports only linear gradients for Connectors. But for Endpoints, jsPlumb supports both linear and radial gradients.
jsPlumb.connect({
source : 'window2',
target : 'window3',
paintStyle:{
gradient:{
stops:[[0,'green'], [1,'red']]
},
lineWidth:15
}
});
Notice the gradient object and the stops list inside it - the gradient consists of an arbitrary number of these "color stops". Each color stop is comprised of two values - [position, color]. Position must be a decimal value between 0 and 1 (inclusive), and indicates where the color stop is situated as a fraction of the length of the entire gradient. Valid values for the colors in the stops list are the same as those that are valid for strokeStyle when describing a color.
As mentioned, the stops list can hold an arbitrary number of entries. Here's an example of a gradient that goes from red to blue to green, and back again through blue to red:
jsPlumb.connect({
source : 'window2',
target : 'window3',
paintStyle : {
gradient:{
stops:[[0,'red'], [0.33,'blue'], [0.66,'green'], [0.33,'blue'], [1,'red']]
},
lineWidth : 15
}
});
jsPlumb.connect({
source : 'window2',
target : 'window3',
paintStyle:{
strokeStyle:'red',
gradient:{
stops:[[0,'red'], [0.33,'blue'], [0.66,'green'], [0.33,'blue'], [1,'red']]
},
lineWidth:15
}
});
This is an example of an Endpoint gradient that is different for each Endpoint in the Connector. This comes from the main demo; it is the Connector joining Window 2 to Window 3:
var w23Stroke = 'rgb(189,11,11)';
jsPlumb.connect({
source : 'window2',
target : 'window3',
paintStyle:{
lineWidth:8,
strokeStyle:w23Stroke
},
anchors:[ jsPlumb.makeAnchor(0.3,1,0,1), jsPlumb.Anchors.TopCenter ],
endpoint:new jsPlumb.Endpoints.Rectangle(),
endpointStyles:[
{ gradient : {stops:[[0, w23Stroke], [1, '#558822']] } },
{ gradient : {stops:[[0, w23Stroke], [1, '#882255']] } }
]
});
The type of gradient you will see depends on the Endpoint type:
Radial gradients actually require more data than linear gradients - in a linear gradient we just move from one point to another, whereas in a radial gradient we move from one circle to another. By default, jsPlumb will render a radial gradient using a source circle of the same radius as the Endpoint itself, and a target circle of 1/3 of the radius of the Endpoint (both circles share the same center as the Endpoint itself). This circle will be offset by radius/2 in each direction.
You can supply your own values for these inside the gradient descriptor:
var w34Stroke = 'rgba(50, 50, 200, 1)';
var w34HlStroke = 'rgba(180, 180, 200, 1)';
jsPlumb.connect({
source : 'window3',
target : 'window4',
paintStyle:{
lineWidth:10,
strokeStyle:w34Stroke
},
anchors:[ jsPlumb.Anchors.RightMiddle, jsPlumb.Anchors.LeftMiddle ],
endpointStyle:{
gradient : {
stops:[ [0, w34Stroke], [1, w34HlStroke] ],
offset:37.5,
innerRadius:40
},
radius:55
}
});
It is also possible to specify the offset and inner radius as percentages - enter the values as strings with a '%' symbol on the end:
var w34Stroke = 'rgba(50, 50, 200, 1)';
var w34HlStroke = 'rgba(180, 180, 200, 1)';
jsPlumb.connect({
source : 'window3',
target : 'window4',
paintStyle:{
lineWidth:10,
strokeStyle:w34Stroke
},
anchors:[ jsPlumb.Anchors.RightMiddle, jsPlumb.Anchors.LeftMiddle ],
endpointStyle:{
gradient : {
stops:[ [0, w34Stroke], [1, w34HlStroke] ],
offset:'68%',
innerRadius:'73%'
},
radius:25
}
});
The method signature is:
jsPlumb.animate : function(el, properties, options)
| component | css class |
|---|---|
| connector | _jsPlumb_connector |
| endpoint | _jsPlumb_endpoint |
The basic syntax of a call is that you execute 'connect', providing a source and a target, and optionally a paintStyle and preferences for where you want the plumbing to be anchored on each element, as well as the type of connector to use. Note that in all of the following examples, if you are using jQuery, you can substitute jsPlumb.connect with $('#someElement').plumb, where 'someElement' is the id of the element you would pass as 'source' to the connect call.
jsPlumb.connect({source:'window1', target:'window2'});
jsPlumb.connect({
source:'window1',
target:'window2',
paintStyle:{lineWidth:15,strokeStyle:'rgb(243,230,18)'},
endpointStyle:{fillStyle:'rgb(243,229,0)'}
});
jsPlumb.connect({
source:'window1',
target:'window2',
paintStyle:{lineWidth:15,strokeStyle:'rgb(243,230,18)'},
endpointStyle:{fillStyle:'rgb(243,229,0)'},
scope:'connectorType1'
});
jsPlumb.connect({
source:'window3',
target:'window4',
paintStyle:{lineWidth:10, strokeStyle:'rgba(0, 0, 200, 0.5)'},
anchors:[jsPlumb.Anchors.RightMiddle, jsPlumb.Anchors.LeftMiddle],
endpointStyle:{radius:25}
});
jsPlumb.connect({
source:'window2',
target:'window3',
paintStyle:{lineWidth:8, strokeStyle:'rgb(189,11,11)'},
anchors:[jsPlumb.Anchors.BottomCenter, jsPlumb.Anchors.TopCenter],
endpoint:new jsPlumb.Endpoints.Rectangle()
});
jsPlumb.connect({
source:'window1',
target:'window2',
anchors:[jsPlumb.Anchors.BottomCenter, jsPlumb.makeAnchor(0.75,0,0,-1)],
paintStyle:{lineWidth:15,strokeStyle:'rgb(243,230,18)'},
endpointStyle:{fillStyle:'rgb(243,229,0)'}
});
var w34Stroke = 'rgba(50, 50, 200, 1)';
var w34HlStroke = 'rgba(180, 180, 200, 1)';
jsPlumb.connect( {
source:'window3',
target:'window4',
paintStyle:{lineWidth:10, strokeStyle:w34Stroke},
anchors:[jsPlumb.Anchors.RightMiddle, jsPlumb.Anchors.LeftMiddle],
endpointStyle:{ gradient : {stops:[[0, w34Stroke], [1, w34HlStroke]], offset:17.5, innerRadius:15 }, radius:35},
//endpointStyle:{ gradient : {stops:[[0, w34Stroke], [1, w34HlStroke]], offset:'78%', innerRadius:'73%'}, radius:35 },
endpointsOnTop:false
}
);
var w23Stroke = 'rgb(189,11,11)';
jsPlumb.connect({
source:'window2',
target:'window3',
paintStyle:{lineWidth:8,strokeStyle:w23Stroke},
anchors:[jsPlumb.makeAnchor(0.3,1,0,1), jsPlumb.Anchors.TopCenter],
endpoint:new jsPlumb.Endpoints.Rectangle(),
endpointStyles:[{ gradient : {stops:[[0, w23Stroke], [1, '#558822']] }},
{ gradient : {stops:[[0, w23Stroke], [1, '#882255']] }}]
});
jsPlumb.connect({
source:'window5',
target:'window6',
anchors:[jsPlumb.Anchors.Center, jsPlumb.Anchors.Center],
paintStyle:{lineWidth:5,strokeStyle:'rgba(0,255,0,0.5)'},
endpointStyle:{radius:125}
});
jsPlumb.connect({
source:'window4',
target:'window5',
anchors:[jsPlumb.Anchors.BottomRight,jsPlumb.Anchors.TopLeft],
paintStyle:{lineWidth:7,strokeStyle:'rgb(131,8,135)'},
endpoint:new jsPlumb.Endpoints.Image({url:"http://morrisonpitt.com/jsPlumb/img/endpointTest1.png"}),
connector:new jsPlumb.Connectors.Straight()
});
jsPlumb.connect({
source:'window5',
target:'window6',
anchors:[jsPlumb.Anchors.Center, jsPlumb.Anchors.Center],
paintStyle:{lineWidth:5,strokeStyle:'rgba(0,255,0,0.5)'},
endpointStyle:{radius:125}
});
jsPlumb.connect({
source:'window7',
target:'window8',
paintStyle:{lineWidth:10, strokeStyle:'blue'},
anchors:[jsPlumb.Anchors.TopLeft, jsPlumb.Anchors.BottomRight]
});
jsPlumb.connect({
source:'window4',
target:'window5',
anchors:[jsPlumb.Anchors.BottomRight,jsPlumb.Anchors.TopLeft],
paintStyle:{lineWidth:7,strokeStyle:'rgb(131,8,135)'},
endpointStyle:{width:40, height:40},
endpoint:new jsPlumb.Endpoints.Rectangle(),
connector:new jsPlumb.Connectors.Straight()
});
jsPlumb.connect({source:'window1', target:'window2', dragOptions:{cursor:'crosshair'}});
jsPlumb.detachAll("window5");
jsPlumb.hide("window5");
jsPlumb.show("window5");
jsPlumb.toggle("window5");
jsPlumb.repaint("window5");
jsPlumb.repaint( [ "window5", "window6", "window11" ] );
jsPlumb.repaintEverything();
jsPlumb.detachEverything();
jsPlumb.removeEndpoint("window1", someEndpoint);
jsPlumb.removeAllEndpoints("window1");
jsPlumb.removeEveryEndpoint();
jsPlumb.clearCache();
jsPlumb.reset();
jsPlumb.setDraggable("window1", false);
jsPlumb.setDraggable(["window1","window2"], false);
jsPlumb.setDraggableByDefault(false);
jsPlumb.draggable("window1");
jsPlumb.draggable(["window1","window2"]);
jsPlumb.draggable("window1");
jsPlumb.draggable($(".window"));
jsPlumb.draggable($$(".window"));
jsPlumb.draggable($("#window1"));
jsPlumb.draggable($("window1"));
The basic procedure is:
var endpointOptions = { isSource:true, isTarget:true };
var window3Endpoint = jsPlumb.addEndpoint('window3', jsPlumb.extend({anchor:jsPlumb.Anchors.TopCenter}, endpointOptions}));
var window4Endpoint = jsPlumb.addEndpoint('window4', jsPlumb.extend({anchor:jsPlumb.Anchors.BottomCenter}, endpointOptions}));
jsPlumb.connect({
sourceEndpoint:window3Endpoint,
targetEndpoint:window4Endpoint,
connector: new jsPlumb.Connectors.Bezier(175),
paintStyle:{lineWidth:25, strokeStyle:'yellow' }
});
var endpointOptions = {
isSource:true,
isTarget:true,
connector : new jsPlumb.Connectors.StraightLine(),
connectorStyle: { lineWidth:20, strokeStyle:'blue' },
dragOptions:{ scope:'blueline' },
dropOptions:{ scope:'blueline' }
};
var endpointOptions = {
isSource:true,
isTarget:true,
endpoint: new jsPlumb.Endpoints.Dot({radius:30}),
style:{fillStyle:'blue'},
connector : new jsPlumb.Connectors.StraightLine(),
connectorStyle: { lineWidth:20, strokeStyle:'blue' },
dragOptions:{ scope:'blueline' },
dropOptions:{ scope:'blueline', drop:function(e, ui) { alert('drop!'); } }
};
var endpointOptions = {
isSource:true,
isTarget:true,
endpoint: new jsPlumb.Endpoints.Dot({radius:30}),
style:{fillStyle:'blue'},
maxConnections:5,
connector : new jsPlumb.Connectors.StraightLine(),
connectorStyle: { lineWidth:20, strokeStyle:'blue' },
dragOptions:{ scope:'blueline' },
dropOptions:{ scope:'blueline', onDrop:function(e, ui) { alert('drop!'); } }
};
var endpointOptions = {
isSource:true,
isTarget:true,
endpoint: new jsPlumb.Endpoints.Dot({radius:30}),
style:{fillStyle:'blue'},
maxConnections:-1,
connector : new jsPlumb.Connectors.StraightLine(),
connectorStyle: { lineWidth:20, strokeStyle:'blue' },
dragOptions:{ scope:'blueline' },
dropOptions:{ scope:'blueline', onDrop:function(e, ui) { alert('drop!'); } }
};
Before you use this method you should understand jsPlumb's notion of 'scope' - documentation is here
getConnections optionally takes an object specifying filter parameters, of which there are three:
The return value of a call to getConnection is a dictionary whose keys are scope names, and whose values are lists of sourceId/targetId pairs, for example:
{
"_jsPlumb_DefaultScope" : [
{sourceId:"window1", targetId:"window2"},
{sourceId:"window5", targetId:"window3"}
],
"someCustomScope": [
{sourceId:"window6", targetId:"window2"},
{sourceId:"window4", targetId:"window13"},
{sourceId:"window2", targetId:"window10"}
]
}
var c = jsPlumb.getConnections();
var c = jsPlumb.getConnections(jsPlumb.getDefaultScope());
var c = jsPlumb.getConnections({scope:"myTestScope"});
var c = jsPlumb.getConnections({scope:["myTestScope", "yourTestScope"]});
var c = jsPlumb.getConnections({source:"mySourceElement"});
var c = jsPlumb.getConnections({source:["mySourceElement", "yourSourceElement"]});
var c = jsPlumb.getConnections({target:"myTargetElement"});
var c = jsPlumb.getConnections({source:"mySourceElement", target:["target1", "target2"]});
var c = jsPlumb.getConnections({scope:'myScope", source:"mySourceElement", target:"myTargetElement"});
var c = jsPlumb.getConnections({scope:"myScope", source:"mySourceElement"});
var conns = c["myScope"];
This is the main jsPlumb engine. It calls out to the underlying library implementation, and it has no Anchors, Endpoints or Connections specified.
This contains the default Anchor, Endpoints and Connections implementations
This contains library-specific helper methods. jsPlumb ships with two of these - one for jQuery and one for MooTools. See below for information on how to create a new library implementation.
Contains jsPlumb-1.2.1.js, jsPlumb-defaults-1.2.1.js and jquery.jsPlumb-1.2.1.js
A minified version of the script above (minified using Google's Closure minifier)
To develop one of these, your test page should include the first two scripts discussed above, and then your own script containing your library specific functionality. The two existing implementations should be documented well enough for you to create your own. If you do this, it would be great to share it with everyone...