mirror of
https://github.com/jquery/jquery.git
synced 2026-02-02 08:55:24 -05:00
184 lines
5.5 KiB
JavaScript
184 lines
5.5 KiB
JavaScript
define( [
|
|
"../core",
|
|
"../var/document",
|
|
"../var/documentElement",
|
|
"../var/support"
|
|
], function( jQuery, document, documentElement, support ) {
|
|
|
|
( function() {
|
|
var pixelPositionVal, pixelMarginRightVal, gBCRDimensionsVal, boxSizingReliableVal,
|
|
reliableHiddenOffsetsVal, reliableMarginRightVal, reliableMarginLeftVal,
|
|
container = document.createElement( "div" ),
|
|
div = document.createElement( "div" );
|
|
|
|
// Finish early in limited (non-browser) environments
|
|
if ( !div.style ) {
|
|
return;
|
|
}
|
|
|
|
div.style.cssText = "float:left;opacity:.5";
|
|
|
|
// Support: IE<9
|
|
// Make sure that element opacity exists (as opposed to filter)
|
|
support.opacity = div.style.opacity === "0.5";
|
|
|
|
// Verify style float existence
|
|
// (IE uses styleFloat instead of cssFloat)
|
|
support.cssFloat = !!div.style.cssFloat;
|
|
|
|
div.style.backgroundClip = "content-box";
|
|
div.cloneNode( true ).style.backgroundClip = "";
|
|
support.clearCloneStyle = div.style.backgroundClip === "content-box";
|
|
|
|
container = document.createElement( "div" );
|
|
container.style.cssText = "border:0;width:8px;height:0;top:0;left:-9999px;" +
|
|
"padding:0;margin-top:1px;position:absolute";
|
|
div.innerHTML = "";
|
|
container.appendChild( div );
|
|
|
|
jQuery.extend( support, {
|
|
reliableHiddenOffsets: function() {
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return reliableHiddenOffsetsVal;
|
|
},
|
|
|
|
boxSizingReliable: function() {
|
|
|
|
// We're checking for pixelPositionVal here instead of boxSizingReliableVal
|
|
// since that compresses better and they're computed together anyway.
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return boxSizingReliableVal;
|
|
},
|
|
|
|
gBCRDimensions: function() {
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return gBCRDimensionsVal;
|
|
},
|
|
|
|
pixelMarginRight: function() {
|
|
|
|
// Support: Android 4.0-4.3
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return pixelMarginRightVal;
|
|
},
|
|
|
|
pixelPosition: function() {
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return pixelPositionVal;
|
|
},
|
|
|
|
reliableMarginRight: function() {
|
|
|
|
// Support: Android 2.3
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return reliableMarginRightVal;
|
|
},
|
|
|
|
reliableMarginLeft: function() {
|
|
|
|
// Support: IE <=8 only, Android 4.0 - 4.3 only, Firefox <=3 - 37
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return reliableMarginLeftVal;
|
|
}
|
|
} );
|
|
|
|
function computeStyleTests() {
|
|
var contents, divStyle,
|
|
documentElement = document.documentElement;
|
|
|
|
// Setup
|
|
documentElement.appendChild( container );
|
|
|
|
div.style.cssText =
|
|
|
|
// Support: Android 2.3
|
|
// Vendor-prefix box-sizing
|
|
"-webkit-box-sizing:border-box;box-sizing:border-box;" +
|
|
"position:relative;display:block;" +
|
|
"margin:auto;border:1px;padding:1px;" +
|
|
"top:1%;width:50%";
|
|
|
|
// Support: IE<9
|
|
// Assume reasonable values in the absence of getComputedStyle
|
|
pixelPositionVal = boxSizingReliableVal = reliableMarginLeftVal = false;
|
|
pixelMarginRightVal = reliableMarginRightVal = true;
|
|
|
|
// Support: IE<9
|
|
// In IE8 gBCR doesn't report width & height.
|
|
gBCRDimensionsVal = !!div.getBoundingClientRect().width;
|
|
|
|
// Check for getComputedStyle so that this code is not run in IE<9.
|
|
if ( window.getComputedStyle ) {
|
|
divStyle = window.getComputedStyle( div );
|
|
pixelPositionVal = ( divStyle || {} ).top !== "1%";
|
|
reliableMarginLeftVal = ( divStyle || {} ).marginLeft === "2px";
|
|
boxSizingReliableVal = ( divStyle || { width: "4px" } ).width === "4px";
|
|
|
|
// Support: Android 4.0 - 4.3 only
|
|
// Some styles come back with percentage values, even though they shouldn't
|
|
div.style.marginRight = "50%";
|
|
pixelMarginRightVal = ( divStyle || { marginRight: "4px" } ).marginRight === "4px";
|
|
|
|
// Support: Android 2.3 only
|
|
// Div with explicit width and no margin-right incorrectly
|
|
// gets computed margin-right based on width of container (#3333)
|
|
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
|
|
contents = div.appendChild( document.createElement( "div" ) );
|
|
|
|
// Reset CSS: box-sizing; display; margin; border; padding
|
|
contents.style.cssText = div.style.cssText =
|
|
|
|
// Support: Android 2.3
|
|
// Vendor-prefix box-sizing
|
|
"-webkit-box-sizing:content-box;box-sizing:content-box;" +
|
|
"display:block;margin:0;border:0;padding:0";
|
|
contents.style.marginRight = contents.style.width = "0";
|
|
div.style.width = "1px";
|
|
|
|
reliableMarginRightVal =
|
|
!parseFloat( ( window.getComputedStyle( contents ) || {} ).marginRight );
|
|
|
|
div.removeChild( contents );
|
|
}
|
|
|
|
// Support: IE<9
|
|
// Check if table cells still have offsetWidth/Height when they are set
|
|
// to display:none and there are still other visible table cells in a
|
|
// table row; if so, offsetWidth/Height are not reliable for use when
|
|
// determining if an element has been hidden directly using
|
|
// display:none (it is still safe to use offsets if a parent element is
|
|
// hidden; don safety goggles and see bug #4512 for more information).
|
|
div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>";
|
|
contents = div.getElementsByTagName( "td" );
|
|
contents[ 0 ].style.cssText = "margin:0;border:0;padding:0;display:none";
|
|
reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0;
|
|
if ( reliableHiddenOffsetsVal ) {
|
|
contents[ 0 ].style.display = "";
|
|
contents[ 1 ].style.display = "none";
|
|
reliableHiddenOffsetsVal = contents[ 0 ].offsetHeight === 0;
|
|
}
|
|
|
|
// Teardown
|
|
documentElement.removeChild( container );
|
|
}
|
|
|
|
} )();
|
|
|
|
return support;
|
|
|
|
} );
|