fixed #612 and added stage drag and drop unit tests

This commit is contained in:
Eric Rowell 2013-09-26 22:40:23 -07:00
parent ba6e30aa97
commit 6b69460d2c
2 changed files with 66 additions and 6 deletions

View File

@ -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() {

View File

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