fix undefined name bug

This commit is contained in:
lavrton
2015-02-08 07:39:43 +07:00
parent 5df69badbf
commit 264a4bab1c
4 changed files with 19 additions and 12 deletions

View File

@@ -1442,7 +1442,8 @@
*/
addName : function(name) {
if (!this.hasName(name)) {
var newName = this.name() + ' ' + name;
var oldName = this.name();
var newName = oldName ? (oldName + ' ' + name) : name;
this.setName(newName);
}
return this;
@@ -1459,7 +1460,7 @@
* node.hasName('selected'); // return false
*/
hasName : function(name) {
var names = this.name().split(/\s/g);
var names = (this.name() || '').split(/\s/g);
return names.indexOf(name) !== -1;
},
/**
@@ -1475,7 +1476,7 @@
* node.name(); // return 'red'
*/
removeName : function(name) {
var names = this.name().split(/\s/g);
var names = (this.name() || '').split(/\s/g);
var index = names.indexOf(name);
if (index !== -1) {
names.splice(index, 1);