Skip to content

Commit

Permalink
Fix fabric.Group#toObject not serializing children image objects. Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kangax committed Oct 8, 2012
1 parent 999f7f5 commit 307c950
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
5 changes: 2 additions & 3 deletions dist/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -8534,8 +8534,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
G_vmlCanvasManager.initElement(el);
}

this.setCoords();
el.width = this.getBoundingRectWidth();
el.width = this.getBoundingRectWidth();
el.height = this.getBoundingRectHeight();

fabric.util.wrapElement(el, 'div');
Expand Down Expand Up @@ -11602,7 +11601,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, {
*/
toObject: function() {
return extend(this.callSuper('toObject'), {
objects: invoke(this.objects, 'clone')
objects: invoke(this.objects, 'toObject')
});
},

Expand Down
2 changes: 1 addition & 1 deletion dist/all.min.js

Large diffs are not rendered by default.

Binary file modified dist/all.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion src/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
*/
toObject: function() {
return extend(this.callSuper('toObject'), {
objects: invoke(this.objects, 'clone')
objects: invoke(this.objects, 'toObject')
});
},

Expand Down
3 changes: 1 addition & 2 deletions src/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,8 +1023,7 @@
G_vmlCanvasManager.initElement(el);
}

this.setCoords();
el.width = this.getBoundingRectWidth();
el.width = this.getBoundingRectWidth();
el.height = this.getBoundingRectHeight();

fabric.util.wrapElement(el, 'div');
Expand Down
30 changes: 30 additions & 0 deletions test/unit/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

var canvas = this.canvas = new fabric.Canvas();

function _createImageElement() {
return fabric.isLikelyNode ? new (require('canvas').Image) : fabric.document.createElement('img');
}

function makeGroupWith2Objects() {
var rect1 = new fabric.Rect({ top: 100, left: 100, width: 30, height: 10 }),
rect2 = new fabric.Rect({ top: 120, left: 50, width: 10, height: 40 });
Expand Down Expand Up @@ -285,4 +289,30 @@
equal(group.toSVG(), expectedSVG);
});

asyncTest('clonining group with 2 objects', function() {
var group = makeGroupWith2Objects();
group.clone(function(clone) {

ok(clone !== group);
deepEqual(clone.toObject(), group.toObject());

start();
});
});

// asyncTest('cloning group with image', function() {
// var rect = new fabric.Rect({ top: 100, left: 100, width: 30, height: 10 }),
// img = new fabric.Image(_createImageElement()),
// group = new fabric.Group([ rect, img ]);

// img.src = 'foo.png';

// group.clone(function(clone) {
// ok(clone !== group);
// deepEqual(clone.toObject(), group.toObject());

// start();
// });
// });

})();

0 comments on commit 307c950

Please sign in to comment.