File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -240,6 +240,25 @@ if ( !jQuery.support.opacity ) {
240240 } ;
241241}
242242
243+ jQuery ( function ( ) {
244+ // This hook cannot be added until DOM ready because the support test
245+ // for it is not run until after DOM ready
246+ if ( ! jQuery . support . reliableMarginRight ) {
247+ jQuery . cssHooks . marginRight = {
248+ get : function ( elem , computed ) {
249+ // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
250+ // Work around by temporarily setting element display to inline-block
251+ var ret = "0px" ,
252+ display = elem . style . display ;
253+ elem . style . display = "inline-block" ;
254+ ret = getComputedStyle ( elem , "margin-right" , "margin-right" ) ;
255+ elem . style . display = display ;
256+ return ret ;
257+ }
258+ }
259+ }
260+ } ) ;
261+
243262if ( document . defaultView && document . defaultView . getComputedStyle ) {
244263 getComputedStyle = function ( elem , newName , name ) {
245264 var ret , defaultView , computedStyle ;
Original file line number Diff line number Diff line change 6767 boxModel : null ,
6868 inlineBlockNeedsLayout : false ,
6969 shrinkWrapBlocks : false ,
70- reliableHiddenOffsets : true
70+ reliableHiddenOffsets : true ,
71+ reliableMarginRight : true
7172 } ;
7273
7374 input . checked = true ;
188189 jQuery . support . reliableHiddenOffsets = jQuery . support . reliableHiddenOffsets && tds [ 0 ] . offsetHeight === 0 ;
189190 div . innerHTML = "" ;
190191
192+ // Check if div with explicit width and no margin-right incorrectly
193+ // gets computed margin-right based on width of container. For more
194+ // info see bug #3333
195+ // Fails in WebKit before Feb 2011 nightlies
196+ // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
197+ if ( document . defaultView && document . defaultView . getComputedStyle ) {
198+ div . style . width = "1px" ;
199+ div . style . marginRight = "0" ;
200+ jQuery . support . reliableMarginRight = ( parseInt ( document . defaultView . getComputedStyle ( div ) . marginRight , 10 ) || 0 ) === 0 ;
201+ }
202+
191203 body . removeChild ( div ) . style . display = "none" ;
192204 div = tds = null ;
193205 } ) ;
Original file line number Diff line number Diff line change @@ -333,3 +333,15 @@ test("internal ref to elem.runtimeStyle (bug #7608)", function () {
333333
334334 ok ( result , "elem.runtimeStyle does not throw exception" ) ;
335335} ) ;
336+
337+ test ( "marginRight computed style (bug #3333)" , function ( ) {
338+ expect ( 1 ) ;
339+
340+ var $div = jQuery ( "#foo" ) ;
341+ $div . css ( {
342+ width : "1px" ,
343+ marginRight : 0
344+ } ) ;
345+
346+ equals ( $div . css ( "marginRight" ) , "0px" ) ;
347+ } ) ;
You can’t perform that action at this time.
0 commit comments