diff options
author | Richard Worth <rdworth@gmail.com> | 2011-03-24 15:41:46 -0400 |
---|---|---|
committer | Richard Worth <rdworth@gmail.com> | 2011-03-24 15:41:46 -0400 |
commit | c3c507e900fceb419628157504004ab2813b7d01 (patch) | |
tree | ec71056ef896dd734c6e0cb6f8e2aacae171be6b /src | |
parent | 0cf336d2c95809ef41d94131e629fd1767f054a0 (diff) | |
download | jquery-c3c507e900fceb419628157504004ab2813b7d01.tar.gz jquery-c3c507e900fceb419628157504004ab2813b7d01.zip |
Added css hook to work around bug in WebKit computed margin-right. Fixes #3333 - .css("marginRight") is incorrect in WebKit
Diffstat (limited to 'src')
-rw-r--r-- | src/css.js | 19 | ||||
-rw-r--r-- | src/support.js | 14 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/css.js b/src/css.js index 8a982312f..d6b488139 100644 --- a/src/css.js +++ b/src/css.js @@ -240,6 +240,25 @@ if ( !jQuery.support.opacity ) { }; } +jQuery(function() { + // This hook cannot be added until DOM ready because the support test + // for it is not run until after DOM ready + if ( !jQuery.support.reliableMarginRight ) { + jQuery.cssHooks.marginRight = { + get: function( elem, computed ) { + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right + // Work around by temporarily setting element display to inline-block + var ret = "0px", + display = elem.style.display; + elem.style.display = "inline-block"; + ret = getComputedStyle( elem, "margin-right", "margin-right" ); + elem.style.display = display; + return ret; + } + } + } +}); + if ( document.defaultView && document.defaultView.getComputedStyle ) { getComputedStyle = function( elem, newName, name ) { var ret, defaultView, computedStyle; diff --git a/src/support.js b/src/support.js index 7470b33e8..939ad4fcb 100644 --- a/src/support.js +++ b/src/support.js @@ -67,7 +67,8 @@ boxModel: null, inlineBlockNeedsLayout: false, shrinkWrapBlocks: false, - reliableHiddenOffsets: true + reliableHiddenOffsets: true, + reliableMarginRight: true }; input.checked = true; @@ -188,6 +189,17 @@ jQuery.support.reliableHiddenOffsets = jQuery.support.reliableHiddenOffsets && tds[0].offsetHeight === 0; div.innerHTML = ""; + // Check if div with explicit width and no margin-right incorrectly + // gets computed margin-right based on width of container. For more + // info see bug #3333 + // Fails in WebKit before Feb 2011 nightlies + // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right + if ( document.defaultView && document.defaultView.getComputedStyle ) { + div.style.width = "1px"; + div.style.marginRight = "0"; + jQuery.support.reliableMarginRight = ( parseInt(document.defaultView.getComputedStyle(div).marginRight, 10) || 0 ) === 0; + } + body.removeChild( div ).style.display = "none"; div = tds = null; }); |