82
82
83
83
84
84
// Define the DOM Level 2 node type constants if they're missing.
85
- if ( ! Node ) GLOBAL . Node = { } ;
85
+ if ( ! GLOBAL . Node ) GLOBAL . Node = { } ;
86
86
87
87
if ( ! GLOBAL . Node . ELEMENT_NODE ) {
88
88
Object . extend ( GLOBAL . Node , {
2112
2112
}
2113
2113
2114
2114
var descendantOf ;
2115
- if ( DIV . contains && typeof DIV . contains === 'function' ) {
2116
- descendantOf = descendantOf_contains ;
2117
- } else if ( DIV . compareDocumentPosition ) {
2115
+ if ( DIV . compareDocumentPosition ) {
2118
2116
descendantOf = descendantOf_compareDocumentPosition ;
2117
+ } else if ( DIV . contains && typeof DIV . contains === 'function' ) {
2118
+ descendantOf = descendantOf_contains ;
2119
2119
} else {
2120
2120
descendantOf = descendantOf_DOM ;
2121
2121
}
2703
2703
2704
2704
for ( var property in styles ) {
2705
2705
if ( property === 'opacity' ) {
2706
- Element . setOpacity ( styles [ property ] ) ;
2706
+ Element . setOpacity ( element , styles [ property ] ) ;
2707
2707
} else {
2708
2708
var value = styles [ property ] ;
2709
2709
if ( property === 'float' || property === 'cssFloat' ) {
2820
2820
}
2821
2821
2822
2822
if ( style === 'opacity' )
2823
- return interpretOpacityValue_IE ( element , opacity ) ;
2823
+ return getOpacity_IE ( element ) ;
2824
2824
2825
2825
if ( value === 'auto' ) {
2826
2826
// If we need a dimension, return null for hidden elements, but return
2833
2833
return value ;
2834
2834
}
2835
2835
2836
+ function stripAlphaFromFilter_IE ( filter ) {
2837
+ return filter . replace ( / a l p h a \( [ ^ \) ] * \) / gi, '' ) ;
2838
+ }
2836
2839
2837
- function interpretOpacityValue_IE ( element , opacity ) {
2838
-
2840
+ function hasLayout_IE ( element ) {
2841
+ if ( ! element . currentStyle . hasLayout )
2842
+ element . style . zoom = 1 ;
2843
+ return element ;
2839
2844
}
2840
2845
2841
2846
2859
2864
* element.setStyle({ opacity: 0.5 });
2860
2865
* element.setStyle("opacity: 0.5");
2861
2866
**/
2862
- function setOpacity ( element , opacity ) {
2867
+ function setOpacity ( element , value ) {
2863
2868
element = $ ( element ) ;
2864
2869
if ( value == 1 || value === '' ) value = '' ;
2870
+ else if ( value < 0.00001 ) value = 0 ;
2871
+ element . style . opacity = value ;
2872
+ return element ;
2873
+ }
2874
+
2875
+ function setOpacity_IE ( element , value ) {
2876
+ element = hasLayout ( $ ( element ) ) ;
2877
+ var filter = Element . getStyle ( element , 'filter' ) ,
2878
+ style = element . style ;
2879
+
2880
+ if ( value == 1 || value === '' ) {
2881
+ // Remove the `alpha` filter from IE's `filter` CSS property. If there
2882
+ // is anything left after removal, put it back where it was; otherwise
2883
+ // remove the property.
2884
+ filter = stripAlphaFromFilter_IE ( filter ) ;
2885
+ if ( filter ) style . filter = filter ;
2886
+ else style . removeAttribute ( 'filter' ) ;
2887
+ return element ;
2888
+ }
2889
+
2865
2890
if ( value < 0.00001 ) value = 0 ;
2866
- element . style . opacity = value ;
2891
+
2892
+ style . filter = stripAlphaFromFilter_IE ( filter ) +
2893
+ 'alpha(opacity=' + ( value * 100 ) + ')' ;
2894
+
2867
2895
return element ;
2868
2896
}
2869
2897
2898
+
2870
2899
/**
2871
2900
* Element.getOpacity(@element) -> String | null
2872
2901
*
2876
2905
return Element . getStyle ( element , 'opacity' ) ;
2877
2906
}
2878
2907
2908
+ function getOpacity_IE ( element ) {
2909
+ var filter = Element . getStyle ( element , 'filter' ) ;
2910
+ var match = ( filter || '' ) . match ( / a l p h a \( o p a c i t y = ( .* ) \) / ) ;
2911
+ if ( match [ 1 ] ) return parseFloat ( match [ 1 ] ) / 100 ;
2912
+ return 1.0 ;
2913
+ }
2914
+
2915
+
2879
2916
Object . extend ( methods , {
2880
2917
setStyle : setStyle ,
2881
2918
getStyle : getStyle ,
2882
2919
setOpacity : setOpacity ,
2883
2920
getOpacity : getOpacity
2884
2921
} ) ;
2885
2922
2923
+ if ( 'styleFloat' in DIV . style ) {
2924
+ methods . getStyle = getStyle_IE ;
2925
+ methods . setOpacity = setOpacity_IE ;
2926
+ methods . getOpacity = getOpacity_IE ;
2927
+ }
2928
+
2929
+
2886
2930
2887
2931
// STORAGE
2888
2932
var UID = 0 ;
3326
3370
3327
3371
Element . addMethods ( methods ) ;
3328
3372
3329
- // TODO: move dimensions stuff to layout
3330
- // getHeight, getWidth, getDimensions, scrollTo,
3331
- // makePositioned, undoPositioned, makeClipping, undoClipping,
3332
- // clonePosition
3333
- // document.viewport
3334
-
3335
3373
} ) ( this ) ;
0 commit comments