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
8b82af9e
Commit
8b82af9e
authored
Jan 09, 2013
by
Oleg
Committed by
Richard Gibson
Jan 11, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ref
0ed497b0
. Close gh-1125.
parent
f40eac1d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
36 deletions
+55
-36
manipulation.js
src/manipulation.js
+23
-25
manipulation.js
test/unit/manipulation.js
+32
-11
No files found.
src/manipulation.js
View file @
8b82af9e
...
@@ -308,9 +308,8 @@ jQuery.fn.extend({
...
@@ -308,9 +308,8 @@ jQuery.fn.extend({
});
});
}
}
if
(
this
[
0
]
)
{
if
(
l
)
{
doc
=
this
[
0
].
ownerDocument
;
fragment
=
jQuery
.
buildFragment
(
args
,
this
[
0
].
ownerDocument
,
false
,
this
);
fragment
=
jQuery
.
buildFragment
(
args
,
doc
,
false
,
this
);
first
=
fragment
.
firstChild
;
first
=
fragment
.
firstChild
;
if
(
fragment
.
childNodes
.
length
===
1
)
{
if
(
fragment
.
childNodes
.
length
===
1
)
{
...
@@ -619,21 +618,20 @@ jQuery.extend({
...
@@ -619,21 +618,20 @@ jQuery.extend({
},
},
buildFragment
:
function
(
elems
,
context
,
scripts
,
selection
)
{
buildFragment
:
function
(
elems
,
context
,
scripts
,
selection
)
{
var
elem
,
j
,
tmp
,
tag
,
wrap
,
tbody
,
var
contains
,
elem
,
tag
,
tmp
,
wrap
,
tbody
,
j
,
nodes
=
[],
i
=
0
,
l
=
elems
.
length
,
l
=
elems
.
length
,
fragment
=
context
.
createDocumentFragment
(),
safe
=
context
===
document
&&
safeFragment
;
// Ensure that context is a document
// Ensure a safe fragment
if
(
!
context
||
typeof
context
.
createDocumentFragment
===
"undefined"
)
{
safe
=
createSafeFragment
(
context
),
context
=
document
;
}
nodes
=
[],
i
=
0
;
for
(
;
i
<
l
;
i
++
)
{
for
(
;
i
<
l
;
i
++
)
{
elem
=
elems
[
i
];
elem
=
elems
[
i
];
if
(
elem
||
elem
===
0
)
{
if
(
elem
||
elem
===
0
)
{
// Add nodes directly
// Add nodes directly
if
(
jQuery
.
type
(
elem
)
===
"object"
)
{
if
(
jQuery
.
type
(
elem
)
===
"object"
)
{
jQuery
.
merge
(
nodes
,
elem
.
nodeType
?
[
elem
]
:
elem
);
jQuery
.
merge
(
nodes
,
elem
.
nodeType
?
[
elem
]
:
elem
);
...
@@ -644,8 +642,6 @@ jQuery.extend({
...
@@ -644,8 +642,6 @@ jQuery.extend({
// Convert html into DOM nodes
// Convert html into DOM nodes
}
else
{
}
else
{
// Ensure a safe container
safe
=
safe
||
createSafeFragment
(
context
);
tmp
=
tmp
||
safe
.
appendChild
(
context
.
createElement
(
"div"
)
);
tmp
=
tmp
||
safe
.
appendChild
(
context
.
createElement
(
"div"
)
);
// Deserialize a standard representation
// Deserialize a standard representation
...
@@ -700,7 +696,7 @@ jQuery.extend({
...
@@ -700,7 +696,7 @@ jQuery.extend({
}
}
}
}
// Fix #11356: Clear elements from
safeF
ragment
// Fix #11356: Clear elements from
f
ragment
if
(
tmp
)
{
if
(
tmp
)
{
safe
.
removeChild
(
tmp
);
safe
.
removeChild
(
tmp
);
}
}
...
@@ -713,18 +709,20 @@ jQuery.extend({
...
@@ -713,18 +709,20 @@ jQuery.extend({
i
=
0
;
i
=
0
;
while
(
(
elem
=
nodes
[
i
++
])
)
{
while
(
(
elem
=
nodes
[
i
++
])
)
{
safe
=
jQuery
.
contains
(
elem
.
ownerDocument
,
elem
);
// Append to fragment
// #4087 - If origin and destination elements are the same, and this is
// #4087 - If origin and destination elements are the same, and this is
// that element, do not
append to fragment
// that element, do not
do anything
if
(
!
selection
||
jQuery
.
inArray
(
elem
,
selection
)
=
==
-
1
)
{
if
(
selection
&&
jQuery
.
inArray
(
elem
,
selection
)
!
==
-
1
)
{
fragment
.
appendChild
(
elem
)
;
continue
;
}
}
tmp
=
getAll
(
elem
,
"script"
);
contains
=
jQuery
.
contains
(
elem
.
ownerDocument
,
elem
);
// Append to fragment
tmp
=
getAll
(
safe
.
appendChild
(
elem
),
"script"
);
// Preserve script evaluation history
// Preserve script evaluation history
if
(
safe
)
{
if
(
contains
)
{
setGlobalEval
(
tmp
);
setGlobalEval
(
tmp
);
}
}
...
@@ -739,9 +737,9 @@ jQuery.extend({
...
@@ -739,9 +737,9 @@ jQuery.extend({
}
}
}
}
elem
=
tmp
=
safe
=
null
;
tmp
=
null
;
return
fragment
;
return
safe
;
},
},
cleanData
:
function
(
elems
,
/* internal */
acceptData
)
{
cleanData
:
function
(
elems
,
/* internal */
acceptData
)
{
...
...
test/unit/manipulation.js
View file @
8b82af9e
...
@@ -395,13 +395,13 @@ var testAppendForObject = function( valueObj, isFragment ) {
...
@@ -395,13 +395,13 @@ var testAppendForObject = function( valueObj, isFragment ) {
var
testAppend
=
function
(
valueObj
)
{
var
testAppend
=
function
(
valueObj
)
{
expect
(
60
);
expect
(
78
);
testAppendForObject
(
valueObj
,
false
);
testAppendForObject
(
valueObj
,
false
);
testAppendForObject
(
valueObj
,
true
);
testAppendForObject
(
valueObj
,
true
);
var
defaultText
,
result
,
message
,
iframe
,
iframeDoc
,
j
,
d
,
var
defaultText
,
result
,
message
,
iframe
,
iframeDoc
,
j
,
d
,
$input
,
$radioChecked
,
$radioUnchecked
,
$radioParent
;
$input
,
$radioChecked
,
$radioUnchecked
,
$radioParent
,
$map
,
$table
;
defaultText
=
"Try them out:"
;
defaultText
=
"Try them out:"
;
result
=
jQuery
(
"#first"
).
append
(
valueObj
(
"<b>buga</b>"
)
);
result
=
jQuery
(
"#first"
).
append
(
valueObj
(
"<b>buga</b>"
)
);
...
@@ -446,18 +446,29 @@ var testAppend = function( valueObj ) {
...
@@ -446,18 +446,29 @@ var testAppend = function( valueObj ) {
jQuery
(
"<fieldset/>"
).
appendTo
(
"#form"
).
append
(
valueObj
(
"<legend id='legend'>test</legend>"
)
);
jQuery
(
"<fieldset/>"
).
appendTo
(
"#form"
).
append
(
valueObj
(
"<legend id='legend'>test</legend>"
)
);
t
(
"Append legend"
,
"#legend"
,
[
"legend"
]
);
t
(
"Append legend"
,
"#legend"
,
[
"legend"
]
);
$map
=
jQuery
(
"<map/>"
).
append
(
valueObj
(
"<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>"
)
);
equal
(
$map
[
0
].
childNodes
.
length
,
1
,
"The area was inserted."
);
equal
(
$map
[
0
].
firstChild
.
nodeName
.
toLowerCase
(),
"area"
,
"The area was inserted."
);
jQuery
(
"#select1"
).
append
(
valueObj
(
"<OPTION>Test</OPTION>"
)
);
jQuery
(
"#select1"
).
append
(
valueObj
(
"<OPTION>Test</OPTION>"
)
);
equal
(
jQuery
(
"#select1 option:last"
).
text
(),
"Test"
,
"Appending OPTION (all caps)"
);
equal
(
jQuery
(
"#select1 option:last"
).
text
(),
"Test"
,
"Appending OPTION (all caps)"
);
jQuery
(
"#table"
).
append
(
valueObj
(
"<colgroup></colgroup>"
)
);
jQuery
(
"#select1"
).
append
(
valueObj
(
"<optgroup label='optgroup'><option>optgroup</option></optgroup>"
)
);
equal
(
jQuery
(
"#table colgroup"
).
length
,
1
,
"Append colgroup"
);
equal
(
jQuery
(
"#select1 optgroup"
).
attr
(
"label"
),
"optgroup"
,
"Label attribute in newly inserted optgroup is correct"
);
equal
(
jQuery
(
"#select1 option:last"
).
text
(),
"optgroup"
,
"Appending optgroup"
);
$table
=
jQuery
(
"#table"
).
empty
();
jQuery
.
each
(
"thead tbody tfoot colgroup caption tr th td"
.
split
(
" "
),
function
(
i
,
name
)
{
$table
.
append
(
valueObj
(
"<"
+
name
+
"/>"
)
);
ok
(
$table
.
find
(
name
).
length
>=
1
,
"Append "
+
name
);
ok
(
jQuery
.
parseHTML
(
"<"
+
name
+
"/>"
).
length
,
name
+
" wrapped correctly"
);
});
jQuery
(
"#table colgroup"
).
append
(
valueObj
(
"<col/>"
)
);
jQuery
(
"#table colgroup"
).
append
(
valueObj
(
"<col/>"
)
);
equal
(
jQuery
(
"#table colgroup col"
).
length
,
1
,
"Append col"
);
equal
(
jQuery
(
"#table colgroup col"
).
length
,
1
,
"Append col"
);
jQuery
(
"#table"
).
append
(
valueObj
(
"<caption></caption>"
)
);
equal
(
jQuery
(
"#table caption"
).
length
,
1
,
"Append caption"
);
jQuery
(
"#form"
)
jQuery
(
"#form"
)
.
append
(
valueObj
(
"<select id='appendSelect1'></select>"
)
)
.
append
(
valueObj
(
"<select id='appendSelect1'></select>"
)
)
.
append
(
valueObj
(
"<select id='appendSelect2'><option>Test</option></select>"
)
);
.
append
(
valueObj
(
"<select id='appendSelect2'><option>Test</option></select>"
)
);
...
@@ -2234,4 +2245,14 @@ test( "Index for function argument should be received (#13094)", 2, function() {
...
@@ -2234,4 +2245,14 @@ test( "Index for function argument should be received (#13094)", 2, function() {
jQuery
(
"<div/><div/>"
).
before
(
function
(
index
)
{
jQuery
(
"<div/><div/>"
).
before
(
function
(
index
)
{
equal
(
index
,
i
++
,
"Index should be correct"
);
equal
(
index
,
i
++
,
"Index should be correct"
);
});
});
});
test
(
"Make sure jQuery.fn.remove can work on elements in documentFragment"
,
1
,
function
()
{
var
fragment
=
document
.
createDocumentFragment
(),
div
=
fragment
.
appendChild
(
document
.
createElement
(
"div"
)
);
jQuery
(
div
).
remove
();
equal
(
fragment
.
childNodes
.
length
,
0
,
"div element was removed from documentFragment"
);
});
});
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