Skip to content

Commit

Permalink
give getSrc a better role in this class. (#3189)
Browse files Browse the repository at this point in the history
  • Loading branch information
kherock authored and asturur committed Aug 22, 2016
1 parent 3544b72 commit 181cdec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@
*/
toObject: function(propertiesToInclude) {
var filters = [ ], resizeFilters = [ ],
element = this._originalElement,
scaleX = 1, scaleY = 1;

this.filters.forEach(function(filterObj) {
Expand All @@ -224,7 +223,7 @@
});

var object = extend(this.callSuper('toObject', propertiesToInclude), {
src: element ? element.src || element._src : '',
src: this.getSrc(),
filters: filters,
resizeFilters: resizeFilters,
crossOrigin: this.crossOrigin,
Expand Down Expand Up @@ -297,8 +296,12 @@
* @return {String} Source of an image
*/
getSrc: function() {
if (this.getElement()) {
return this.getElement().src || this.getElement()._src;
var element = this.getElement();
if (element) {
return fabric.isLikelyNode ? element._src : element.src;
}
else {
return this.src || '';
}
},

Expand Down
3 changes: 2 additions & 1 deletion test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
'flipX': false,
'flipY': false,
'opacity': 1,
'src': fabric.isLikelyNode ? undefined : IMG_SRC,
'src': IMG_SRC,
'shadow': null,
'visible': true,
'backgroundColor': '',
Expand Down Expand Up @@ -115,6 +115,7 @@
require('fs').readFile(src, function(err, imgData) {
if (err) throw err;
img.src = imgData;
img._src = src;
callback && callback();
});
}
Expand Down
9 changes: 5 additions & 4 deletions test/unit/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'flipX': false,
'flipY': false,
'opacity': 1,
'src': fabric.isLikelyNode ? undefined : IMG_SRC,
'src': IMG_SRC,
'shadow': null,
'visible': true,
'backgroundColor': '',
Expand Down Expand Up @@ -79,6 +79,7 @@
require('fs').readFile(src, function(err, imgData) {
if (err) throw err;
img.src = imgData;
img._src = src;
callback && callback();
});
}
Expand Down Expand Up @@ -131,7 +132,7 @@
if (toObject.height === 0) {
toObject.height = IMG_HEIGHT;
}
deepEqual(toObject, fabric.util.object.extend(REFERENCE_IMG_OBJECT, {src: ''}));
deepEqual(toObject, REFERENCE_IMG_OBJECT);
start();
});
});
Expand Down Expand Up @@ -212,15 +213,15 @@
asyncTest('toString', function() {
createImageObject(function(image) {
ok(typeof image.toString == 'function');
equal(image.toString(), '#<fabric.Image: { src: "' + (fabric.isLikelyNode ? undefined : IMG_SRC) + '" }>');
equal(image.toString(), '#<fabric.Image: { src: "' + IMG_SRC + '" }>');
start();
});
});

asyncTest('getSrc', function() {
createImageObject(function(image) {
ok(typeof image.getSrc == 'function');
equal(image.getSrc(), fabric.isLikelyNode ? undefined : IMG_SRC);
equal(image.getSrc(), IMG_SRC);
start();
});
});
Expand Down

0 comments on commit 181cdec

Please sign in to comment.