Skip to content

Commit

Permalink
Merge branch 'fix_8402' of https://github.com/lrbabe/jquery into lrba…
Browse files Browse the repository at this point in the history
…be-fix_8402
  • Loading branch information
jeresig committed Apr 12, 2011
2 parents 430d9e0 + 272b8d6 commit db80ad9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/css.js
Expand Up @@ -123,18 +123,24 @@ jQuery.extend({


css: function( elem, name, extra ) { css: function( elem, name, extra ) {
// Make sure that we're working with the right name // Make sure that we're working with the right name
var ret, origName = jQuery.camelCase( name ), var ret,
hooks = jQuery.cssHooks[ origName ]; hooks;


name = jQuery.cssProps[ origName ] || origName; name = jQuery.camelCase( name );
hooks = jQuery.cssHooks[ name ];
name = jQuery.cssProps[ name ] || name;
// cssFloat needs a special treatment
if ( name === 'cssFloat' ) {
name = 'float';
}


// If a hook was provided get the computed value from there // If a hook was provided get the computed value from there
if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) { if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
return ret; return ret;


// Otherwise, if a way to get the computed value exists, use that // Otherwise, if a way to get the computed value exists, use that
} else if ( curCSS ) { } else if ( curCSS ) {
return curCSS( elem, name, origName ); return curCSS( elem, name );
} }
}, },


Expand Down Expand Up @@ -274,7 +280,7 @@ jQuery(function() {
}); });


if ( document.defaultView && document.defaultView.getComputedStyle ) { if ( document.defaultView && document.defaultView.getComputedStyle ) {
getComputedStyle = function( elem, newName, name ) { getComputedStyle = function( elem, name ) {
var ret, defaultView, computedStyle; var ret, defaultView, computedStyle;


name = name.replace( rupper, "-$1" ).toLowerCase(); name = name.replace( rupper, "-$1" ).toLowerCase();
Expand Down
14 changes: 14 additions & 0 deletions test/unit/css.js
Expand Up @@ -395,3 +395,17 @@ test("$().css override !important css declarations (bug #4427)", function(){
equals( div.css("background-color"), "rgb(0, 255, 0)", "Background color is overrided to rgb(0, 255, 0)" ); equals( div.css("background-color"), "rgb(0, 255, 0)", "Background color is overrided to rgb(0, 255, 0)" );


}); });

test("jQuery.cssProps behavior, (bug #8402)", function() {
var div = jQuery( "<div>" ).appendTo(document.body).css({
position: "absolute",
top: 0,
left: 10
});
jQuery.cssProps.top = "left";
equal( div.css("top"), "10px", "the fixed property is used when accessing the computed style");
div.css("top", "100px");
equal( div[0].style.left, "100px", "the fixed property is used when setting the style");
// cleanup jQuery.cssProps
jQuery.cssProps.top = undefined;
});

0 comments on commit db80ad9

Please sign in to comment.