Make object fire deselect event (#3195)

This commit is contained in:
Andrea Bogazzi 2016-08-28 22:25:51 +02:00 committed by GitHub
parent 37689f52eb
commit 148b5c1434
2 changed files with 21 additions and 9 deletions

View file

@ -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;
},

View file

@ -23,6 +23,7 @@
* @fires removed
*
* @fires selected
* @fires deselected
* @fires modified
* @fires rotating
* @fires scaling