Permalink
Browse files

Fixes #8908

  • Loading branch information...
1 parent 40e08f8 commit 3b2a06fce5a03a291148c0ab0c0efd2bfb3a24c0 @markelog committed Nov 18, 2012
Showing with 80 additions and 21 deletions.
  1. +0 −9 src/css.js
  2. +3 −8 src/manipulation.js
  3. +0 −4 src/support.js
  4. +77 −0 test/unit/css.js
View
9 src/css.js
@@ -544,15 +544,6 @@ jQuery.each([ "height", "width" ], function( i, name ) {
};
});
-if ( !jQuery.support.clearCloneStyle ) {
- // #8908, this part for IE9 only; see gh-886
- jQuery.cssHooks.backgroundPosition = {
- set: function( elem, value ) {
- return value === "" ? "0% 0%" : value;
- }
- };
-}
-
if ( !jQuery.support.opacity ) {
jQuery.cssHooks.opacity = {
get: function( elem, computed ) {
View
11 src/manipulation.js
@@ -433,7 +433,7 @@ function cloneCopyEvent( src, dest ) {
}
}
-function cloneFixAttributes( src, dest ) {
+function fixCloneNodeIssues( src, dest ) {
var nodeName, data, e;
// We do not need to do anything for non-Elements
@@ -565,12 +565,8 @@ jQuery.extend({
inPage = jQuery.contains( elem.ownerDocument, elem );
if ( jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) {
- // Break the original-clone style connection in IE9/10 (#8909)
- if ( !jQuery.support.clearCloneStyle && elem.nodeType === 1 ) {
- 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;
@@ -580,15 +576,14 @@ jQuery.extend({
if ( (!jQuery.support.noCloneEvent || !jQuery.support.noCloneChecked) &&
(elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) {
- // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
destElements = getAll( clone );
srcElements = getAll( elem );
// Fix all IE cloning issues
for ( i = 0; (node = srcElements[i]) != null; ++i ) {
// Ensure that the destination node is not null; Fixes #9587
if ( destElements[i] ) {
- cloneFixAttributes( node, destElements[i] );
+ fixCloneNodeIssues( node, destElements[i] );
}
}
}
View
4 src/support.js
@@ -169,10 +169,6 @@ jQuery.support = (function() {
}
}
- div.style.backgroundClip = "content-box";
- div.cloneNode( true ).style.backgroundClip = "";
- support.clearCloneStyle = div.style.backgroundClip === "content-box";
-
// Run tests that need a body at doc ready
jQuery(function() {
var container, div, tds, marginDiv,
View
77 test/unit/css.js
@@ -923,4 +923,81 @@ test( "css opacity consistency across browsers (#12685)", function() {
equal( Math.round( el.css("opacity") * 100 ), 20, "remove opacity override" );
});
+asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", 16, function() {
+ var baseUrl = document.location.href.replace( /([^\/]*)$/, "" ),
+ styles = [{
+ name: "backgroundAttachment",
+ value: ["fixed"],
+ expected: [ "scroll" ]
+ },{
+ name: "backgroundColor",
+ value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ],
+ expected: ["transparent"]
+ }, {
+ // Firefox returns auto's value
+ 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\")" ]
+ }, {
+ name: "backgroundPosition",
+ value: ["5% 5%"],
+ expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ]
+ }, {
+ // Firefox returns no-repeat
+ name: "backgroundRepeat",
+ value: ["repeat-y"],
+ expected: [ "repeat", "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 $clone, $clonedChildren,
+ $source = jQuery( "#firstp" ),
+ source = $source[ 0 ],
+ $children = $source.children();
+
+ style.expected = style.expected.concat( [ "", "auto" ] );
+
+ 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 ] );
+ $children.css( style.name, style.value[ 0 ] );
+
+ $clone = $source.clone();
+ $clonedChildren = $clone.children();
+
+ $clone.css( style.name, "" );
+ $clonedChildren.css( style.name, "" );
+
+ window.setTimeout(function() {
+ ok( jQuery.inArray( $source.css( style.name ) !== -1, style.value ),
+ "Clearing clone.css() doesn't affect source.css(): " + style.name +
+ "; result: " + $source.css( style.name ) +
+ "; expected: " + style.value.join( "," ) );
+
+ ok( jQuery.inArray( $children.css( style.name ) !== -1, style.value ),
+ "Clearing clonedChildren.css() doesn't affect children.css(): " + style.name +
+ "; result: " + $children.css( style.name ) +
+ "; expected: " + style.value.join( "," ) );
+ }, 100 );
+ });
+
+ window.setTimeout( start, 1000 );
+});
+
}

0 comments on commit 3b2a06f

Please sign in to comment.