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
f5b649fa
Commit
f5b649fa
authored
Dec 08, 2009
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure that events are cloned for wrap, fixes #2977.
parent
77510fec
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
manipulation.js
src/manipulation.js
+1
-1
manipulation.js
test/unit/manipulation.js
+15
-1
No files found.
src/manipulation.js
View file @
f5b649fa
...
@@ -48,7 +48,7 @@ jQuery.fn.extend({
...
@@ -48,7 +48,7 @@ jQuery.fn.extend({
if
(
this
[
0
]
)
{
if
(
this
[
0
]
)
{
// The elements to wrap the target around
// The elements to wrap the target around
var
wrap
=
jQuery
(
html
,
this
[
0
].
ownerDocument
).
eq
(
0
).
clone
();
var
wrap
=
jQuery
(
html
,
this
[
0
].
ownerDocument
).
eq
(
0
).
clone
(
true
);
if
(
this
[
0
].
parentNode
)
{
if
(
this
[
0
].
parentNode
)
{
wrap
.
insertBefore
(
this
[
0
]
);
wrap
.
insertBefore
(
this
[
0
]
);
...
...
test/unit/manipulation.js
View file @
f5b649fa
...
@@ -13,7 +13,7 @@ test("text()", function() {
...
@@ -13,7 +13,7 @@ test("text()", function() {
});
});
var
testWrap
=
function
(
val
)
{
var
testWrap
=
function
(
val
)
{
expect
(
1
5
);
expect
(
1
8
);
var
defaultText
=
'Try them out:'
var
defaultText
=
'Try them out:'
var
result
=
jQuery
(
'#first'
).
wrap
(
val
(
'<div class="red"><span></span></div>'
)).
text
();
var
result
=
jQuery
(
'#first'
).
wrap
(
val
(
'<div class="red"><span></span></div>'
)).
text
();
equals
(
defaultText
,
result
,
'Check for wrapping of on-the-fly html'
);
equals
(
defaultText
,
result
,
'Check for wrapping of on-the-fly html'
);
...
@@ -54,6 +54,20 @@ var testWrap = function(val) {
...
@@ -54,6 +54,20 @@ var testWrap = function(val) {
equals
(
j
[
0
].
parentNode
.
parentNode
.
childNodes
.
length
,
1
,
"There should only be one element wrapping."
);
equals
(
j
[
0
].
parentNode
.
parentNode
.
childNodes
.
length
,
1
,
"There should only be one element wrapping."
);
equals
(
j
.
length
,
1
,
"There should only be one element (no cloning)."
);
equals
(
j
.
length
,
1
,
"There should only be one element (no cloning)."
);
equals
(
j
[
0
].
parentNode
.
nodeName
.
toUpperCase
(),
"P"
,
"The span should be in the paragraph."
);
equals
(
j
[
0
].
parentNode
.
nodeName
.
toUpperCase
(),
"P"
,
"The span should be in the paragraph."
);
// Wrap an element with a jQuery set
j
=
jQuery
(
"<span/>"
).
wrap
(
jQuery
(
"<div></div>"
));
equals
(
j
[
0
].
parentNode
.
nodeName
.
toLowerCase
(),
"div"
,
"Wrapping works."
);
// Wrap an element with a jQuery set and event
result
=
jQuery
(
"<div></div>"
).
click
(
function
(){
ok
(
true
,
"Event triggered."
);
});
j
=
jQuery
(
"<span/>"
).
wrap
(
result
);
equals
(
j
[
0
].
parentNode
.
nodeName
.
toLowerCase
(),
"div"
,
"Wrapping works."
);
j
.
parent
().
trigger
(
"click"
);
}
}
test
(
"wrap(String|Element)"
,
function
()
{
test
(
"wrap(String|Element)"
,
function
()
{
...
...
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