Projet

Général

Profil

Paste
Télécharger (3,51 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / libraries / flexslider-2.5.0 / bower_components / jquery / src / css / curCSS.js @ 0aee3c58

1
define([
2
        "exports",
3
        "../core",
4
        "./var/rnumnonpx",
5
        "./var/rmargin",
6
        "../selector" // contains
7
], function( exports, jQuery, rnumnonpx, rmargin ) {
8

    
9
var getStyles, curCSS,
10
        rposition = /^(top|right|bottom|left)$/;
11

    
12
if ( window.getComputedStyle ) {
13
        getStyles = function( elem ) {
14
                // Support: IE<=11+, Firefox<=30+ (#15098, #14150)
15
                // IE throws on elements created in popups
16
                // FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
17
                if ( elem.ownerDocument.defaultView.opener ) {
18
                        return elem.ownerDocument.defaultView.getComputedStyle( elem, null );
19
                }
20

    
21
                return window.getComputedStyle( elem, null );
22
        };
23

    
24
        curCSS = function( elem, name, computed ) {
25
                var width, minWidth, maxWidth, ret,
26
                        style = elem.style;
27

    
28
                computed = computed || getStyles( elem );
29

    
30
                // getPropertyValue is only needed for .css('filter') in IE9, see #12537
31
                ret = computed ? computed.getPropertyValue( name ) || computed[ name ] : undefined;
32

    
33
                if ( computed ) {
34

    
35
                        if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
36
                                ret = jQuery.style( elem, name );
37
                        }
38

    
39
                        // A tribute to the "awesome hack by Dean Edwards"
40
                        // Chrome < 17 and Safari 5.0 uses "computed value" instead of "used value" for margin-right
41
                        // Safari 5.1.7 (at least) returns percentage for a larger set of values, but width seems to be reliably pixels
42
                        // this is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
43
                        if ( rnumnonpx.test( ret ) && rmargin.test( name ) ) {
44

    
45
                                // Remember the original values
46
                                width = style.width;
47
                                minWidth = style.minWidth;
48
                                maxWidth = style.maxWidth;
49

    
50
                                // Put in the new values to get a computed value out
51
                                style.minWidth = style.maxWidth = style.width = ret;
52
                                ret = computed.width;
53

    
54
                                // Revert the changed values
55
                                style.width = width;
56
                                style.minWidth = minWidth;
57
                                style.maxWidth = maxWidth;
58
                        }
59
                }
60

    
61
                // Support: IE
62
                // IE returns zIndex value as an integer.
63
                return ret === undefined ?
64
                        ret :
65
                        ret + "";
66
        };
67
} else if ( document.documentElement.currentStyle ) {
68
        getStyles = function( elem ) {
69
                return elem.currentStyle;
70
        };
71

    
72
        curCSS = function( elem, name, computed ) {
73
                var left, rs, rsLeft, ret,
74
                        style = elem.style;
75

    
76
                computed = computed || getStyles( elem );
77
                ret = computed ? computed[ name ] : undefined;
78

    
79
                // Avoid setting ret to empty string here
80
                // so we don't default to auto
81
                if ( ret == null && style && style[ name ] ) {
82
                        ret = style[ name ];
83
                }
84

    
85
                // From the awesome hack by Dean Edwards
86
                // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
87

    
88
                // If we're not dealing with a regular pixel number
89
                // but a number that has a weird ending, we need to convert it to pixels
90
                // but not position css attributes, as those are proportional to the parent element instead
91
                // and we can't measure the parent instead because it might trigger a "stacking dolls" problem
92
                if ( rnumnonpx.test( ret ) && !rposition.test( name ) ) {
93

    
94
                        // Remember the original values
95
                        left = style.left;
96
                        rs = elem.runtimeStyle;
97
                        rsLeft = rs && rs.left;
98

    
99
                        // Put in the new values to get a computed value out
100
                        if ( rsLeft ) {
101
                                rs.left = elem.currentStyle.left;
102
                        }
103
                        style.left = name === "fontSize" ? "1em" : ret;
104
                        ret = style.pixelLeft + "px";
105

    
106
                        // Revert the changed values
107
                        style.left = left;
108
                        if ( rsLeft ) {
109
                                rs.left = rsLeft;
110
                        }
111
                }
112

    
113
                // Support: IE
114
                // IE returns zIndex value as an integer.
115
                return ret === undefined ?
116
                        ret :
117
                        ret + "" || "auto";
118
        };
119
}
120

    
121
exports.getStyles = getStyles;
122
exports.curCSS = curCSS;
123

    
124
});