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
61e80c55
Commit
61e80c55
authored
Jan 21, 2011
by
jeresig
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '8013p' of
https://github.com/rwldrn/jquery
into rwldrn-8013p
parents
328a86f9
33a67ffa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
64 deletions
+86
-64
core.js
src/core.js
+1
-1
manipulation.js
src/manipulation.js
+73
-63
manipulation.js
test/unit/manipulation.js
+12
-0
No files found.
src/core.js
View file @
61e80c55
...
@@ -130,7 +130,7 @@ jQuery.fn = jQuery.prototype = {
...
@@ -130,7 +130,7 @@ jQuery.fn = jQuery.prototype = {
}
else
{
}
else
{
ret
=
jQuery
.
buildFragment
(
[
match
[
1
]
],
[
doc
]
);
ret
=
jQuery
.
buildFragment
(
[
match
[
1
]
],
[
doc
]
);
selector
=
(
ret
.
cacheable
?
jQuery
(
ret
.
fragment
).
clone
()[
0
]
:
ret
.
fragment
).
childNodes
;
selector
=
(
ret
.
cacheable
?
jQuery
.
clone
(
ret
.
fragment
)
:
ret
.
fragment
).
childNodes
;
}
}
return
jQuery
.
merge
(
this
,
selector
);
return
jQuery
.
merge
(
this
,
selector
);
...
...
src/manipulation.js
View file @
61e80c55
...
@@ -183,43 +183,13 @@ jQuery.fn.extend({
...
@@ -183,43 +183,13 @@ jQuery.fn.extend({
return
this
;
return
this
;
},
},
clone
:
function
(
events
)
{
clone
:
function
(
dataAndEvents
,
deepDataAndEvents
)
{
// Do the clone
dataAndEvents
=
dataAndEvents
==
null
?
true
:
dataAndEvents
;
var
ret
=
this
.
map
(
function
()
{
deepDataAndEvents
=
deepDataAndEvents
==
null
?
dataAndEvents
:
deepDataAndEvents
;
var
clone
=
this
.
cloneNode
(
true
);
if
(
!
jQuery
.
support
.
noCloneEvent
&&
(
this
.
nodeType
===
1
||
this
.
nodeType
===
11
)
&&
!
jQuery
.
isXMLDoc
(
this
)
)
{
return
this
.
map
(
function
()
{
// IE copies events bound via attachEvent when using cloneNode.
return
jQuery
.
clone
(
this
,
dataAndEvents
,
deepDataAndEvents
);
// Calling detachEvent on the clone will also remove the events
// from the original. In order to get around this, we use some
// proprietary methods to clear the events. Thanks to MooTools
// guys for this hotness.
// Using Sizzle here is crazy slow, so we use getElementsByTagName
// instead
var
srcElements
=
this
.
getElementsByTagName
(
"*"
),
destElements
=
clone
.
getElementsByTagName
(
"*"
);
// Weird iteration because IE will replace the length property
// with an element if you are cloning the body and one of the
// elements on the page has a name or id of "length"
for
(
var
i
=
0
;
srcElements
[
i
];
++
i
)
{
cloneFixAttributes
(
srcElements
[
i
],
destElements
[
i
]
);
}
cloneFixAttributes
(
this
,
clone
);
}
return
clone
;
});
});
// Copy the events from the original to the clone
if
(
events
===
true
)
{
cloneCopyEvent
(
this
,
ret
);
cloneCopyEvent
(
this
.
find
(
"*"
),
ret
.
find
(
"*"
)
);
}
// Return the cloned set
return
ret
;
},
},
html
:
function
(
value
)
{
html
:
function
(
value
)
{
...
@@ -347,7 +317,7 @@ jQuery.fn.extend({
...
@@ -347,7 +317,7 @@ jQuery.fn.extend({
root
(
this
[
i
],
first
)
:
root
(
this
[
i
],
first
)
:
this
[
i
],
this
[
i
],
i
>
0
||
results
.
cacheable
||
(
this
.
length
>
1
&&
i
>
0
)
?
i
>
0
||
results
.
cacheable
||
(
this
.
length
>
1
&&
i
>
0
)
?
jQuery
(
fragment
).
clone
(
true
)[
0
]
:
jQuery
.
clone
(
fragment
,
true
,
true
)
:
fragment
fragment
);
);
}
}
...
@@ -369,40 +339,33 @@ function root( elem, cur ) {
...
@@ -369,40 +339,33 @@ function root( elem, cur ) {
elem
;
elem
;
}
}
function
cloneCopyEvent
(
orig
,
ret
)
{
function
cloneCopyEvent
(
src
,
dest
)
{
ret
.
each
(
function
(
nodeIndex
)
{
if
(
this
.
nodeType
!==
1
||
!
jQuery
.
hasData
(
orig
[
nodeIndex
])
)
{
return
;
}
// XXX remove for 1.5 RC or merge back in if there is actually a reason for this check that has been
if
(
dest
.
nodeType
!==
1
||
!
jQuery
.
hasData
(
src
)
)
{
// unexposed by unit tests
return
;
if
(
this
.
nodeName
!==
(
orig
[
nodeIndex
]
&&
orig
[
nodeIndex
].
nodeName
)
)
{
}
throw
"Cloned data mismatch"
;
}
var
internalKey
=
jQuery
.
expando
,
var
internalKey
=
jQuery
.
expando
,
oldData
=
jQuery
.
data
(
orig
[
nodeIndex
]
),
oldData
=
jQuery
.
data
(
src
),
curData
=
jQuery
.
data
(
this
,
oldData
);
curData
=
jQuery
.
data
(
dest
,
oldData
);
// Switch to use the internal data object, if it exists, for the next
// Switch to use the internal data object, if it exists, for the next
// stage of data copying
// stage of data copying
if
(
(
oldData
=
oldData
[
internalKey
])
)
{
if
(
(
oldData
=
oldData
[
internalKey
])
)
{
var
events
=
oldData
.
events
;
var
events
=
oldData
.
events
;
curData
=
curData
[
internalKey
]
=
jQuery
.
extend
({},
oldData
);
curData
=
curData
[
internalKey
]
=
jQuery
.
extend
({},
oldData
);
if
(
events
)
{
if
(
events
)
{
delete
curData
.
handle
;
delete
curData
.
handle
;
curData
.
events
=
{};
curData
.
events
=
{};
for
(
var
type
in
events
)
{
for
(
var
type
in
events
)
{
for
(
var
i
=
0
,
l
=
events
[
type
].
length
;
i
<
l
;
i
++
)
{
for
(
var
i
=
0
,
l
=
events
[
type
].
length
;
i
<
l
;
i
++
)
{
jQuery
.
event
.
add
(
this
,
type
,
events
[
type
][
i
],
events
[
type
][
i
].
data
);
jQuery
.
event
.
add
(
dest
,
type
,
events
[
type
][
i
],
events
[
type
][
i
].
data
);
}
}
}
}
}
}
}
}
);
}
}
}
function
cloneFixAttributes
(
src
,
dest
)
{
function
cloneFixAttributes
(
src
,
dest
)
{
...
@@ -520,6 +483,53 @@ jQuery.each({
...
@@ -520,6 +483,53 @@ jQuery.each({
});
});
jQuery
.
extend
({
jQuery
.
extend
({
clone
:
function
(
elem
,
dataAndEvents
,
deepDataAndEvents
)
{
var
clone
=
elem
.
cloneNode
(
true
),
srcElements
,
destElements
;
if
(
!
jQuery
.
support
.
noCloneEvent
&&
(
elem
.
nodeType
===
1
||
elem
.
nodeType
===
11
)
&&
!
jQuery
.
isXMLDoc
(
elem
)
)
{
// IE copies events bound via attachEvent when using cloneNode.
// Calling detachEvent on the clone will also remove the events
// from the original. In order to get around this, we use some
// proprietary methods to clear the events. Thanks to MooTools
// guys for this hotness.
// Using Sizzle here is crazy slow, so we use getElementsByTagName
// instead
srcElements
=
elem
.
getElementsByTagName
(
"*"
);
destElements
=
clone
.
getElementsByTagName
(
"*"
);
// Weird iteration because IE will replace the length property
// with an element if you are cloning the body and one of the
// elements on the page has a name or id of "length"
for
(
var
i
=
0
;
srcElements
[
i
];
++
i
)
{
cloneFixAttributes
(
srcElements
[
i
],
destElements
[
i
]
);
}
cloneFixAttributes
(
elem
,
clone
);
}
// Copy the events from the original to the clone
if
(
dataAndEvents
)
{
cloneCopyEvent
(
elem
,
clone
);
if
(
deepDataAndEvents
&&
"getElementsByTagName"
in
elem
)
{
srcElements
=
elem
.
getElementsByTagName
(
"*"
);
destElements
=
clone
.
getElementsByTagName
(
"*"
);
if
(
srcElements
.
length
)
{
for
(
var
i
=
0
;
srcElements
[
i
];
++
i
)
{
cloneCopyEvent
(
srcElements
[
i
],
destElements
[
i
]
);
}
}
}
}
// Return the cloned set
return
clone
;
},
clean
:
function
(
elems
,
context
,
fragment
,
scripts
)
{
clean
:
function
(
elems
,
context
,
fragment
,
scripts
)
{
context
=
context
||
document
;
context
=
context
||
document
;
...
...
test/unit/manipulation.js
View file @
61e80c55
...
@@ -871,6 +871,18 @@ test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
...
@@ -871,6 +871,18 @@ test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
ok
(
!
jQuery
(
"#yahoo"
)[
0
],
'Verify that original element is gone, after set of elements'
);
ok
(
!
jQuery
(
"#yahoo"
)[
0
],
'Verify that original element is gone, after set of elements'
);
});
});
test
(
"jQuery.clone() (#8017)"
,
function
()
{
expect
(
2
);
ok
(
jQuery
.
clone
&&
jQuery
.
isFunction
(
jQuery
.
clone
)
,
"jQuery.clone() utility exists and is a function."
);
var
main
=
jQuery
(
"#main"
)[
0
],
clone
=
jQuery
.
clone
(
main
);
equals
(
main
.
children
.
length
,
clone
.
children
.
length
,
"Simple child length to ensure a large dom tree copies correctly"
);
});
test
(
"clone()"
,
function
()
{
test
(
"clone()"
,
function
()
{
expect
(
37
);
expect
(
37
);
equals
(
'This is a normal link: Yahoo'
,
jQuery
(
'#en'
).
text
(),
'Assert text for #en'
);
equals
(
'This is a normal link: Yahoo'
,
jQuery
(
'#en'
).
text
(),
'Assert text for #en'
);
...
...
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