mirror of
https://github.com/konvajs/konva.git
synced 2025-08-25 06:59:47 +08:00
fix remove name bug
This commit is contained in:
parent
264a4bab1c
commit
0ea9f0e257
37
konva.js
37
konva.js
@ -510,18 +510,11 @@ var Konva = {};
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
_addName: function(node, name) {
|
_addName: function(node, name) {
|
||||||
if(name !== undefined) {
|
if(name) {
|
||||||
|
if(!this.names[name]) {
|
||||||
var names = name.split(/\s/g);
|
this.names[name] = [];
|
||||||
for(var n = 0; n < names.length; n++) {
|
|
||||||
var subname = names[n];
|
|
||||||
if (subname) {
|
|
||||||
if(this.names[subname] === undefined) {
|
|
||||||
this.names[subname] = [];
|
|
||||||
}
|
|
||||||
this.names[subname].push(node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
this.names[name].push(node);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_removeName: function(name, _id) {
|
_removeName: function(name, _id) {
|
||||||
@ -3697,10 +3690,26 @@ var Konva = {};
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
setName: function(name) {
|
setName: function(name) {
|
||||||
var oldName = this.getName();
|
debugger;
|
||||||
|
var oldNames = (this.getName() || '').split(/\s/g);
|
||||||
|
var newNames = (name || '').split(/\s/g);
|
||||||
|
var subname, i;
|
||||||
|
// remove all subnames
|
||||||
|
for(i = 0; i < oldNames.length; i++) {
|
||||||
|
subname = oldNames[i];
|
||||||
|
if ((newNames.indexOf(subname)) === -1 && subname) {
|
||||||
|
Konva._removeName(subname, this._id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add new names
|
||||||
|
for(i = 0; i < newNames.length; i++) {
|
||||||
|
subname = newNames[i];
|
||||||
|
if ((oldNames.indexOf(subname) === -1) && subname) {
|
||||||
|
Konva._addName(this, subname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Konva._removeName(oldName, this._id);
|
|
||||||
Konva._addName(this, name);
|
|
||||||
this._setAttr(NAME, name);
|
this._setAttr(NAME, name);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
6
konva.min.js
vendored
6
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -292,18 +292,11 @@ var Konva = {};
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
_addName: function(node, name) {
|
_addName: function(node, name) {
|
||||||
if(name !== undefined) {
|
if(name) {
|
||||||
|
if(!this.names[name]) {
|
||||||
var names = name.split(/\s/g);
|
this.names[name] = [];
|
||||||
for(var n = 0; n < names.length; n++) {
|
|
||||||
var subname = names[n];
|
|
||||||
if (subname) {
|
|
||||||
if(this.names[subname] === undefined) {
|
|
||||||
this.names[subname] = [];
|
|
||||||
}
|
|
||||||
this.names[subname].push(node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
this.names[name].push(node);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_removeName: function(name, _id) {
|
_removeName: function(name, _id) {
|
||||||
|
22
src/Node.js
22
src/Node.js
@ -1421,10 +1421,26 @@
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
setName: function(name) {
|
setName: function(name) {
|
||||||
var oldName = this.getName();
|
debugger;
|
||||||
|
var oldNames = (this.getName() || '').split(/\s/g);
|
||||||
|
var newNames = (name || '').split(/\s/g);
|
||||||
|
var subname, i;
|
||||||
|
// remove all subnames
|
||||||
|
for(i = 0; i < oldNames.length; i++) {
|
||||||
|
subname = oldNames[i];
|
||||||
|
if ((newNames.indexOf(subname)) === -1 && subname) {
|
||||||
|
Konva._removeName(subname, this._id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add new names
|
||||||
|
for(i = 0; i < newNames.length; i++) {
|
||||||
|
subname = newNames[i];
|
||||||
|
if ((oldNames.indexOf(subname) === -1) && subname) {
|
||||||
|
Konva._addName(this, subname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Konva._removeName(oldName, this._id);
|
|
||||||
Konva._addName(this, name);
|
|
||||||
this._setAttr(NAME, name);
|
this._setAttr(NAME, name);
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
@ -1129,6 +1129,7 @@ suite('Node', function() {
|
|||||||
// removing name
|
// removing name
|
||||||
circle.removeName('foo');
|
circle.removeName('foo');
|
||||||
assert.equal(circle.getName(), 'myCircle');
|
assert.equal(circle.getName(), 'myCircle');
|
||||||
|
assert.equal(layer.find('.foo').length, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
Loading…
Reference in New Issue
Block a user