Commit f2963353 authored by Elijah Manor's avatar Elijah Manor

Add support check, added assertion to check if cleared, add edge case for backgroundPosition

parent f952b979
...@@ -204,6 +204,9 @@ jQuery.extend({ ...@@ -204,6 +204,9 @@ jQuery.extend({
// If a hook was provided, use that value, otherwise just set the specified value // 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 ) { 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 // Wrapped to prevent IE from throwing errors when 'invalid' values are provided
// Fixes bug #5509 // Fixes bug #5509
try { try {
......
...@@ -585,14 +585,13 @@ jQuery.extend({ ...@@ -585,14 +585,13 @@ jQuery.extend({
var srcElements, var srcElements,
destElements, destElements,
i, i,
clone, clone;
fix8908;
if ( jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) { if ( jQuery.support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) {
// Fixes #8909 - By accessing one of the element's computed styles it breaks the // Fixes #8909 - By accessing one of the element's computed styles it breaks the
// connection with the cloned element's styles in IE9/10 // connection with the cloned element's styles in IE9/10
if ( elem.nodeType === 1 && window.getComputedStyle ) { if ( !jQuery.support.clearCloneStyle && elem.nodeType === 1 && window.getComputedStyle ) {
fix8908 = ( window.getComputedStyle( elem, null ) || {} ).backgroundImage; i = ( window.getComputedStyle( elem, null ) || {} ).backgroundPosition;
} }
clone = elem.cloneNode( true ); clone = elem.cloneNode( true );
......
...@@ -170,6 +170,19 @@ jQuery.support = (function() { ...@@ -170,6 +170,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 // Run tests that need a body at doc ready
jQuery(function() { jQuery(function() {
var container, div, tds, marginDiv, var container, div, tds, marginDiv,
......
This diff is collapsed.
This diff is collapsed.
...@@ -1909,18 +1909,18 @@ test("checked state is cloned with clone()", function(){ ...@@ -1909,18 +1909,18 @@ test("checked state is cloned with clone()", function(){
}); });
test( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", function() { test( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", function() {
expect( 8 ); expect( 16 );
var baseUrl = document.location.href.replace( /([^\/]*)$/, "" ); var baseUrl = document.location.href.replace( /([^\/]*)$/, "" );
var styles = [ var styles = [
{ name: "background-attachment", value: [ "fixed" ], expected: [ "scroll" ] }, { name: "backgroundAttachment", value: [ "fixed" ], expected: [ "scroll" ] },
{ name: "background-color", value: [ "rgb(255, 0, 0)", "rgb(255,0,0)" ], expected: [ "transparent" ] }, { name: "backgroundColor", value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ], expected: [ "transparent" ] },
{ name: "background-image", value: [ 'url("test.png")', 'url(' + baseUrl + 'test.png)', 'url("' + baseUrl + 'test.png")' ], expected: [ "none" ] }, { 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: "background-position", value: [ "5% 5%" ], expected: [ "0% 0%" ] }, { name: "backgroundPosition", value: [ "5% 5%" ], expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ] },
{ name: "background-repeat", value: [ "repeat-y" ], expected: [ "repeat" ] }, { name: "backgroundRepeat", value: [ "repeat-y" ], expected: [ "repeat", "no-repeat" ] }, // Firefox returns no-repeat
{ name: "background-clip", value: [ "content-box" ], expected: [ "border-box" ] }, { name: "backgroundClip", value: [ "padding-box" ], expected: [ "border-box" ] },
{ name: "background-origin", value: [ "content-box" ], expected: [ "padding-box" ] }, { name: "backgroundOrigin", value: [ "content-box" ], expected: [ "padding-box" ] },
{ name: "background-size", value: [ "80px 60px" ], expected: [] } { name: "backgroundSize", value: [ "80px 60px" ], expected: [ "auto auto" ] }
]; ];
jQuery.each( styles, function(index, style) { jQuery.each( styles, function(index, style) {
...@@ -1931,6 +1931,7 @@ test( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's ...@@ -1931,6 +1931,7 @@ test( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's
source = $source[ 0 ]; source = $source[ 0 ];
if ( source.style[ style.name ] === undefined ) { if ( source.style[ style.name ] === undefined ) {
ok( true, style.name + ": style isn't supported and therefore not an issue" ); ok( true, style.name + ": style isn't supported and therefore not an issue" );
ok( true );
return true; return true;
} }
$source.css( style.name, style.value[0] ); $source.css( style.name, style.value[0] );
...@@ -1941,5 +1942,9 @@ test( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's ...@@ -1941,5 +1942,9 @@ test( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's
"Clearning clone.css() doesn't affect source.css(): " + style.name + "Clearning clone.css() doesn't affect source.css(): " + style.name +
"; result: " + $source.css( style.name ) + "; result: " + $source.css( style.name ) +
"; expected: " + style.value.join( "," ) ); "; 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( "," ) );
}); });
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment