Offset: allow offset setter to throw for disconnected elements
[jquery.git] / src / css / curCSS.js
blob207139726110b3248b69b1b4528328c9f74546a7
1 define([
2         "../core",
3         "./var/rnumnonpx",
4         "./var/rmargin",
5         "./var/getStyles",
6         "./support",
7         "../selector" // contains
8 ], function( jQuery, rnumnonpx, rmargin, getStyles, support ) {
10 function curCSS( elem, name, computed ) {
11         var width, minWidth, maxWidth, ret,
12                 style = elem.style;
14         computed = computed || getStyles( elem );
16         // Support: IE9
17         // getPropertyValue is only needed for .css('filter') (#12537)
18         if ( computed ) {
19                 ret = computed.getPropertyValue( name ) || computed[ name ];
20         }
22         if ( computed ) {
24                 if ( ret === "" && !jQuery.contains( elem.ownerDocument, elem ) ) {
25                         ret = jQuery.style( elem, name );
26                 }
28                 // A tribute to the "awesome hack by Dean Edwards"
29                 // Android Browser returns percentage for some values,
30                 // but width seems to be reliably pixels.
31                 // This is against the CSSOM draft spec:
32                 // http://dev.w3.org/csswg/cssom/#resolved-values
33                 if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) {
35                         // Remember the original values
36                         width = style.width;
37                         minWidth = style.minWidth;
38                         maxWidth = style.maxWidth;
40                         // Put in the new values to get a computed value out
41                         style.minWidth = style.maxWidth = style.width = ret;
42                         ret = computed.width;
44                         // Revert the changed values
45                         style.width = width;
46                         style.minWidth = minWidth;
47                         style.maxWidth = maxWidth;
48                 }
49         }
51         return ret !== undefined ?
52                 // Support: IE9-11+
53                 // IE returns zIndex value as an integer.
54                 ret + "" :
55                 ret;
58 return curCSS;
59 });