give getSrc a better role in this class. (#3189)

This commit is contained in:
Kyle Herock 2016-08-22 04:43:17 -04:00 committed by Andrea Bogazzi
parent 3544b727be
commit 181cdec80c
3 changed files with 14 additions and 9 deletions

View file

@ -206,7 +206,6 @@
*/
toObject: function(propertiesToInclude) {
var filters = [ ], resizeFilters = [ ],
element = this._originalElement,
scaleX = 1, scaleY = 1;
this.filters.forEach(function(filterObj) {
@ -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,
@ -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 || '';
}
},

View file

@ -75,7 +75,7 @@
'flipX': false,
'flipY': false,
'opacity': 1,
'src': fabric.isLikelyNode ? undefined : IMG_SRC,
'src': IMG_SRC,
'shadow': null,
'visible': true,
'backgroundColor': '',
@ -115,6 +115,7 @@
require('fs').readFile(src, function(err, imgData) {
if (err) throw err;
img.src = imgData;
img._src = src;
callback && callback();
});
}

View file

@ -35,7 +35,7 @@
'flipX': false,
'flipY': false,
'opacity': 1,
'src': fabric.isLikelyNode ? undefined : IMG_SRC,
'src': IMG_SRC,
'shadow': null,
'visible': true,
'backgroundColor': '',
@ -79,6 +79,7 @@
require('fs').readFile(src, function(err, imgData) {
if (err) throw err;
img.src = imgData;
img._src = src;
callback && callback();
});
}
@ -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();
});
});
@ -212,7 +213,7 @@
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();
});
});
@ -220,7 +221,7 @@
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();
});
});