mirror of
https://github.com/konvajs/konva.git
synced 2026-01-09 11:34:38 +08:00
better test
This commit is contained in:
38
konva.js
38
konva.js
@@ -625,20 +625,16 @@
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_waiting: false,
|
|
||||||
animQueue: [],
|
animQueue: [],
|
||||||
requestAnimFrame: function (callback) {
|
requestAnimFrame: function (callback) {
|
||||||
Util.animQueue.push(callback);
|
Util.animQueue.push(callback);
|
||||||
if (Util._waiting) {
|
if (Util.animQueue.length === 1) {
|
||||||
return;
|
requestAnimationFrame(function () {
|
||||||
}
|
var queue = Util.animQueue;
|
||||||
requestAnimationFrame(function () {
|
Util.animQueue = [];
|
||||||
Util.animQueue.forEach(function (cb) {
|
queue.forEach(function (cb) { cb(); });
|
||||||
cb();
|
|
||||||
});
|
});
|
||||||
Util.animQueue = [];
|
}
|
||||||
Util._waiting = false;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
createCanvasElement: function () {
|
createCanvasElement: function () {
|
||||||
var canvas = isBrowser
|
var canvas = isBrowser
|
||||||
@@ -2961,7 +2957,7 @@
|
|||||||
if (parent && parent.children) {
|
if (parent && parent.children) {
|
||||||
parent.children.splice(this.index, 1);
|
parent.children.splice(this.index, 1);
|
||||||
parent._setChildrenIndices();
|
parent._setChildrenIndices();
|
||||||
delete this.parent;
|
this.parent = null;
|
||||||
}
|
}
|
||||||
// every cached attr that is calculated via node tree
|
// every cached attr that is calculated via node tree
|
||||||
// traversal must be cleared when removing a node
|
// traversal must be cleared when removing a node
|
||||||
@@ -4938,7 +4934,7 @@
|
|||||||
for (var i = 0; i < children.length; i++) {
|
for (var i = 0; i < children.length; i++) {
|
||||||
child = children[i];
|
child = children[i];
|
||||||
// reset parent to prevent many _setChildrenIndices calls
|
// reset parent to prevent many _setChildrenIndices calls
|
||||||
delete child.parent;
|
child.parent = null;
|
||||||
child.index = 0;
|
child.index = 0;
|
||||||
child.remove();
|
child.remove();
|
||||||
}
|
}
|
||||||
@@ -4957,7 +4953,7 @@
|
|||||||
for (var i = 0; i < children.length; i++) {
|
for (var i = 0; i < children.length; i++) {
|
||||||
child = children[i];
|
child = children[i];
|
||||||
// reset parent to prevent many _setChildrenIndices calls
|
// reset parent to prevent many _setChildrenIndices calls
|
||||||
delete child.parent;
|
child.parent = null;
|
||||||
child.index = 0;
|
child.index = 0;
|
||||||
child.destroy();
|
child.destroy();
|
||||||
}
|
}
|
||||||
@@ -5727,10 +5723,6 @@
|
|||||||
};
|
};
|
||||||
Stage.prototype._mouseover = function (evt) {
|
Stage.prototype._mouseover = function (evt) {
|
||||||
this._setPointerPosition(evt);
|
this._setPointerPosition(evt);
|
||||||
// TODO: add test on mouseover
|
|
||||||
// I guess it should fire on:
|
|
||||||
// 1. mouseenter
|
|
||||||
// 2. leave or enter any shape
|
|
||||||
this._fire(CONTENT_MOUSEOVER, { evt: evt });
|
this._fire(CONTENT_MOUSEOVER, { evt: evt });
|
||||||
this._fire(MOUSEOVER, { evt: evt, target: this, currentTarget: this });
|
this._fire(MOUSEOVER, { evt: evt, target: this, currentTarget: this });
|
||||||
};
|
};
|
||||||
@@ -6355,13 +6347,13 @@
|
|||||||
*/
|
*/
|
||||||
BaseLayer.prototype.batchDraw = function () {
|
BaseLayer.prototype.batchDraw = function () {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
if (this._waitingForDraw) {
|
if (!this._waitingForDraw) {
|
||||||
return;
|
this._waitingForDraw = true;
|
||||||
|
Util.requestAnimFrame(function () {
|
||||||
|
_this.draw();
|
||||||
|
_this._waitingForDraw = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Util.requestAnimFrame(function () {
|
|
||||||
_this._waitingForDraw = false;
|
|
||||||
_this.draw();
|
|
||||||
});
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
// the apply transform method is handled by the Layer and FastLayer class
|
// the apply transform method is handled by the Layer and FastLayer class
|
||||||
|
|||||||
4
konva.min.js
vendored
4
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -345,10 +345,6 @@ export class Stage extends Container {
|
|||||||
}
|
}
|
||||||
_mouseover(evt) {
|
_mouseover(evt) {
|
||||||
this._setPointerPosition(evt);
|
this._setPointerPosition(evt);
|
||||||
// TODO: add test on mouseover
|
|
||||||
// I guess it should fire on:
|
|
||||||
// 1. mouseenter
|
|
||||||
// 2. leave or enter any shape
|
|
||||||
this._fire(CONTENT_MOUSEOVER, { evt: evt });
|
this._fire(CONTENT_MOUSEOVER, { evt: evt });
|
||||||
this._fire(MOUSEOVER, { evt: evt, target: this, currentTarget: this });
|
this._fire(MOUSEOVER, { evt: evt, target: this, currentTarget: this });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1092,18 +1092,27 @@ suite('Stage', function() {
|
|||||||
assert.equal(dblicks, 1, 'first dbclick registered');
|
assert.equal(dblicks, 1, 'first dbclick registered');
|
||||||
});
|
});
|
||||||
|
|
||||||
test.only('test mouseover event on stage', function() {
|
test('test mouseover event on stage', function() {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
var layer = new Konva.Layer();
|
var layer = new Konva.Layer();
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
var rect = new Konva.Rect({
|
var rect1 = new Konva.Rect({
|
||||||
x: 50,
|
x: 50,
|
||||||
y: 50,
|
y: 50,
|
||||||
width: stage.width(),
|
width: 50,
|
||||||
height: stage.height(),
|
height: 50,
|
||||||
fill: 'red'
|
fill: 'red'
|
||||||
});
|
});
|
||||||
layer.add(rect);
|
layer.add(rect1);
|
||||||
|
|
||||||
|
var rect2 = new Konva.Rect({
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
width: 50,
|
||||||
|
height: 50,
|
||||||
|
fill: 'red'
|
||||||
|
});
|
||||||
|
layer.add(rect2);
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
var mouseover = 0;
|
var mouseover = 0;
|
||||||
@@ -1116,8 +1125,10 @@ suite('Stage', function() {
|
|||||||
assert.equal(e.currentTarget, stage);
|
assert.equal(e.currentTarget, stage);
|
||||||
}
|
}
|
||||||
if (mouseover === 2) {
|
if (mouseover === 2) {
|
||||||
assert.equal(e.target, rect);
|
assert.equal(e.target, rect1);
|
||||||
assert.equal(e.currentTarget, stage);
|
}
|
||||||
|
if (mouseover === 3) {
|
||||||
|
assert.equal(e.target, rect2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1141,6 +1152,17 @@ suite('Stage', function() {
|
|||||||
|
|
||||||
assert.equal(mouseover, 2, 'moved into inner shape, trigger new mouseover');
|
assert.equal(mouseover, 2, 'moved into inner shape, trigger new mouseover');
|
||||||
|
|
||||||
|
stage.simulateMouseMove({
|
||||||
|
x: 110,
|
||||||
|
y: 110
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
mouseover,
|
||||||
|
3,
|
||||||
|
'moved into second shape, trigger new mouseover'
|
||||||
|
);
|
||||||
|
|
||||||
stage.simulateMouseMove({
|
stage.simulateMouseMove({
|
||||||
x: 10,
|
x: 10,
|
||||||
y: 10
|
y: 10
|
||||||
@@ -1148,8 +1170,8 @@ suite('Stage', function() {
|
|||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
mouseover,
|
mouseover,
|
||||||
3,
|
4,
|
||||||
'moved out of inner shape, trigger new mouseover'
|
'moved to empty space shape, trigger new mouseover'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user