mirror of
https://github.com/konvajs/konva.git
synced 2026-03-03 16:58:33 +08:00
more tweaks
This commit is contained in:
@@ -88,6 +88,7 @@
|
||||
constructor.prototype[method] = function(val) {
|
||||
this[setX](val.x);
|
||||
this[setY](val.y);
|
||||
|
||||
return this;
|
||||
};
|
||||
},
|
||||
|
||||
52
src/Node.js
52
src/Node.js
@@ -302,31 +302,6 @@
|
||||
|
||||
return ancestors;
|
||||
},
|
||||
/**
|
||||
* set attr
|
||||
* @method
|
||||
* @memberof Kinetic.Node.prototype
|
||||
* @param {String} attr
|
||||
* #param {*} val
|
||||
* @example
|
||||
* node.setAttr('x', 5);
|
||||
*/
|
||||
setAttr: function() {
|
||||
var args = Array.prototype.slice.call(arguments),
|
||||
attr = args[0],
|
||||
method = SET + Kinetic.Util._capitalize(attr),
|
||||
func = this[method];
|
||||
|
||||
args.shift();
|
||||
if(Kinetic.Util._isFunction(func)) {
|
||||
func.apply(this, args);
|
||||
}
|
||||
// otherwise set directly
|
||||
else {
|
||||
this.attrs[attr] = args[0];
|
||||
}
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
* get attrs object literal
|
||||
* @method
|
||||
@@ -1167,12 +1142,35 @@
|
||||
this._setAttr(NAME, name);
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
* set attr
|
||||
* @method
|
||||
* @memberof Kinetic.Node.prototype
|
||||
* @param {String} attr
|
||||
* #param {*} val
|
||||
* @example
|
||||
* node.setAttr('x', 5);
|
||||
*/
|
||||
setAttr: function() {
|
||||
var args = Array.prototype.slice.call(arguments),
|
||||
attr = args[0],
|
||||
val = args[1],
|
||||
method = SET + Kinetic.Util._capitalize(attr),
|
||||
func = this[method];
|
||||
|
||||
if(Kinetic.Util._isFunction(func)) {
|
||||
func.call(this, val);
|
||||
}
|
||||
// otherwise set directly
|
||||
else {
|
||||
this._setAttr(attr, val);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
_setAttr: function(key, val) {
|
||||
var oldVal;
|
||||
if(val !== undefined) {
|
||||
oldVal = this.attrs[key];
|
||||
// NOTE: before events removed to improve performance
|
||||
//this._fireBeforeChangeEvent(key, oldVal, val);
|
||||
this.attrs[key] = val;
|
||||
this._fireChangeEvent(key, oldVal, val);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user