mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Simplify PathStyle further, by removing the _get/_setChildrenStyle methods and moving their functionality into the closure injection code.
This commit is contained in:
parent
4e05faaa11
commit
2c06ec965c
1 changed files with 13 additions and 21 deletions
|
@ -15,25 +15,6 @@ PathStyle = Base.extend(new function() {
|
|||
this[key] = style[key];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_setChildrenStyle: function(name, value) {
|
||||
for (var i = 0, l = this.item.children.length; i < l; i++) {
|
||||
this.item.children[i].style[name] = value;
|
||||
}
|
||||
},
|
||||
|
||||
_getChildrenStyle: function(name) {
|
||||
var style;
|
||||
for (var i = 0, l = this.item.children.length; i < l; i++) {
|
||||
if(!style) {
|
||||
style = this.item.children[i].style[name];
|
||||
} else if(style != this.item.children[i].style[name]) {
|
||||
// If there is another item with a different style:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return style;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +24,9 @@ PathStyle = Base.extend(new function() {
|
|||
|
||||
fields['set' + key.capitalize()] = function(value) {
|
||||
if(this.item && this.item.children) {
|
||||
this._setChildrenStyle(key, value);
|
||||
for (var i = 0, l = this.item.children.length; i < l; i++) {
|
||||
this.item.children[i].style[key] = value;
|
||||
}
|
||||
} else {
|
||||
this['_' + key] = value;
|
||||
}
|
||||
|
@ -51,7 +34,16 @@ PathStyle = Base.extend(new function() {
|
|||
|
||||
fields['get' + key.capitalize()] = function() {
|
||||
if(this.item && this.item.children) {
|
||||
return this._getChildrenStyle(key);
|
||||
var style;
|
||||
for (var i = 0, l = this.item.children.length; i < l; i++) {
|
||||
if(!style) {
|
||||
style = this.item.children[i].style[key];
|
||||
} else if(style != this.item.children[i].style[key]) {
|
||||
// If there is another item with a different style:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return style;
|
||||
} else {
|
||||
return this['_' + key];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue