mirror of
https://github.com/konvajs/konva.git
synced 2026-03-03 08:56:15 +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);
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ suite('Node', function() {
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('test offset attr change', function() {
|
||||
test.only('test offset attr change', function() {
|
||||
/*
|
||||
* the premise of this test to make sure that only
|
||||
* root level attributes trigger an attr change event.
|
||||
@@ -352,9 +352,9 @@ suite('Node', function() {
|
||||
width: 200,
|
||||
height: 50,
|
||||
fill: 'blue',
|
||||
offset: [10, 10],
|
||||
offset: {x:10, y:10},
|
||||
shadowColor: 'black',
|
||||
shadowOffset: [20, 20]
|
||||
shadowOffset: {x:20, y:20}
|
||||
});
|
||||
|
||||
layer.add(rect);
|
||||
@@ -367,7 +367,7 @@ suite('Node', function() {
|
||||
offsetChange = true;
|
||||
});
|
||||
|
||||
rect.setOffset(1, 2);
|
||||
rect.setOffset({x:1, y:2});
|
||||
|
||||
assert.equal(offsetChange, true);
|
||||
});
|
||||
@@ -1406,8 +1406,6 @@ suite('Node', function() {
|
||||
scaleX: 2
|
||||
});
|
||||
|
||||
console.log(rect4);
|
||||
|
||||
var rect5 = new Kinetic.Rect({
|
||||
x: 200,
|
||||
y: 20,
|
||||
|
||||
Reference in New Issue
Block a user