diff options
author | Richard Gibson <richard.gibson@gmail.com> | 2014-02-14 09:21:03 -0800 |
---|---|---|
committer | Richard Gibson <richard.gibson@gmail.com> | 2014-03-04 17:00:38 -0500 |
commit | b96522acfe2808e5fc3397a620db8845f6987680 (patch) | |
tree | bd3690155f04b484fedb282b7d3a930984064049 /src/css | |
parent | f361f0378b80f6141e79d906821f6964bcdfbfc4 (diff) | |
download | jquery-b96522acfe2808e5fc3397a620db8845f6987680.tar.gz jquery-b96522acfe2808e5fc3397a620db8845f6987680.zip |
Support: Reduce size via code consolidation and minification awareness
Ref badcd1b6f301e6253405f17759c1270549a34e12
Closes gh-1518
Diffstat (limited to 'src/css')
-rw-r--r-- | src/css/support.js | 175 |
1 files changed, 65 insertions, 110 deletions
diff --git a/src/css/support.js b/src/css/support.js index 2b525ebf6..07a2a7f48 100644 --- a/src/css/support.js +++ b/src/css/support.js @@ -4,89 +4,40 @@ define([ ], 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", - // Support: Firefox<29, Android 2.3 (Prefixed box-sizing versions). - divReset = - "-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;" + - "display:block;padding:0;margin:0;border:0"; + // Minified: var b,c,d,e,f,g, h,i + var div, style, a, pixelPositionVal, boxSizingVal, boxSizingReliableVal, + reliableHiddenOffsetsVal, reliableMarginRightVal; // Setup + div = document.createElement( "div" ); div.innerHTML = " <link/><table></table><a href='/a'>a</a><input type='checkbox'/>"; a = div.getElementsByTagName( "a" )[ 0 ]; + style = a && a.style; // Finish early in limited (non-browser) environments - if ( !a || !a.style ) { + if ( !style ) { return; } - a.style.cssText = "float:left;opacity:.5"; + style.cssText = "float:left;opacity:.5"; // Support: IE<9 // Make sure that element opacity exists (as opposed to filter) - support.opacity = a.style.opacity === "0.5"; + support.opacity = style.opacity === "0.5"; // Verify style float existence // (IE uses styleFloat instead of cssFloat) - support.cssFloat = !!a.style.cssFloat; + support.cssFloat = !!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; + if ( reliableHiddenOffsetsVal == null ) { + computeStyleTests(); } - - // 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; }, @@ -113,65 +64,35 @@ define([ // Support: Android 2.3 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 ); + if ( reliableMarginRightVal == null ) { + computeStyleTests(); } - return reliableMarginRightVal; } }); function computeStyleTests() { - var container, div, - body = document.getElementsByTagName( "body" )[ 0 ]; + // Minified: var b,c,d,j + var div, body, container, contents; - if ( !body ) { + body = document.getElementsByTagName( "body" )[ 0 ]; + if ( !body || !body.style ) { // Test fired too early or in an unsupported environment, exit. return; } - container = document.createElement( "div" ); + // Setup div = document.createElement( "div" ); - container.style.cssText = containerStyles; - + container = document.createElement( "div" ); + container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px"; body.appendChild( container ).appendChild( div ); - // Support: Firefox<29, Android 2.3 (Prefixed box-sizing versions). 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%"; + // Support: Firefox<29, Android 2.3 + // Vendor-prefix box-sizing + "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" + + "box-sizing:border-box;display:block;margin-top:1%;top:1%;" + + "border:1px;padding:1px;width:4px;position:absolute"; // Workaround failing boxSizing test due to offsetWidth returning wrong value // with some non-1 values of body zoom, ticket #13543 @@ -179,21 +100,55 @@ define([ boxSizingVal = div.offsetWidth === 4; }); - // Will be changed later if needed. - boxSizingReliableVal = true; + // Support: IE<9 + // Assume reasonable values in the absence of getComputedStyle pixelPositionVal = false; + reliableMarginRightVal = boxSizingReliableVal = true; - // Use window.getComputedStyle because jsdom on node.js will break without it. + // Support: node.js jsdom + // Don't assume that getComputedStyle is a property of the global object if ( window.getComputedStyle ) { pixelPositionVal = ( window.getComputedStyle( div, null ) || {} ).top !== "1%"; boxSizingReliableVal = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px"; + + // Support: Android 2.3 + // 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: Firefox<29, Android 2.3 + // Vendor-prefix box-sizing + "-webkit-box-sizing:content-box;-moz-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, null ) || {} ).marginRight ); } - body.removeChild( container ); + // 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>"; + 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; + } - // Null elements to avoid leaks in IE. - div = body = null; + body.removeChild( container ); } })(); |