mirror of
https://github.com/konvajs/konva.git
synced 2025-09-19 19:07:59 +08:00
improved OO design for remove() and add()
This commit is contained in:
22
dist/kinetic-core.js
vendored
22
dist/kinetic-core.js
vendored
@@ -1411,11 +1411,6 @@ Kinetic.Node.prototype = {
|
|||||||
while(this.children && this.children.length > 0) {
|
while(this.children && this.children.length > 0) {
|
||||||
this.children[0].remove();
|
this.children[0].remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// do extra stuff if needed
|
|
||||||
if(this._remove !== undefined) {
|
|
||||||
this._remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@@ -2510,11 +2505,6 @@ Kinetic.Container.prototype = {
|
|||||||
go._pullNodes(stage);
|
go._pullNodes(stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// do extra stuff if needed
|
|
||||||
if(this._add !== undefined) {
|
|
||||||
this._add(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
// chainable
|
// chainable
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
@@ -3063,13 +3053,17 @@ Kinetic.Stage.prototype = {
|
|||||||
* add layer to stage
|
* add layer to stage
|
||||||
* @param {Layer} layer
|
* @param {Layer} layer
|
||||||
*/
|
*/
|
||||||
_add: function(layer) {
|
add: function(layer) {
|
||||||
|
Kinetic.Container.prototype.add.call(this, layer);
|
||||||
layer.canvas.setSize(this.attrs.width, this.attrs.height);
|
layer.canvas.setSize(this.attrs.width, this.attrs.height);
|
||||||
layer.bufferCanvas.setSize(this.attrs.width, this.attrs.height);
|
layer.bufferCanvas.setSize(this.attrs.width, this.attrs.height);
|
||||||
|
|
||||||
// draw layer and append canvas to container
|
// draw layer and append canvas to container
|
||||||
layer.draw();
|
layer.draw();
|
||||||
this.content.appendChild(layer.canvas.element);
|
this.content.appendChild(layer.canvas.element);
|
||||||
|
|
||||||
|
// chainable
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
_setUserPosition: function(evt) {
|
_setUserPosition: function(evt) {
|
||||||
if(!evt) {
|
if(!evt) {
|
||||||
@@ -3690,7 +3684,8 @@ Kinetic.Layer.prototype = {
|
|||||||
/**
|
/**
|
||||||
* remove layer from stage
|
* remove layer from stage
|
||||||
*/
|
*/
|
||||||
_remove: function() {
|
remove: function() {
|
||||||
|
Kinetic.Node.prototype.remove.call(this);
|
||||||
/*
|
/*
|
||||||
* remove canvas DOM from the document if
|
* remove canvas DOM from the document if
|
||||||
* it exists
|
* it exists
|
||||||
@@ -4196,7 +4191,8 @@ Kinetic.Shape.prototype = {
|
|||||||
var p = bufferCanvas.context.getImageData(Math.round(pos.x), Math.round(pos.y), 1, 1).data;
|
var p = bufferCanvas.context.getImageData(Math.round(pos.x), Math.round(pos.y), 1, 1).data;
|
||||||
return p[3] > 0;
|
return p[3] > 0;
|
||||||
},
|
},
|
||||||
_remove: function() {
|
remove: function() {
|
||||||
|
Kinetic.Node.prototype.remove.call(this);
|
||||||
delete Kinetic.Global.shapes[this.colorKey];
|
delete Kinetic.Global.shapes[this.colorKey];
|
||||||
},
|
},
|
||||||
__draw: function(canvas) {
|
__draw: function(canvas) {
|
||||||
|
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
@@ -86,11 +86,6 @@ Kinetic.Container.prototype = {
|
|||||||
go._pullNodes(stage);
|
go._pullNodes(stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// do extra stuff if needed
|
|
||||||
if(this._add !== undefined) {
|
|
||||||
this._add(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
// chainable
|
// chainable
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
@@ -229,7 +229,8 @@ Kinetic.Layer.prototype = {
|
|||||||
/**
|
/**
|
||||||
* remove layer from stage
|
* remove layer from stage
|
||||||
*/
|
*/
|
||||||
_remove: function() {
|
remove: function() {
|
||||||
|
Kinetic.Node.prototype.remove.call(this);
|
||||||
/*
|
/*
|
||||||
* remove canvas DOM from the document if
|
* remove canvas DOM from the document if
|
||||||
* it exists
|
* it exists
|
||||||
|
@@ -188,11 +188,6 @@ Kinetic.Node.prototype = {
|
|||||||
while(this.children && this.children.length > 0) {
|
while(this.children && this.children.length > 0) {
|
||||||
this.children[0].remove();
|
this.children[0].remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// do extra stuff if needed
|
|
||||||
if(this._remove !== undefined) {
|
|
||||||
this._remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
@@ -422,7 +422,8 @@ Kinetic.Shape.prototype = {
|
|||||||
var p = bufferCanvas.context.getImageData(Math.round(pos.x), Math.round(pos.y), 1, 1).data;
|
var p = bufferCanvas.context.getImageData(Math.round(pos.x), Math.round(pos.y), 1, 1).data;
|
||||||
return p[3] > 0;
|
return p[3] > 0;
|
||||||
},
|
},
|
||||||
_remove: function() {
|
remove: function() {
|
||||||
|
Kinetic.Node.prototype.remove.call(this);
|
||||||
delete Kinetic.Global.shapes[this.colorKey];
|
delete Kinetic.Global.shapes[this.colorKey];
|
||||||
},
|
},
|
||||||
__draw: function(canvas) {
|
__draw: function(canvas) {
|
||||||
|
@@ -418,13 +418,17 @@ Kinetic.Stage.prototype = {
|
|||||||
* add layer to stage
|
* add layer to stage
|
||||||
* @param {Layer} layer
|
* @param {Layer} layer
|
||||||
*/
|
*/
|
||||||
_add: function(layer) {
|
add: function(layer) {
|
||||||
|
Kinetic.Container.prototype.add.call(this, layer);
|
||||||
layer.canvas.setSize(this.attrs.width, this.attrs.height);
|
layer.canvas.setSize(this.attrs.width, this.attrs.height);
|
||||||
layer.bufferCanvas.setSize(this.attrs.width, this.attrs.height);
|
layer.bufferCanvas.setSize(this.attrs.width, this.attrs.height);
|
||||||
|
|
||||||
// draw layer and append canvas to container
|
// draw layer and append canvas to container
|
||||||
layer.draw();
|
layer.draw();
|
||||||
this.content.appendChild(layer.canvas.element);
|
this.content.appendChild(layer.canvas.element);
|
||||||
|
|
||||||
|
// chainable
|
||||||
|
return this;
|
||||||
},
|
},
|
||||||
_setUserPosition: function(evt) {
|
_setUserPosition: function(evt) {
|
||||||
if(!evt) {
|
if(!evt) {
|
||||||
|
Reference in New Issue
Block a user