black list for clone function. fix #583

This commit is contained in:
Лаврёнов Антон
2014-03-02 21:51:35 +08:00
parent 53ac9329de
commit e5db9115a0
2 changed files with 13 additions and 3 deletions

View File

@@ -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];

View File

@@ -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');
/*