mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
better test
This commit is contained in:
38
konva.js
38
konva.js
@@ -625,20 +625,16 @@
|
||||
return -1;
|
||||
}
|
||||
},
|
||||
_waiting: false,
|
||||
animQueue: [],
|
||||
requestAnimFrame: function (callback) {
|
||||
Util.animQueue.push(callback);
|
||||
if (Util._waiting) {
|
||||
return;
|
||||
}
|
||||
requestAnimationFrame(function () {
|
||||
Util.animQueue.forEach(function (cb) {
|
||||
cb();
|
||||
if (Util.animQueue.length === 1) {
|
||||
requestAnimationFrame(function () {
|
||||
var queue = Util.animQueue;
|
||||
Util.animQueue = [];
|
||||
queue.forEach(function (cb) { cb(); });
|
||||
});
|
||||
Util.animQueue = [];
|
||||
Util._waiting = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
createCanvasElement: function () {
|
||||
var canvas = isBrowser
|
||||
@@ -2961,7 +2957,7 @@
|
||||
if (parent && parent.children) {
|
||||
parent.children.splice(this.index, 1);
|
||||
parent._setChildrenIndices();
|
||||
delete this.parent;
|
||||
this.parent = null;
|
||||
}
|
||||
// every cached attr that is calculated via node tree
|
||||
// traversal must be cleared when removing a node
|
||||
@@ -4938,7 +4934,7 @@
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
child = children[i];
|
||||
// reset parent to prevent many _setChildrenIndices calls
|
||||
delete child.parent;
|
||||
child.parent = null;
|
||||
child.index = 0;
|
||||
child.remove();
|
||||
}
|
||||
@@ -4957,7 +4953,7 @@
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
child = children[i];
|
||||
// reset parent to prevent many _setChildrenIndices calls
|
||||
delete child.parent;
|
||||
child.parent = null;
|
||||
child.index = 0;
|
||||
child.destroy();
|
||||
}
|
||||
@@ -5727,10 +5723,6 @@
|
||||
};
|
||||
Stage.prototype._mouseover = function (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(MOUSEOVER, { evt: evt, target: this, currentTarget: this });
|
||||
};
|
||||
@@ -6355,13 +6347,13 @@
|
||||
*/
|
||||
BaseLayer.prototype.batchDraw = function () {
|
||||
var _this = this;
|
||||
if (this._waitingForDraw) {
|
||||
return;
|
||||
if (!this._waitingForDraw) {
|
||||
this._waitingForDraw = true;
|
||||
Util.requestAnimFrame(function () {
|
||||
_this.draw();
|
||||
_this._waitingForDraw = false;
|
||||
});
|
||||
}
|
||||
Util.requestAnimFrame(function () {
|
||||
_this._waitingForDraw = false;
|
||||
_this.draw();
|
||||
});
|
||||
return this;
|
||||
};
|
||||
// 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) {
|
||||
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(MOUSEOVER, { evt: evt, target: this, currentTarget: this });
|
||||
}
|
||||
|
@@ -1092,18 +1092,27 @@ suite('Stage', function() {
|
||||
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 layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
var rect = new Konva.Rect({
|
||||
var rect1 = new Konva.Rect({
|
||||
x: 50,
|
||||
y: 50,
|
||||
width: stage.width(),
|
||||
height: stage.height(),
|
||||
width: 50,
|
||||
height: 50,
|
||||
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();
|
||||
|
||||
var mouseover = 0;
|
||||
@@ -1116,8 +1125,10 @@ suite('Stage', function() {
|
||||
assert.equal(e.currentTarget, stage);
|
||||
}
|
||||
if (mouseover === 2) {
|
||||
assert.equal(e.target, rect);
|
||||
assert.equal(e.currentTarget, stage);
|
||||
assert.equal(e.target, rect1);
|
||||
}
|
||||
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');
|
||||
|
||||
stage.simulateMouseMove({
|
||||
x: 110,
|
||||
y: 110
|
||||
});
|
||||
|
||||
assert.equal(
|
||||
mouseover,
|
||||
3,
|
||||
'moved into second shape, trigger new mouseover'
|
||||
);
|
||||
|
||||
stage.simulateMouseMove({
|
||||
x: 10,
|
||||
y: 10
|
||||
@@ -1148,8 +1170,8 @@ suite('Stage', function() {
|
||||
|
||||
assert.equal(
|
||||
mouseover,
|
||||
3,
|
||||
'moved out of inner shape, trigger new mouseover'
|
||||
4,
|
||||
'moved to empty space shape, trigger new mouseover'
|
||||
);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user