mirror of
https://github.com/konvajs/konva.git
synced 2025-12-17 18:01:15 +08:00
ignoring index functions (moveToTop, moveUp, moveDown, moveToBottom, setZIndex) if node has no parent
This commit is contained in:
20
src/Node.js
20
src/Node.js
@@ -860,6 +860,10 @@
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
moveToTop: function() {
|
moveToTop: function() {
|
||||||
|
if (!this.parent) {
|
||||||
|
Kinetic.Util.warn('Node has no parent. moveToTop function is ignored.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
var index = this.index;
|
var index = this.index;
|
||||||
this.parent.children.splice(index, 1);
|
this.parent.children.splice(index, 1);
|
||||||
this.parent.children.push(this);
|
this.parent.children.push(this);
|
||||||
@@ -873,6 +877,10 @@
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
moveUp: function() {
|
moveUp: function() {
|
||||||
|
if (!this.parent) {
|
||||||
|
Kinetic.Util.warn('Node has no parent. moveUp function is ignored.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
var index = this.index,
|
var index = this.index,
|
||||||
len = this.parent.getChildren().length;
|
len = this.parent.getChildren().length;
|
||||||
if(index < len - 1) {
|
if(index < len - 1) {
|
||||||
@@ -890,6 +898,10 @@
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
moveDown: function() {
|
moveDown: function() {
|
||||||
|
if (!this.parent) {
|
||||||
|
Kinetic.Util.warn('Node has no parent. moveDown function is ignored.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
var index = this.index;
|
var index = this.index;
|
||||||
if(index > 0) {
|
if(index > 0) {
|
||||||
this.parent.children.splice(index, 1);
|
this.parent.children.splice(index, 1);
|
||||||
@@ -906,6 +918,10 @@
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
moveToBottom: function() {
|
moveToBottom: function() {
|
||||||
|
if (!this.parent) {
|
||||||
|
Kinetic.Util.warn('Node has no parent. moveToBottom function is ignored.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
var index = this.index;
|
var index = this.index;
|
||||||
if(index > 0) {
|
if(index > 0) {
|
||||||
this.parent.children.splice(index, 1);
|
this.parent.children.splice(index, 1);
|
||||||
@@ -923,6 +939,10 @@
|
|||||||
* @returns {Kinetic.Node}
|
* @returns {Kinetic.Node}
|
||||||
*/
|
*/
|
||||||
setZIndex: function(zIndex) {
|
setZIndex: function(zIndex) {
|
||||||
|
if (!this.parent) {
|
||||||
|
Kinetic.Util.warn('Node has no parent. zIndex parameter is ignored.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
var index = this.index;
|
var index = this.index;
|
||||||
this.parent.children.splice(index, 1);
|
this.parent.children.splice(index, 1);
|
||||||
this.parent.children.splice(zIndex, 0, this);
|
this.parent.children.splice(zIndex, 0, this);
|
||||||
|
|||||||
Reference in New Issue
Block a user