aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/css.js10
-rw-r--r--src/manipulation.js6
-rw-r--r--src/support.js4
-rw-r--r--test/unit/manipulation.js41
4 files changed, 60 insertions, 1 deletions
diff --git a/src/css.js b/src/css.js
index 1723223e5..eb0aed639 100644
--- a/src/css.js
+++ b/src/css.js
@@ -198,6 +198,7 @@ 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 ) {
+
// Wrapped to prevent IE from throwing errors when 'invalid' values are provided
// Fixes bug #5509
try {
@@ -515,6 +516,15 @@ 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 ) {
diff --git a/src/manipulation.js b/src/manipulation.js
index b6dd6f086..473fa5c82 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -596,8 +596,12 @@ jQuery.extend({
clone;
if ( jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) {
- clone = elem.cloneNode( true );
+ // 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;
diff --git a/src/support.js b/src/support.js
index 7629c38e7..1001f407a 100644
--- a/src/support.js
+++ b/src/support.js
@@ -169,6 +169,10 @@ 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,
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 6c37e5196..19897af74 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -2023,6 +2023,47 @@ test("checked state is cloned with clone()", function(){
equal( jQuery(elem).clone().attr("id","clone")[0].checked, true, "Checked true state correctly cloned" );
});
+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 ),
+ "Clearing 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 ),
+ "Cloned element was reset to its default value: " + style.name +
+ "; result: " + $clone.css( style.name ) +
+ "; expected: " + style.expected.join( "," ) );
+ });
+});
+
test("manipulate mixed jQuery and text (#12384, #12346)", function() {
expect(2);