diff --git a/src/shapes/group.class.js b/src/shapes/group.class.js index 6f03b50c..ee7ee312 100644 --- a/src/shapes/group.class.js +++ b/src/shapes/group.class.js @@ -266,6 +266,24 @@ }); }, + /** + * Returns object representation of an instance, in dataless mode. + * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output + * @return {Object} object representation of an instance + */ + toDatalessObject: function(propertiesToInclude) { + var objsToObject = this.getObjects().map(function(obj) { + var originalDefaults = obj.includeDefaultValues; + obj.includeDefaultValues = obj.group.includeDefaultValues; + var _obj = obj.toDatalessObject(propertiesToInclude); + obj.includeDefaultValues = originalDefaults; + return _obj; + }); + return extend(this.callSuper('toDatalessObject', propertiesToInclude), { + objects: objsToObject + }); + }, + /** * Renders instance on a given context * @param {CanvasRenderingContext2D} ctx context to render instance on diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 2f2265f5..56e470f2 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -1296,11 +1296,9 @@ /** * Renders controls and borders for the object * @param {CanvasRenderingContext2D} ctx Context to render on - * @param {Boolean} [noTransform] When true, context is not transformed */ - _renderControls: function(ctx, noTransform) { - if (!this.active || noTransform - || (this.group && this.group !== this.canvas.getActiveGroup())) { + _renderControls: function(ctx) { + if (!this.active || (this.group && this.group !== this.canvas.getActiveGroup())) { return; } diff --git a/test/unit/group.js b/test/unit/group.js index c84ff29f..11345ca9 100644 --- a/test/unit/group.js +++ b/test/unit/group.js @@ -590,6 +590,16 @@ equal(isTransparent(ctx, 11, 11, 0), false, '11,11 is opaque'); equal(isTransparent(ctx, 12, 12, 0), true, '12,12 is transparent'); }); + + test('group toDatalessObject', function() { + var rect1 = new fabric.Rect({ top: 1, left: 1, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: false}), + rect2 = new fabric.Rect({ top: 5, left: 5, width: 2, height: 2, strokeWidth: 0, fill: 'red', opacity: 1, objectCaching: false}), + pathGroup = new fabric.PathGroup([rect1, rect2], { sourcePath: 'sourcePath'}), + group = new fabric.Group([pathGroup]), + dataless = group.toDatalessObject(); + + equal(dataless.objects[0].paths, 'sourcePath', 'the paths have been changed with the sourcePath'); + }); // asyncTest('cloning group with image', function() { // var rect = new fabric.Rect({ top: 100, left: 100, width: 30, height: 10 }), // img = new fabric.Image(_createImageElement()),