Merge pull request #1212 from CapCap/master

Fix loadFromJSON 404s breaking fabric #1079
This commit is contained in:
Juriy Zaytsev 2014-03-08 00:29:17 -05:00
commit 858b050ba2
3 changed files with 29 additions and 12 deletions

View file

@ -137,6 +137,11 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
? this.source()
: this.source;
// if the image failed to load, return, and allow rest to continue loading
if (!source) {
return '';
}
// if an image
if (typeof source.src !== 'undefined') {
if (!source.complete) {

View file

@ -252,7 +252,9 @@
* @return {String} Source of an image
*/
getSrc: function() {
return this.getElement().src || this.getElement()._src;
if (this.getElement()) {
return this.getElement().src || this.getElement()._src;
}
},
/**
@ -281,6 +283,10 @@
*/
applyFilters: function(callback) {
if (!this._originalElement) {
return;
}
if (this.filters.length === 0) {
this._element = this._originalElement;
callback && callback();
@ -330,13 +336,13 @@
* @param {CanvasRenderingContext2D} ctx Context to render on
*/
_render: function(ctx) {
ctx.drawImage(
this._element,
-this.width / 2,
-this.height / 2,
this.width,
this.height
);
this._element && ctx.drawImage(
this._element,
-this.width / 2,
-this.height / 2,
this.width,
this.height
);
},
/**
@ -368,7 +374,9 @@
options || (options = { });
this.setOptions(options);
this._setWidthHeight(options);
this._element.crossOrigin = this.crossOrigin;
if (this._element) {
this._element.crossOrigin = this.crossOrigin;
}
},
/**
@ -394,11 +402,15 @@
_setWidthHeight: function(options) {
this.width = 'width' in options
? options.width
: (this.getElement().width || 0);
: (this.getElement()
? this.getElement().width || 0
: 0);
this.height = 'height' in options
? options.height
: (this.getElement().height || 0);
: (this.getElement()
? this.getElement().height || 0
: 0);
},
/**

View file

@ -68,7 +68,7 @@
* @param {String} className Class to add to an element
*/
function addClass(element, className) {
if ((' ' + element.className + ' ').indexOf(' ' + className + ' ') === -1) {
if (element && (' ' + element.className + ' ').indexOf(' ' + className + ' ') === -1) {
element.className += (element.className ? ' ' : '') + className;
}
}