From 97ce8187fdcb956145d23ff96e01eefbe4074e73 Mon Sep 17 00:00:00 2001 From: javi Date: Tue, 12 Feb 2013 18:44:10 +0100 Subject: [PATCH] fixed setOpacity in IE7 and IE8 --- src/core/Browser.js | 2 +- src/dom/DomUtil.js | 10 +--------- src/layer/tile/TileLayer.js | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/core/Browser.js b/src/core/Browser.js index 06496d1e..8ce06adf 100644 --- a/src/core/Browser.js +++ b/src/core/Browser.js @@ -6,7 +6,6 @@ var ie = !!window.ActiveXObject, ie6 = ie && !window.XMLHttpRequest, - ie7 = ie && !document.querySelector, // terrible browser detection to work around Safari / iOS / Android browser bugs ua = navigator.userAgent.toLowerCase(), @@ -14,6 +13,7 @@ chrome = ua.indexOf('chrome') !== -1, android = ua.indexOf('android') !== -1, android23 = ua.search('android [23]') !== -1, + ie7 = ie && !document.querySelector && ua.search('msie 7') !== -1, mobile = typeof orientation !== undefined + '', msTouch = window.navigator && window.navigator.msPointerEnabled && diff --git a/src/dom/DomUtil.js b/src/dom/DomUtil.js index 98ad9668..dfeeb505 100644 --- a/src/dom/DomUtil.js +++ b/src/dom/DomUtil.js @@ -151,17 +151,9 @@ L.DomUtil = { var filter = false, filterName = 'DXImageTransform.Microsoft.Alpha'; - // filters collection throws an error if we try to retrieve a filter that doesn't exist - try { filter = el.filters.item(filterName); } catch (e) {} - value = Math.round(value * 100); - if (filter) { - filter.Enabled = (value !== 100); - filter.Opacity = value; - } else { - el.style.filter += ' progid:' + filterName + '(opacity=' + value + ')'; - } + el.style.filter = ' progid:' + filterName + '(opacity=' + value + ')'; } }, diff --git a/src/layer/tile/TileLayer.js b/src/layer/tile/TileLayer.js index d17b6184..ed1d6864 100644 --- a/src/layer/tile/TileLayer.js +++ b/src/layer/tile/TileLayer.js @@ -186,7 +186,9 @@ L.TileLayer = L.Class.extend({ }, _updateOpacity: function () { - L.DomUtil.setOpacity(this._container, this.options.opacity); + if (!L.Browser.ie7) { + L.DomUtil.setOpacity(this._container, this.options.opacity); + } // stupid webkit hack to force redrawing of tiles var i, @@ -199,6 +201,15 @@ L.TileLayer = L.Class.extend({ } } } + + if (L.Browser.ie7) { + for (i in tiles) { + if (tiles.hasOwnProperty(i)) { + tiles[i].style.filter = 'alpha(opacity=' + (this.options.opacity * 100) + ')'; + } + } + } + }, _initContainer: function () { @@ -471,6 +482,10 @@ L.TileLayer = L.Class.extend({ _createTile: function () { var tile = this._tileImg.cloneNode(false); tile.onselectstart = tile.onmousemove = L.Util.falseFn; + if (L.Browser.ie7 && this.options.opacity !== undefined) { + tile.style.filter = 'alpha(opacity=' + (this.options.opacity * 100) + ')'; + } + return tile; },