How to identify the type of a selected object?

anam picture anam · Sep 19, 2013 · Viewed 28k times · Source

I am placing Text, Image and Shapes on canvas using Fabric.js. I have made Three different Edit-Panels for all three. When user select text I want to show text panel. like wise for image and shapes.

How to identify type of selected Object?

Answer

Kienz picture Kienz · Sep 19, 2013

canvas.getActiveObject().get('type') as simmi simmi said is correct. You can also listen to events:

function onObjectSelected(e) {
  console.log(e.target.get('type'));
}
canvas.on('object:selected', onObjectSelected);