Fix set({ key1: value1, key2: value2 }) not working with groups.

This commit is contained in:
kangax 2012-08-07 22:41:00 +02:00
parent 4b5816ae79
commit 3e6b880086
2 changed files with 36 additions and 37 deletions

View file

@ -161,31 +161,19 @@
},
/**
* Sets property to a given value
* @method set
* @param {String} name
* @param {Object|Function} value
* @return {fabric.Group} thisArg
* @chainable
* @private
*/
set: function(name, value) {
if (typeof value == 'function') {
// recurse
this.set(name, value(this[name]));
_set: function(key, value) {
if (key === 'fill' || key === 'opacity') {
var i = this.objects.length;
this[key] = value;
while (i--) {
this.objects[i].set(key, value);
}
}
else {
if (name === 'fill' || name === 'opacity') {
var i = this.objects.length;
this[name] = value;
while (i--) {
this.objects[i].set(name, value);
}
}
else {
this[name] = value;
}
this[key] = value;
}
return this;
},
/**

View file

@ -281,34 +281,45 @@
},
/**
* Basic setter
* @param {Any} property
* @param {Any} value
* @return {fabric.Object} thisArg
* Sets property to a given value
* @method set
* @param {String} name
* @param {Object|Function} value
* @return {fabric.Group} thisArg
* @chainable
*/
set: function(property, value) {
var shouldConstrainValue = (property === 'scaleX' || property === 'scaleY') && value < this.MIN_SCALE_LIMIT;
if (shouldConstrainValue) {
value = this.MIN_SCALE_LIMIT;
}
if (typeof property == 'object') {
for (var prop in property) {
this.set(prop, property[prop]);
set: function(key, value) {
if (typeof key === 'object') {
for (var prop in key) {
this._set(prop, key[prop]);
}
}
else {
if (property === 'angle') {
this.setAngle(value);
if (typeof value === 'function') {
this._set(key, value(this.get(key)));
}
else {
this[property] = value;
this._set(key, value);
}
}
return this;
},
_set: function(key, value) {
var shouldConstrainValue = (key === 'scaleX' || key === 'scaleY') &&
value < this.MIN_SCALE_LIMIT;
if (shouldConstrainValue) {
value = this.MIN_SCALE_LIMIT;
}
if (key === 'angle') {
this.setAngle(value);
}
else {
this[key] = value;
}
},
/**
* Toggles specified property from `true` to `false` or from `false` to `true`
* @method toggle