mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-20 03:11:52 +00:00
Make events more consistent.
"object:moved" --> "object:moving" (since it's a continuously fired event). "object:scaled" is gone (since this case can be solved with "object:modified"). "group:modified" is gone (since this case can be solved with "object:modified"). "group:selected" --> "selection:created". "before:group:destroyed" --> "before:selection:cleared" (only fires when there is active object or group). "after:group:destroyed" --> "selection:cleared" (only fires when there is active object or group).
This commit is contained in:
parent
2b3a166d2f
commit
85a256a8e7
5 changed files with 21 additions and 41 deletions
|
|
@ -57,16 +57,12 @@
|
|||
}
|
||||
|
||||
observe('object:modified');
|
||||
observe('object:moved');
|
||||
observe('object:scaled');
|
||||
observe('object:moving');
|
||||
observe('object:selected');
|
||||
|
||||
observe('before:selection:cleared');
|
||||
observe('selection:cleared');
|
||||
|
||||
observe('group:modified');
|
||||
observe('group:selected');
|
||||
observe('before:group:destroyed');
|
||||
observe('after:group:destroyed');
|
||||
observe('selection:created');
|
||||
|
||||
// observe('after:render');
|
||||
observe('mouse:up');
|
||||
|
|
|
|||
24
dist/all.js
vendored
24
dist/all.js
vendored
|
|
@ -4385,7 +4385,6 @@ fabric.util.getElementOffset = getElementOffset;
|
|||
target = transform.target;
|
||||
|
||||
if (target._scaling) {
|
||||
this.fire('object:scaled', { target: target });
|
||||
target._scaling = false;
|
||||
}
|
||||
|
||||
|
|
@ -4407,10 +4406,6 @@ fabric.util.getElementOffset = getElementOffset;
|
|||
}
|
||||
var activeGroup = this.getActiveGroup();
|
||||
if (activeGroup) {
|
||||
if (this.stateful && activeGroup.hasStateChanged() &&
|
||||
activeGroup.containsPoint(this.getPointer(e))) {
|
||||
this.fire('group:modified', { target: activeGroup });
|
||||
}
|
||||
activeGroup.setObjectsCoords();
|
||||
activeGroup.set('isMoving', false);
|
||||
this._setCursor('default');
|
||||
|
|
@ -4524,17 +4519,14 @@ fabric.util.getElementOffset = getElementOffset;
|
|||
* @return {fabric.Canvas} thisArg
|
||||
*/
|
||||
deactivateAllWithDispatch: function () {
|
||||
var activeGroup = this.getActiveGroup();
|
||||
if (activeGroup) {
|
||||
this.fire('before:group:destroyed', {
|
||||
target: activeGroup
|
||||
});
|
||||
var activeObject = this.getActiveGroup() || this.getActiveObject();
|
||||
if (activeObject) {
|
||||
this.fire('before:selection:cleared', { target: activeObject });
|
||||
}
|
||||
this.deactivateAll();
|
||||
if (activeGroup) {
|
||||
this.fire('after:group:destroyed');
|
||||
if (activeObject) {
|
||||
this.fire('selection:cleared');
|
||||
}
|
||||
this.fire('selection:cleared');
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -4595,7 +4587,7 @@ fabric.util.getElementOffset = getElementOffset;
|
|||
else {
|
||||
activeGroup.add(target);
|
||||
}
|
||||
this.fire('group:selected', { target: activeGroup });
|
||||
this.fire('selection:created', { target: activeGroup });
|
||||
activeGroup.setActive(true);
|
||||
}
|
||||
else {
|
||||
|
|
@ -4768,7 +4760,7 @@ fabric.util.getElementOffset = getElementOffset;
|
|||
else {
|
||||
this._translateObject(x, y);
|
||||
|
||||
this.fire('object:moved', {
|
||||
this.fire('object:moving', {
|
||||
target: this._currentTransform.target
|
||||
});
|
||||
}
|
||||
|
|
@ -4957,7 +4949,7 @@ fabric.util.getElementOffset = getElementOffset;
|
|||
var group = new fabric.Group(group);
|
||||
this.setActiveGroup(group);
|
||||
group.saveCoords();
|
||||
this.fire('group:selected', { target: group });
|
||||
this.fire('selection:created', { target: group });
|
||||
}
|
||||
|
||||
this.renderAll();
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ function initAligningGuidelines(canvas) {
|
|||
var verticalLines = [ ],
|
||||
horizontalLines = [ ];
|
||||
|
||||
canvas.observe('object:moved', function(e) {
|
||||
canvas.observe('object:moving', function(e) {
|
||||
|
||||
var activeObject = e.memo.target,
|
||||
canvasObjects = canvas.getObjects(),
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ function initCenteringGuidelines(canvas) {
|
|||
isInVerticalCenter,
|
||||
isInHorizontalCenter;
|
||||
|
||||
canvas.observe('object:moved', function(e) {
|
||||
canvas.observe('object:moving', function(e) {
|
||||
object = e.memo.target;
|
||||
|
||||
isInVerticalCenter = object.get('left') in canvasWidthCenterMap,
|
||||
|
|
|
|||
|
|
@ -511,7 +511,6 @@
|
|||
target = transform.target;
|
||||
|
||||
if (target._scaling) {
|
||||
this.fire('object:scaled', { target: target });
|
||||
target._scaling = false;
|
||||
}
|
||||
|
||||
|
|
@ -536,10 +535,6 @@
|
|||
}
|
||||
var activeGroup = this.getActiveGroup();
|
||||
if (activeGroup) {
|
||||
if (this.stateful && activeGroup.hasStateChanged() &&
|
||||
activeGroup.containsPoint(this.getPointer(e))) {
|
||||
this.fire('group:modified', { target: activeGroup });
|
||||
}
|
||||
activeGroup.setObjectsCoords();
|
||||
activeGroup.set('isMoving', false);
|
||||
this._setCursor('default');
|
||||
|
|
@ -661,17 +656,14 @@
|
|||
* @return {fabric.Canvas} thisArg
|
||||
*/
|
||||
deactivateAllWithDispatch: function () {
|
||||
var activeGroup = this.getActiveGroup();
|
||||
if (activeGroup) {
|
||||
this.fire('before:group:destroyed', {
|
||||
target: activeGroup
|
||||
});
|
||||
var activeObject = this.getActiveGroup() || this.getActiveObject();
|
||||
if (activeObject) {
|
||||
this.fire('before:selection:cleared', { target: activeObject });
|
||||
}
|
||||
this.deactivateAll();
|
||||
if (activeGroup) {
|
||||
this.fire('after:group:destroyed');
|
||||
if (activeObject) {
|
||||
this.fire('selection:cleared');
|
||||
}
|
||||
this.fire('selection:cleared');
|
||||
return this;
|
||||
},
|
||||
|
||||
|
|
@ -735,7 +727,7 @@
|
|||
else {
|
||||
activeGroup.add(target);
|
||||
}
|
||||
this.fire('group:selected', { target: activeGroup });
|
||||
this.fire('selection:created', { target: activeGroup });
|
||||
activeGroup.setActive(true);
|
||||
}
|
||||
else {
|
||||
|
|
@ -928,7 +920,7 @@
|
|||
else {
|
||||
this._translateObject(x, y);
|
||||
|
||||
this.fire('object:moved', {
|
||||
this.fire('object:moving', {
|
||||
target: this._currentTransform.target
|
||||
});
|
||||
}
|
||||
|
|
@ -1120,7 +1112,7 @@
|
|||
var group = new fabric.Group(group);
|
||||
this.setActiveGroup(group);
|
||||
group.saveCoords();
|
||||
this.fire('group:selected', { target: group });
|
||||
this.fire('selection:created', { target: group });
|
||||
}
|
||||
|
||||
this.renderAll();
|
||||
|
|
|
|||
Loading…
Reference in a new issue