Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make object fire deselect event #3195

Merged
merged 4 commits into from
Aug 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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