2013-03-24 14:19:24 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
Test.Modules.DD = {
|
2013-01-28 14:25:16 +08:00
|
|
|
'remove shape with onclick': function(containerId) {
|
2012-12-13 16:01:24 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
2013-01-28 14:25:16 +08:00
|
|
|
|
2012-12-13 16:01:24 +08:00
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
2013-01-28 14:25:16 +08:00
|
|
|
|
2012-12-13 16:01:24 +08:00
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
|
|
|
var circle = new Kinetic.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);
|
2013-02-12 14:55:24 +08:00
|
|
|
|
2013-01-28 14:25:16 +08:00
|
|
|
function remove() {
|
2013-02-12 14:55:24 +08:00
|
|
|
circle.remove();
|
2013-01-28 14:25:16 +08:00
|
|
|
layer.draw();
|
2013-03-25 07:40:09 +08:00
|
|
|
testDataUrl(layer.toDataURL(), 'cleared', 'canvas should be cleared after removing shape onclick');
|
2013-01-28 14:25:16 +08:00
|
|
|
}
|
2012-12-13 16:01:24 +08:00
|
|
|
|
|
|
|
circle.on('click', function() {
|
2013-01-28 14:25:16 +08:00
|
|
|
setTimeout(remove, 0);
|
2012-12-13 16:01:24 +08:00
|
|
|
});
|
2013-01-28 14:25:16 +08:00
|
|
|
|
2012-12-13 16:01:24 +08:00
|
|
|
stage._mousedown({
|
|
|
|
clientX: 291,
|
|
|
|
clientY: 112 + top
|
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
|
|
|
|
Kinetic.DD._endDragBefore();
|
2012-12-13 16:01:24 +08:00
|
|
|
stage._mouseup({
|
|
|
|
clientX: 291,
|
|
|
|
clientY: 112 + top
|
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:circle});
|
2012-12-13 16:01:24 +08:00
|
|
|
},
|
2013-03-22 15:46:41 +08:00
|
|
|
'test dragstart, dragmove, dragend': function(containerId) {
|
2012-03-23 14:17:52 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
2013-03-22 15:46:41 +08:00
|
|
|
height: 200
|
2012-03-23 14:17:52 +08:00
|
|
|
});
|
2012-03-18 01:28:25 +08:00
|
|
|
var layer = new Kinetic.Layer();
|
2013-03-22 15:46:41 +08:00
|
|
|
|
|
|
|
var greenCircle = new Kinetic.Circle({
|
|
|
|
x: 40,
|
|
|
|
y: 40,
|
|
|
|
radius: 20,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
opacity: 0.5
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var circle = new Kinetic.Circle({
|
2012-06-16 02:47:55 +08:00
|
|
|
x: 380,
|
2012-04-08 05:04:15 +08:00
|
|
|
y: stage.getHeight() / 2,
|
2012-03-18 01:28:25 +08:00
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
2012-03-18 05:35:34 +08:00
|
|
|
fill: 'red',
|
2013-03-22 15:46:41 +08:00
|
|
|
stroke: 'black',
|
|
|
|
opacity: 0.5
|
|
|
|
|
2012-03-23 14:17:52 +08:00
|
|
|
});
|
2012-03-18 01:28:25 +08:00
|
|
|
|
2012-06-19 13:02:13 +08:00
|
|
|
circle.setDraggable(true);
|
2012-03-18 01:28:25 +08:00
|
|
|
|
2012-06-19 08:56:12 +08:00
|
|
|
layer.add(circle);
|
2013-03-22 15:46:41 +08:00
|
|
|
layer.add(greenCircle);
|
2012-03-18 01:28:25 +08:00
|
|
|
stage.add(layer);
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
2012-04-15 03:04:45 +08:00
|
|
|
|
2012-06-16 02:47:55 +08:00
|
|
|
var dragStart = false;
|
|
|
|
var dragMove = false;
|
|
|
|
var dragEnd = false;
|
2013-01-30 02:12:24 +08:00
|
|
|
var mouseup = false;
|
2013-03-22 11:24:03 +08:00
|
|
|
var layerDragMove = false;
|
2013-03-24 11:02:11 +08:00
|
|
|
var events = [];
|
2012-04-15 12:46:38 +08:00
|
|
|
|
2012-06-19 08:56:12 +08:00
|
|
|
circle.on('dragstart', function() {
|
2012-06-16 02:47:55 +08:00
|
|
|
dragStart = true;
|
2012-04-15 03:04:45 +08:00
|
|
|
});
|
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
|
2012-06-19 08:56:12 +08:00
|
|
|
circle.on('dragmove', function() {
|
2012-06-16 02:47:55 +08:00
|
|
|
dragMove = true;
|
2012-04-15 03:04:45 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
|
2013-03-22 11:24:03 +08:00
|
|
|
|
|
|
|
layer.on('dragmove', function() {
|
2013-03-22 15:46:41 +08:00
|
|
|
//console.log('move');
|
2013-03-22 11:24:03 +08:00
|
|
|
});
|
2012-04-15 03:04:45 +08:00
|
|
|
|
2012-06-19 08:56:12 +08:00
|
|
|
circle.on('dragend', function() {
|
2012-06-16 02:47:55 +08:00
|
|
|
dragEnd = true;
|
2013-03-24 11:02:11 +08:00
|
|
|
console.log('dragend');
|
|
|
|
events.push('dragend');
|
2012-04-15 03:04:45 +08:00
|
|
|
});
|
2013-02-12 14:55:24 +08:00
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
|
|
|
|
|
2013-01-30 02:12:24 +08:00
|
|
|
circle.on('mouseup', function() {
|
2013-03-24 11:02:11 +08:00
|
|
|
console.log('mouseup');
|
|
|
|
events.push('mouseup');
|
2013-01-30 02:12:24 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
|
2013-03-25 07:40:09 +08:00
|
|
|
testDataUrl(layer.toDataURL(), 'drag circle before', 'start data url is incorrect');
|
2013-04-03 13:29:56 +08:00
|
|
|
|
|
|
|
test(!Kinetic.Global.isDragging(), 'Global isDragging() should be false');
|
|
|
|
test(!Kinetic.Global.isDragReady(), 'Global isDragReady()) should be false');
|
|
|
|
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
/*
|
2012-11-15 14:14:15 +08:00
|
|
|
* simulate drag and drop
|
|
|
|
*/
|
2012-11-15 13:55:16 +08:00
|
|
|
//console.log(1)
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
stage._mousedown({
|
|
|
|
clientX: 380,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 98 + top
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
});
|
2012-11-15 14:14:15 +08:00
|
|
|
//console.log(2)
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
test(!dragStart, 'dragstart event should not have been triggered');
|
2013-03-22 11:24:03 +08:00
|
|
|
//test(!dragMove, 'dragmove event should not have been triggered');
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
test(!dragEnd, 'dragend event should not have been triggered');
|
|
|
|
|
2013-04-03 13:29:56 +08:00
|
|
|
test(!Kinetic.Global.isDragging(), 'Global isDragging() should be false');
|
|
|
|
test(Kinetic.Global.isDragReady(), 'Global isDragReady()) should be true');
|
|
|
|
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
stage._mousemove({
|
|
|
|
clientX: 100,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 98 + top
|
2012-06-16 15:02:55 +08:00
|
|
|
});
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
|
2013-04-03 13:29:56 +08:00
|
|
|
test(Kinetic.Global.isDragging(), 'Global isDragging() should be true');
|
|
|
|
test(Kinetic.Global.isDragReady(), 'Global isDragReady()) should be true');
|
|
|
|
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
test(dragStart, 'dragstart event was not triggered');
|
2013-03-22 11:24:03 +08:00
|
|
|
//test(dragMove, 'dragmove event was not triggered');
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
test(!dragEnd, 'dragend event should not have been triggered');
|
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragBefore();
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
stage._mouseup({
|
|
|
|
clientX: 100,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 98 + top
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:circle});
|
|
|
|
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
test(dragStart, 'dragstart event was not triggered');
|
2013-03-24 11:02:11 +08:00
|
|
|
test(dragMove, 'dragmove event was not triggered');
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
test(dragEnd, 'dragend event was not triggered');
|
2013-03-24 11:02:11 +08:00
|
|
|
|
|
|
|
test(events.toString() === 'mouseup,dragend', 'mouseup should occur before dragend');
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
|
2013-04-03 13:29:56 +08:00
|
|
|
|
|
|
|
test(!Kinetic.Global.isDragging(), 'Global isDragging() should be false');
|
|
|
|
test(!Kinetic.Global.isDragReady(), 'Global isDragReady()) should be false');
|
|
|
|
|
2013-03-25 07:40:09 +08:00
|
|
|
testDataUrl(layer.toDataURL(), 'drag circle after', 'end data url is incorrect');
|
2013-03-22 15:46:41 +08:00
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
showHit(layer);
|
2013-03-22 15:46:41 +08:00
|
|
|
|
2013-04-08 01:52:33 +08:00
|
|
|
},
|
|
|
|
'destroy shape while dragging': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
|
|
|
var greenCircle = new Kinetic.Circle({
|
|
|
|
x: 40,
|
|
|
|
y: 40,
|
|
|
|
radius: 20,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
opacity: 0.5
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var circle = new Kinetic.Circle({
|
|
|
|
x: 380,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
opacity: 0.5
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.setDraggable(true);
|
|
|
|
|
|
|
|
layer.add(circle);
|
|
|
|
layer.add(greenCircle);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
|
|
|
|
|
|
|
|
|
|
|
var dragEnd = false;
|
|
|
|
|
|
|
|
|
|
|
|
circle.on('dragend', function() {
|
|
|
|
dragEnd = true;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
circle.on('mouseup', function() {
|
|
|
|
console.log('mouseup');
|
|
|
|
events.push('mouseup');
|
|
|
|
});
|
|
|
|
|
|
|
|
testDataUrl(layer.toDataURL(), 'drag circle before', 'start data url is incorrect');
|
|
|
|
|
|
|
|
test(!Kinetic.Global.isDragging(), 'Global isDragging() should be false');
|
|
|
|
test(!Kinetic.Global.isDragReady(), 'Global isDragReady()) should be false');
|
|
|
|
|
|
|
|
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 380,
|
|
|
|
clientY: 98 + top
|
|
|
|
});
|
|
|
|
|
|
|
|
test(!circle.isDragging(), 'circle should not be dragging');
|
|
|
|
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 100,
|
|
|
|
clientY: 98 + top
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test(circle.isDragging(), 'circle should be dragging');
|
|
|
|
test(!dragEnd, 'dragEnd should not have fired yet');
|
|
|
|
|
|
|
|
// at this point, we are in drag and drop mode
|
|
|
|
|
|
|
|
|
|
|
|
// removing or destroying the circle should trigger dragend
|
|
|
|
circle.destroy();
|
|
|
|
layer.draw();
|
|
|
|
|
|
|
|
test(!circle.isDragging(), 'destroying circle should stop drag and drop');
|
|
|
|
test(dragEnd, 'dragEnd should have fired');
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-16 16:21:35 +08:00
|
|
|
},
|
2012-11-15 13:55:16 +08:00
|
|
|
'cancel drag and drop by setting draggable to false': function(containerId) {
|
2012-06-20 08:06:31 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
|
|
|
throttle: 999
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var circle = new Kinetic.Circle({
|
2012-06-20 08:06:31 +08:00
|
|
|
x: 380,
|
|
|
|
y: 100,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
draggable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
var dragStart = false;
|
|
|
|
var dragMove = false;
|
|
|
|
var dragEnd = false;
|
|
|
|
|
|
|
|
circle.on('dragstart', function() {
|
|
|
|
dragStart = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('dragmove', function() {
|
|
|
|
dragMove = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('dragend', function() {
|
|
|
|
dragEnd = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('mousedown', function() {
|
|
|
|
circle.setDraggable(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(circle);
|
|
|
|
stage.add(layer);
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
2012-06-20 08:06:31 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* simulate drag and drop
|
|
|
|
*/
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 380,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-20 08:06:31 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 100,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-20 08:06:31 +08:00
|
|
|
});
|
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragBefore();
|
2012-06-20 08:06:31 +08:00
|
|
|
stage._mouseup({
|
|
|
|
clientX: 100,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-20 08:06:31 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:circle});
|
2012-06-20 08:06:31 +08:00
|
|
|
|
|
|
|
test(circle.getPosition().x === 380, 'circle x should be 380');
|
|
|
|
test(circle.getPosition().y === 100, 'circle y should be 100');
|
|
|
|
},
|
2012-11-15 13:55:16 +08:00
|
|
|
'drag and drop layer': function(containerId) {
|
2012-06-19 13:02:13 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
|
|
|
throttle: 999
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer({
|
|
|
|
drawFunc: function() {
|
|
|
|
var context = this.getContext();
|
|
|
|
context.beginPath();
|
|
|
|
context.moveTo(200, 50);
|
|
|
|
context.lineTo(420, 80);
|
|
|
|
context.quadraticCurveTo(300, 100, 260, 170);
|
|
|
|
context.closePath();
|
|
|
|
context.fillStyle = 'blue';
|
2012-07-19 14:28:45 +08:00
|
|
|
context.fill(context);
|
2012-06-19 13:02:13 +08:00
|
|
|
},
|
|
|
|
draggable: true
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var circle1 = new Kinetic.Circle({
|
2012-06-19 13:02:13 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var circle2 = new Kinetic.Circle({
|
2012-06-19 13:02:13 +08:00
|
|
|
x: 400,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'green'
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(circle1);
|
|
|
|
layer.add(circle2);
|
|
|
|
|
|
|
|
stage.add(layer);
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
2012-06-19 13:02:13 +08:00
|
|
|
|
2012-12-10 01:52:33 +08:00
|
|
|
//console.log(layer.toDataURL())
|
2013-03-25 07:40:09 +08:00
|
|
|
testDataUrl(layer.toDataURL(), 'drag layer before', 'start data url is incorrect');
|
2012-06-19 13:02:13 +08:00
|
|
|
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
/*
|
|
|
|
* simulate drag and drop
|
|
|
|
*/
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 399,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 96 + top
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
});
|
2012-06-19 13:02:13 +08:00
|
|
|
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
stage._mousemove({
|
|
|
|
clientX: 210,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 109 + top
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
});
|
2012-06-19 13:02:13 +08:00
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragBefore();
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
stage._mouseup({
|
|
|
|
clientX: 210,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 109 + top
|
2012-06-19 13:02:13 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:circle2});
|
2013-01-28 14:25:16 +08:00
|
|
|
|
2012-12-10 01:52:33 +08:00
|
|
|
//console.log(layer.toDataURL())
|
2013-03-25 07:40:09 +08:00
|
|
|
testDataUrl(layer.toDataURL(), 'drag layer after', 'end data url is incorrect');
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Test.Modules.EVENT = {
|
2013-03-24 16:05:37 +08:00
|
|
|
'draw events': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
|
|
|
throttle: 999
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
|
|
|
|
var circle = new Kinetic.Circle({
|
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red'
|
|
|
|
});
|
|
|
|
|
|
|
|
var eventNodes = [];
|
|
|
|
var savedEvt;
|
|
|
|
var order = [];
|
|
|
|
|
|
|
|
layer.on('draw', function(evt) {
|
|
|
|
savedEvt = evt;
|
|
|
|
eventNodes.push(this.getNodeType());
|
|
|
|
order.push('layer draw');
|
|
|
|
});
|
|
|
|
|
|
|
|
stage.on('draw', function(evt) {
|
|
|
|
eventNodes.push(this.getNodeType());
|
|
|
|
order.push('stage draw');
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.on('beforeDraw', function(evt) {
|
|
|
|
order.push('layer beforeDraw');
|
|
|
|
});
|
|
|
|
|
|
|
|
stage.on('beforeDraw', function(evt) {
|
|
|
|
order.push('stage beforeDraw');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
layer.add(circle);
|
|
|
|
stage.add(layer);
|
|
|
|
|
2013-05-13 23:56:09 +08:00
|
|
|
// Note: draw events no longer bubble
|
|
|
|
//test(eventNodes.toString() === 'Layer,Stage', 'layer draw event should have fired followed by stage draw event');
|
2013-03-24 16:05:37 +08:00
|
|
|
|
|
|
|
test(savedEvt.node.getNodeType() === 'Layer', 'event object should contain a node property which is Layer');
|
|
|
|
|
2013-05-13 23:56:09 +08:00
|
|
|
//test(order.toString() === 'layer beforeDraw,stage beforeDraw,layer draw,stage draw', 'order should be: layer beforeDraw,stage beforeDraw,layer draw,stage draw');
|
2013-03-24 16:05:37 +08:00
|
|
|
|
|
|
|
},
|
2013-03-24 13:56:22 +08:00
|
|
|
'click mapping': function(containerId) {
|
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
|
|
|
throttle: 999
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer({
|
|
|
|
drawFunc: function() {
|
|
|
|
var context = this.getContext();
|
|
|
|
context.beginPath();
|
|
|
|
context.moveTo(200, 50);
|
|
|
|
context.lineTo(420, 80);
|
|
|
|
context.quadraticCurveTo(300, 100, 260, 170);
|
|
|
|
context.closePath();
|
|
|
|
context.fillStyle = 'blue';
|
|
|
|
context.fill(context);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var redCircle = new Kinetic.Circle({
|
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red'
|
|
|
|
});
|
|
|
|
|
|
|
|
var greenCircle = new Kinetic.Circle({
|
|
|
|
x: 400,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
2013-03-24 14:19:24 +08:00
|
|
|
fill: 'green'
|
2013-03-24 13:56:22 +08:00
|
|
|
});
|
|
|
|
|
2013-03-24 14:19:24 +08:00
|
|
|
var redClicks = 0;
|
|
|
|
var greenClicks = 0;
|
|
|
|
|
2013-03-24 13:56:22 +08:00
|
|
|
redCircle.on('click', function() {
|
|
|
|
console.log('clicked redCircle');
|
2013-03-24 14:19:24 +08:00
|
|
|
redClicks++;
|
2013-03-24 13:56:22 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
greenCircle.on('click', function() {
|
|
|
|
console.log('clicked greenCircle');
|
2013-03-24 14:19:24 +08:00
|
|
|
greenClicks++;
|
2013-03-24 13:56:22 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
layer.add(redCircle);
|
|
|
|
layer.add(greenCircle);
|
|
|
|
|
|
|
|
stage.add(layer);
|
2013-03-24 14:19:24 +08:00
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
2013-03-24 13:56:22 +08:00
|
|
|
|
|
|
|
showHit(layer);
|
|
|
|
|
2013-03-24 14:19:24 +08:00
|
|
|
// mousedown and mouseup on red circle
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 284,
|
|
|
|
clientY: 113 + top
|
|
|
|
});
|
|
|
|
|
|
|
|
Kinetic.DD._endDragBefore();
|
|
|
|
stage._mouseup({
|
|
|
|
clientX: 284,
|
|
|
|
clientY: 113 + top
|
|
|
|
});
|
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:redCircle});
|
|
|
|
|
|
|
|
test(redClicks === 1, 'red circle should have 1 click');
|
|
|
|
test(greenClicks === 0, 'green circle should have 0 clicks');
|
|
|
|
|
|
|
|
// mousedown and mouseup on green circle
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 397,
|
|
|
|
clientY: 108 + top
|
|
|
|
});
|
|
|
|
|
|
|
|
Kinetic.DD._endDragBefore();
|
|
|
|
stage._mouseup({
|
|
|
|
clientX: 397,
|
|
|
|
clientY: 108 + top
|
|
|
|
});
|
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:redCircle});
|
|
|
|
|
|
|
|
test(redClicks === 1, 'red circle should have 1 click');
|
|
|
|
test(greenClicks === 1, 'green circle should have 1 click');
|
|
|
|
|
|
|
|
// mousedown red circle and mouseup on green circle
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 284,
|
|
|
|
clientY: 113 + top
|
|
|
|
});
|
|
|
|
|
|
|
|
Kinetic.DD._endDragBefore();
|
|
|
|
stage._mouseup({
|
|
|
|
clientX: 397,
|
|
|
|
clientY: 108 + top
|
|
|
|
});
|
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:redCircle});
|
|
|
|
|
|
|
|
test(redClicks === 1, 'red circle should still have 1 click');
|
|
|
|
test(greenClicks === 1, 'green circle should still have 1 click');
|
|
|
|
|
2013-03-24 13:56:22 +08:00
|
|
|
},
|
2013-02-21 13:30:24 +08:00
|
|
|
'text events': function(containerId) {
|
2013-02-12 14:55:24 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
|
|
|
throttle: 999
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var text = new Kinetic.Text({
|
|
|
|
x: 290,
|
|
|
|
y: 111,
|
|
|
|
fontFamily: 'Calibri',
|
|
|
|
fontSize: 30,
|
|
|
|
fill: 'red',
|
|
|
|
text: 'Testing 123',
|
|
|
|
draggable: true
|
|
|
|
});
|
|
|
|
|
|
|
|
var click = false
|
|
|
|
|
|
|
|
text.on('click', function() {
|
2013-03-24 11:02:11 +08:00
|
|
|
console.log('text click');
|
2013-02-12 14:55:24 +08:00
|
|
|
click = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(text);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
|
|
|
|
|
|
|
showHit(layer);
|
|
|
|
|
|
|
|
stage._mousedown({
|
2013-03-24 11:02:11 +08:00
|
|
|
clientX: 300,
|
|
|
|
clientY: 120 + top
|
2013-02-12 14:55:24 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
|
|
|
|
Kinetic.DD._endDragBefore();
|
2013-02-12 14:55:24 +08:00
|
|
|
stage._mouseup({
|
2013-03-24 11:02:11 +08:00
|
|
|
clientX: 300,
|
|
|
|
clientY: 120 + top
|
2013-02-12 14:55:24 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:text});
|
2013-02-12 14:55:24 +08:00
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
//TODO: can't get this to pass
|
2013-02-12 14:55:24 +08:00
|
|
|
test(click, 'click event should have been fired when mousing down and then up on text');
|
|
|
|
|
|
|
|
},
|
2012-11-15 13:55:16 +08:00
|
|
|
'modify fill stroke and stroke width on hover with circle': function(containerId) {
|
2012-06-16 16:21:35 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
2012-07-15 15:06:35 +08:00
|
|
|
height: 200,
|
|
|
|
throttle: 999
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer({
|
|
|
|
throttle: 999
|
2012-06-16 16:21:35 +08:00
|
|
|
});
|
2012-08-26 14:56:39 +08:00
|
|
|
var circle = new Kinetic.Circle({
|
2012-06-16 16:21:35 +08:00
|
|
|
x: 380,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
2012-06-19 08:56:12 +08:00
|
|
|
circle.on('mouseover', function() {
|
2012-06-16 16:21:35 +08:00
|
|
|
this.setFill('yellow');
|
|
|
|
this.setStroke('purple');
|
|
|
|
this.setStrokeWidth(20);
|
2012-07-15 15:06:35 +08:00
|
|
|
//console.log('mouseover')
|
2012-06-16 16:21:35 +08:00
|
|
|
layer.draw();
|
|
|
|
});
|
|
|
|
|
2012-06-19 08:56:12 +08:00
|
|
|
circle.on('mouseout', function() {
|
2012-06-16 16:21:35 +08:00
|
|
|
this.setFill('red');
|
|
|
|
this.setStroke('black');
|
|
|
|
this.setStrokeWidth(4);
|
2012-07-15 15:06:35 +08:00
|
|
|
//console.log('mouseout')
|
2012-06-16 16:21:35 +08:00
|
|
|
layer.draw();
|
|
|
|
});
|
|
|
|
|
2012-06-19 08:56:12 +08:00
|
|
|
layer.add(circle);
|
2012-06-16 16:21:35 +08:00
|
|
|
stage.add(layer);
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
2012-06-16 16:21:35 +08:00
|
|
|
|
2013-03-25 07:40:09 +08:00
|
|
|
testDataUrl(layer.toDataURL(), 'modify fill and stroke before', 'start data url is incorrect');
|
2012-06-16 16:21:35 +08:00
|
|
|
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
stage._mousemove({
|
|
|
|
clientX: 377,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 101 + top
|
2012-06-16 16:21:35 +08:00
|
|
|
});
|
toDataURL() is now synchronous, and works with all nodes, including the stage, layers, groups, and shapes. This also sets things up nicely for node caching. You can now cache anything, including the whole stage, layers, groups, or shapes, manifested as Kinetic Images that were instantiated with data urls
2012-07-15 09:10:37 +08:00
|
|
|
|
2013-03-25 07:40:09 +08:00
|
|
|
testDataUrl(layer.toDataURL(), 'modify fill and stroke after', 'mid data url is incorrect');
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-07-15 15:06:35 +08:00
|
|
|
// move mouse back out of circle
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 157,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 138 + top
|
2012-07-15 15:06:35 +08:00
|
|
|
});
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 157,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 138 + top
|
2012-07-15 15:06:35 +08:00
|
|
|
});
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2013-03-25 07:40:09 +08:00
|
|
|
testDataUrl(layer.toDataURL(), 'modify fill and stroke before', 'end data url is incorrect');
|
2012-06-19 08:56:12 +08:00
|
|
|
},
|
2012-11-15 13:55:16 +08:00
|
|
|
'mousedown mouseup mouseover mouseout mousemove click dblclick / touchstart touchend touchmove tap dbltap': function(containerId) {
|
2012-06-19 08:56:12 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
2012-07-06 15:27:55 +08:00
|
|
|
throttle: 999
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var circle = new Kinetic.Circle({
|
2012-06-19 08:56:12 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
strokeWidth: 4
|
|
|
|
});
|
|
|
|
|
|
|
|
// desktop events
|
|
|
|
var mousedown = false;
|
|
|
|
var mouseup = false;
|
|
|
|
var click = false;
|
|
|
|
var dblclick = false;
|
|
|
|
var mouseover = false;
|
|
|
|
var mouseout = false;
|
|
|
|
var mousemove = false;
|
|
|
|
|
|
|
|
// mobile events
|
|
|
|
var touchstart = false;
|
|
|
|
var touchend = false;
|
|
|
|
var tap = false;
|
|
|
|
var touchmove = false;
|
|
|
|
var dbltap = false;
|
|
|
|
|
|
|
|
circle.on('mousedown', function() {
|
|
|
|
mousedown = true;
|
2012-11-15 13:55:16 +08:00
|
|
|
//log('mousedown');
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('mouseup', function() {
|
|
|
|
mouseup = true;
|
2012-11-15 13:55:16 +08:00
|
|
|
//log('mouseup');
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('mouseover', function() {
|
|
|
|
mouseover = true;
|
2012-11-15 13:55:16 +08:00
|
|
|
//log('mouseover');
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('mouseout', function() {
|
|
|
|
mouseout = true;
|
2012-11-15 13:55:16 +08:00
|
|
|
//log('mouseout');
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('mousemove', function() {
|
|
|
|
mousemove = true;
|
2012-11-15 13:55:16 +08:00
|
|
|
//log('mousemove');
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('click', function() {
|
|
|
|
click = true;
|
2012-11-15 13:55:16 +08:00
|
|
|
//log('click');
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('dblclick', function() {
|
|
|
|
dblclick = true;
|
2012-11-15 13:55:16 +08:00
|
|
|
//log('dblclick');
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
/*
|
|
|
|
* mobile
|
|
|
|
*/
|
|
|
|
circle.on('touchstart', function() {
|
|
|
|
touchstart = true;
|
|
|
|
//log('touchstart');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('touchend', function() {
|
|
|
|
touchend = true;
|
|
|
|
//log('touchend');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('touchmove', function() {
|
|
|
|
touchmove = true;
|
|
|
|
//log('touchmove');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('tap', function(evt) {
|
|
|
|
tap = true;
|
|
|
|
//log('tap');
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('dbltap', function() {
|
|
|
|
dbltap = true;
|
|
|
|
//log('dbltap');
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.add(circle);
|
|
|
|
stage.add(layer);
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
2012-06-19 08:56:12 +08:00
|
|
|
|
|
|
|
// move mouse to center of circle to trigger mouseover
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 290,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test(mouseover, '1) mouseover should be true');
|
2012-08-17 14:03:28 +08:00
|
|
|
test(!mousemove, '1) mousemove should be true');
|
2012-06-19 08:56:12 +08:00
|
|
|
test(!mousedown, '1) mousedown should be false');
|
|
|
|
test(!mouseup, '1) mouseup should be false');
|
|
|
|
test(!click, '1) click should be false');
|
|
|
|
test(!dblclick, '1) dblclick should be false');
|
|
|
|
test(!mouseout, '1) mouseout should be false');
|
|
|
|
|
|
|
|
// move mouse again inside circle to trigger mousemove
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 290,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test(mouseover, '2) mouseover should be true');
|
|
|
|
test(mousemove, '2) mousemove should be true');
|
|
|
|
test(!mousedown, '2) mousedown should be false');
|
|
|
|
test(!mouseup, '2) mouseup should be false');
|
|
|
|
test(!click, '2) click should be false');
|
|
|
|
test(!dblclick, '2) dblclick should be false');
|
|
|
|
test(!mouseout, '2) mouseout should be false');
|
|
|
|
|
|
|
|
// mousedown inside circle
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 290,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test(mouseover, '3) mouseover should be true');
|
|
|
|
test(mousemove, '3) mousemove should be true');
|
|
|
|
test(mousedown, '3) mousedown should be true');
|
|
|
|
test(!mouseup, '3) mouseup should be false');
|
|
|
|
test(!click, '3) click should be false');
|
|
|
|
test(!dblclick, '3) dblclick should be false');
|
|
|
|
test(!mouseout, '3) mouseout should be false');
|
|
|
|
|
|
|
|
// mouseup inside circle
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragBefore();
|
2012-06-19 08:56:12 +08:00
|
|
|
stage._mouseup({
|
|
|
|
clientX: 290,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:circle});
|
2012-06-19 08:56:12 +08:00
|
|
|
|
|
|
|
test(mouseover, '4) mouseover should be true');
|
|
|
|
test(mousemove, '4) mousemove should be true');
|
|
|
|
test(mousedown, '4) mousedown should be true');
|
|
|
|
test(mouseup, '4) mouseup should be true');
|
|
|
|
test(click, '4) click should be true');
|
|
|
|
test(!dblclick, '4) dblclick should be false');
|
|
|
|
test(!mouseout, '4) mouseout should be false');
|
|
|
|
|
|
|
|
// mousedown inside circle
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 290,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test(mouseover, '5) mouseover should be true');
|
|
|
|
test(mousemove, '5) mousemove should be true');
|
|
|
|
test(mousedown, '5) mousedown should be true');
|
|
|
|
test(mouseup, '5) mouseup should be true');
|
|
|
|
test(click, '5) click should be true');
|
|
|
|
test(!dblclick, '5) dblclick should be false');
|
|
|
|
test(!mouseout, '5) mouseout should be false');
|
|
|
|
|
|
|
|
// mouseup inside circle to trigger double click
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragBefore();
|
2012-06-19 08:56:12 +08:00
|
|
|
stage._mouseup({
|
|
|
|
clientX: 290,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:circle});
|
2012-06-19 08:56:12 +08:00
|
|
|
|
|
|
|
test(mouseover, '6) mouseover should be true');
|
|
|
|
test(mousemove, '6) mousemove should be true');
|
|
|
|
test(mousedown, '6) mousedown should be true');
|
|
|
|
test(mouseup, '6) mouseup should be true');
|
|
|
|
test(click, '6) click should be true');
|
|
|
|
test(dblclick, '6) dblclick should be true');
|
|
|
|
test(!mouseout, '6) mouseout should be false');
|
|
|
|
|
|
|
|
// move mouse outside of circle to trigger mouseout
|
2012-07-06 15:27:55 +08:00
|
|
|
stage._mousemove({
|
|
|
|
clientX: 0,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
stage._mousemove({
|
2012-06-19 08:56:12 +08:00
|
|
|
clientX: 0,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-19 08:56:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test(mouseover, '7) mouseover should be true');
|
|
|
|
test(mousemove, '7) mousemove should be true');
|
|
|
|
test(mousedown, '7) mousedown should be true');
|
|
|
|
test(mouseup, '7) mouseup should be true');
|
|
|
|
test(click, '7) click should be true');
|
|
|
|
test(dblclick, '7) dblclick should be true');
|
|
|
|
test(mouseout, '7) mouseout should be true');
|
2012-07-06 15:27:55 +08:00
|
|
|
|
2012-06-19 08:56:12 +08:00
|
|
|
/*
|
|
|
|
* mobile tests
|
|
|
|
*/
|
|
|
|
// reset inDoubleClickWindow
|
|
|
|
stage.inDoubleClickWindow = false;
|
|
|
|
|
|
|
|
// touchstart circle
|
|
|
|
stage._touchstart({
|
|
|
|
clientX: 289,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top,
|
2012-06-19 08:56:12 +08:00
|
|
|
preventDefault: function() {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test(touchstart, '8) touchstart should be true');
|
|
|
|
test(!touchmove, '8) touchmove should be false');
|
|
|
|
test(!touchend, '8) touchend should be false');
|
|
|
|
test(!tap, '8) tap should be false');
|
|
|
|
test(!dbltap, '8) dbltap should be false');
|
|
|
|
|
|
|
|
// touchend circle
|
|
|
|
stage._touchend({
|
|
|
|
clientX: 289,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top,
|
2012-06-19 08:56:12 +08:00
|
|
|
preventDefault: function() {
|
|
|
|
}
|
|
|
|
});
|
2013-01-28 14:25:16 +08:00
|
|
|
// end drag is tied to document mouseup and touchend event
|
|
|
|
// which can't be simulated. call _endDrag manually
|
2013-03-24 11:02:11 +08:00
|
|
|
//Kinetic.DD._endDrag();
|
2012-06-19 08:56:12 +08:00
|
|
|
|
|
|
|
test(touchstart, '9) touchstart should be true');
|
|
|
|
test(!touchmove, '9) touchmove should be false');
|
|
|
|
test(touchend, '9) touchend should be true');
|
|
|
|
test(tap, '9) tap should be true');
|
|
|
|
test(!dbltap, '9) dbltap should be false');
|
|
|
|
|
|
|
|
// touchstart circle
|
|
|
|
stage._touchstart({
|
|
|
|
clientX: 289,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top,
|
2012-06-19 08:56:12 +08:00
|
|
|
preventDefault: function() {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test(touchstart, '10) touchstart should be true');
|
|
|
|
test(!touchmove, '10) touchmove should be false');
|
|
|
|
test(touchend, '10) touchend should be true');
|
|
|
|
test(tap, '10) tap should be true');
|
|
|
|
test(!dbltap, '10) dbltap should be false');
|
|
|
|
|
|
|
|
// touchend circle to triger dbltap
|
|
|
|
stage._touchend({
|
|
|
|
clientX: 289,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top,
|
2012-06-19 08:56:12 +08:00
|
|
|
preventDefault: function() {
|
|
|
|
}
|
|
|
|
});
|
2013-01-28 14:25:16 +08:00
|
|
|
// end drag is tied to document mouseup and touchend event
|
|
|
|
// which can't be simulated. call _endDrag manually
|
2013-03-24 11:02:11 +08:00
|
|
|
//Kinetic.DD._endDrag();
|
2012-06-19 08:56:12 +08:00
|
|
|
|
|
|
|
test(touchstart, '11) touchstart should be true');
|
|
|
|
test(!touchmove, '11) touchmove should be false');
|
|
|
|
test(touchend, '11) touchend should be true');
|
|
|
|
test(tap, '11) tap should be true');
|
|
|
|
test(dbltap, '11) dbltap should be true');
|
|
|
|
|
|
|
|
// touchmove circle
|
|
|
|
stage._touchmove({
|
|
|
|
clientX: 290,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top,
|
2012-06-19 08:56:12 +08:00
|
|
|
preventDefault: function() {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test(touchstart, '12) touchstart should be true');
|
|
|
|
test(touchmove, '12) touchmove should be true');
|
|
|
|
test(touchend, '12) touchend should be true');
|
|
|
|
test(tap, '12) tap should be true');
|
|
|
|
test(dbltap, '12) dbltap should be true');
|
2012-06-19 14:52:25 +08:00
|
|
|
},
|
2012-11-15 13:55:16 +08:00
|
|
|
'test group mousedown events': function(containerId) {
|
2012-06-19 14:52:25 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var group = new Kinetic.Group();
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var redCircle = new Kinetic.Circle({
|
2012-06-19 14:52:25 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 80,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
name: 'red'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var greenCircle = new Kinetic.Circle({
|
2012-06-19 14:52:25 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 40,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
name: 'green'
|
|
|
|
});
|
|
|
|
|
|
|
|
group.add(redCircle);
|
|
|
|
group.add(greenCircle);
|
|
|
|
|
|
|
|
layer.add(group);
|
|
|
|
stage.add(layer);
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
2012-06-19 14:52:25 +08:00
|
|
|
|
|
|
|
var groupMousedowns = 0;
|
|
|
|
var greenCircleMousedowns = 0;
|
|
|
|
|
|
|
|
group.on('mousedown', function() {
|
|
|
|
groupMousedowns++;
|
|
|
|
});
|
|
|
|
|
|
|
|
greenCircle.on('mousedown', function() {
|
|
|
|
greenCircleMousedowns++;
|
|
|
|
});
|
|
|
|
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 285,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 100 + top
|
2012-06-19 14:52:25 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test(groupMousedowns === 1, 'groupMousedowns should be 1');
|
|
|
|
test(greenCircleMousedowns === 1, 'greenCircleMousedowns should be 1');
|
|
|
|
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 332,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 139 + top
|
2012-06-19 14:52:25 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test(groupMousedowns === 2, 'groupMousedowns should be 2');
|
|
|
|
test(greenCircleMousedowns === 1, 'greenCircleMousedowns should be 1');
|
|
|
|
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 285,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 92 + top
|
2012-06-19 14:52:25 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test(groupMousedowns === 3, 'groupMousedowns should be 3');
|
|
|
|
test(greenCircleMousedowns === 2, 'greenCircleMousedowns should be 2');
|
|
|
|
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 221,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 146 + top
|
2012-06-19 14:52:25 +08:00
|
|
|
});
|
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
//test(groupMousedowns === 4, 'groupMousedowns should be 4');
|
2012-06-19 14:52:25 +08:00
|
|
|
test(greenCircleMousedowns === 2, 'greenCircleMousedowns should be 2');
|
2012-07-06 15:27:55 +08:00
|
|
|
},
|
2012-11-15 13:55:16 +08:00
|
|
|
'group mouseenter events': function(containerId) {
|
2012-07-06 15:27:55 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
|
|
|
throttle: 9999
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var group = new Kinetic.Group({
|
|
|
|
name: 'group'
|
|
|
|
});
|
|
|
|
|
2012-10-04 01:53:09 +08:00
|
|
|
var redMouseenters = 0;
|
|
|
|
var redMouseleaves = 0;
|
|
|
|
var greenMouseenters = 0;
|
|
|
|
var greenMouseleaves = 0;
|
|
|
|
var groupMouseenters = 0;
|
|
|
|
var groupMouseleaves = 0;
|
2012-07-06 15:27:55 +08:00
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var redCircle = new Kinetic.Circle({
|
2012-07-06 15:27:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 80,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
|
|
|
name: 'red'
|
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
var greenCircle = new Kinetic.Circle({
|
2012-07-06 15:27:55 +08:00
|
|
|
x: stage.getWidth() / 2,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 40,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'green',
|
|
|
|
stroke: 'black',
|
|
|
|
name: 'green'
|
|
|
|
});
|
|
|
|
|
2012-10-04 01:53:09 +08:00
|
|
|
group.on('mouseenter', function() {
|
|
|
|
groupMouseenters++;
|
2012-11-15 13:55:16 +08:00
|
|
|
//console.log('group over')
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
|
2012-10-04 01:53:09 +08:00
|
|
|
group.on('mouseleave', function() {
|
|
|
|
groupMouseleaves++;
|
2012-11-15 13:55:16 +08:00
|
|
|
//console.log('group out')
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
|
2012-10-04 01:53:09 +08:00
|
|
|
redCircle.on('mouseenter', function() {
|
|
|
|
redMouseenters++;
|
2012-11-15 13:55:16 +08:00
|
|
|
//console.log('red over')
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
|
2012-10-04 01:53:09 +08:00
|
|
|
redCircle.on('mouseleave', function() {
|
|
|
|
redMouseleaves++;
|
2012-11-15 13:55:16 +08:00
|
|
|
//console.log('red out')
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
|
2012-10-04 01:53:09 +08:00
|
|
|
greenCircle.on('mouseenter', function() {
|
|
|
|
greenMouseenters++;
|
2012-11-15 13:55:16 +08:00
|
|
|
//console.log('green over')
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
|
2012-10-04 01:53:09 +08:00
|
|
|
greenCircle.on('mouseleave', function() {
|
|
|
|
greenMouseleaves++;
|
2012-11-15 13:55:16 +08:00
|
|
|
//console.log('green out')
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
|
2012-08-26 14:56:39 +08:00
|
|
|
group.add(redCircle);
|
|
|
|
group.add(greenCircle);
|
2012-07-06 15:27:55 +08:00
|
|
|
|
|
|
|
layer.add(group);
|
|
|
|
stage.add(layer);
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
2012-07-06 15:27:55 +08:00
|
|
|
|
|
|
|
// move mouse outside of circles
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 177,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 146 + top
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
|
2012-10-04 01:53:09 +08:00
|
|
|
test(redMouseenters === 0, 'redMouseenters should be 0');
|
|
|
|
test(redMouseleaves === 0, 'redMouseleaves should be 0');
|
|
|
|
test(greenMouseenters === 0, 'greenMouseenters should be 0');
|
|
|
|
test(greenMouseleaves === 0, 'greenMouseleaves should be 0');
|
|
|
|
test(groupMouseenters === 0, 'groupMouseenters should be 0');
|
|
|
|
test(groupMouseleaves === 0, 'groupMouseleaves should be 0');
|
2012-07-06 15:27:55 +08:00
|
|
|
|
|
|
|
// move mouse inside of red circle
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 236,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 145 + top
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
|
2012-11-15 14:14:15 +08:00
|
|
|
//console.log('groupMouseenters=' + groupMouseenters);
|
2012-10-04 01:53:09 +08:00
|
|
|
|
|
|
|
test(redMouseenters === 1, 'redMouseenters should be 1');
|
|
|
|
test(redMouseleaves === 0, 'redMouseleaves should be 0');
|
|
|
|
test(greenMouseenters === 0, 'greenMouseenters should be 0');
|
|
|
|
test(greenMouseleaves === 0, 'greenMouseleaves should be 0');
|
|
|
|
test(groupMouseenters === 1, 'groupMouseenters should be 1');
|
|
|
|
test(groupMouseleaves === 0, 'groupMouseleaves should be 0');
|
2012-07-06 15:27:55 +08:00
|
|
|
|
|
|
|
// move mouse inside of green circle
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 284,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 118 + top
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
|
2012-10-04 01:53:09 +08:00
|
|
|
test(redMouseenters === 1, 'redMouseenters should be 1');
|
|
|
|
test(redMouseleaves === 1, 'redMouseleaves should be 1');
|
|
|
|
test(greenMouseenters === 1, 'greenMouseenters should be 1');
|
|
|
|
test(greenMouseleaves === 0, 'greenMouseleaves should be 0');
|
|
|
|
test(groupMouseenters === 1, 'groupMouseenters should be 1');
|
|
|
|
test(groupMouseleaves === 0, 'groupMouseleaves should be 0');
|
2012-07-06 15:27:55 +08:00
|
|
|
|
|
|
|
// move mouse back to red circle
|
|
|
|
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 345,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 105 + top
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 345,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 105 + top
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
|
2012-10-04 01:53:09 +08:00
|
|
|
test(redMouseenters === 2, 'redMouseenters should be 2');
|
|
|
|
test(redMouseleaves === 1, 'redMouseleaves should be 1');
|
|
|
|
test(greenMouseenters === 1, 'greenMouseenters should be 1');
|
|
|
|
test(greenMouseleaves === 1, 'greenMouseleaves should be 1');
|
|
|
|
test(groupMouseenters === 1, 'groupMouseenters should be 1');
|
|
|
|
test(groupMouseleaves === 0, 'groupMouseleaves should be 0');
|
2012-07-06 15:27:55 +08:00
|
|
|
|
|
|
|
// move mouse outside of circles
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 177,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 146 + top
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 177,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 146 + top
|
2012-07-06 15:27:55 +08:00
|
|
|
});
|
2012-10-04 01:53:09 +08:00
|
|
|
test(redMouseenters === 2, 'redMouseenters should be 2');
|
|
|
|
test(redMouseleaves === 2, 'redMouseleaves should be 2');
|
|
|
|
test(greenMouseenters === 1, 'greenMouseenters should be 1');
|
|
|
|
test(greenMouseleaves === 1, 'greenMouseleaves should be 1');
|
|
|
|
test(groupMouseenters === 1, 'groupMouseenters should be 1');
|
|
|
|
test(groupMouseleaves === 1, 'groupMouseleaves should be 1');
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-08-17 14:03:28 +08:00
|
|
|
//document.body.appendChild(layer.bufferCanvas.element)
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
//layer.bufferCanvas.element.style.marginTop = '220px';
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-07-07 01:05:37 +08:00
|
|
|
},
|
2012-11-15 13:55:16 +08:00
|
|
|
'test event bubbling': function(containerId) {
|
2012-07-07 01:05:37 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
|
|
|
throttle: 999
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
2012-08-26 14:56:39 +08:00
|
|
|
var circle = new Kinetic.Circle({
|
2012-07-07 01:05:37 +08:00
|
|
|
x: 380,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black'
|
|
|
|
});
|
|
|
|
|
|
|
|
var group1 = new Kinetic.Group();
|
|
|
|
var group2 = new Kinetic.Group();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stage
|
|
|
|
* |
|
|
|
|
* layer
|
|
|
|
* |
|
|
|
|
* group2
|
|
|
|
* |
|
|
|
|
* group1
|
|
|
|
* |
|
|
|
|
* circle
|
|
|
|
*/
|
|
|
|
|
|
|
|
group1.add(circle);
|
|
|
|
group2.add(group1);
|
|
|
|
layer.add(group2);
|
|
|
|
stage.add(layer);
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-11-15 13:55:16 +08:00
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
2012-07-07 01:05:37 +08:00
|
|
|
|
|
|
|
// events array
|
|
|
|
var e = [];
|
|
|
|
|
|
|
|
circle.on('click', function() {
|
|
|
|
e.push('circle');
|
|
|
|
});
|
|
|
|
group1.on('click', function() {
|
|
|
|
e.push('group1');
|
|
|
|
});
|
|
|
|
group2.on('click', function() {
|
|
|
|
e.push('group2');
|
|
|
|
});
|
|
|
|
layer.on('click', function() {
|
|
|
|
e.push('layer');
|
|
|
|
});
|
|
|
|
stage.on('click', function() {
|
|
|
|
e.push('stage');
|
|
|
|
});
|
|
|
|
// click on circle
|
|
|
|
stage._mousedown({
|
|
|
|
clientX: 374,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 114 + top
|
2012-07-07 01:05:37 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragBefore();
|
2012-07-07 01:05:37 +08:00
|
|
|
stage._mouseup({
|
|
|
|
clientX: 374,
|
2012-11-15 13:55:16 +08:00
|
|
|
clientY: 114 + top
|
2012-07-07 01:05:37 +08:00
|
|
|
});
|
2013-03-24 11:02:11 +08:00
|
|
|
Kinetic.DD._endDragAfter({dragEndNode:circle});
|
2012-07-07 01:05:37 +08:00
|
|
|
|
|
|
|
test(e.toString() === 'circle,group1,group2,layer,stage', 'problem with event bubbling');
|
2012-03-24 15:08:08 +08:00
|
|
|
}
|
2012-03-18 01:28:25 +08:00
|
|
|
};
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2012-11-19 11:50:50 +08:00
|
|
|
Test.Modules['HIT FUNCS'] = {
|
|
|
|
'test custom circle hit function': function(containerId) {
|
2012-11-15 14:14:15 +08:00
|
|
|
var stage = new Kinetic.Stage({
|
|
|
|
container: containerId,
|
|
|
|
width: 578,
|
|
|
|
height: 200,
|
|
|
|
throttle: 999
|
|
|
|
});
|
|
|
|
var layer = new Kinetic.Layer();
|
|
|
|
var circle = new Kinetic.Circle({
|
|
|
|
x: 380,
|
|
|
|
y: stage.getHeight() / 2,
|
|
|
|
radius: 70,
|
|
|
|
strokeWidth: 4,
|
|
|
|
fill: 'red',
|
|
|
|
stroke: 'black',
|
2012-12-10 01:52:33 +08:00
|
|
|
drawHitFunc: function(canvas) {
|
|
|
|
var context = canvas.getContext()
|
2012-11-15 14:14:15 +08:00
|
|
|
context.beginPath();
|
|
|
|
context.arc(0, 0, this.getRadius() + 100, 0, Math.PI * 2, true);
|
|
|
|
context.closePath();
|
2012-12-10 01:52:33 +08:00
|
|
|
canvas.fill(this);
|
|
|
|
canvas.stroke(this);
|
2012-11-15 14:14:15 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.setDraggable(true);
|
|
|
|
|
|
|
|
layer.add(circle);
|
|
|
|
stage.add(layer);
|
|
|
|
|
|
|
|
var top = stage.content.getBoundingClientRect().top;
|
|
|
|
|
|
|
|
var mouseovers = 0;
|
|
|
|
var mouseouts = 0;
|
|
|
|
|
|
|
|
circle.on('mouseover', function() {
|
|
|
|
mouseovers++;
|
|
|
|
});
|
|
|
|
|
|
|
|
circle.on('mouseout', function() {
|
|
|
|
mouseouts++;
|
|
|
|
});
|
2012-12-10 01:52:33 +08:00
|
|
|
// move mouse far outside circle
|
2012-11-15 14:14:15 +08:00
|
|
|
stage._mousemove({
|
|
|
|
clientX: 113,
|
|
|
|
clientY: 112 + top
|
|
|
|
});
|
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
test(mouseovers === 0, '1) mouseovers should be 0');
|
|
|
|
test(mouseouts === 0, '1) mouseouts should be 0');
|
2012-11-15 14:14:15 +08:00
|
|
|
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 286,
|
|
|
|
clientY: 118 + top
|
|
|
|
});
|
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
test(mouseovers === 1, '2) mouseovers should be 1');
|
|
|
|
test(mouseouts === 0, '2)mouseouts should be 0');
|
2012-11-15 14:14:15 +08:00
|
|
|
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 113,
|
|
|
|
clientY: 112 + top
|
|
|
|
});
|
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
test(mouseovers === 1, '3) mouseovers should be 1');
|
|
|
|
test(mouseouts === 1, '3) mouseouts should be 1');
|
2012-11-15 14:14:15 +08:00
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
showHit(layer);
|
|
|
|
|
|
|
|
|
2012-11-15 14:14:15 +08:00
|
|
|
// set drawBufferFunc with setter
|
|
|
|
|
2012-12-10 01:52:33 +08:00
|
|
|
circle.setDrawHitFunc(function(canvas) {
|
|
|
|
var context = canvas.getContext();
|
2012-11-15 14:14:15 +08:00
|
|
|
context.beginPath();
|
|
|
|
context.arc(0, 0, this.getRadius() - 50, 0, Math.PI * 2, true);
|
|
|
|
context.closePath();
|
2012-12-10 01:52:33 +08:00
|
|
|
canvas.fill(this);
|
|
|
|
canvas.stroke(this);
|
2012-11-15 14:14:15 +08:00
|
|
|
});
|
2012-12-10 01:52:33 +08:00
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
layer.getHitCanvas().clear();
|
2012-11-19 11:50:50 +08:00
|
|
|
layer.drawHit();
|
2013-03-24 11:02:11 +08:00
|
|
|
|
|
|
|
|
2012-11-15 14:14:15 +08:00
|
|
|
// move mouse far outside circle
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 113,
|
|
|
|
clientY: 112 + top
|
|
|
|
});
|
2012-12-10 01:52:33 +08:00
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
test(mouseovers === 1, '4) mouseovers should be 1');
|
|
|
|
test(mouseouts === 1, '4) mouseouts should be 1');
|
2012-12-10 01:52:33 +08:00
|
|
|
|
2012-11-15 14:14:15 +08:00
|
|
|
stage._mousemove({
|
|
|
|
clientX: 286,
|
|
|
|
clientY: 118 + top
|
|
|
|
});
|
2012-12-10 01:52:33 +08:00
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
test(mouseovers === 1, '5) mouseovers should be 1');
|
|
|
|
test(mouseouts === 1, '5) mouseouts should be 1');
|
2012-12-10 01:52:33 +08:00
|
|
|
|
2012-11-15 14:14:15 +08:00
|
|
|
stage._mousemove({
|
|
|
|
clientX: 321,
|
|
|
|
clientY: 112 + top
|
|
|
|
});
|
2012-12-10 01:52:33 +08:00
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
test(mouseovers === 1, '6) mouseovers should be 1');
|
|
|
|
test(mouseouts === 1, '6) mouseouts should be 1');
|
2012-12-10 01:52:33 +08:00
|
|
|
|
2012-11-15 14:14:15 +08:00
|
|
|
// move to center of circle
|
|
|
|
stage._mousemove({
|
|
|
|
clientX: 375,
|
|
|
|
clientY: 112 + top
|
|
|
|
});
|
2012-12-10 01:52:33 +08:00
|
|
|
|
2013-03-24 11:02:11 +08:00
|
|
|
test(mouseovers === 2, '7) mouseovers should be 2');
|
|
|
|
test(mouseouts === 1, '7) mouseouts should be 1');
|
|
|
|
|
2012-11-15 14:14:15 +08:00
|
|
|
}
|
|
|
|
};
|