Skip to content

Commit c8ef764

Browse files
Perform a feature test for CSS opacity and prefer it over the IE-proprietary filter property if it's present. IE 10 will drop support for filter except in compatibility rendering modes. (Andrew Dupont)
1 parent a07aa90 commit c8ef764

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/prototype/dom/dom.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,11 @@
29152915
return element;
29162916
}
29172917

2918+
// Opacity feature test borrowed from Modernizr.
2919+
var STANDARD_CSS_OPACITY_SUPPORTED = (function() {
2920+
DIV.style.cssText = "opacity:.55";
2921+
return /^0.55/.test(DIV.style.opacity);
2922+
})();
29182923

29192924
/**
29202925
* Element.setOpacity(@element, opacity) -> [Element...]
@@ -2944,7 +2949,15 @@
29442949
return element;
29452950
}
29462951

2952+
// The IE versions of `setOpacity` and `getOpacity` are aware of both
2953+
// the standard approach (an `opacity` property in CSS) and the old-style
2954+
// IE approach (a proprietary `filter` property). They are written to
2955+
// prefer the standard approach unless it isn't supported.
29472956
function setOpacity_IE(element, value) {
2957+
// Prefer the standard CSS approach unless it's not supported.
2958+
if (STANDARD_CSS_OPACITY_SUPPORTED)
2959+
return setOpacity(element, value);
2960+
29482961
element = hasLayout_IE($(element));
29492962
var filter = Element.getStyle(element, 'filter'),
29502963
style = element.style;
@@ -2978,6 +2991,10 @@
29782991
}
29792992

29802993
function getOpacity_IE(element) {
2994+
// Prefer the standard CSS approach unless it's not supported.
2995+
if (STANDARD_CSS_OPACITY_SUPPORTED)
2996+
return getOpacity(element);
2997+
29812998
var filter = Element.getStyle(element, 'filter');
29822999
if (filter.length === 0) return 1.0;
29833000
var match = (filter || '').match(/alpha\(opacity=(.*)\)/);
@@ -2992,7 +3009,7 @@
29923009
setOpacity: setOpacity,
29933010
getOpacity: getOpacity
29943011
});
2995-
3012+
29963013
if ('styleFloat' in DIV.style) {
29973014
methods.getStyle = getStyle_IE;
29983015
methods.setOpacity = setOpacity_IE;

0 commit comments

Comments
 (0)