]> source.dussan.org Git - jquery.git/commitdiff
Added css hook to work around bug in WebKit computed margin-right. Fixes #3333 -... 286/head
authorRichard Worth <rdworth@gmail.com>
Thu, 24 Mar 2011 19:41:46 +0000 (15:41 -0400)
committerRichard Worth <rdworth@gmail.com>
Thu, 24 Mar 2011 19:41:46 +0000 (15:41 -0400)
src/css.js
src/support.js
test/unit/css.js

index 8a982312f17a0c70263af45323c7028494c8b1c7..d6b48813976655040e0ffb6c30f09373b75ecfb0 100644 (file)
@@ -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;
index 7470b33e8af3100819c0c3156b00ed085065091f..939ad4fcb55a457fe926552232ba2201b6dbf97b 100644 (file)
@@ -67,7 +67,8 @@
                boxModel: null,
                inlineBlockNeedsLayout: false,
                shrinkWrapBlocks: false,
-               reliableHiddenOffsets: true
+               reliableHiddenOffsets: true,
+               reliableMarginRight: true
        };
 
        input.checked = true;
                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;
        });
index 555f135756f887a9814ceeb22ebe549819e6c534..8ae8fcb346848b8c028951dd3ecc99c373e2494f 100644 (file)
@@ -333,3 +333,15 @@ test("internal ref to elem.runtimeStyle (bug #7608)", function () {
 
        ok( result, "elem.runtimeStyle does not throw exception" );
 });
+
+test("marginRight computed style (bug #3333)", function() {
+       expect(1);
+
+       var $div = jQuery("#foo");
+       $div.css({
+               width: "1px",
+               marginRight: 0
+       });
+
+       equals($div.css("marginRight"), "0px");
+});