new naming methods

This commit is contained in:
lavrton
2015-02-08 06:24:11 +07:00
parent b51c5a0816
commit 5df69badbf
5 changed files with 135 additions and 8 deletions

View File

@@ -1428,6 +1428,60 @@
this._setAttr(NAME, name);
return this;
},
// naming methods
/**
* add name to node
* @method
* @memberof Konva.Node.prototype
* @param {String} name
* @returns {Konva.Node}
* @example
* node.name('red');
* node.addName('selected');
* node.name(); // return 'red selected'
*/
addName : function(name) {
if (!this.hasName(name)) {
var newName = this.name() + ' ' + name;
this.setName(newName);
}
return this;
},
/**
* check is node has name
* @method
* @memberof Konva.Node.prototype
* @param {String} name
* @returns {Boolean}
* @example
* node.name('red');
* node.hasName('red'); // return true
* node.hasName('selected'); // return false
*/
hasName : function(name) {
var names = this.name().split(/\s/g);
return names.indexOf(name) !== -1;
},
/**
* remove name from node
* @method
* @memberof Konva.Node.prototype
* @param {String} name
* @returns {Konva.Node}
* @example
* node.name('red selected');
* node.removeName('selected');
* node.hasName('selected'); // return false
* node.name(); // return 'red'
*/
removeName : function(name) {
var names = this.name().split(/\s/g);
var index = names.indexOf(name);
if (index !== -1) {
names.splice(index, 1);
this.setName(names.join(' '));
}
},
/**
* set attr
* @method