diff --git a/src/canvas.class.js b/src/canvas.class.js index fd1c8d6d..457ff8a7 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -1285,7 +1285,8 @@ if (this.getActiveObject() === obj) { this.fire('before:selection:cleared', { target: obj }); this._discardActiveObject(); - this.fire('selection:cleared'); + this.fire('selection:cleared', { target: obj }); + obj.fire('deselected'); } this.callSuper('_onObjectRemoved', obj); }, @@ -1301,14 +1302,17 @@ }, /** - * Discards currently active object + * Discards currently active object and fire events + * @param {event} e * @return {fabric.Canvas} thisArg * @chainable */ discardActiveObject: function (e) { + var activeObject = this._activeObject; + this.fire('before:selection:cleared', { target: activeObject, e: e }); this._discardActiveObject(); - this.renderAll(); this.fire('selection:cleared', { e: e }); + activeObject && activeObject.fire('deselected', { e: e }); return this; }, @@ -1359,10 +1363,13 @@ }, /** - * Discards currently active group + * Discards currently active group and fire events * @return {fabric.Canvas} thisArg + * @chainable */ discardActiveGroup: function (e) { + var g = this.getActiveGroup(); + this.fire('before:selection:cleared', { e: e, target: g }); this._discardActiveGroup(); this.fire('selection:cleared', { e: e }); return this; @@ -1371,6 +1378,7 @@ /** * Deactivates all objects on canvas, removing any active group or object * @return {fabric.Canvas} thisArg + * @chainable */ deactivateAll: function () { var allObjects = this.getObjects(), @@ -1387,15 +1395,18 @@ /** * Deactivates all objects and dispatches appropriate events * @return {fabric.Canvas} thisArg + * @chainable */ deactivateAllWithDispatch: function (e) { - var activeObject = this.getActiveGroup() || this.getActiveObject(); - if (activeObject) { - this.fire('before:selection:cleared', { target: activeObject, e: e }); + var activeGroup = this.getActiveGroup(), + activeObject = this.getActiveObject(); + if (activeObject || activeGroup) { + this.fire('before:selection:cleared', { target: activeObject || activeGroup, e: e }); } this.deactivateAll(); - if (activeObject) { - this.fire('selection:cleared', { e: e }); + if (activeObject || activeGroup) { + this.fire('selection:cleared', { e: e, target: activeObject }); + activeObject && activeObject.fire('deselected'); } return this; }, diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 158911c7..16fcfb23 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -23,6 +23,7 @@ * @fires removed * * @fires selected + * @fires deselected * @fires modified * @fires rotating * @fires scaling