Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make .canvas property always present #2141

Merged
merged 3 commits into from
Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
if (object) {
this._objects.push(object);
object.group = this;
object._set('canvas', this.canvas);
}
// since _restoreObjectsState set objects inactive
this.forEachObject(this._setObjectActive, this);
Expand Down Expand Up @@ -163,6 +164,7 @@
*/
_onObjectAdded: function(object) {
object.group = this;
object._set('canvas', this.canvas);
},

/**
Expand Down Expand Up @@ -194,7 +196,7 @@
* @private
*/
_set: function(key, value) {
if (key in this.delegatedProperties) {
if (key in this.delegatedProperties || key === 'canvas') {
var i = this._objects.length;
while (i--) {
this._objects[i].set(key, value);
Expand Down
2 changes: 1 addition & 1 deletion src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@
*/
_onObjectAdded: function(obj) {
this.stateful && obj.setupState();
obj.canvas = this;
obj._set('canvas', this);
obj.setCoords();
this.fire('object:added', { target: obj });
obj.fire('added');
Expand Down
19 changes: 19 additions & 0 deletions test/unit/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,25 @@ test('toObject without default values', function() {
equal(group.insertAt(rect1, 2), group, 'should be chainable');
});

test('canvas property propagation', function() {
var g1 = makeGroupWith4Objects(),
g2 = makeGroupWith4Objects(),
rect1 = new fabric.Rect(),
rect2 = new fabric.Rect(),
group1 = new fabric.Group([g1]);

group1.add(g2);
group1.insertAt(rect1, 0);
g2.insertAt(rect2, 0);

canvas.add(group1);
equal(g2.canvas, canvas);
equal(g2._objects[3].canvas, canvas);
equal(g1.canvas, canvas);
equal(g1._objects[3].canvas, canvas);
equal(rect2.canvas, canvas);
equal(rect1.canvas, canvas);
});
// asyncTest('cloning group with image', function() {
// var rect = new fabric.Rect({ top: 100, left: 100, width: 30, height: 10 }),
// img = new fabric.Image(_createImageElement()),
Expand Down