mirror of
https://github.com/konvajs/konva.git
synced 2025-08-24 03:08:49 +08:00
fix undefined name bug
This commit is contained in:
parent
5df69badbf
commit
264a4bab1c
7
konva.js
7
konva.js
@ -3718,7 +3718,8 @@ var Konva = {};
|
||||
*/
|
||||
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;
|
||||
@ -3735,7 +3736,7 @@ var Konva = {};
|
||||
* 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;
|
||||
},
|
||||
/**
|
||||
@ -3751,7 +3752,7 @@ var Konva = {};
|
||||
* 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);
|
||||
|
4
konva.min.js
vendored
4
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -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);
|
||||
|
@ -1103,17 +1103,22 @@ suite('Node', function() {
|
||||
radius: 70,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myCircle foo'
|
||||
strokeWidth: 4
|
||||
});
|
||||
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
assert.equal(circle.getName(),'myCircle foo');
|
||||
assert.equal(circle.getName(), undefined);
|
||||
|
||||
circle.addName('foo');
|
||||
assert.equal(circle.getName(),'foo');
|
||||
circle.addName('myCircle');
|
||||
assert.equal(circle.getName(),'foo myCircle');
|
||||
|
||||
// add existing name
|
||||
circle.addName('foo');
|
||||
assert.equal(circle.getName(),'myCircle foo');
|
||||
assert.equal(circle.getName(),'foo myCircle');
|
||||
|
||||
|
||||
// check hasName
|
||||
assert.equal(circle.hasName('myCircle'), true);
|
||||
|
Loading…
Reference in New Issue
Block a user