diff options
author | Michał Gołębiowski <m.goleb@gmail.com> | 2013-08-27 00:54:13 +0200 |
---|---|---|
committer | Michał Gołębiowski <m.goleb@gmail.com> | 2013-09-06 03:38:22 +0200 |
commit | bbbdd947256a3fcd788fb9d4f306046082a1ef1f (patch) | |
tree | 2fc5a02969653d281a44a7b3ff6426b5561c8140 /src/css | |
parent | 776012b8b3898fad2e0727880f1dc4af5c7b33c1 (diff) | |
download | jquery-bbbdd947256a3fcd788fb9d4f306046082a1ef1f.tar.gz jquery-bbbdd947256a3fcd788fb9d4f306046082a1ef1f.zip |
Fix #10814. Make support tests lazy and broken out to components.
Diffstat (limited to 'src/css')
-rw-r--r-- | src/css/hiddenVisibleSelectors.js (renamed from src/css/hidden-visible-selectors.js) | 0 | ||||
-rw-r--r-- | src/css/support.js | 82 | ||||
-rw-r--r-- | src/css/swap.js | 27 |
3 files changed, 109 insertions, 0 deletions
diff --git a/src/css/hidden-visible-selectors.js b/src/css/hiddenVisibleSelectors.js index c7f1c7ee7..c7f1c7ee7 100644 --- a/src/css/hidden-visible-selectors.js +++ b/src/css/hiddenVisibleSelectors.js diff --git a/src/css/support.js b/src/css/support.js new file mode 100644 index 000000000..6ddf6c1a8 --- /dev/null +++ b/src/css/support.js @@ -0,0 +1,82 @@ +define([ + "../var/support" +], function( support ) { + +(function () { + var pixelPositionVal, boxSizingReliableVal, + // Support: Firefox, Android 2.3 (Prefixed box-sizing versions). + divReset = "padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;" + + "-moz-box-sizing:content-box;box-sizing:content-box", + docElem = document.documentElement, + container = document.createElement( "div" ), + div = document.createElement( "div" ); + + div.style.backgroundClip = "content-box"; + div.cloneNode( true ).style.backgroundClip = ""; + support.clearCloneStyle = div.style.backgroundClip === "content-box"; + + container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;" + + "margin-top:1px"; + container.appendChild( div ); + + // Executing both pixelPosition & boxSizingReliable tests require only one layout + // so they're executed at the same time to save the second computation. + function computePixelPositionAndBoxSizingReliable() { + // Support: Firefox, Android 2.3 (Prefixed box-sizing versions). + div.style.cssText = "-webkit-box-sizing:border-box;-moz-box-sizing:border-box;" + + "box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;" + + "position:absolute;top:1%"; + docElem.appendChild( container ); + + var divStyle = window.getComputedStyle( div, null ); + pixelPositionVal = divStyle.top !== "1%"; + boxSizingReliableVal = divStyle.width === "4px"; + + docElem.removeChild( container ); + } + + // Use window.getComputedStyle because jsdom on node.js will break without it. + if ( window.getComputedStyle ) { + jQuery.extend(support, { + pixelPosition: function() { + // This test is executed only once but we still do memoizing + // since we can use the boxSizingReliable pre-computing. + // No need to check if the test was already performed, though. + computePixelPositionAndBoxSizingReliable(); + return pixelPositionVal; + }, + boxSizingReliable: function() { + if ( boxSizingReliableVal == null ) { + computePixelPositionAndBoxSizingReliable(); + } + return boxSizingReliableVal; + }, + reliableMarginRight: function() { + // Support: Android 2.3 + // Check if 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 + // This support function is only executed once so no memoizing is needed. + var ret, + marginDiv = div.appendChild( document.createElement( "div" ) ); + marginDiv.style.cssText = div.style.cssText = divReset; + marginDiv.style.marginRight = marginDiv.style.width = "0"; + div.style.width = "1px"; + docElem.appendChild( container ); + + ret = !parseFloat( window.getComputedStyle( marginDiv, null ).marginRight ); + + docElem.removeChild( container ); + + // Clean up the div for other support tests. + div.innerHTML = ""; + + return ret; + } + }); + } +})(); + +return support; + +}); diff --git a/src/css/swap.js b/src/css/swap.js new file mode 100644 index 000000000..07a661c03 --- /dev/null +++ b/src/css/swap.js @@ -0,0 +1,27 @@ +define([ + "../core" +], function( jQuery ) { + + // A method for quickly swapping in/out CSS properties to get correct calculations. + jQuery.swap = function( elem, options, callback, args ) { + var ret, name, + old = {}; + + // Remember the old values, and insert the new ones + for ( name in options ) { + old[ name ] = elem.style[ name ]; + elem.style[ name ] = options[ name ]; + } + + ret = callback.apply( elem, args || [] ); + + // Revert the old values + for ( name in options ) { + elem.style[ name ] = old[ name ]; + } + + return ret; + }; + + return jQuery.swap; +}); |