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

includeDefaults for background and overlay #3415

Merged
merged 2 commits into from
Nov 12, 2016
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
8 changes: 4 additions & 4 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@
objects: this._toObjects(methodName, propertiesToInclude)
};

extend(data, this.__serializeBgOverlay(propertiesToInclude));
extend(data, this.__serializeBgOverlay(methodName, propertiesToInclude));

fabric.util.populateWithProperties(this, data, propertiesToInclude);

Expand Down Expand Up @@ -1081,7 +1081,7 @@
/**
* @private
*/
__serializeBgOverlay: function(propertiesToInclude) {
__serializeBgOverlay: function(methodName, propertiesToInclude) {
var data = {
background: (this.backgroundColor && this.backgroundColor.toObject)
? this.backgroundColor.toObject(propertiesToInclude)
Expand All @@ -1094,10 +1094,10 @@
: this.overlayColor;
}
if (this.backgroundImage) {
data.backgroundImage = this.backgroundImage.toObject(propertiesToInclude);
data.backgroundImage = this._toObject(this.backgroundImage, methodName, propertiesToInclude);
}
if (this.overlayImage) {
data.overlayImage = this.overlayImage.toObject(propertiesToInclude);
data.overlayImage = this._toObject(this.overlayImage, methodName, propertiesToInclude);
}

return data;
Expand Down
10 changes: 10 additions & 0 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,16 @@
equal(canvas.toObject().objects[0].type, rect.type);
});

test('toObject non includeDefaultValues', function() {
canvas.includeDefaultValues = false;
var rect = makeRect();
canvas.add(rect);
var cObject = canvas.toObject();
var expectedRect = { type: 'rect', width: 10, height: 10 };
deepEqual(cObject.objects[0], expectedRect, 'Rect should be exported withoud defaults');
canvas.includeDefaultValues = true;
});

test('toObject excludeFromExport', function() {
var rect = makeRect(), rect2 = makeRect(), rect3 = makeRect();
canvas.clear();
Expand Down