diff --git a/src/shapes/image.class.js b/src/shapes/image.class.js index 94f5dddf..54db3244 100644 --- a/src/shapes/image.class.js +++ b/src/shapes/image.class.js @@ -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,11 @@ _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); }, /** diff --git a/src/util/dom_misc.js b/src/util/dom_misc.js index fbcdf594..541cf201 100644 --- a/src/util/dom_misc.js +++ b/src/util/dom_misc.js @@ -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; } }