calling functions after connecting or disconnecting a cap.

70 views
Skip to first unread message

Silc Vale

unread,
May 6, 2012, 9:19:55 PM5/6/12
to JointJS
I am wondering whether it is possible to call functions when a user
disconnects or drags and connects a joint to an object. The reason i
ask is because i am creating joints using the following class code
using the mootools library to create the relationship:

var Relationship = new Class({
initialize: function(fromObject, toObject)
{
objectA = fromObject.SHAPE;
objectB = toObject.SHAPE;

this.joint = objectA.joint(objectB,
ARROW).registerForever(shapesArray);
}
});

It does work but, when a user connects the joint to another object
objectA and/or objectB variables are wrong. Is there a way to call a
function when the cap is connected or disconnected from an object. I
need this as i am saving each relationship in an XML document?

Thanks for any feedback!

dave

unread,
May 7, 2012, 4:47:28 AM5/7/12
to JointJS
'justConnected' and 'disconnected' events are the ones you need to
register callbacks for.

this.joint = objectA.joint(objectB,
ARROW).registerForever(shapesArray);
this.joint.registerCallback('justConnected', function(side) {
console.log(side); // prints 'start' or 'end'
console.log(this); // prints object the joint gets connected to
});

this.joint.registerCallback('disconnected', function(side) {
console.log(side); // prints 'start' or 'end'
console.log(this); // prints object the joint gets disconnected
from
});


Please consult API reference for registerCallback() for other events.

Cheers,
David
Reply all
Reply to author
Forward
0 new messages