Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
d5d86223
Commit
d5d86223
authored
Aug 08, 2012
by
Elijah Manor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix weird clone bug and add a unit test to verify
parent
0d07e7fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
2 deletions
+44
-2
manipulation.js
src/manipulation.js
+8
-2
manipulation.js
test/unit/manipulation.js
+36
-0
No files found.
src/manipulation.js
View file @
d5d86223
...
...
@@ -585,11 +585,17 @@ jQuery.extend({
var
srcElements
,
destElements
,
i
,
clone
;
clone
,
fix8908
;
if
(
jQuery
.
support
.
html5Clone
||
jQuery
.
isXMLDoc
(
elem
)
||
!
rnoshimcache
.
test
(
"<"
+
elem
.
nodeName
+
">"
)
)
{
clone
=
elem
.
cloneNode
(
true
);
// Fixes #8909 - By accessing one of the cloned element's computed styles it breaks the
// connection with the source element's styles in IE9/10
if
(
elem
.
nodeType
===
1
&&
window
.
getComputedStyle
)
{
fix8908
=
(
window
.
getComputedStyle
(
elem
,
null
)
||
{}
).
backgroundImage
;
}
clone
=
elem
.
cloneNode
(
true
);
// IE<=8 does not properly clone detached, unknown element nodes
}
else
{
fragmentDiv
.
innerHTML
=
elem
.
outerHTML
;
...
...
test/unit/manipulation.js
View file @
d5d86223
...
...
@@ -1907,3 +1907,39 @@ test("checked state is cloned with clone()", function(){
elem
.
checked
=
true
;
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
(
8
);
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
:
[]
}
];
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"
);
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
(
","
)
);
});
});
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment