mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 06:00:56 -05:00
Return 'this' in more places to facilitate chained calls inside the library.
This commit is contained in:
parent
76789e8df4
commit
5da4e89672
4 changed files with 23 additions and 12 deletions
|
@ -105,6 +105,7 @@ var Gradient = this.Gradient = Base.extend(/** @lends Gradient# */{
|
|||
stop.setRampPoint(i / (l - 1));
|
||||
}
|
||||
this._changed();
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -206,6 +206,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
this._project._changes.push(entry);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -268,7 +269,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
(namedChildren[name] = namedChildren[name] || []).push(this);
|
||||
children[name] = this;
|
||||
}
|
||||
this._changed(/*#=*/ ChangeFlag.ATTRIBUTE);
|
||||
return this._changed(/*#=*/ ChangeFlag.ATTRIBUTE);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -328,7 +329,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
if (value != this[name]) {
|
||||
this[name] = value;
|
||||
// #locked does not change appearance, all others do:
|
||||
this._changed(name === '_locked'
|
||||
return this._changed(name === '_locked'
|
||||
? /*#=*/ ChangeFlag.ATTRIBUTE : /*#=*/ Change.ATTRIBUTE);
|
||||
}
|
||||
};
|
||||
|
@ -480,6 +481,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
this._project._updateSelection(this);
|
||||
this._changed(/*#=*/ Change.ATTRIBUTE);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
_selected: false,
|
||||
|
@ -501,7 +503,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
this._children[i].setFullySelected(selected);
|
||||
}
|
||||
// Pass true for hidden noChildren argument
|
||||
this.setSelected(selected, true);
|
||||
return this.setSelected(selected, true);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -530,6 +532,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
if (this._parent)
|
||||
this._parent._changed(/*#=*/ ChangeFlag.CLIPPING);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
_clipMask: false,
|
||||
|
@ -588,7 +591,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// Calculate the distance to the current position, by which to
|
||||
// translate the item. Pass true for dontLink, as we do not need a
|
||||
// LinkedPoint to simply calculate this distance.
|
||||
this.translate(Point.read(arguments).subtract(this.getPosition(true)));
|
||||
return this.translate(Point.read(arguments).subtract(this.getPosition(true)));
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -605,7 +608,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
setMatrix: function(matrix) {
|
||||
// Use Matrix#initialize to easily copy over values.
|
||||
this._matrix.initialize(matrix);
|
||||
this._changed(/*#=*/ Change.GEOMETRY);
|
||||
return this._changed(/*#=*/ Change.GEOMETRY);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1223,7 +1226,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* @param {Item[]} items The items to be added as children
|
||||
*/
|
||||
addChildren: function(items) {
|
||||
this.insertChildren(this._children.length, items);
|
||||
return this.insertChildren(this._children.length, items);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1239,10 +1242,12 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
// an Item#children array. Use Array.prototype.slice because
|
||||
// in certain cases items is an arguments object
|
||||
items = items && Array.prototype.slice.apply(items);
|
||||
for (var i = 0, l = items && items.length; i < l; i++) {
|
||||
if (this.insertChild(index, items[i]))
|
||||
index++;
|
||||
var i = index;
|
||||
for (var j = 0, l = items && items.length; j < l; j++) {
|
||||
if (this.insertChild(i, items[j]))
|
||||
i++;
|
||||
}
|
||||
return i != index;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1417,6 +1422,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
this._children[i]._index = i;
|
||||
this._changed(/*#=*/ Change.HIERARCHY);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
// TODO: Item#isEditable is currently ignored in the documentation, as
|
||||
|
@ -2021,7 +2027,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
|||
newBounds = new Rectangle(new Point(),
|
||||
Size.create(bounds.width * scale, bounds.height * scale));
|
||||
newBounds.setCenter(rectangle.getCenter());
|
||||
this.setBounds(newBounds);
|
||||
return this.setBounds(newBounds);
|
||||
},
|
||||
|
||||
toString: function() {
|
||||
|
|
|
@ -115,6 +115,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
// Make sure new curves are calculated next time we call getCurves()
|
||||
delete this._curves;
|
||||
this._add(Segment.readAll(segments));
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -229,6 +230,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
}
|
||||
this._changed(/*#=*/ Change.GEOMETRY);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
// TODO: Consider adding getSubPath(a, b), returning a part of the current
|
||||
|
@ -683,7 +685,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
this._segments[i]._selectionState = selected
|
||||
? /*#=*/ SelectionState.POINT : 0;
|
||||
// No need to pass true for noChildren since Path has none anyway.
|
||||
this.setSelected(selected);
|
||||
return this.setSelected(selected);
|
||||
},
|
||||
|
||||
_updateSelection: function(segment, oldState, newState) {
|
||||
|
@ -738,7 +740,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
segments.push(new Segment(flattener.evaluate(pos, 0)));
|
||||
pos += step;
|
||||
}
|
||||
this.setSegments(segments);
|
||||
return this.setSegments(segments);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -785,6 +787,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
var fitter = new PathFitter(this, tolerance || 2.5);
|
||||
this.setSegments(fitter.fit());
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
// TODO: reduceSegments([flatness])
|
||||
|
|
|
@ -67,6 +67,7 @@ var Style = Item.extend({
|
|||
|
||||
owner['set' + stylePart] = function(style) {
|
||||
this[styleKey].initialize(style);
|
||||
return this;
|
||||
};
|
||||
|
||||
Base.each(src._defaults, function(value, key) {
|
||||
|
|
Loading…
Reference in a new issue