|
2915 | 2915 | return element;
|
2916 | 2916 | }
|
2917 | 2917 |
|
| 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 | + })(); |
2918 | 2923 |
|
2919 | 2924 | /**
|
2920 | 2925 | * Element.setOpacity(@element, opacity) -> [Element...]
|
|
2944 | 2949 | return element;
|
2945 | 2950 | }
|
2946 | 2951 |
|
| 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. |
2947 | 2956 | 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 | + |
2948 | 2961 | element = hasLayout_IE($(element));
|
2949 | 2962 | var filter = Element.getStyle(element, 'filter'),
|
2950 | 2963 | style = element.style;
|
|
2978 | 2991 | }
|
2979 | 2992 |
|
2980 | 2993 | 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 | + |
2981 | 2998 | var filter = Element.getStyle(element, 'filter');
|
2982 | 2999 | if (filter.length === 0) return 1.0;
|
2983 | 3000 | var match = (filter || '').match(/alpha\(opacity=(.*)\)/);
|
|
2992 | 3009 | setOpacity: setOpacity,
|
2993 | 3010 | getOpacity: getOpacity
|
2994 | 3011 | });
|
2995 |
| - |
| 3012 | + |
2996 | 3013 | if ('styleFloat' in DIV.style) {
|
2997 | 3014 | methods.getStyle = getStyle_IE;
|
2998 | 3015 | methods.setOpacity = setOpacity_IE;
|
|
0 commit comments