mirror of
https://github.com/jquery/jquery.git
synced 2026-02-01 17:14:58 -05:00
197 lines
6.0 KiB
JavaScript
197 lines
6.0 KiB
JavaScript
define([
|
|
"../core",
|
|
"../var/support"
|
|
], function( jQuery, support ) {
|
|
|
|
(function() {
|
|
var a, reliableHiddenOffsetsVal, boxSizingVal, boxSizingReliableVal,
|
|
pixelPositionVal,
|
|
div = document.createElement( "div" ),
|
|
containerStyles = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px",
|
|
divReset =
|
|
"-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;" +
|
|
"display:block;padding:0;margin:0;border:0";
|
|
|
|
// Setup
|
|
div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
|
|
a = div.getElementsByTagName( "a" )[ 0 ];
|
|
|
|
a.style.cssText = "float:left;opacity:.5";
|
|
|
|
// Make sure that element opacity exists
|
|
// (IE uses filter instead)
|
|
// Use a regex to work around a WebKit issue. See #5145
|
|
support.opacity = /^0.5/.test( a.style.opacity );
|
|
|
|
// Verify style float existence
|
|
// (IE uses styleFloat instead of cssFloat)
|
|
support.cssFloat = !!a.style.cssFloat;
|
|
|
|
div.style.backgroundClip = "content-box";
|
|
div.cloneNode( true ).style.backgroundClip = "";
|
|
support.clearCloneStyle = div.style.backgroundClip === "content-box";
|
|
|
|
// Null elements to avoid leaks in IE.
|
|
a = div = null;
|
|
|
|
jQuery.extend(support, {
|
|
reliableHiddenOffsets: function() {
|
|
if ( reliableHiddenOffsetsVal != null ) {
|
|
return reliableHiddenOffsetsVal;
|
|
}
|
|
|
|
var container, tds, isSupported,
|
|
div = document.createElement( "div" ),
|
|
body = document.getElementsByTagName( "body" )[ 0 ];
|
|
|
|
if ( !body ) {
|
|
// Return for frameset docs that don't have a body
|
|
return;
|
|
}
|
|
|
|
// Setup
|
|
div.setAttribute( "className", "t" );
|
|
div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
|
|
|
|
container = document.createElement( "div" );
|
|
container.style.cssText = containerStyles;
|
|
|
|
body.appendChild( container ).appendChild( div );
|
|
|
|
// Support: IE8
|
|
// 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>";
|
|
tds = div.getElementsByTagName( "td" );
|
|
tds[ 0 ].style.cssText = "padding:0;margin:0;border:0;display:none";
|
|
isSupported = ( tds[ 0 ].offsetHeight === 0 );
|
|
|
|
tds[ 0 ].style.display = "";
|
|
tds[ 1 ].style.display = "none";
|
|
|
|
// Support: IE8
|
|
// Check if empty table cells still have offsetWidth/Height
|
|
reliableHiddenOffsetsVal = isSupported && ( tds[ 0 ].offsetHeight === 0 );
|
|
|
|
body.removeChild( container );
|
|
|
|
// Null elements to avoid leaks in IE.
|
|
div = body = null;
|
|
|
|
return reliableHiddenOffsetsVal;
|
|
},
|
|
|
|
boxSizing: function() {
|
|
if ( boxSizingVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return boxSizingVal;
|
|
},
|
|
|
|
boxSizingReliable: function() {
|
|
if ( boxSizingReliableVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return boxSizingReliableVal;
|
|
},
|
|
|
|
pixelPosition: function() {
|
|
if ( pixelPositionVal == null ) {
|
|
computeStyleTests();
|
|
}
|
|
return pixelPositionVal;
|
|
},
|
|
|
|
reliableMarginRight: function() {
|
|
var body, container, div, marginDiv,
|
|
// Support: IE<9.
|
|
// IE should pass the test but we're using getComputedStyle
|
|
// to compute it so just return true if the method is not present.
|
|
reliableMarginRightVal = true;
|
|
|
|
// Use window.getComputedStyle because jsdom on node.js will break without it.
|
|
if ( window.getComputedStyle ) {
|
|
body = document.getElementsByTagName( "body" )[ 0 ];
|
|
if ( !body ) {
|
|
// Test fired too early or in an unsupported environment, exit.
|
|
return;
|
|
}
|
|
|
|
container = document.createElement( "div" );
|
|
div = document.createElement( "div" );
|
|
container.style.cssText = containerStyles;
|
|
|
|
body.appendChild( container ).appendChild( div );
|
|
|
|
// Check if div with explicit width and no margin-right incorrectly
|
|
// gets computed margin-right based on width of container. (#3333)
|
|
// Fails in WebKit before Feb 2011 nightlies
|
|
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
|
|
marginDiv = div.appendChild( document.createElement( "div" ) );
|
|
marginDiv.style.cssText = div.style.cssText = divReset;
|
|
marginDiv.style.marginRight = marginDiv.style.width = "0";
|
|
div.style.width = "1px";
|
|
|
|
reliableMarginRightVal =
|
|
!parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight );
|
|
|
|
body.removeChild( container );
|
|
}
|
|
|
|
return reliableMarginRightVal;
|
|
}
|
|
});
|
|
|
|
function computeStyleTests() {
|
|
var container, div,
|
|
body = document.getElementsByTagName( "body" )[ 0 ];
|
|
|
|
if ( !body ) {
|
|
// Test fired too early or in an unsupported environment, exit.
|
|
return;
|
|
}
|
|
|
|
container = document.createElement( "div" );
|
|
div = document.createElement( "div" );
|
|
container.style.cssText = containerStyles;
|
|
|
|
body.appendChild( container ).appendChild( div );
|
|
|
|
div.style.cssText =
|
|
"-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;" +
|
|
"position:absolute;display:block;padding:1px;border:1px;width:4px;" +
|
|
"margin-top:1%;top:1%";
|
|
|
|
// Workaround failing boxSizing test due to offsetWidth returning wrong value
|
|
// with some non-1 values of body zoom, ticket #13543
|
|
jQuery.swap( body, body.style.zoom != null ? { zoom: 1 } : {}, function() {
|
|
boxSizingVal = div.offsetWidth === 4;
|
|
});
|
|
|
|
// Will be changed later if needed.
|
|
boxSizingReliableVal = true;
|
|
pixelPositionVal = false;
|
|
|
|
// Use window.getComputedStyle because jsdom on node.js will break without it.
|
|
if ( window.getComputedStyle ) {
|
|
pixelPositionVal = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";
|
|
boxSizingReliableVal =
|
|
( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px";
|
|
}
|
|
|
|
body.removeChild( container );
|
|
|
|
// Null elements to avoid leaks in IE.
|
|
div = body = null;
|
|
}
|
|
|
|
})();
|
|
|
|
return support;
|
|
|
|
});
|