From ffa4bbc8df739c6308c4c1258cc8ba7f72546d67 Mon Sep 17 00:00:00 2001 From: zakharov-aa Date: Wed, 28 Sep 2016 10:39:20 +0300 Subject: [PATCH] IE8 naturalWidth and naturalHeight more clear fix --- src/imagetilesource.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/imagetilesource.js b/src/imagetilesource.js index 5ae9e869..417243c6 100644 --- a/src/imagetilesource.js +++ b/src/imagetilesource.js @@ -72,13 +72,6 @@ $.TileSource.apply(this, [options]); }; - - /* IE8 fix for tileSources type: 'image' */ - $.getNatural = function (DOMelement) { - var img = new Image(); - img.src = DOMelement.src; - return { width: img.width, height: img.height }; - }; $.extend($.ImageTileSource.prototype, $.TileSource.prototype, /** @lends OpenSeadragon.ImageTileSource.prototype */{ /** @@ -121,8 +114,9 @@ } $.addEvent(image, 'load', function () { - _this.width = $.getNatural(image).width; - _this.height = $.getNatural(image).height; + /* IE8 fix since it has no naturalWidth and naturalHeight */ + _this.width = Object.prototype.hasOwnProperty.call(image, 'naturalWidth') ? image.naturalWidth : image.width; + _this.height = Object.prototype.hasOwnProperty.call(image, 'naturalHeight') ? image.naturalHeight : image.height; _this.aspectRatio = _this.width / _this.height; _this.dimensions = new $.Point(_this.width, _this.height); _this._tileWidth = _this.width; @@ -209,8 +203,9 @@ _buildLevels: function () { var levels = [{ url: this._image.src, - width: $.getNatural(this._image).width, - height: $.getNatural(this._image).height + /* IE8 fix since it has no naturalWidth and naturalHeight */ + width: Object.prototype.hasOwnProperty.call(this._image, 'naturalWidth') ? this._image.naturalWidth : this._image.width, + height: Object.prototype.hasOwnProperty.call(this._image, 'naturalHeight') ? this._image.naturalHeight : this._image.height }]; if (!this.buildPyramid || !$.supportsCanvas || !this.useCanvas) { @@ -219,8 +214,10 @@ return levels; } - var currentWidth = this._image.naturalWidth; - var currentHeight = this._image.naturalHeight; + /* IE8 fix since it has no naturalWidth and naturalHeight */ + var currentWidth = Object.prototype.hasOwnProperty.call(this._image, 'naturalWidth') ? this._image.naturalWidth : this._image.width; + var currentHeight = Object.prototype.hasOwnProperty.call(this._image, 'naturalHeight') ? this._image.naturalHeight : this._image.height; + var bigCanvas = document.createElement("canvas"); var bigContext = bigCanvas.getContext("2d");