Offset: allow offset setter to throw for disconnected elements
[jquery.git] / src / css / support.js
blob522406943cb8d0121bcf0b0a323f73a4970121fc
1 define([
2         "../core",
3         "../var/document",
4         "../var/documentElement",
5         "../var/support"
6 ], function( jQuery, document, documentElement, support ) {
8 (function() {
9         var pixelPositionVal, boxSizingReliableVal, pixelMarginRightVal,
10                 container = document.createElement( "div" ),
11                 div = document.createElement( "div" );
13         // Finish early in limited (non-browser) environments
14         if ( !div.style ) {
15                 return;
16         }
18         // Support: IE9-11+
19         // Style of cloned element affects source element cloned (#8908)
20         div.style.backgroundClip = "content-box";
21         div.cloneNode( true ).style.backgroundClip = "";
22         support.clearCloneStyle = div.style.backgroundClip === "content-box";
24         container.style.cssText = "border:0;width:8px;height:0;top:0;left:-9999px;" +
25                 "padding:0;margin-top:1px;position:absolute";
26         container.appendChild( div );
28         // Executing both pixelPosition & boxSizingReliable tests require only one layout
29         // so they're executed at the same time to save the second computation.
30         function computeStyleTests() {
31                 div.style.cssText =
32                         // Support: Android 2.3
33                         // Vendor-prefix box-sizing
34                         "-webkit-box-sizing:border-box;box-sizing:border-box;" +
35                         "display:block;position:absolute;" +
36                         "margin:0;margin-top:1%;margin-right:50%;" +
37                         "border:1px;padding:1px;" +
38                         "top:1%;width:50%;height:4px";
39                 div.innerHTML = "";
40                 documentElement.appendChild( container );
42                 var divStyle = window.getComputedStyle( div );
43                 pixelPositionVal = divStyle.top !== "1%";
44                 boxSizingReliableVal = divStyle.height === "4px";
45                 pixelMarginRightVal = divStyle.marginRight === "4px";
47                 documentElement.removeChild( container );
48         }
50         jQuery.extend( support, {
51                 pixelPosition: function() {
52                         // This test is executed only once but we still do memoizing
53                         // since we can use the boxSizingReliable pre-computing.
54                         // No need to check if the test was already performed, though.
55                         computeStyleTests();
56                         return pixelPositionVal;
57                 },
58                 boxSizingReliable: function() {
59                         if ( boxSizingReliableVal == null ) {
60                                 computeStyleTests();
61                         }
62                         return boxSizingReliableVal;
63                 },
64                 pixelMarginRight: function() {
65                         // Support: Android 4.0-4.3
66                         // We're checking for boxSizingReliableVal here instead of pixelMarginRightVal
67                         // since that compresses better and they're computed together anyway.
68                         if ( boxSizingReliableVal == null ) {
69                                 computeStyleTests();
70                         }
71                         return pixelMarginRightVal;
72                 },
73                 reliableMarginRight: function() {
75                         // Support: Android 2.3
76                         // Check if div with explicit width and no margin-right incorrectly
77                         // gets computed margin-right based on width of container. (#3333)
78                         // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
79                         // This support function is only executed once so no memoizing is needed.
80                         var ret,
81                                 marginDiv = div.appendChild( document.createElement( "div" ) );
83                         // Reset CSS: box-sizing; display; margin; border; padding
84                         marginDiv.style.cssText = div.style.cssText =
85                                 // Support: Android 2.3
86                                 // Vendor-prefix box-sizing
87                                 "-webkit-box-sizing:content-box;box-sizing:content-box;" +
88                                 "display:block;margin:0;border:0;padding:0";
89                         marginDiv.style.marginRight = marginDiv.style.width = "0";
90                         div.style.width = "1px";
91                         documentElement.appendChild( container );
93                         ret = !parseFloat( window.getComputedStyle( marginDiv ).marginRight );
95                         documentElement.removeChild( container );
96                         div.removeChild( marginDiv );
98                         return ret;
99                 }
100         });
101 })();
103 return support;