4 "../var/documentElement",
6 ], function( jQuery, document, documentElement, support ) {
9 var pixelPositionVal, boxSizingReliableVal, pixelMarginRightVal, reliableMarginLeftVal,
10 container = document.createElement( "div" ),
11 div = document.createElement( "div" );
13 // Finish early in limited (non-browser) environments
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() {
33 // Support: Firefox<29, Android 2.3
34 // Vendor-prefix box-sizing
35 "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;" +
36 "position:relative;display:block;" +
37 "margin:auto;border:1px;padding:1px;" +
40 documentElement.appendChild( container );
42 var divStyle = window.getComputedStyle( div );
43 pixelPositionVal = divStyle.top !== "1%";
44 reliableMarginLeftVal = divStyle.marginLeft === "2px";
45 boxSizingReliableVal = divStyle.width === "4px";
47 // Support: Android 4.0 - 4.3 only
48 // Some styles come back with percentage values, even though they shouldn't
49 div.style.marginRight = "50%";
50 pixelMarginRightVal = divStyle.marginRight === "4px";
52 documentElement.removeChild( container );
55 jQuery.extend( support, {
56 pixelPosition: function() {
58 // This test is executed only once but we still do memoizing
59 // since we can use the boxSizingReliable pre-computing.
60 // No need to check if the test was already performed, though.
62 return pixelPositionVal;
64 boxSizingReliable: function() {
65 if ( boxSizingReliableVal == null ) {
68 return boxSizingReliableVal;
70 pixelMarginRight: function() {
72 // Support: Android 4.0-4.3
73 // We're checking for boxSizingReliableVal here instead of pixelMarginRightVal
74 // since that compresses better and they're computed together anyway.
75 if ( boxSizingReliableVal == null ) {
78 return pixelMarginRightVal;
80 reliableMarginLeft: function() {
82 // Support: IE <=8 only, Android 4.0 - 4.3 only, Firefox <=3 - 37
83 if ( boxSizingReliableVal == null ) {
86 return reliableMarginLeftVal;
88 reliableMarginRight: function() {
90 // Support: Android 2.3
91 // Check if div with explicit width and no margin-right incorrectly
92 // gets computed margin-right based on width of container. (#3333)
93 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
94 // This support function is only executed once so no memoizing is needed.
96 marginDiv = div.appendChild( document.createElement( "div" ) );
98 // Reset CSS: box-sizing; display; margin; border; padding
99 marginDiv.style.cssText = div.style.cssText =
101 // Support: Android 2.3
102 // Vendor-prefix box-sizing
103 "-webkit-box-sizing:content-box;box-sizing:content-box;" +
104 "display:block;margin:0;border:0;padding:0";
105 marginDiv.style.marginRight = marginDiv.style.width = "0";
106 div.style.width = "1px";
107 documentElement.appendChild( container );
109 ret = !parseFloat( window.getComputedStyle( marginDiv ).marginRight );
111 documentElement.removeChild( container );
112 div.removeChild( marginDiv );