Hareeshchandera / jsplumb

Automatically exported from code.google.com/p/jsplumb
0 stars 0 forks source link

Expose Connection so that it can be extended such as Connector, EndPoint etc.. #65

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
the way to do this would be to support the user supplying their own Connection 
class. jsPlumb creates a new Connection in two places in the code - lines 737 
and 2442. changing this at line 737, for example:

var jpc = new Connection(_p);

into

var jpc = _newConnection(_p);

and having this private method up with all the others at the top:

var _newConnection = function(params) {
  var func = _currentInstance.Defaults.ConnectionClass || Connection;
  return new func(_p);
};

Original issue reported on code.google.com by mastudeb...@gmail.com on 27 Mar 2011 at 3:03

GoogleCodeExporter commented 8 years ago
should probably add support for users doing this with Endpoint aswell.

Original comment by simon.po...@gmail.com on 27 Mar 2011 at 10:54

GoogleCodeExporter commented 8 years ago
support for your own Connection class is checked in now.  you would do 
something like this:

var MyConnection = function(params) {
  jsPlumb.getDefaultConnectionType().apply(this, arguments);

  ... your stuff ...
};

then tell jsPlumb about it:

jsPlumb.Defaults.ConnectionType = MyConnection;

let me know if you have any trouble. this may need some tweaking.  i will do 
Endpoint later on today.

Original comment by simon.po...@gmail.com on 28 Mar 2011 at 10:46

GoogleCodeExporter commented 8 years ago
I'm not sure if it's something I'm doing wrong but when I click on an endpoint 
to create a new connection, it errors out.  I'm able to grab the endPoint and 
move it around the screen - but there is no connection attached.  I'm not sure 
if it's something I'm doing wrong???  Can you point me in the right direction :)

Thanks

// The code I put inline in our js file - yes, I copied what you have above  :)

    var MyConnection = function(params) {
        jsPlumb.getDefaultConnectionType().apply(this, arguments);
        var selected = 'testing';

    };

    jsPlumb.Defaults.ConnectionType = MyConnection;

  // This is the error I receive when I try and click on an endPoint  
   jsplumb-1.2.6-RC1-all.js:263jsPlumb function failed : TypeError: Object [object Object] has no method 'getDefaultConnectionType'

  // This is output from the debug console.  It looks like MyConnection has been created 
   MyConnection
function (params) {
            jsPlumb.getDefaultConnectionType().apply(this, arguments);
            var selected = 'testing';

        }
// and it looks like it was added to jsPlumb        
jsPlumb.Defaults.ConnectionType
function (params) {
            jsPlumb.getDefaultConnectionType().apply(this, arguments);
            var selected = 'testing';

        }
 // but I guess maybe not?       
jsPlumb.Defaults.ConnectionType()
TypeError: Object [object Object] has no method 'getDefaultConnectionType'

Original comment by mastudeb...@gmail.com on 29 Mar 2011 at 2:15

GoogleCodeExporter commented 8 years ago
the script you're using is this:

  jsplumb-1.2.6-RC1-all.js

where did you get that from? did you build it?

Original comment by simon.po...@gmail.com on 29 Mar 2011 at 2:29

GoogleCodeExporter commented 8 years ago
Actually that is the new jsplumb files concant together. I'll double check it's 
correct.  Maybe I should just load the files seperatly and give that a try.

Original comment by mastudeb...@gmail.com on 29 Mar 2011 at 3:05

GoogleCodeExporter commented 8 years ago
oh balls, i think i added that method to the wrong object.  one sec.

Original comment by simon.po...@gmail.com on 29 Mar 2011 at 3:18

GoogleCodeExporter commented 8 years ago
ahem.  maybe try this again.  i did add it to the wrong object.

Original comment by simon.po...@gmail.com on 29 Mar 2011 at 3:21

GoogleCodeExporter commented 8 years ago
Hey Simon

MyConnection is working now!  Thank you.

Were you going to do the same thing with the endPoint or somehow expose 
connectorSelector?

Original comment by mastudeb...@gmail.com on 30 Mar 2011 at 1:34

GoogleCodeExporter commented 8 years ago
cool.  tonight i will do the same thing for Endpoint, yep, and arrange it so 
that you'll be able to override the connectorSelector.

Original comment by simon.po...@gmail.com on 30 Mar 2011 at 2:05

GoogleCodeExporter commented 8 years ago
Endpoint is done now too, and the 'connectorSelector' function is exposed on 
Endpoint so subclasses can access it.  i used this for a test in 
draggableConnectorsDemo.html:

var MyEndpoint = function(params) {

  jsPlumb.getDefaultEndpointType().apply(this, arguments);

  console.log("MY ENDPOINT");

  var cs = this.connectorSelector;
  this.connectorSelector = function() {
    console.log("MY CONNECTOR SELECTOR");
    return cs();
  };
};

jsPlumb.Defaults.EndpointType = MyEndpoint;

marking fixed.

Original comment by simon.po...@gmail.com on 30 Mar 2011 at 7:03

GoogleCodeExporter commented 8 years ago

Original comment by simon.po...@gmail.com on 2 Jun 2011 at 4:26