mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-08 16:30:59 +00:00
Merge pull request #1212 from CapCap/master
Fix loadFromJSON 404s breaking fabric #1079
This commit is contained in:
commit
858b050ba2
3 changed files with 29 additions and 12 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue