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
ea783777
Commit
ea783777
authored
Jan 12, 2009
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only try to wrap the element if it's not disconnected, fixed #3828.
parent
0c971785
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
14 deletions
+21
-14
core.js
src/core.js
+15
-13
core.js
test/unit/core.js
+6
-1
No files found.
src/core.js
View file @
ea783777
...
...
@@ -206,20 +206,22 @@ jQuery.fn = jQuery.prototype = {
},
wrapAll
:
function
(
html
)
{
if
(
this
[
0
]
)
if
(
this
[
0
]
)
{
// The elements to wrap the target around
jQuery
(
html
,
this
[
0
].
ownerDocument
)
.
clone
()
.
insertBefore
(
this
[
0
]
)
.
map
(
function
(){
var
elem
=
this
;
while
(
elem
.
firstChild
)
elem
=
elem
.
firstChild
;
return
elem
;
})
.
append
(
this
);
var
wrap
=
jQuery
(
html
,
this
[
0
].
ownerDocument
).
clone
();
if
(
this
[
0
].
parentNode
)
wrap
.
insertBefore
(
this
[
0
]
);
wrap
.
map
(
function
(){
var
elem
=
this
;
while
(
elem
.
firstChild
)
elem
=
elem
.
firstChild
;
return
elem
;
}).
append
(
this
);
}
return
this
;
},
...
...
test/unit/core.js
View file @
ea783777
...
...
@@ -751,7 +751,7 @@ test("text()", function() {
});
test
(
"wrap(String|Element)"
,
function
()
{
expect
(
8
);
expect
(
10
);
var
defaultText
=
'Try them out:'
var
result
=
jQuery
(
'#first'
).
wrap
(
'<div class="red"><span></span></div>'
).
text
();
equals
(
defaultText
,
result
,
'Check for wrapping of on-the-fly html'
);
...
...
@@ -776,6 +776,11 @@ test("wrap(String|Element)", function() {
j
.
wrap
(
"<i></i>"
);
equals
(
jQuery
(
"#nonnodes > i"
).
length
,
3
,
"Check node,textnode,comment wraps ok"
);
equals
(
jQuery
(
"#nonnodes > i"
).
text
(),
j
.
text
()
+
j
[
1
].
nodeValue
,
"Check node,textnode,comment wraps doesn't hurt text"
);
// Try wrapping a disconnected node
j
=
jQuery
(
"<label/>"
).
wrap
(
"<li/>"
);
equals
(
j
[
0
].
nodeName
,
"LABEL"
,
"Element is a label"
);
equals
(
j
[
0
].
parentNode
.
nodeName
,
"LI"
,
"Element has been wrapped"
);
});
test
(
"wrapAll(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