Skip to content

Commit

Permalink
give getSrc a better role in this class.
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored and kherock committed Aug 22, 2016
1 parent 3938c83 commit 2015e3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/shapes/image.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,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 +297,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 element.src || element._src;
}
else {
return this.src || '';
}
},

Expand Down
6 changes: 3 additions & 3 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': fabric.isLikelyNode ? '' : IMG_SRC,
'shadow': null,
'visible': true,
'backgroundColor': '',
Expand Down Expand Up @@ -212,15 +212,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: "' + (fabric.isLikelyNode ? '' : 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(), fabric.isLikelyNode ? '' : IMG_SRC);
start();
});
});
Expand Down

0 comments on commit 2015e3e

Please sign in to comment.