mirror of
https://github.com/konvajs/konva.git
synced 2025-11-24 08:46:44 +08:00
black list for clone function. fix #583
This commit is contained in:
11
src/Node.js
11
src/Node.js
@@ -22,6 +22,7 @@
|
||||
TRANSFORM = 'transform',
|
||||
UPPER_STAGE = 'Stage',
|
||||
VISIBLE = 'visible',
|
||||
CLONE_BLACK_LIST = ['id'],
|
||||
|
||||
TRANSFORM_CHANGE_STR = [
|
||||
'xChange.kinetic',
|
||||
@@ -36,6 +37,7 @@
|
||||
'transformsEnabledChange.kinetic'
|
||||
].join(SPACE);
|
||||
|
||||
|
||||
Kinetic.Util.addMethods(Kinetic.Node, {
|
||||
_init: function(config) {
|
||||
var that = this;
|
||||
@@ -1181,9 +1183,14 @@
|
||||
clone: function(obj) {
|
||||
// instantiate new node
|
||||
var className = this.getClassName(),
|
||||
node = new Kinetic[className](this.attrs),
|
||||
attrs = this.attrs,
|
||||
key, allListeners, len, n, listener;
|
||||
|
||||
// filter black attrs
|
||||
for (var i in CLONE_BLACK_LIST) {
|
||||
var blockAttr = CLONE_BLACK_LIST[i];
|
||||
delete attrs[blockAttr];
|
||||
}
|
||||
var node = new Kinetic[className](attrs);
|
||||
// copy over listeners
|
||||
for(key in this.eventListeners) {
|
||||
allListeners = this.eventListeners[key];
|
||||
|
||||
@@ -416,7 +416,8 @@ suite('Node', function() {
|
||||
shadowOffsetX: 20,
|
||||
shadowOffsetY: 20,
|
||||
draggable: true,
|
||||
name: 'myRect'
|
||||
name: 'myRect',
|
||||
id : 'myRect'
|
||||
});
|
||||
|
||||
var clicks = [];
|
||||
@@ -439,6 +440,8 @@ suite('Node', function() {
|
||||
assert.equal(rect.getShadowColor(), 'black');
|
||||
assert.equal(clone.getShadowColor(), 'black');
|
||||
|
||||
assert.equal(clone.id() == undefined, true, 'do not clone id');
|
||||
|
||||
clone.setShadowColor('green');
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user