diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2016-03-28 16:11:39 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2016-03-28 19:24:31 +0300 |
commit | 44cb97e0cfc8d3e62bef7c621bfeba6fe4f65d7c (patch) | |
tree | e9672f64f085b842385e40d05d058cbdf14ebb70 | |
parent | e8ff8176fcef5a78a2447fc1b3d6e371cd3de929 (diff) | |
download | jquery-44cb97e0cfc8d3e62bef7c621bfeba6fe4f65d7c.tar.gz jquery-44cb97e0cfc8d3e62bef7c621bfeba6fe4f65d7c.zip |
Support: improve support properties computation
* Remove div from the memory if it is not needed anymore
* Make `computeStyleTests` method a singleton
Fixes gh-3018
Closes gh-3021
-rw-r--r-- | src/css/support.js | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/src/css/support.js b/src/css/support.js index 1150485bf..0c02b71d7 100644 --- a/src/css/support.js +++ b/src/css/support.js @@ -28,6 +28,12 @@ define( [ // Executing both pixelPosition & boxSizingReliable tests require only one layout // so they're executed at the same time to save the second computation. function computeStyleTests() { + + // This is a singleton, we need to execute it only once + if ( !div ) { + return; + } + div.style.cssText = "box-sizing:border-box;" + "position:relative;display:block;" + @@ -38,6 +44,8 @@ define( [ var divStyle = window.getComputedStyle( div ); pixelPositionVal = divStyle.top !== "1%"; + + // Support: Android 4.0 - 4.3 only, Firefox <=3 - 44+ reliableMarginLeftVal = divStyle.marginLeft === "2px"; boxSizingReliableVal = divStyle.width === "4px"; @@ -47,39 +55,27 @@ define( [ pixelMarginRightVal = divStyle.marginRight === "4px"; documentElement.removeChild( container ); + + // Nullify the div so it wouldn't be stored in the memory and + // it will also be a sign that checks already performed + div = null; } 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. computeStyleTests(); return pixelPositionVal; }, boxSizingReliable: function() { - if ( boxSizingReliableVal == null ) { - computeStyleTests(); - } + computeStyleTests(); return boxSizingReliableVal; }, pixelMarginRight: function() { - - // Support: Android 4.0 - 4.3 only - // We're checking for boxSizingReliableVal here instead of pixelMarginRightVal - // since that compresses better and they're computed together anyway. - if ( boxSizingReliableVal == null ) { - computeStyleTests(); - } + computeStyleTests(); return pixelMarginRightVal; }, reliableMarginLeft: function() { - - // Support: Android 4.0 - 4.3 only, Firefox <=3 - 44+ - if ( boxSizingReliableVal == null ) { - computeStyleTests(); - } + computeStyleTests(); return reliableMarginLeftVal; } } ); |