Skip to content

Commit

Permalink
add custom properties to bg and overlay (#3250)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Sep 11, 2016
1 parent d7157d1 commit 5d0bf5a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/static_canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@
objects: this._toObjects(methodName, propertiesToInclude)
};

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

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

Expand Down Expand Up @@ -1148,23 +1148,23 @@
/**
* @private
*/
__serializeBgOverlay: function() {
__serializeBgOverlay: function(propertiesToInclude) {
var data = {
background: (this.backgroundColor && this.backgroundColor.toObject)
? this.backgroundColor.toObject()
? this.backgroundColor.toObject(propertiesToInclude)
: this.backgroundColor
};

if (this.overlayColor) {
data.overlay = this.overlayColor.toObject
? this.overlayColor.toObject()
? this.overlayColor.toObject(propertiesToInclude)
: this.overlayColor;
}
if (this.backgroundImage) {
data.backgroundImage = this.backgroundImage.toObject();
data.backgroundImage = this.backgroundImage.toObject(propertiesToInclude);
}
if (this.overlayImage) {
data.overlayImage = this.overlayImage.toObject();
data.overlayImage = this.overlayImage.toObject(propertiesToInclude);
}

return data;
Expand Down
33 changes: 33 additions & 0 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,23 @@
ok('backgroundImage' in canvas);
ok('overlayImage' in canvas);
ok('clipTo' in canvas);
ok('includeDefaultValues' in canvas);
ok('stateful' in canvas);
ok('renderOnAddRemove' in canvas);
ok('controlsAboveOverlay' in canvas);
ok('allowTouchScrolling' in canvas);
ok('imageSmoothingEnabled' in canvas);
ok('backgroundVpt' in canvas);
ok('overlayVpt' in canvas);

equal(canvas.includeDefaultValues, true);
equal(canvas.stateful, true);
equal(canvas.renderOnAddRemove, true);
equal(canvas.controlsAboveOverlay, false);
equal(canvas.allowTouchScrolling, false);
equal(canvas.imageSmoothingEnabled, true);
equal(canvas.backgroundVpt, true);
equal(canvas.overlayVpt, true);

notStrictEqual(canvas.viewportTransform, canvas2.viewportTransform);
});
Expand Down Expand Up @@ -766,6 +777,17 @@
});
});

asyncTest('toJSON backgroundImage with custom props', function() {
createImageObject(function(image) {
canvas.backgroundImage = image;
image.custom = 'yes';
var json = canvas.toJSON(['custom']);
equal(json.backgroundImage.custom, 'yes');
canvas.backgroundImage = null;
start();
});
});

asyncTest('toJSON overlayImage', function() {
createImageObject(function(image) {

Expand All @@ -782,6 +804,17 @@
});
});

asyncTest('toJSON overlayImage with custom props', function() {
createImageObject(function(image) {
canvas.overlayImage = image;
image.custom = 'yes';
var json = canvas.toJSON(['custom']);
equal(json.overlayImage.custom, 'yes');
canvas.overlayImage = null;
start();
});
});

test('toDatalessJSON', function() {
var path = new fabric.Path('M 100 100 L 300 100 L 200 300 z', {
sourcePath: 'http://example.com/'
Expand Down

0 comments on commit 5d0bf5a

Please sign in to comment.