fix remove name bug

This commit is contained in:
lavrton
2015-02-08 09:52:19 +07:00
parent 264a4bab1c
commit 0ea9f0e257
5 changed files with 50 additions and 31 deletions

View File

@@ -1421,10 +1421,26 @@
return this;
},
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);
return this;
},