How to deactivate all objects in Fabric.js

MP. picture MP. · Jan 15, 2014 · Viewed 10.4k times · Source

How to deactivate all objects in Fabric.js before saving an image?

function rasterize() {
  if (!myscript.Canvas.supports('toDataURL')) {
    alert('This browser doesn\'t provide means to serialize canvas to an image');
  }
  else {
    /*i want to deactivate all object here*/
    window.open(canvas.toDataURL('png'));
  }
}

Answer

Kienz picture Kienz · Jan 15, 2014

canvas.deactivateAll(); => no events are fired http://fabricjs.com/docs/fabric.Canvas.html#deactivateAll

or

canvas.deactivateAllWithDispatch(); => if activeObject exists the events 'before:selection:cleared' and 'selection:cleared' are fired. http://fabricjs.com/docs/fabric.Canvas.html#deactivateAllWithDispatch