mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 19:07:59 +08:00
it turns out that there was only a problem with moveDown. refactored logic proposed by Adam
This commit is contained in:
28
dist/kinetic-core.js
vendored
28
dist/kinetic-core.js
vendored
@@ -3,7 +3,7 @@
|
|||||||
* http://www.kineticjs.com/
|
* http://www.kineticjs.com/
|
||||||
* Copyright 2012, Eric Rowell
|
* Copyright 2012, Eric Rowell
|
||||||
* Licensed under the MIT or GPL Version 2 licenses.
|
* Licensed under the MIT or GPL Version 2 licenses.
|
||||||
* Date: Sep 14 2012
|
* Date: Sep 17 2012
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011 - 2012 by Eric Rowell
|
* Copyright (C) 2011 - 2012 by Eric Rowell
|
||||||
*
|
*
|
||||||
@@ -1734,10 +1734,8 @@ Kinetic.Node.prototype = {
|
|||||||
var stage = this.getStage();
|
var stage = this.getStage();
|
||||||
if(stage) {
|
if(stage) {
|
||||||
var children = stage.getChildren();
|
var children = stage.getChildren();
|
||||||
if(children.length > 1) {
|
stage.content.removeChild(this.canvas.element);
|
||||||
stage.content.removeChild(this.canvas.element);
|
stage.content.insertBefore(this.canvas.element, children[this.index + 1].canvas.element);
|
||||||
stage.content.insertBefore(this.canvas.element, children[this.index + 1].canvas.element);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1749,17 +1747,17 @@ Kinetic.Node.prototype = {
|
|||||||
*/
|
*/
|
||||||
moveToBottom: function() {
|
moveToBottom: function() {
|
||||||
var index = this.index;
|
var index = this.index;
|
||||||
this.parent.children.splice(index, 1);
|
if(index > 0) {
|
||||||
this.parent.children.unshift(this);
|
this.parent.children.splice(index, 1);
|
||||||
this.parent._setChildrenIndices();
|
this.parent.children.unshift(this);
|
||||||
|
this.parent._setChildrenIndices();
|
||||||
|
|
||||||
if(this.nodeType === 'Layer') {
|
if(this.nodeType === 'Layer') {
|
||||||
var stage = this.getStage();
|
var stage = this.getStage();
|
||||||
if(stage) {
|
if(stage) {
|
||||||
var children = stage.getChildren();
|
var children = stage.getChildren();
|
||||||
if(children.length > 1) {
|
stage.content.removeChild(this.canvas.element);
|
||||||
stage.content.removeChild(this.canvas.element);
|
stage.content.insertBefore(this.canvas.element, children[1].canvas.element);
|
||||||
stage.content.insertBefore(this.canvas.element, children[1].canvas.element);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
dist/kinetic-core.min.js
vendored
6
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
26
src/Node.js
26
src/Node.js
@@ -578,10 +578,8 @@ Kinetic.Node.prototype = {
|
|||||||
var stage = this.getStage();
|
var stage = this.getStage();
|
||||||
if(stage) {
|
if(stage) {
|
||||||
var children = stage.getChildren();
|
var children = stage.getChildren();
|
||||||
if(children.length > 1) {
|
stage.content.removeChild(this.canvas.element);
|
||||||
stage.content.removeChild(this.canvas.element);
|
stage.content.insertBefore(this.canvas.element, children[this.index + 1].canvas.element);
|
||||||
stage.content.insertBefore(this.canvas.element, children[this.index + 1].canvas.element);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -593,17 +591,17 @@ Kinetic.Node.prototype = {
|
|||||||
*/
|
*/
|
||||||
moveToBottom: function() {
|
moveToBottom: function() {
|
||||||
var index = this.index;
|
var index = this.index;
|
||||||
this.parent.children.splice(index, 1);
|
if(index > 0) {
|
||||||
this.parent.children.unshift(this);
|
this.parent.children.splice(index, 1);
|
||||||
this.parent._setChildrenIndices();
|
this.parent.children.unshift(this);
|
||||||
|
this.parent._setChildrenIndices();
|
||||||
|
|
||||||
if(this.nodeType === 'Layer') {
|
if(this.nodeType === 'Layer') {
|
||||||
var stage = this.getStage();
|
var stage = this.getStage();
|
||||||
if(stage) {
|
if(stage) {
|
||||||
var children = stage.getChildren();
|
var children = stage.getChildren();
|
||||||
if(children.length > 1) {
|
stage.content.removeChild(this.canvas.element);
|
||||||
stage.content.removeChild(this.canvas.element);
|
stage.content.insertBefore(this.canvas.element, children[1].canvas.element);
|
||||||
stage.content.insertBefore(this.canvas.element, children[1].canvas.element);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
test.run();
|
test.run();
|
||||||
|
|
||||||
document.getElementsByTagName('body')[0].addEventListener('mousemove', function(evt) {
|
document.getElementsByTagName('body')[0].addEventListener('mousemove', function(evt) {
|
||||||
console.log(evt.clientX + ',' + evt.clientY);
|
//console.log(evt.clientX + ',' + evt.clientY);
|
||||||
}, false);
|
}, false);
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@@ -4228,6 +4228,41 @@ Test.prototype.tests = {
|
|||||||
|
|
||||||
layer.draw();
|
layer.draw();
|
||||||
},
|
},
|
||||||
|
'*LAYERING - layer layer when only one layer': function(containerId) {
|
||||||
|
var stage = new Kinetic.Stage({
|
||||||
|
container: containerId,
|
||||||
|
width: 578,
|
||||||
|
height: 200
|
||||||
|
});
|
||||||
|
var layer = new Kinetic.Layer();
|
||||||
|
|
||||||
|
var bluecircle = new Kinetic.Circle({
|
||||||
|
x: 200,
|
||||||
|
y: stage.getHeight() / 2,
|
||||||
|
radius: 70,
|
||||||
|
fill: 'blue',
|
||||||
|
stroke: 'black',
|
||||||
|
strokeWidth: 4
|
||||||
|
});
|
||||||
|
|
||||||
|
layer.add(bluecircle);
|
||||||
|
stage.add(layer);
|
||||||
|
|
||||||
|
test(layer.getZIndex() === 0, 'layer should have zindex of 0');
|
||||||
|
|
||||||
|
layer.moveDown();
|
||||||
|
test(layer.getZIndex() === 0, 'layer should have zindex of 0');
|
||||||
|
|
||||||
|
layer.moveToBottom();
|
||||||
|
test(layer.getZIndex() === 0, 'layer should have zindex of 0');
|
||||||
|
|
||||||
|
layer.moveUp();
|
||||||
|
test(layer.getZIndex() === 0, 'layer should have zindex of 0');
|
||||||
|
|
||||||
|
layer.moveToTop();
|
||||||
|
test(layer.getZIndex() === 0, 'layer should have zindex of 0');
|
||||||
|
|
||||||
|
},
|
||||||
'LAYERING - move blue group on top of green group with moveToTop': function(containerId) {
|
'LAYERING - move blue group on top of green group with moveToTop': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
|
Reference in New Issue
Block a user