mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
Fixed "calling remove() for dragging shape will throw an error". close #184
This commit is contained in:
parent
7b4e10fba8
commit
9b92331410
@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fixed bug when `Konva.Tag` width was not changing its width dynamically
|
- Fixed bug when `Konva.Tag` width was not changing its width dynamically
|
||||||
|
- Fixed "calling remove() for dragging shape will throw an error"
|
||||||
|
|
||||||
## [1.2.2][2016-09-15]
|
## [1.2.2][2016-09-15]
|
||||||
|
|
||||||
|
13
konva.js
13
konva.js
@ -3,7 +3,7 @@
|
|||||||
* Konva JavaScript Framework v1.2.2
|
* Konva JavaScript Framework v1.2.2
|
||||||
* http://konvajs.github.io/
|
* http://konvajs.github.io/
|
||||||
* Licensed under the MIT or GPL Version 2 licenses.
|
* Licensed under the MIT or GPL Version 2 licenses.
|
||||||
* Date: Mon Oct 31 2016
|
* Date: Thu Nov 10 2016
|
||||||
*
|
*
|
||||||
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
||||||
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
|
* Modified work Copyright (C) 2014 - 2015 by Anton Lavrenov (Konva)
|
||||||
@ -3449,7 +3449,9 @@
|
|||||||
moveTo: function(newContainer) {
|
moveTo: function(newContainer) {
|
||||||
// do nothing if new container is already parent
|
// do nothing if new container is already parent
|
||||||
if (this.getParent() !== newContainer) {
|
if (this.getParent() !== newContainer) {
|
||||||
this.remove();
|
// this.remove my be overrided by drag and drop
|
||||||
|
// buy we need original
|
||||||
|
(this.__originalRemove || this.remove).call(this);
|
||||||
newContainer.add(this);
|
newContainer.add(this);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@ -11345,9 +11347,10 @@
|
|||||||
this._dragChange();
|
this._dragChange();
|
||||||
};
|
};
|
||||||
|
|
||||||
var origDestroy = Konva.Node.prototype.destroy;
|
var origRemove = Konva.Node.prototype.remove;
|
||||||
|
|
||||||
Konva.Node.prototype.destroy = function() {
|
Konva.Node.prototype.__originalRemove = origRemove;
|
||||||
|
Konva.Node.prototype.remove = function() {
|
||||||
var dd = Konva.DD;
|
var dd = Konva.DD;
|
||||||
|
|
||||||
// stop DD
|
// stop DD
|
||||||
@ -11356,7 +11359,7 @@
|
|||||||
this.stopDrag();
|
this.stopDrag();
|
||||||
}
|
}
|
||||||
|
|
||||||
origDestroy.call(this);
|
origRemove.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
8
konva.min.js
vendored
8
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -168,9 +168,10 @@
|
|||||||
this._dragChange();
|
this._dragChange();
|
||||||
};
|
};
|
||||||
|
|
||||||
var origDestroy = Konva.Node.prototype.destroy;
|
var origRemove = Konva.Node.prototype.remove;
|
||||||
|
|
||||||
Konva.Node.prototype.destroy = function() {
|
Konva.Node.prototype.__originalRemove = origRemove;
|
||||||
|
Konva.Node.prototype.remove = function() {
|
||||||
var dd = Konva.DD;
|
var dd = Konva.DD;
|
||||||
|
|
||||||
// stop DD
|
// stop DD
|
||||||
@ -179,7 +180,7 @@
|
|||||||
this.stopDrag();
|
this.stopDrag();
|
||||||
}
|
}
|
||||||
|
|
||||||
origDestroy.call(this);
|
origRemove.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1156,7 +1156,9 @@
|
|||||||
moveTo: function(newContainer) {
|
moveTo: function(newContainer) {
|
||||||
// do nothing if new container is already parent
|
// do nothing if new container is already parent
|
||||||
if (this.getParent() !== newContainer) {
|
if (this.getParent() !== newContainer) {
|
||||||
this.remove();
|
// this.remove my be overrided by drag and drop
|
||||||
|
// buy we need original
|
||||||
|
(this.__originalRemove || this.remove).call(this);
|
||||||
newContainer.add(this);
|
newContainer.add(this);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -369,4 +369,79 @@ suite('DragAndDrop', function() {
|
|||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('removing shape while drag and drop should no throw error', function() {
|
||||||
|
var stage = addStage();
|
||||||
|
var layer = new Konva.Layer();
|
||||||
|
|
||||||
|
var circle = new Konva.Circle({
|
||||||
|
x: stage.getWidth() / 2,
|
||||||
|
y: stage.getHeight() / 2,
|
||||||
|
radius: 70,
|
||||||
|
fill: 'green',
|
||||||
|
stroke: 'black',
|
||||||
|
strokeWidth: 4,
|
||||||
|
name: 'myCircle',
|
||||||
|
draggable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(circle);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
stage.simulateMouseDown({
|
||||||
|
x: 291,
|
||||||
|
y: 112
|
||||||
|
});
|
||||||
|
|
||||||
|
circle.remove();
|
||||||
|
|
||||||
|
stage.simulateMouseMove({
|
||||||
|
x: 311,
|
||||||
|
y: 112
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
stage.simulateMouseUp({
|
||||||
|
x: 291,
|
||||||
|
y: 112,
|
||||||
|
button: 2
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('destroying shape while drag and drop should no throw error', function() {
|
||||||
|
var stage = addStage();
|
||||||
|
var layer = new Konva.Layer();
|
||||||
|
|
||||||
|
var circle = new Konva.Circle({
|
||||||
|
x: stage.getWidth() / 2,
|
||||||
|
y: stage.getHeight() / 2,
|
||||||
|
radius: 70,
|
||||||
|
fill: 'green',
|
||||||
|
stroke: 'black',
|
||||||
|
strokeWidth: 4,
|
||||||
|
name: 'myCircle',
|
||||||
|
draggable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(circle);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
stage.simulateMouseDown({
|
||||||
|
x: 291,
|
||||||
|
y: 112
|
||||||
|
});
|
||||||
|
|
||||||
|
circle.destroy();
|
||||||
|
|
||||||
|
stage.simulateMouseMove({
|
||||||
|
x: 311,
|
||||||
|
y: 112
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
stage.simulateMouseUp({
|
||||||
|
x: 291,
|
||||||
|
y: 112,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -5,7 +5,7 @@ suite('Enhance', function () {
|
|||||||
|
|
||||||
var imageObj = new Image();
|
var imageObj = new Image();
|
||||||
imageObj.onload = function() {
|
imageObj.onload = function() {
|
||||||
|
|
||||||
var layer = new Konva.Layer();
|
var layer = new Konva.Layer();
|
||||||
var filt = new Konva.Image({
|
var filt = new Konva.Image({
|
||||||
x: 10,
|
x: 10,
|
||||||
@ -41,7 +41,7 @@ suite('Enhance', function () {
|
|||||||
|
|
||||||
var imageObj = new Image();
|
var imageObj = new Image();
|
||||||
imageObj.onload = function() {
|
imageObj.onload = function() {
|
||||||
|
|
||||||
var layer = new Konva.Layer();
|
var layer = new Konva.Layer();
|
||||||
darth = new Konva.Image({
|
darth = new Konva.Image({
|
||||||
x: 10,
|
x: 10,
|
||||||
@ -59,16 +59,16 @@ suite('Enhance', function () {
|
|||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
var tween = new Konva.Tween({
|
var tween = new Konva.Tween({
|
||||||
node: darth,
|
node: darth,
|
||||||
duration: 2.0,
|
duration: 2.0,
|
||||||
enhance: 1.0,
|
enhance: 1.0,
|
||||||
easing: Konva.Easings.EaseInOut
|
easing: Konva.Easings.EaseInOut
|
||||||
});
|
});
|
||||||
|
|
||||||
darth.on('mouseover', function() {
|
darth.on('mouseover', function() {
|
||||||
tween.play();
|
tween.play();
|
||||||
});
|
});
|
||||||
|
|
||||||
darth.on('mouseout', function() {
|
darth.on('mouseout', function() {
|
||||||
tween.reverse();
|
tween.reverse();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user