Skip to content

Commit

Permalink
Make object fire deselect event (#3195)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Aug 28, 2016
1 parent 37689f5 commit 148b5c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand All @@ -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;
},

Expand Down Expand Up @@ -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;
Expand All @@ -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(),
Expand All @@ -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;
},
Expand Down
1 change: 1 addition & 0 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @fires removed
*
* @fires selected
* @fires deselected
* @fires modified
* @fires rotating
* @fires scaling
Expand Down

0 comments on commit 148b5c1

Please sign in to comment.