Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return value of elem.css('background-position') #748

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/css.js
Expand Up @@ -8,7 +8,9 @@ var curCSS, iframe, iframeDoc,
rnumnonpx = /^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i, rnumnonpx = /^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i,
rrelNum = /^([\-+])=([\-+.\de]+)/, rrelNum = /^([\-+])=([\-+.\de]+)/,
rmargin = /^margin/, rmargin = /^margin/,
rmultiplebg = /,\s?/,
elemdisplay = {}, elemdisplay = {},

cssShow = { position: "absolute", visibility: "hidden", display: "block" }, cssShow = { position: "absolute", visibility: "hidden", display: "block" },


cssExpand = jQuery.cssExpand, cssExpand = jQuery.cssExpand,
Expand Down Expand Up @@ -139,6 +141,33 @@ jQuery.extend({
return elem.style.opacity; return elem.style.opacity;
} }
} }
},

backgroundPosition: {
get: function( elem, computed ) {
if ( !computed ) {
return elem.style.backgroundPosition;
Copy link
Member

Choose a reason for hiding this comment

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

over here you can just say return; without a value, and it'll know to look up the property normally.

}

var posY, glue, i, len,
propName = "backgroundPosition",
ret = curCSS( elem, propName );

if ( ret !== "0% 0%" ) {
return ret;
}

ret = curCSS( elem, propName + "X" );
posY = curCSS( elem, propName + "Y" ).split( rmultiplebg );
glue = rmultiplebg.exec( ret ) || [""];
ret = ret.split( rmultiplebg );

for ( i = 0, len = ret.length; i < len; ++i ) {
ret[i] += " " + posY[i];
}

return ret.join( glue[0] );
}
} }
}, },


Expand Down
16 changes: 16 additions & 0 deletions test/unit/css.js
Expand Up @@ -779,3 +779,19 @@ test( "cssHooks - expand", function() {
}); });


}); });

test( "css('backgroundPosition') should be valid value", function() {
jQuery( "<style type='text/css'>" +
"#test-backgroundPosition {background-position: 10px 20px;}" +
"#test-backgroundPositionCSS3 {background-position: 10px 20px, 30px 40px;}" +
"</style>" ).appendTo( "head" );

jQuery( "<div id='test-backgroundPosition' style='background-color:#FFF' />" ).appendTo( "#qunit-fixture" );
notEqual( jQuery( "#test-backgroundPosition" ).css( "backgroundPosition" ), "0% 0%", "css('background-position') expands properly with not 0% 0%" );

// This test case is only supported in IE9
if ( document.documentMode && document.documentMode === 9 ) {
jQuery( "<div id='test-backgroundPositionCSS3' style='background-color:#FFF' />" ).appendTo( "#qunit-fixture" );
equal( jQuery( "#test-backgroundPositionCSS3" ).css( "backgroundPosition" ), "10px 20px, 30px 40px", "css('background-position') of CSS3 expands properly with 10px 20px, 30px 40px" );
}
});