Skip to content
Permalink
Browse files
Fix #11337. Properly calculate $.support.reliableMarginRight.
  • Loading branch information
vlazar authored and dmethvin committed Feb 24, 2012
1 parent 5281661 commit 1c35f3816a3b1be0855dcea8ab212af506e91f83
Showing 1 changed file with 19 additions and 21 deletions.
@@ -8,7 +8,6 @@ jQuery.support = (function() {
select,
opt,
input,
marginDiv,
fragment,
tds,
events,
@@ -143,23 +142,6 @@ jQuery.support = (function() {
fragment.removeChild( input );
fragment.appendChild( div );

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 ( window.getComputedStyle ) {
marginDiv = document.createElement( "div" );
marginDiv.style.width = "0";
marginDiv.style.marginRight = "0";
div.style.width = "2px";
div.appendChild( marginDiv );
support.reliableMarginRight =
( parseInt( ( window.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0;
}

// Technique from Juriy Zaytsev
// http://perfectionkills.com/detecting-event-support-without-browser-sniffing/
// We only care about the case where non-standard event systems
@@ -185,12 +167,12 @@ jQuery.support = (function() {
fragment.removeChild( div );

// Null elements to avoid leaks in IE
fragment = select = opt = marginDiv = div = input = null;
fragment = select = opt = div = input = null;

// Run tests that need a body at doc ready
jQuery(function() {
var container, outer, inner, table, td, offsetSupport,
conMarginTop, ptlm, vb, style, html,
marginDiv, conMarginTop, ptlm, vb, style, html,
body = document.getElementsByTagName("body")[0];

if ( !body ) {
@@ -233,6 +215,22 @@ jQuery.support = (function() {
// (IE <= 8 fail this test)
support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );

// 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 ( window.getComputedStyle ) {
div.innerHTML = "";
marginDiv = document.createElement( "div" );
marginDiv.style.width = "0";
marginDiv.style.marginRight = "0";
div.style.width = "2px";
div.appendChild( marginDiv );
support.reliableMarginRight =
( parseInt( ( window.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0;
}

// Figure out if the W3C box model works as expected
div.innerHTML = "";
div.style.width = div.style.paddingLeft = "1px";
@@ -289,7 +287,7 @@ jQuery.support = (function() {
}

body.removeChild( container );
div = container = null;
marginDiv = div = container = null;

jQuery.extend( support, offsetSupport );
});

3 comments on commit 1c35f38

@jdalton
Copy link
Member

@jdalton jdalton commented on 1c35f38 Feb 24, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the change... it just looks like shuffling code. The ticket mentions needing to append a test to the body...

@dmethvin
Copy link
Member

@dmethvin dmethvin commented on 1c35f38 Feb 24, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it's basically moving the test to the group that runs on ready() so that the body will be available.

@jdalton
Copy link
Member

@jdalton jdalton commented on 1c35f38 Feb 24, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks.

Please sign in to comment.