Permalink
Browse files

Merge with latest master

  • Loading branch information...
1 parent 05fb5de commit e26ef4eae2b50ef2987f7c37d1f2a99b5764febf @elijahmanor elijahmanor committed Nov 15, 2012
Showing with 63 additions and 1 deletion.
  1. +3 −0 src/css.js
  2. +6 −1 src/manipulation.js
  3. +13 −0 src/support.js
  4. +41 −0 test/unit/manipulation.js
View
@@ -198,6 +198,9 @@ jQuery.extend({
// If a hook was provided, use that value, otherwise just set the specified value
if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) {
+ // IE9/10 Clearing Cloned Style Clear's Original Style. Fixes bug #8908
+ value = !jQuery.support.clearCloneStyle && value === "" && name.match( /backgroundPosition/ ) ? "0% 0%" : value;
+
// Wrapped to prevent IE from throwing errors when 'invalid' values are provided
// Fixes bug #5509
try {
View
@@ -596,8 +596,13 @@ jQuery.extend({
clone;
if ( jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) {
- clone = elem.cloneNode( true );
+ // Fixes #8909 - By accessing one of the element's computed styles it breaks the
+ // connection with the cloned element's styles in IE9/10
+ if ( !jQuery.support.clearCloneStyle && elem.nodeType === 1 && window.getComputedStyle ) {
+ i = ( window.getComputedStyle( elem, null ) || {} ).backgroundPosition;
+ }
+ clone = elem.cloneNode( true );
// IE<=8 does not properly clone detached, unknown element nodes
} else {
fragmentDiv.innerHTML = elem.outerHTML;
View
@@ -169,6 +169,19 @@ jQuery.support = (function() {
}
}
+ support.clearCloneStyle = (function() {
+ var source = document.createElement( "div" ),
+ styleName = "backgroundClip",
+ value = "content-box",
+ clone;
+
+ source.style[ styleName ] = value;
+ clone = source.cloneNode( true );
+ clone.style[ styleName ] = "";
+
+ return source.style[ styleName ] === value;
+ })();
+
// Run tests that need a body at doc ready
jQuery(function() {
var container, div, tds, marginDiv,
View
@@ -2042,3 +2042,44 @@ testIframeWithCallback( "buildFragment works even if document[0] is iframe's win
ok( test.status, test.description );
});
+
+test( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", function() {
+ expect( 16 );
+
+ var baseUrl = document.location.href.replace( /([^\/]*)$/, "" );
+ var styles = [
+ { name: "backgroundAttachment", value: [ "fixed" ], expected: [ "scroll" ] },
+ { name: "backgroundColor", value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ], expected: [ "transparent" ] },
+ { name: "backgroundImage", value: [ 'url("test.png")', 'url(' + baseUrl + 'test.png)', 'url("' + baseUrl + 'test.png")' ], expected: [ "none", 'url("http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif")' ] }, // Firefox returns auto's value
+ { name: "backgroundPosition", value: [ "5% 5%" ], expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ] },
+ { name: "backgroundRepeat", value: [ "repeat-y" ], expected: [ "repeat", "no-repeat" ] }, // Firefox returns no-repeat
+ { name: "backgroundClip", value: [ "padding-box" ], expected: [ "border-box" ] },
+ { name: "backgroundOrigin", value: [ "content-box" ], expected: [ "padding-box" ] },
+ { name: "backgroundSize", value: [ "80px 60px" ], expected: [ "auto auto" ] }
+ ];
+
+ jQuery.each( styles, function(index, style) {
+ var $source, source, $clone;
+
+ style.expected = style.expected.concat( [ "", "auto" ] );
+ $source = jQuery( "<div />" );
+ source = $source[ 0 ];
+ if ( source.style[ style.name ] === undefined ) {
+ ok( true, style.name + ": style isn't supported and therefore not an issue" );
+ ok( true );
+ return true;
+ }
+ $source.css( style.name, style.value[0] );
+ $clone = $source.clone();
+ $clone.css( style.name, "" );
+
+ ok( ~jQuery.inArray( $source.css( style.name ), style.value ),
+ "Clearning clone.css() doesn't affect source.css(): " + style.name +
+ "; result: " + $source.css( style.name ) +
+ "; expected: " + style.value.join( "," ) );
+ ok( ~jQuery.inArray( $clone.css( style.name ), style.expected ),
+ "The cloned element was reset to it's default value: " + style.name +
+ "; result: " + $clone.css( style.name ) +
+ "; expected: " + style.expected.join( "," ) );
+ });
+});

0 comments on commit e26ef4e

Please sign in to comment.