it turns out that there was only a problem with moveDown. refactored logic proposed by Adam

This commit is contained in:
Eric Rowell
2012-09-17 22:49:24 -07:00
parent 0bf3db0688
commit 01c2b28a6c
5 changed files with 64 additions and 33 deletions

28
dist/kinetic-core.js vendored
View File

@@ -3,7 +3,7 @@
* http://www.kineticjs.com/
* Copyright 2012, Eric Rowell
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Sep 14 2012
* Date: Sep 17 2012
*
* Copyright (C) 2011 - 2012 by Eric Rowell
*
@@ -1734,10 +1734,8 @@ Kinetic.Node.prototype = {
var stage = this.getStage();
if(stage) {
var children = stage.getChildren();
if(children.length > 1) {
stage.content.removeChild(this.canvas.element);
stage.content.insertBefore(this.canvas.element, children[this.index + 1].canvas.element);
}
stage.content.removeChild(this.canvas.element);
stage.content.insertBefore(this.canvas.element, children[this.index + 1].canvas.element);
}
}
}
@@ -1749,17 +1747,17 @@ Kinetic.Node.prototype = {
*/
moveToBottom: function() {
var index = this.index;
this.parent.children.splice(index, 1);
this.parent.children.unshift(this);
this.parent._setChildrenIndices();
if(index > 0) {
this.parent.children.splice(index, 1);
this.parent.children.unshift(this);
this.parent._setChildrenIndices();
if(this.nodeType === 'Layer') {
var stage = this.getStage();
if(stage) {
var children = stage.getChildren();
if(children.length > 1) {
stage.content.removeChild(this.canvas.element);
stage.content.insertBefore(this.canvas.element, children[1].canvas.element);
if(this.nodeType === 'Layer') {
var stage = this.getStage();
if(stage) {
var children = stage.getChildren();
stage.content.removeChild(this.canvas.element);
stage.content.insertBefore(this.canvas.element, children[1].canvas.element);
}
}
}

File diff suppressed because one or more lines are too long

View File

@@ -578,10 +578,8 @@ Kinetic.Node.prototype = {
var stage = this.getStage();
if(stage) {
var children = stage.getChildren();
if(children.length > 1) {
stage.content.removeChild(this.canvas.element);
stage.content.insertBefore(this.canvas.element, children[this.index + 1].canvas.element);
}
stage.content.removeChild(this.canvas.element);
stage.content.insertBefore(this.canvas.element, children[this.index + 1].canvas.element);
}
}
}
@@ -593,17 +591,17 @@ Kinetic.Node.prototype = {
*/
moveToBottom: function() {
var index = this.index;
this.parent.children.splice(index, 1);
this.parent.children.unshift(this);
this.parent._setChildrenIndices();
if(index > 0) {
this.parent.children.splice(index, 1);
this.parent.children.unshift(this);
this.parent._setChildrenIndices();
if(this.nodeType === 'Layer') {
var stage = this.getStage();
if(stage) {
var children = stage.getChildren();
if(children.length > 1) {
stage.content.removeChild(this.canvas.element);
stage.content.insertBefore(this.canvas.element, children[1].canvas.element);
if(this.nodeType === 'Layer') {
var stage = this.getStage();
if(stage) {
var children = stage.getChildren();
stage.content.removeChild(this.canvas.element);
stage.content.insertBefore(this.canvas.element, children[1].canvas.element);
}
}
}

View File

@@ -15,7 +15,7 @@
test.run();
document.getElementsByTagName('body')[0].addEventListener('mousemove', function(evt) {
console.log(evt.clientX + ',' + evt.clientY);
//console.log(evt.clientX + ',' + evt.clientY);
}, false);
};
</script>

View File

@@ -4228,6 +4228,41 @@ Test.prototype.tests = {
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) {
var stage = new Kinetic.Stage({
container: containerId,