Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

… for backgroundPosition
  • Loading branch information...
commit f29633536076e831e25705b560c983674ed839ee 1 parent f952b97
@elijahmanor elijahmanor authored
View
0  grep
No changes.
View
3  src/css.js
@@ -204,6 +204,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
7 src/manipulation.js
@@ -585,14 +585,13 @@ jQuery.extend({
var srcElements,
destElements,
i,
- clone,
- fix8908;
+ clone;
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
// connection with the cloned element's styles in IE9/10
- if ( elem.nodeType === 1 && window.getComputedStyle ) {
- fix8908 = ( window.getComputedStyle( elem, null ) || {} ).backgroundImage;
+ if ( !jQuery.support.clearCloneStyle && elem.nodeType === 1 && window.getComputedStyle ) {
+ i = ( window.getComputedStyle( elem, null ) || {} ).backgroundPosition;
}
clone = elem.cloneNode( true );
View
13 src/support.js
@@ -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
jQuery(function() {
var container, div, tds, marginDiv,
View
295 test/unit/clone.html
@@ -0,0 +1,295 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
+ <title>jQuery Test Suite</title>
+ <link rel="Stylesheet" media="screen" href="../qunit/qunit/qunit.css" />
+ <link rel="Stylesheet" media="screen" href="../data/testsuite.css" />
+ <!-- Includes -->
+
+ <script src="../data/testinit.js"></script>
+
+ <script src="../qunit/qunit/qunit.js"></script>
+ <!-- Loads minified version if min=true is present in the search -->
+ <!-- Nullifies querySelectorAll if noqsa=true is present -->
+ <script>
+ (function() {
+ var src = "../../dist/jquery.js";
+
+ QUnit.config.urlConfig.push( "min" );
+ if ( QUnit.urlParams.min ) {
+ src = "../../dist/jquery.min.js";
+ }
+
+ QUnit.config.urlConfig.push( "noqsa" );
+ if ( QUnit.urlParams.noqsa ) {
+ document.querySelectorAll = null;
+ }
+
+ document.write( "<script src='" + src + "'><\/script>" );
+ })();
+ </script>
+ <script src="../data/testrunner.js"></script>
+
+ <script src="clone.js"></script>
+
+ <script>
+ // html5shiv, enabling HTML5 elements to be used with jQuery
+ ( "abbr article aside audio bdi canvas data details figcaption figure footer header hgroup " +
+ "mark meter nav output progress section summary time video"
+ ).replace(/\w+/g, function(n) {
+ document.createElement(n);
+ });
+ </script>
+</head>
+
+<body id="body">
+ <h1 id="qunit-header"><a href="../jquery/test/index.html">jQuery Test Suite</a></h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+
+ <!-- Test HTML -->
+ <div id="nothiddendiv" style="height:1px;background:white;" class="nothiddendiv">
+ <div id="nothiddendivchild"></div>
+ </div>
+ <!-- this iframe is outside the #qunit-fixture so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
+ <iframe id="loadediframe" name="loadediframe" style="display:none;" src="../data/iframe.html"></iframe>
+ <textarea id="console" style="width: 100%; height: 300px;"></textarea>
+ <dl id="dl" style="position:absolute;top:-32767px;left:-32767px;width:1px">
+ <div id="qunit-fixture">
+ <p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
+ <p id="ap">
+ Here are some links in a normal paragraph: <a id="google" href="http://www.google.com/" title="Google!">Google</a>,
+ <a id="groups" href="http://groups.google.com/" class="GROUPS">Google Groups (Link)</a>.
+ This link has <code><a href="http://smin" id="anchor1">class="blog"</a></code>:
+ <a href="http://diveintomark.org/" class="blog" hreflang="en" id="mark">diveintomark</a>
+
+ </p>
+ <div id="foo">
+ <p id="sndp">Everything inside the red border is inside a div with <code>id="foo"</code>.</p>
+ <p lang="en" id="en">This is a normal link: <a id="yahoo" href="http://www.yahoo.com/" class="blogTest">Yahoo</a></p>
+ <p id="sap">This link has <code><a href="#2" id="anchor2">class="blog"</a></code>: <a href="http://simon.incutio.com/" class="blog link" id="simon">Simon Willison's Weblog</a></p>
+
+ </div>
+ <span id="name+value"></span>
+ <p id="first">Try them out:</p>
+ <ul id="firstUL"></ul>
+ <ol id="empty"></ol>
+ <form id="form" action="formaction">
+ <label for="action" id="label-for">Action:</label>
+ <input type="text" name="action" value="Test" id="text1" maxlength="30"/>
+ <input type="text" name="text2" value="Test" id="text2" disabled="disabled"/>
+ <input type="radio" name="radio1" id="radio1" value="on"/>
+
+ <input type="radio" name="radio2" id="radio2" checked="checked"/>
+ <input type="checkbox" name="check" id="check1" checked="checked"/>
+ <input type="checkbox" id="check2" value="on"/>
+
+ <input type="hidden" name="hidden" id="hidden1"/>
+ <input type="text" style="display:none;" name="foo[bar]" id="hidden2"/>
+
+ <input type="text" id="name" name="name" value="name" />
+ <input type="search" id="search" name="search" value="search" />
+
+ <button id="button" name="button" type="button">Button</button>
+
+ <textarea id="area1" maxlength="30">foobar</textarea>
+
+ <select name="select1" id="select1">
+ <option id="option1a" class="emptyopt" value="">Nothing</option>
+ <option id="option1b" value="1">1</option>
+ <option id="option1c" value="2">2</option>
+ <option id="option1d" value="3">3</option>
+ </select>
+ <select name="select2" id="select2">
+ <option id="option2a" class="emptyopt" value="">Nothing</option>
+ <option id="option2b" value="1">1</option>
+ <option id="option2c" value="2">2</option>
+ <option id="option2d" selected="selected" value="3">3</option>
+ </select>
+ <select name="select3" id="select3" multiple="multiple">
+ <option id="option3a" class="emptyopt" value="">Nothing</option>
+ <option id="option3b" selected="selected" value="1">1</option>
+ <option id="option3c" selected="selected" value="2">2</option>
+ <option id="option3d" value="3">3</option>
+ <option id="option3e">no value</option>
+ </select>
+ <select name="select4" id="select4" multiple="multiple">
+ <optgroup disabled="disabled">
+ <option id="option4a" class="emptyopt" value="">Nothing</option>
+ <option id="option4b" disabled="disabled" selected="selected" value="1">1</option>
+ <option id="option4c" selected="selected" value="2">2</option>
+ </optgroup>
+ <option selected="selected" disabled="disabled" id="option4d" value="3">3</option>
+ <option id="option4e">no value</option>
+ </select>
+ <select name="select5" id="select5">
+ <option id="option5a" value="3">1</option>
+ <option id="option5b" value="2">2</option>
+ <option id="option5c" value="1" data-attr="">3</option>
+ </select>
+
+ <object id="object1" codebase="stupid">
+ <param name="p1" value="x1" />
+ <param name="p2" value="x2" />
+ </object>
+
+ <span id="台北Táiběi"></span>
+ <span id="台北" lang="中文"></span>
+ <span id="utf8class1" class="台北Táiběi 台北"></span>
+ <span id="utf8class2" class="台北"></span>
+ <span id="foo:bar" class="foo:bar"></span>
+ <span id="test.foo[5]bar" class="test.foo[5]bar"></span>
+
+ <foo_bar id="foobar">test element</foo_bar>
+ </form>
+ <b id="floatTest">Float test.</b>
+ <iframe id="iframe" name="iframe"></iframe>
+ <form id="lengthtest">
+ <input type="text" id="length" name="test"/>
+ <input type="text" id="idTest" name="id"/>
+ </form>
+ <table id="table"></table>
+
+ <form id="name-tests">
+ <!-- Inputs with a grouped name attribute. -->
+ <input name="types[]" id="types_all" type="checkbox" value="all" />
+ <input name="types[]" id="types_anime" type="checkbox" value="anime" />
+ <input name="types[]" id="types_movie" type="checkbox" value="movie" />
+ </form>
+
+ <form id="testForm" action="#" method="get">
+ <textarea name="T3" rows="2" cols="15">?
+Z</textarea>
+ <input type="hidden" name="H1" value="x" />
+ <input type="hidden" name="H2" />
+ <input name="PWD" type="password" value="" />
+ <input name="T1" type="text" />
+ <input name="T2" type="text" value="YES" readonly="readonly" />
+ <input type="checkbox" name="C1" value="1" />
+ <input type="checkbox" name="C2" />
+ <input type="radio" name="R1" value="1" />
+ <input type="radio" name="R1" value="2" />
+ <input type="text" name="My Name" value="me" />
+ <input type="reset" name="reset" value="NO" />
+ <select name="S1">
+ <option value="abc">ABC</option>
+ <option value="abc">ABC</option>
+ <option value="abc">ABC</option>
+ </select>
+ <select name="S2" multiple="multiple" size="3">
+ <option value="abc">ABC</option>
+ <option value="abc">ABC</option>
+ <option value="abc">ABC</option>
+ </select>
+ <select name="S3">
+ <option selected="selected">YES</option>
+ </select>
+ <select name="S4">
+ <option value="" selected="selected">NO</option>
+ </select>
+ <input type="submit" name="sub1" value="NO" />
+ <input type="submit" name="sub2" value="NO" />
+ <input type="image" name="sub3" value="NO" />
+ <button name="sub4" type="submit" value="NO">NO</button>
+ <input name="D1" type="text" value="NO" disabled="disabled" />
+ <input type="checkbox" checked="checked" disabled="disabled" name="D2" value="NO" />
+ <input type="radio" name="D3" value="NO" checked="checked" disabled="disabled" />
+ <select name="D4" disabled="disabled">
+ <option selected="selected" value="NO">NO</option>
+ </select>
+ <input id="list-test" type="text" />
+ <datalist id="datalist">
+ <option value="option"></option>
+ </datalist>
+ </form>
+ <div id="moretests">
+ <form>
+ <div id="checkedtest" style="display:none;">
+ <input type="radio" name="checkedtestradios" checked="checked"/>
+ <input type="radio" name="checkedtestradios" value="on"/>
+ <input type="checkbox" name="checkedtestcheckboxes" checked="checked"/>
+ <input type="checkbox" name="checkedtestcheckboxes" />
+ </div>
+ </form>
+ <div id="nonnodes"><span>hi</span> there <!-- mon ami --></div>
+ <div id="t2037">
+ <div><div class="hidden">hidden</div></div>
+ </div>
+ <div id="t6652">
+ <div></div>
+ </div>
+ <div id="no-clone-exception"><object><embed></embed></object></div>
+ </div>
+
+ <div id="tabindex-tests">
+ <ol id="listWithTabIndex" tabindex="5">
+ <li id="foodWithNegativeTabIndex" tabindex="-1">Rice</li>
+ <li id="foodNoTabIndex">Beans</li>
+ <li>Blinis</li>
+ <li>Tofu</li>
+ </ol>
+
+ <div id="divWithNoTabIndex">I'm hungry. I should...</div>
+ <span>...</span><a href="#" id="linkWithNoTabIndex">Eat lots of food</a><span>...</span> |
+ <span>...</span><a href="#" id="linkWithTabIndex" tabindex="2">Eat a little food</a><span>...</span> |
+ <span>...</span><a href="#" id="linkWithNegativeTabIndex" tabindex="-1">Eat no food</a><span>...</span>
+ <span>...</span><a id="linkWithNoHrefWithNoTabIndex">Eat a burger</a><span>...</span>
+ <span>...</span><a id="linkWithNoHrefWithTabIndex" tabindex="1">Eat some funyuns</a><span>...</span>
+ <span>...</span><a id="linkWithNoHrefWithNegativeTabIndex" tabindex="-1">Eat some funyuns</a><span>...</span>
+ </div>
+
+ <div id="liveHandlerOrder">
+ <span id="liveSpan1"><a href="#" id="liveLink1"></a></span>
+ <span id="liveSpan2"><a href="#" id="liveLink2"></a></span>
+ </div>
+
+ <div id="siblingTest">
+ <em id="siblingfirst">1</em>
+ <em id="siblingnext">2</em>
+ <em id="siblingthird">
+ <em id="siblingchild">
+ <em id="siblinggrandchild">
+ <em id="siblinggreatgrandchild"></em>
+ </em>
+ </em>
+ </em>
+ <span id="siblingspan"></span>
+ </div>
+ </div>
+ </dl>
+ <div id="fx-test-group" style="position:absolute;width:1px;height:1px;overflow:hidden;">
+ <div id="fx-queue" name="test">
+ <div id="fadein" class='chain test' name='div'>fadeIn<div>fadeIn</div></div>
+ <div id="fadeout" class='chain test out'>fadeOut<div>fadeOut</div></div>
+
+ <div id="show" class='chain test'>show<div>show</div></div>
+ <div id="hide" class='chain test out'>hide<div>hide</div></div>
+
+ <div id="togglein" class='chain test'>togglein<div>togglein</div></div>
+ <div id="toggleout" class='chain test out'>toggleout<div>toggleout</div></div>
+
+
+ <div id="slideup" class='chain test'>slideUp<div>slideUp</div></div>
+ <div id="slidedown" class='chain test out'>slideDown<div>slideDown</div></div>
+
+ <div id="slidetogglein" class='chain test'>slideToggleIn<div>slideToggleIn</div></div>
+ <div id="slidetoggleout" class='chain test out'>slideToggleOut<div>slideToggleOut</div></div>
+
+ <div id="fadetogglein" class='chain test'>fadeToggleIn<div>fadeToggleIn</div></div>
+ <div id="fadetoggleout" class='chain test out'>fadeToggleOut<div>fadeToggleOut</div></div>
+
+ <div id="fadeto" class='chain test'>fadeTo<div>fadeTo</div></div>
+ </div>
+
+ <div id="fx-tests"></div>
+ </div>
+ <map name="imgmap" id="imgmap">
+ <area shape="rect" coords="0,0,200,50">
+ </map>
+
+</body>
+</html>
View
523 test/unit/clone.js
@@ -0,0 +1,523 @@
+/*global module:false, window:false, moduleTeardown:false, console:false, test:false, equal:false, $:false, ok:false, alert:false, jQuery:false, document:false*/
+/*jshint laxcomma:true */
+
+(function( $ ) {
+"use strict";
+
+var _console, $console;
+
+module( "clone", {
+ setup: function() {
+ $console = $( "#console" );
+ $console.val( "" );
+ _console = window.console || {};
+ window.console = {
+ log: function( message ) {
+ if ( _console.log ) {
+ // _console.log.apply( _console, arguments );
+ }
+ $console.val(function(index, value) {
+ return value + ( value ? "\n" : "" ) + message;
+ });
+ }
+ };
+ },
+ teardown: function() {
+ window.console = _console;
+ moduleTeardown();
+ }
+});
+
+test( "Clearing Clone's Property Doesn't Clear Original Element's Property", function() {
+ // Define styles from http://www.w3.org/TR/CSS/#indices
+ // Array.prototype.forEach.call( document.querySelectorAll( "tr" ), function( row ) { var imgs = row.querySelectorAll( "img" ); if ( imgs[2] && imgs[2].attributes.alt.value === "no" && imgs[3] && imgs[3].attributes.alt.value === "yes" ) { console.log( "skipping" ); } else { row.style.display = "none"; } } );
+ var baseUrl = document.location.href.replace( /([^\/]*)$/, "" ), count = 0;
+ var styles = [
+ { name: "background-attachment", value: ["fixed"], expected: ["scroll"] },
+ { name: "background-color", value: ["rgb(255, 0, 0)", "rgb(255,0,0)"], expected: ["transparent"] },
+ {
+ name: "background-image",
+ value: [
+ 'url("test.png")',
+ 'url(' + baseUrl + 'test.png)',
+ 'url("' + baseUrl + 'test.png")'
+ ],
+ expected: ["none"]
+ },
+ { name: "background-position", value: ["5% 5%"], expected: ["0% 0%"] },
+ { name: "background-repeat", value: ["repeat-y"], expected: ["repeat"] },
+ {
+ name: "background",
+ value: [
+ "rgb(255, 0, 0) 50% 50%",
+ "50% 50% rgb(255, 0, 0)",
+ "rgb(255,0,0) 50% 50%",
+ "none repeat scroll 50% 50% rgb(255, 0, 0)"
+ ],
+ expected: ["none", "none transparent scroll repeat 0% 0%"]
+ },
+ { name: "border-collapse", value: ["collapse"], expected: ["separate"] },
+ { name: "border-color", value: ["rgb(255, 0, 0)", "rgb(255,0,0)"], expected: ["none", "#000000"] },
+ // BEGIN
+ { name: "border-spacing", value: ["5px 5px", "5px"], expected: ["0px 0px"] },
+ // END
+ { name: "border-style", value: ["dashed"], expected: ["none"] },
+ {
+ name: "border-top",
+ value: ["thick double rgb(255, 0, 0)", "rgb(255,0,0) thick double"],
+ expected: ["none", "medium none"]
+ },
+ {
+ name: "border-right",
+ value: ["thick double rgb(255, 0, 0)", "rgb(255,0,0) thick double"],
+ expected: ["none", "medium none"]
+ },
+ {
+ name: "border-bottom",
+ value: ["thick double rgb(255, 0, 0)", "rgb(255,0,0) thick double"],
+ expected: ["none", "medium none"]
+ },
+ {
+ name: "border-left",
+ value: ["thick double rgb(255, 0, 0)", "rgb(255,0,0) thick double"],
+ expected: ["none", "medium none"]
+ },
+ { name: "border-top-color", value: ["rgb(255, 0, 0)", "rgb(255,0,0)"], expected: ["rgb(0, 0, 0)", "#000000"] },
+ { name: "border-right-color", value: ["rgb(255, 0, 0)", "rgb(255,0,0)"], expected: ["rgb(0, 0, 0)", "#000000"] },
+ { name: "border-bottom-color", value: ["rgb(255, 0, 0)", "rgb(255,0,0)"], expected: ["rgb(0, 0, 0)", "#000000"] },
+ { name: "border-left-color", value: ["rgb(255, 0, 0)", "rgb(255,0,0)"], expected: ["rgb(0, 0, 0)", "#000000"] },
+ { name: "border-top-style", value: ["dotted"], expected: ["none"] },
+ { name: "border-right-style", value: ["dotted"], expected: ["none"] },
+ { name: "border-bottom-style", value: ["dotted"], expected: ["none"] },
+ { name: "border-left-style", value: ["dotted"], expected: ["none"] },
+ // BEGIN - IE10 doesn't seem to apply these correctly getComputedStyle shows as 0px for thick
+ // { name: "border-top-width", value: ["thick"], expected: ["medium"] },
+ // { name: "border-right-width", value: ["thick"], expected: ["medium"] },
+ // { name: "border-bottom-width", value: ["thick"], expected: ["medium"] },
+ // { name: "border-left-width", value: ["thick"], expected: ["medium"] },
+ // END
+ { name: "border-width", value: ["5px"], expected: ["0px", "medium"] },
+ { name: "border", value: ["5px solid rgb(255, 0, 0)", "rgb(255,0,0) 5px solid"], expected: ["none", undefined, "undefined"] },
+ { name: "bottom", value: ["5px"], expected: [] },
+ { name: "caption-side", value: ["bottom"], expected: ["top"] },
+ { name: "clear", value: ["right"], expected: ["none"] },
+ {
+ name: "clip",
+ value: [
+ "rect(110px 160px 170px 60px)",
+ "rect(110px, 160px, 170px, 60px)",
+ "rect(110px,160px,170px,60px)"
+ ],
+ expected: [
+ "rect(auto,auto,auto,auto)",
+ "rect(auto auto auto auto)",
+ "rect(0px, 0px, 0px, 0px)"
+ ]
+ },
+ { name: "color", value: ["rgb(255, 0, 0)", "rgb(255,0,0)"], expected: ["rgb(0, 0, 0)", "#000000"] },
+ // { name: "content", value: ["test"], expected: ["normal", "none"] }, // Content isn't found in DOM
+ { name: "counter-increment", value: ["section", "section 1"], expected: ["none"] },
+ { name: "counter-reset", value: ["section", "section 0"], expected: ["none"] },
+ { name: "cursor", value: ["crosshair"], expected: [] },
+ { name: "direction", value: ["rtl"], expected: ["ltr"] },
+ { name: "display", value: ["list-item"], expected: ["block"] },
+ { name: "empty-cells", value: ["hide"], expected: ["show"] },
+ { name: "float", value: ["right"], expected: ["none"] },
+ { name: "font-family", value: ["Georgia, serif"], expected: ["Times New Roman", "serif"] },
+ { name: "font-size", value: ["12px"], expected: ["16px"] },
+ { name: "font-style", value: ["italic"], expected: ["normal"] },
+ { name: "font-variant", value: ["small-caps"], expected: ["normal"] },
+ { name: "font-weight", value: ["700", 700], expected: ["400", 400, "700"] },
+ {
+ name: "font",
+ value: [
+ "italic 12px Georgia",
+ "italic 12px/normal Georgia",
+ "italic normal normal 12px/normal Georgia"
+ ],
+ expected: ["italic 12px Georgia"]
+ },
+ { name: "height", value: ["5px"], expected: ["0px"] },
+ { name: "left", value: ["5px"], expected: [] },
+ { name: "letter-spacing", value: ["5px"], expected: [0] },
+ { name: "line-height", value: ["12px"], expected: [1, "19.2px"] },
+ {
+ name: "list-style-image",
+ value: [
+ 'url("test.png")',
+ 'url(' + baseUrl + 'test.png)',
+ 'url("' + baseUrl + 'test.png")'
+ ],
+ expected: ["none"]
+ },
+ { name: "list-style-position", value: ["inside"], expected: ["outside"] },
+ { name: "list-style-type", value: ["disc"], expected: ["disc"] },
+ {
+ name: "list-style",
+ value: [
+ 'square url("test.png")',
+ 'square url(' + baseUrl + 'test.png)',
+ 'square url("' + baseUrl + 'test.png")',
+ 'square url(test.png)'
+ ],
+ expected: ["none", undefined]
+ },
+ { name: "margin-right", value: ["5px"], expected: ["0px"] },
+ { name: "margin-left", value: ["5px"], expected: ["0px"] },
+ { name: "margin-top", value: ["5px"], expected: ["0px"] },
+ { name: "margin-bottom", value: ["5px"], expected: ["0px"] },
+ { name: "margin", value: ["5px"], expected: ["", "0px"] },
+ { name: "max-height", value: ["5px"], expected: ["none"] },
+ { name: "max-width", value: ["5px"], expected: ["none"] },
+ { name: "min-height", value: ["5px"], expected: ["0px"] },
+ { name: "min-width", value: ["5px"], expected: ["0px"] },
+ { name: "opacity", value: ["0.5"], expected: [1, "1"] },
+ { name: "orphans", value: ["3", 3], expected: [0, "0"] },
+ {
+ name: "outline-color",
+ value: ["rgb(255, 0, 0)", "rgb(255,0,0)"],
+ expected: ["transparent", "rgb(0, 0, 0)", "#000000"]
+ },
+ { name: "outline-style", value: ["dashed"], expected: ["none"] },
+ // BEGIN - IE8 throws exception when trying to check for curCSS
+ // { name: "outline", value: ["red dotted thick", "thick dotted red"], expected: ["none"] },
+ // END
+ { name: "overflow", value: ["scroll"], expected: ["visible"] },
+ { name: "padding-top", value: ["5px"], expected: ["0px"] },
+ { name: "padding-right", value: ["5px"], expected: ["0px"] },
+ { name: "padding-bottom", value: ["5px"], expected: ["0px"] },
+ { name: "padding-left", value: ["5px"], expected: ["0px"] },
+ { name: "padding", value: ["5px"], expected: ["0px"] },
+ { name: "page-break-after", value: ["right"], expected: [] },
+ { name: "page-break-before", value: ["right"], expected: [] },
+ { name: "page-break-inside", value: ["avoid"], expected: [] },
+ { name: "position", value: ["absolute"], expected: ["static"] },
+ {
+ name: "quotes",
+ value: [
+ '"«" "»" "\'" "\'"',
+ "«, », '\\'', '\\''",
+ '"«" "»" "\\\'" "\\\'"'
+ ],
+ expected: [
+ '"“" "”" "‘" "’"',
+ '"“" "”" "‘" "’"',
+ '“, ”, ‘, ’'
+ ]
+ },
+ { name: "right", value: ["5px"], expected: [] },
+ { name: "table-layout", value: ["fixed"], expected: [] },
+ { name: "text-align", value: ["right"], expected: ["left", "start"] },
+ { name: "text-decoration", value: ["underline"], expected: ["none"] },
+ { name: "text-indent", value: ["5px"], expected: ["0px"] },
+ { name: "text-transform", value: ["uppercase"], expected: ["none"] },
+ { name: "top", value: ["5px"], expected: [] },
+ { name: "unicode-bidi", value: ["bidi-override"], expected: ["normal"] },
+ { name: "vertical-align", value: ["text-top"], expected: ["baseline"] },
+ { name: "visibility", value: ["hidden"], expected: ["visible", "inherit"] },
+ { name: "white-space", value: ["nowrap"], expected: ["normal"] },
+ { name: "widows", value: ["2", 2], expected: [0, "0"] },
+ { name: "width", value: ["5px"], expected: ["0px"] },
+ { name: "word-spacing", value: ["5px"], expected: ["0px", "normal"] },
+ { name: "z-index", value: [100, "100"], expected: [0] },
+ { name: "alignment-adjust", value: ["middle"], expected: [] },
+ { name: "alignment-baseline", value: ["middle"], expected: ["baseline"] },
+ { name: "anchor-point", value: ["5px"], expected: ["none"] },
+ { name: "animation", value: ["test 5s infinite"], expected: ["none 0 ease 0 1 normal"] },
+ { name: "animation-delay", value: ["2s"], expected: ["0s"] },
+ { name: "animation-direction", value: ["alternate"], expected: ["normal"] },
+ { name: "animation-duration", value: ["2s"], expected: ["0s"] },
+ { name: "animation-iteration-count", value: ["3"], expected: ["1"] },
+ { name: "animation-name", value: ["test"], expected: ["none"] },
+ { name: "animation-play-state", value: ["paused"], expected: ["running"] },
+ {
+ name: "animation-timing-function",
+ value: ["linear", "cubic-bezier(0, 0, 1, 1)"],
+ expected: ["ease", "cubic-bezier(0.25, 0.1, 0.25, 1)"]
+ },
+ { name: "appearance", value: ["button"], expected: ["normal"] },
+ { name: "backface-visibility", value: ["hidden"], expected: ["visible"] },
+ { name: "background-clip", value: ["content-box"], expected: ["border-box"] },
+ { name: "background-origin", value: ["content-box"], expected: ["padding-box"] },
+ { name: "background-size", value: ["80px 60px"], expected: [] },
+ { name: "baseline-shift", value: ["super"], expected: ["baseline"] },
+ {
+ name: "binding",
+ value: ['url("test.png")'],
+ expected: []
+ },
+ { name: "bleed", value: ["3pt"], expected: ["6pt"] },
+ { name: "bookmark-label", value: ["test"], expected: ["content()"] },
+ { name: "bookmark-level", value: ["3"], expected: ["none"] },
+ { name: "bookmark-state", value: ["closed"], expected: ["open"] },
+ { name: "bookmark-target", value: ["attr(href, url)"], expected: ["none"] },
+ { name: "border-bottom-left-radius", value: ["32px", "32px 32px"], expected: ["0px"] },
+ { name: "border-bottom-right-radius", value: ["32px", "32px 32px"], expected: ["0px"] },
+ // Setting border-image in Chrome splits out to border-image-source, border-image-slice, and border-image-repeate
+ // { name: "border-image", value: ["url(border.png) 30 30 round"], expected: ["none 100% 1 0 stretch"] },
+ { name: "border-image-outset", value: ["30 30", "30"], expected: [0] },
+ { name: "border-image-repeat", value: ["round"], expected: ["stretch"] },
+ { name: "border-image-slice", value: ["50% 50%", "50%"], expected: ["100%"] },
+ {
+ name: "border-image-source",
+ value: [
+ 'url("border.png")',
+ 'url(' + baseUrl + 'border.png)',
+ 'url("' + baseUrl + 'border.png")',
+ 'url(border.png)'
+ ],
+ expected: ["none"]
+ },
+ { name: "border-image-width", value: ["30 30", "30"], expected: [1] },
+ // Setting border-radius in Chrome splits out to border-top-left-radius, etc...
+ // { name: "border-radius", value: ["25px"], expected: [0] },
+ { name: "border-top-left-radius", value: ["32px", "32px 32px"], expected: ["0px"] },
+ { name: "border-top-right-radius", value: ["32px", "32px 32px"], expected: ["0px"] },
+ { name: "box-decoration-break", value: ["clone"], expected: ["slice"] },
+ {
+ name: "box-shadow",
+ value: ["10px 10px 5px #cccccc", "rgb(204, 204, 204) 10px 10px 5px"],
+ expected: ["none"]
+ },
+ { name: "box-sizing", value: ["border-box"], expected: ["content-box"] },
+ { name: "break-after", value: ["right"], expected: [] },
+ { name: "break-before", value: ["right"], expected: [] },
+ { name: "break-inside", value: ["avoid"], expected: [] },
+ // I can't seem to get this to take in Chrome
+ // { name: "color-profile", value: ['url("http://eg.icm")'], expected: [] },
+ { name: "column-count", value: ["3"], expected: [] },
+ { name: "column-fill", value: ["auto"], expected: ["balance"] },
+ { name: "column-gap", value: ["40px"], expected: ["normal"] },
+ { name: "column-rule", value: ["3px outset rgb(255, 0, 255)"], expected: ["medium none black"] },
+ { name: "column-rule-color", value: ["#ff0000", "rgb(255, 0, 0)"], expected: ["rgb(0, 0, 0)"] },
+ { name: "column-rule-style", value: ["dotted"], expected: ["none"] },
+ { name: "column-rule-width", value: ["5px"], expected: ["medium"] },
+ { name: "column-span", value: ["all"], expected: ["1"] },
+ { name: "column-width", value: ["100px"], expected: [] },
+ { name: "columns", value: ["12em", "auto 12em"], expected: [] },
+ { name: "crop", value: ["rect(0px, 115px, 85px, 30px)"], expected: [] },
+ { name: "dominant-baseline", value: ["alphabetic"], expected: [] },
+ { name: "drop-initial-after-adjust", value: [""], expected: ["text-after-edge"] },
+ { name: "drop-initial-after-align", value: [""], expected: ["baseline"] },
+ { name: "drop-initial-before-adjust", value: [""], expected: ["text-before-edge"] },
+ { name: "drop-initial-before-align", value: [""], expected: ["caps-height"] },
+ { name: "drop-initial-size", value: [""], expected: [] },
+ { name: "drop-initial-value", value: [""], expected: ["initial"] },
+ { name: "fit", value: ["meet"], expected: ["fill"] },
+ { name: "fit-position", value: ["50% 50%"], expected: ["0% 0%"] },
+ { name: "align-items", value: ["baseline"], expected: ["streth"] },
+ { name: "align-self", value: ["baseline"], expected: [] },
+ { name: "align-content", value: ["center"], expected: ["stretch"] },
+ { name: "order", value: ["3"], expected: [0] },
+ { name: "justify-content", value: ["center"], expected: ["flex-start"] },
+ { name: "flex-grow", value: ["5"], expected: ["0"] },
+ { name: "flex-shrink", value: ["3"], expected: ["1"] },
+ { name: "flex-basis", value: ["22px"], expected: [] },
+ { name: "float-offset", value: ["-50% 3em"], expected: ["0 0"] },
+ { name: "font-feature-settings", value: ['"smcp" 1, "swsh" 2'], expected: ["normal"] },
+ { name: "font-kerning", value: ["normal"], expected: [] },
+ { name: "font-language-override", value: ["SRB"], expected: ["normal"] },
+ // I can't seem to get this to take in Chrome
+ // { name: "font-size-adjust", value: ["0.5"], expected: ["none"] },
+ // I can't seem to get this to take in Chrome
+ // { name: "font-stretch", value: ["condensed"], expected: ["normal"] },
+ { name: "font-synthesis", value: ["none"], expected: ["weight style"] },
+ { name: "font-variant-alternates", value: ["swash(flowing)"], expected: ["normal"] },
+ { name: "font-variant-caps", value: ["all-petite-caps"], expected: ["normal"] },
+ { name: "font-variant-east-asian", value: ["traditional"], expected: ["normal"] },
+ { name: "font-variant-ligatures", value: ["historical-ligatures"], expected: ["normal"] },
+ { name: "font-variant-numeric", value: ["diagonal-fractions"], expected: ["normal"] },
+ { name: "font-variant-position", value: ["super"], expected: ["normal"] },
+ { name: "hanging-punctuation", value: ["first"], expected: ["none"] },
+ { name: "hyphens", value: ["auto"], expected: ["manual"] },
+ { name: "icon", value: ['url("icon.png")'], expected: [] },
+ { name: "image-orientation", value: ["90deg"], expected: ["0deg"] },
+ // I can't seem to get this to take in Chrome
+ // { name: "image-rendering", value: ["optimizeQuality"], expected: [] },
+ { name: "image-resolution", value: ["300dpi"], expected: ["normal"] },
+ { name: "inline-box-align", value: ["initial"], expected: ["last"] },
+ { name: "line-break", value: ["strict"], expected: ["normal"] },
+ { name: "line-stacking", value: ["grid-height include-ruby disregard-shifts"], expected: [] },
+ { name: "line-stacking-ruby", value: ["include-ruby"], expected: ["exclude-ruby"] },
+ { name: "line-stacking-shift", value: ["disregard-shifts"], expected: ["consider-shifts"] },
+ { name: "line-stacking-strategy", value: ["grid-height"], expected: ["inline-line-height"] },
+ { name: "marks", value: ["cross"], expected: ["none"] },
+ { name: "marquee-direction", value: ["reverse"], expected: ["forward"] },
+ { name: "marquee-loop", value: ["5"], expected: [1] },
+ { name: "marquee-play-count", value: ["5"], expected: [1] },
+ { name: "marquee-speed", value: ["fast"], expected: ["normal"] },
+ { name: "marquee-style", value: ["alternate"], expected: ["scroll"] },
+ { name: "move-to", value: ["here"], expected: ["normal"] },
+ { name: "nav-down", value: ["#test"], expected: [] },
+ { name: "nav-index", value: ["5"], expected: [] },
+ { name: "nav-left", value: ["#test"], expected: [] },
+ { name: "nav-right", value: ["#test"], expected: [] },
+ { name: "nav-up", value: ["#test"], expected: [] },
+ { name: "opacity", value: ["0.5"], expected: ["1"] },
+ { name: "outline-offset", value: ["5px"], expected: [0] },
+ { name: "overflow-style", value: ["marquee-line"], expected: [] },
+ { name: "overflow-wrap", value: ["break-word"], expected: ["normal"] },
+ { name: "overflow-x", value: ["scroll"], expected: ["visible"] },
+ { name: "overflow-y", value: ["scroll"], expected: ["visible"] },
+ { name: "page", value: ["rotated"], expected: [] },
+ { name: "page-policy", value: ["last"], expected: ["start"] },
+ { name: "perspective", value: ["500px"], expected: ["none"] },
+ { name: "perspective-origin", value: ["10px 10px"], expected: ["50% 50%", "0px 0px"] },
+ { name: "presentation-level", value: ["same"], expected: [0] },
+ { name: "punctuation-trim", value: ["start"], expected: ["none"] },
+ { name: "rendering-intent", value: ["saturation"], expected: [] },
+ { name: "resize", value: ["horizontal"], expected: ["none"] },
+ { name: "rest", value: ["weak strong"], expected: [] },
+ { name: "rest-after", value: ["x-weak"], expected: [] },
+ { name: "rest-before", value: ["strong"], expected: [] },
+ { name: "rotation", value: ["180deg"], expected: [0] },
+ { name: "rotation-point", value: ["25% 75%"], expected: ["50% 50%"] },
+ { name: "ruby-align", value: ["center"], expected: [] },
+ { name: "ruby-overhang", value: ["whitespace"], expected: ["none"] },
+ { name: "ruby-position", value: ["inline"], expected: ["above"] },
+ { name: "ruby-span", value: ["attr(rbspan)"], expected: ["none"] },
+ { name: "size", value: ["landscape"], expected: ["auto"] },
+ { name: "speak-as", value: ["literal-punctuation"], expected: ["normal"] },
+ { name: "string-set", value: ["index content(first-letter)"], expected: ["none"] },
+ { name: "tab-size", value: ["4"], expected: [8] },
+ { name: "target", value: ["parent tab front"], expected: [] },
+ { name: "target-name", value: ["parent"], expected: ["current"] },
+ { name: "target-new", value: ["tab"], expected: ["window"] },
+ { name: "target-position", value: ["front"], expected: ["above"] },
+ { name: "text-align-last", value: ["right"], expected: [] },
+ { name: "text-decoration-color", value: ["rgb(255, 0, 0)"], expected: ["currentColor"] },
+ { name: "text-decoration-line", value: ["line-through"], expected: ["none"] },
+ { name: "text-decoration-skip", value: ["spaces"], expected: ["objects"] },
+ { name: "text-decoration-style", value: ["dotted"], expected: ["solid"] },
+ { name: "text-emphasis", value: ["double-circle"], expected: ["none"] },
+ { name: "text-emphasis-color", value: ["rgb(255, 0, 0)"], expected: ["currentColor"] },
+ { name: "text-emphasis-position", value: ["below left"], expected: ["above right"] },
+ { name: "text-emphasis-style", value: ["double-circle"], expected: ["none"] },
+ { name: "text-height", value: ["text-size"], expected: [] },
+ // Unable to Set Style on Source Element
+ // { name: "text-justify", value: ["distribute"], expected: [] },
+ { name: "text-outline", value: ["inter-word"], expected: ["none"] },
+ {
+ name: "text-shadow",
+ value: ["2px 2px #ff0000", "rgb(255, 0, 0) 2px 2px"],
+ expected: ["none"]
+ },
+ { name: "text-space-collapse", value: ["preserve"], expected: ["collapse"] },
+ { name: "text-underline-position", value: ["below"], expected: [] },
+ { name: "text-wrap", value: ["avoid"], expected: ["normal"] },
+ { name: "transform", value: ["rotate(7deg)", "matrix(0.992546, 0.121869, -0.121869, 0.992546, 0, 0)"], expected: ["none"] },
+ { name: "transform-origin", value: ["20px 40px"], expected: ["50% 50% 0%", "0px 0px"] },
+ { name: "transform-style", value: ["flat"], expected: ["flat"] },
+ { name: "transition", value: ["background-color linear 1s", "background-color 1s linear"], expected: [] },
+ { name: "transition-delay", value: ["2s"], expected: [0, "0s"] },
+ { name: "transition-duration", value: ["5s"], expected: [0, "0s"] },
+ { name: "transition-property", value: ["width"], expected: ["all"] },
+ {
+ name: "transition-timing-function",
+ value: ["linear", "cubic-bezier(0, 0, 1, 1)"],
+ expected: ["ease", "cubic-bezier(0.25, 0.1, 0.25, 1)"]
+ },
+ { name: "voice-balance", value: ["right"], expected: ["center"] },
+ { name: "voice-duration", value: ["+3s"], expected: [] },
+ { name: "voice-pitch", value: ["250Hz"], expected: ["medium"] },
+ { name: "voice-range", value: ["+20Hz"], expected: ["medium"] },
+ { name: "voice-rate", value: ["fast"], expected: ["normal"] },
+ { name: "voice-stress", value: ["strong"], expected: ["moderate"] },
+ { name: "voice-volume", value: ["soft"], expected: ["medium"] },
+ { name: "word-break", value: ["break-all"], expected: ["normal"] },
+ { name: "overflow-wrap", value: ["break-word"], expected: ["normal"] }
+ ];
+
+ $.each( styles, function(index, style) {
+ var defaultValue = {
+ "background-attachment": "scroll"
+ , "background-color": "transparent"
+ , "background-image": "none"
+ , "background-position": "0% 0%"
+ , "background-repeat": "repeat"
+ , "background-clip": "border-box"
+ , "background-origin": "padding-box"
+ , "background-size": "auto auto" // Fails in PhantomJS, but not IE10 or Chrome
+ , "orphans": 0
+ , "widows": 0
+ , "quotes": '"“" "”" "‘" "’"'
+ , "clip": "rect(auto,auto,auto,auto)"
+ },
+ domStyleName = cssPropertyToDomStyleProperty(style.name),
+ newValue, $source, source, $clone, clone;
+
+ // defaultValue = {}; // TODO: Remove this...
+
+ count++;
+ style.expected = style.expected.concat(["", "auto"]);
+ $source = $("<div />");
+ source = $source[0];
+ if ( source.style[style.name] === undefined ) {
+ console.log( "NOT SUPPORTED: " + style.name );
+ return true;
+ } else if ( window.getComputedStyle &&
+ window.getComputedStyle(source)[domStyleName] === undefined ) {
+ console.log( "SUPPORTED, BUT NOT REALLY: " + style.name );
+ return true;
+ }
+ $source.css( style.name, style.value[0] );
+
+ /*
+ // By accessing the .css() getter it masks the bug we are trying to detect
+ ok( ~$.inArray($source.css(style.name), style.value), "Style applied to source before cloning: " + style.name +
+ "; result: " + $source.css(style.name) +
+ "; expected: " + style.value.join(",") );
+ if ( ~$.inArray($source.css(style.name), style.value) ) {
+ */
+ $clone = $source.clone();
+ clone = $clone[0];
+ newValue = defaultValue[style.name] !== undefined ? defaultValue[style.name] : "";
+ $clone.css( style.name, newValue );
+
+ ok( source !== clone, "Verify objects different: " + style.name );
+ ok( source.style !== clone.style, "Verify style properties different: " + style.name );
+
+ ok( ~$.inArray($clone.css(style.name) !== undefined ? $clone.css(style.name) : "undefined", style.expected),
+ "Clearing clone.css() works: " + style.name +
+ "; result: " + $clone.css(style.name) +
+ "; expected: " + style.expected.join(",") );
+ ok( ~$.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(",") );
+ if ( !~$.inArray($source.css(style.name), style.value) ) {
+ console.log( "FAILED: " + style.name +
+ "; result: " + $source.css(style.name) +
+ "; expected: " + style.value.join(",") );
+ }
+
+ // IE actually clears out the source style in many cases, but
+ // .css() still gets answer because it uses getComputedStyle
+ ok( ~$.inArray(source.style[domStyleName], style.value),
+ "Underlying source style unchanged: " + style.name +
+ "; result: " + source.style[style.name] +
+ "; expected: " + style.value.join(",") );
+ if ( !~$.inArray(source.style[domStyleName], style.value) ) {
+ console.log( "FAILED: Underlying Cleared: " + style.name +
+ "; result: " + source.style[domStyleName] +
+ "; expected: " + style.value.join(",") );
+ }
+ equal( clone.style[domStyleName], "",
+ "Underlying clone style cleared: " + style.name );
+ /*
+ } else {
+ console.log( "NOT WORKING: " + style.name );
+ }
+ */
+ });
+
+ console.log( "Number of styles tested: " + count );
+});
+
+function cssPropertyToDomStyleProperty( name ) {
+ return name .replace( /-(\w)/g, function(match, group) {
+ return group.toUpperCase();
+ });
+}
+
+})( jQuery );
View
23 test/unit/manipulation.js
@@ -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() {
- expect( 8 );
+ expect( 16 );
var baseUrl = document.location.href.replace( /([^\/]*)$/, "" );
var styles = [
- { name: "background-attachment", value: [ "fixed" ], expected: [ "scroll" ] },
- { name: "background-color", value: [ "rgb(255, 0, 0)", "rgb(255,0,0)" ], expected: [ "transparent" ] },
- { name: "background-image", value: [ 'url("test.png")', 'url(' + baseUrl + 'test.png)', 'url("' + baseUrl + 'test.png")' ], expected: [ "none" ] },
- { name: "background-position", value: [ "5% 5%" ], expected: [ "0% 0%" ] },
- { name: "background-repeat", value: [ "repeat-y" ], expected: [ "repeat" ] },
- { name: "background-clip", value: [ "content-box" ], expected: [ "border-box" ] },
- { name: "background-origin", value: [ "content-box" ], expected: [ "padding-box" ] },
- { name: "background-size", value: [ "80px 60px" ], expected: [] }
+ { 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) {
@@ -1931,6 +1931,7 @@ test( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's
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] );
@@ -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 +
"; 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( "," ) );
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.