Skip to content

Commit

Permalink
fix group initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
sapics committed Apr 29, 2015
1 parent 91897de commit e21f1f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
24 changes: 17 additions & 7 deletions src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@
* @param {Object} [options] Options object
* @return {Object} thisArg
*/
initialize: function(objects, options) {
initialize: function(objects, options, skipPropagation) {
options = options || { };

this._objects = [];
skipPropagation && this.callSuper('initialize', options);

this._objects = objects || [];
for (var i = this._objects.length; i--; ) {
this._objects[i].group = this;
Expand All @@ -60,15 +63,22 @@
if (options.originX) {
this.originX = options.originX;
}

if (options.originY) {
this.originY = options.originY;
}

this._calcBounds();
this._updateObjectsCoords();

this.callSuper('initialize', options);
if (!skipPropagation) {
this._calcBounds();
this._updateObjectsCoords();
this.callSuper('initialize', options);
}
else {
for (i = this._objects.length; i--; ) {
this._objects[i].setCoords();
this._objects[i].__origHasControls = this._objects[i].hasControls;
this._objects[i].hasControls = false;
}
}

this.setCoords();
this.saveCoords();
Expand Down Expand Up @@ -548,7 +558,7 @@
fabric.Group.fromObject = function(object, callback) {
fabric.util.enlivenObjects(object.objects, function(enlivenedObjects) {
delete object.objects;
callback && callback(new fabric.Group(enlivenedObjects, object));
callback && callback(new fabric.Group(enlivenedObjects, object, true));
});
};

Expand Down
12 changes: 11 additions & 1 deletion test/unit/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
return new fabric.Group([ rect1, rect2 ], {strokeWidth: 0});
}

function makeGroupWith2ObjectsWithOpacity() {
var rect1 = new fabric.Rect({ top: 100, left: 100, width: 30, height: 10, strokeWidth: 0, opacity: 0.5 }),
rect2 = new fabric.Rect({ top: 120, left: 50, width: 10, height: 40, strokeWidth: 0, opacity: 0.8 });

return new fabric.Group([ rect1, rect2 ], {strokeWidth: 0});
}

function makeGroupWith4Objects() {
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 @@ -361,7 +368,7 @@ test('toObject without default values', function() {
});

asyncTest('fromObject', function() {
var group = makeGroupWith2Objects();
var group = makeGroupWith2ObjectsWithOpacity();

ok(typeof fabric.Group.fromObject == 'function');
var groupObject = group.toObject();
Expand All @@ -373,6 +380,9 @@ test('toObject without default values', function() {

ok(newGroupFromObject instanceof fabric.Group);

deepEqual(objectFromOldGroup.objects[0], objectFromNewGroup.objects[0]);
deepEqual(objectFromOldGroup.objects[1], objectFromNewGroup.objects[1]);

// delete `objects` arrays, since `assertHashEqual` fails to compare them for equality
delete objectFromOldGroup.objects;
delete objectFromNewGroup.objects;
Expand Down

0 comments on commit e21f1f4

Please sign in to comment.