Reputation: 270
I have a fabric element inside a canvas, and I want to add a dbclick event on that specific element.
customText = new fabric.Text(customTextContent, {
pp_type: 'custom_text',
pp_label: _t('my text'),
// lockUniScaling: true,
uniqId: uniqId,
fill: customColor,
fontFamily: customFont,
fontSize: 12,
scaleX: self.baseTextScale,
scaleY: self.baseTextScale
});
customText.on('mouse:dblclick', function (e){
console.log('canvas db clicked');
console.log(e);
});
What am I doing wrong ?
Upvotes: 1
Views: 370
Reputation: 14731
Look at the official docs/demos.
Here is explained that if you are listening for a generic double click event on the canvas you need to use:
canvas.on('mouse:dblclick', eventHandler)
while if you are listening on objects:
text.on('mousedblclick', eventHandler)
This is the old naming schema and has never been change to preserve backward compatibility where possible
Upvotes: 0
Reputation: 270
window.fabric.util.addListener(canvas.upperCanvasEl, 'dblclick', function (e, self) {
var target = canvas.findTarget(e);
}
Target wil contains all the specification of the clicked element. So just need to switch the bahavior considering the type or whatever the kind of condition you need.
Upvotes: 1