Here's a quick and easy way to add a double-click event handler in Fabric JS -
Include the following code snippet in your html file. Just make sure this is loaded after the main fabric.js library.
<script type="text/javascript"> fabric = (function(f) { var nativeOn = f.on; var dblClickSubscribers = []; var nativeCanvas = f.Canvas; f.Canvas = (function(domId, options) { var canvasDomElement = document.getElementById(domId); var c = new nativeCanvas(domId, options); c.dblclick = function(handler) { dblClickSubscribers.push(handler) }; canvasDomElement.nextSibling.ondblclick = function(ev){ for(var i = 0; i < dblClickSubscribers.length; i++) { console.log(ev); dblClickSubscribers[i]({ e :ev }); } }; return c; }); return f; }(fabric)); </script>
Then add this code to listen for the double-click event:
canvas.dblclick(function(e) { });
To get information about the actual object clicked on the canvas, use the following method -
canvas.getActiveObject();
eg.
canvas.dblclick(function(e) { activeObject = canvas.getActiveObject(); });
Rohit siddha
source share