mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
fixed #612 and added stage drag and drop unit tests
This commit is contained in:
parent
ba6e30aa97
commit
6b69460d2c
@ -156,13 +156,24 @@
|
||||
};
|
||||
|
||||
Kinetic.Node.prototype._listenDrag = function() {
|
||||
this._dragCleanup();
|
||||
var that = this;
|
||||
this.on('mousedown.kinetic touchstart.kinetic', function(evt) {
|
||||
if(!Kinetic.DD.node) {
|
||||
that.startDrag(evt);
|
||||
}
|
||||
});
|
||||
|
||||
this._dragCleanup();
|
||||
|
||||
if (this.getClassName() === 'Stage') {
|
||||
this.on('contentMousedown.kinetic contentTouchstart.kinetic', function(evt) {
|
||||
if(!Kinetic.DD.node) {
|
||||
that.startDrag(evt);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.on('mousedown.kinetic touchstart.kinetic', function(evt) {
|
||||
if(!Kinetic.DD.node) {
|
||||
that.startDrag(evt);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Kinetic.Node.prototype._dragChange = function() {
|
||||
|
@ -396,4 +396,53 @@ suite('DragAndDropEvents', function() {
|
||||
assert.equal(layer.getY(), 13, 'layer y should be 13');
|
||||
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('drag and drop stage', function() {
|
||||
var stage = addStage();
|
||||
|
||||
stage.setDraggable(true);
|
||||
|
||||
var layer = new Kinetic.Layer();
|
||||
|
||||
var circle = new Kinetic.Circle({
|
||||
x: 100,
|
||||
y: 100,
|
||||
radius: 70,
|
||||
fill: 'red'
|
||||
});
|
||||
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
var top = stage.content.getBoundingClientRect().top;
|
||||
|
||||
assert.equal(stage.getX(), 0);
|
||||
assert.equal(stage.getY(), 0);
|
||||
|
||||
/*
|
||||
* simulate drag and drop
|
||||
*/
|
||||
stage._mousedown({
|
||||
clientX: 100,
|
||||
clientY: 100 + top
|
||||
});
|
||||
|
||||
stage._mousemove({
|
||||
clientX: 300,
|
||||
clientY: 110 + top
|
||||
});
|
||||
|
||||
Kinetic.DD._endDragBefore();
|
||||
stage._mouseup({
|
||||
clientX: 300,
|
||||
clientY: 110 + top
|
||||
});
|
||||
Kinetic.DD._endDragAfter();
|
||||
|
||||
assert.equal(stage.getX(), 200);
|
||||
assert.equal(stage.getY(), 10);
|
||||
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user