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
c04bfce5
Commit
c04bfce5
authored
Mar 30, 2012
by
Oleg
Committed by
Dave Methvin
Apr 05, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #11338, .replaceWith should work on detached nodes.
parent
4cd57d72
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
+12
-9
manipulation.js
src/manipulation.js
+7
-7
manipulation.js
test/unit/manipulation.js
+5
-2
No files found.
src/manipulation.js
View file @
c04bfce5
...
@@ -46,7 +46,7 @@ wrapMap.optgroup = wrapMap.option;
...
@@ -46,7 +46,7 @@ wrapMap.optgroup = wrapMap.option;
wrapMap
.
tbody
=
wrapMap
.
tfoot
=
wrapMap
.
colgroup
=
wrapMap
.
caption
=
wrapMap
.
thead
;
wrapMap
.
tbody
=
wrapMap
.
tfoot
=
wrapMap
.
colgroup
=
wrapMap
.
caption
=
wrapMap
.
thead
;
wrapMap
.
th
=
wrapMap
.
td
;
wrapMap
.
th
=
wrapMap
.
td
;
// IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags,
// IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags,
// unless wrapped in a div with non-breaking characters in front of it.
// unless wrapped in a div with non-breaking characters in front of it.
if
(
!
jQuery
.
support
.
htmlSerialize
)
{
if
(
!
jQuery
.
support
.
htmlSerialize
)
{
wrapMap
.
_default
=
[
1
,
"X<div>"
,
"</div>"
];
wrapMap
.
_default
=
[
1
,
"X<div>"
,
"</div>"
];
...
@@ -222,7 +222,7 @@ jQuery.fn.extend({
...
@@ -222,7 +222,7 @@ jQuery.fn.extend({
}
}
// See if we can take a shortcut and just use innerHTML
// See if we can take a shortcut and just use innerHTML
if
(
typeof
value
===
"string"
&&
!
rnoInnerhtml
.
test
(
value
)
&&
if
(
typeof
value
===
"string"
&&
!
rnoInnerhtml
.
test
(
value
)
&&
(
jQuery
.
support
.
htmlSerialize
||
!
rnoshimcache
.
test
(
value
)
)
&&
(
jQuery
.
support
.
htmlSerialize
||
!
rnoshimcache
.
test
(
value
)
)
&&
(
jQuery
.
support
.
leadingWhitespace
||
!
rleadingWhitespace
.
test
(
value
)
)
&&
(
jQuery
.
support
.
leadingWhitespace
||
!
rleadingWhitespace
.
test
(
value
)
)
&&
!
wrapMap
[
(
rtagName
.
exec
(
value
)
||
[
""
,
""
]
)[
1
].
toLowerCase
()
]
)
{
!
wrapMap
[
(
rtagName
.
exec
(
value
)
||
[
""
,
""
]
)[
1
].
toLowerCase
()
]
)
{
...
@@ -252,7 +252,7 @@ jQuery.fn.extend({
...
@@ -252,7 +252,7 @@ jQuery.fn.extend({
},
},
replaceWith
:
function
(
value
)
{
replaceWith
:
function
(
value
)
{
if
(
this
[
0
]
&&
this
[
0
].
parentNode
)
{
if
(
this
[
0
]
&&
this
[
0
].
parentNode
&&
this
[
0
].
parentNode
.
nodeType
!=
11
)
{
// Make sure that the elements are removed from the DOM before they are inserted
// Make sure that the elements are removed from the DOM before they are inserted
// this can help fix replacing a parent with child elements
// this can help fix replacing a parent with child elements
if
(
jQuery
.
isFunction
(
value
)
)
{
if
(
jQuery
.
isFunction
(
value
)
)
{
...
@@ -278,11 +278,11 @@ jQuery.fn.extend({
...
@@ -278,11 +278,11 @@ jQuery.fn.extend({
jQuery
(
parent
).
append
(
value
);
jQuery
(
parent
).
append
(
value
);
}
}
});
});
}
else
{
return
this
.
length
?
this
.
pushStack
(
jQuery
(
jQuery
.
isFunction
(
value
)
?
value
()
:
value
),
"replaceWith"
,
value
)
:
this
;
}
}
return
this
.
length
?
this
.
pushStack
(
jQuery
(
jQuery
.
isFunction
(
value
)
?
value
()
:
value
),
"replaceWith"
,
value
)
:
this
;
},
},
detach
:
function
(
selector
)
{
detach
:
function
(
selector
)
{
...
...
test/unit/manipulation.js
View file @
c04bfce5
...
@@ -915,7 +915,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
...
@@ -915,7 +915,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
});
});
var
testReplaceWith
=
function
(
val
)
{
var
testReplaceWith
=
function
(
val
)
{
expect
(
2
1
);
expect
(
2
2
);
jQuery
(
"#yahoo"
).
replaceWith
(
val
(
"<b id='replace'>buga</b>"
));
jQuery
(
"#yahoo"
).
replaceWith
(
val
(
"<b id='replace'>buga</b>"
));
ok
(
jQuery
(
"#replace"
)[
0
],
"Replace element with string"
);
ok
(
jQuery
(
"#replace"
)[
0
],
"Replace element with string"
);
ok
(
!
jQuery
(
"#yahoo"
)[
0
],
"Verify that original element is gone, after string"
);
ok
(
!
jQuery
(
"#yahoo"
)[
0
],
"Verify that original element is gone, after string"
);
...
@@ -976,6 +976,9 @@ var testReplaceWith = function(val) {
...
@@ -976,6 +976,9 @@ var testReplaceWith = function(val) {
equal
(
set
[
0
].
nodeName
.
toLowerCase
(),
"span"
,
"Replace the disconnected node."
);
equal
(
set
[
0
].
nodeName
.
toLowerCase
(),
"span"
,
"Replace the disconnected node."
);
equal
(
set
.
length
,
1
,
"Replace the disconnected node."
);
equal
(
set
.
length
,
1
,
"Replace the disconnected node."
);
// #11338
ok
(
jQuery
(
"<div>1</div>"
).
replaceWith
(
val
(
"<span/>"
)
).
is
(
"span"
),
"#11338, Make sure disconnected node with content is replaced"
);
var
non_existant
=
jQuery
(
"#does-not-exist"
).
replaceWith
(
val
(
"<b>should not throw an error</b>"
)
);
var
non_existant
=
jQuery
(
"#does-not-exist"
).
replaceWith
(
val
(
"<b>should not throw an error</b>"
)
);
equal
(
non_existant
.
length
,
0
,
"Length of non existant element."
);
equal
(
non_existant
.
length
,
0
,
"Length of non existant element."
);
...
@@ -1006,7 +1009,7 @@ test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
...
@@ -1006,7 +1009,7 @@ test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
test
(
"replaceWith(Function)"
,
function
()
{
test
(
"replaceWith(Function)"
,
function
()
{
testReplaceWith
(
functionReturningObj
);
testReplaceWith
(
functionReturningObj
);
expect
(
2
2
);
expect
(
2
3
);
var
y
=
jQuery
(
"#yahoo"
)[
0
];
var
y
=
jQuery
(
"#yahoo"
)[
0
];
...
...
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