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
93e18922
Commit
93e18922
authored
Nov 18, 2012
by
Oleg
Committed by
Dave Methvin
Dec 12, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #12956. Improve cloneFixAttributes for IE9/10 case. Close gh-1034.
Remove clear(merge)Attributes hack
parent
f42e1e65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
26 deletions
+64
-26
manipulation.js
src/manipulation.js
+15
-26
event.js
test/unit/event.js
+49
-0
No files found.
src/manipulation.js
View file @
93e18922
...
@@ -434,26 +434,26 @@ function cloneCopyEvent( src, dest ) {
...
@@ -434,26 +434,26 @@ function cloneCopyEvent( src, dest ) {
}
}
function
cloneFixAttributes
(
src
,
dest
)
{
function
cloneFixAttributes
(
src
,
dest
)
{
var
nodeName
;
var
nodeName
,
data
,
e
;
// We do not need to do anything for non-Elements
// We do not need to do anything for non-Elements
if
(
dest
.
nodeType
!==
1
)
{
if
(
dest
.
nodeType
!==
1
)
{
return
;
return
;
}
}
// clearAttributes removes the attributes, which we don't want,
nodeName
=
dest
.
nodeName
.
toLowerCase
();
// but also removes the attachEvent events, which we *do* want
if
(
dest
.
clearAttributes
)
{
dest
.
clearAttributes
();
}
// mergeAttributes, in contrast, only merges back on the
// IE6-8 copies events bound via attachEvent when using cloneNode.
// original attributes, not the events
if
(
!
jQuery
.
support
.
noCloneEvent
&&
dest
[
jQuery
.
expando
]
)
{
if
(
dest
.
mergeAttributes
)
{
data
=
jQuery
.
_data
(
dest
);
dest
.
mergeAttributes
(
src
);
}
nodeName
=
dest
.
nodeName
.
toLowerCase
();
for
(
e
in
data
.
events
)
{
jQuery
.
removeEvent
(
dest
,
e
,
data
.
handle
);
}
// Event data gets referenced instead of copied if the expando gets copied too
dest
.
removeAttribute
(
jQuery
.
expando
);
}
// IE blanks contents when cloning scripts, and tries to evaluate newly-set text
// IE blanks contents when cloning scripts, and tries to evaluate newly-set text
if
(
nodeName
===
"script"
&&
dest
.
text
!==
src
.
text
)
{
if
(
nodeName
===
"script"
&&
dest
.
text
!==
src
.
text
)
{
...
@@ -498,10 +498,6 @@ function cloneFixAttributes( src, dest ) {
...
@@ -498,10 +498,6 @@ function cloneFixAttributes( src, dest ) {
}
else
if
(
nodeName
===
"input"
||
nodeName
===
"textarea"
)
{
}
else
if
(
nodeName
===
"input"
||
nodeName
===
"textarea"
)
{
dest
.
defaultValue
=
src
.
defaultValue
;
dest
.
defaultValue
=
src
.
defaultValue
;
}
}
// Event data gets referenced instead of copied if the expando
// gets copied too
dest
.
removeAttribute
(
jQuery
.
expando
);
}
}
jQuery
.
each
({
jQuery
.
each
({
...
@@ -583,19 +579,12 @@ jQuery.extend({
...
@@ -583,19 +579,12 @@ jQuery.extend({
if
(
(
!
jQuery
.
support
.
noCloneEvent
||
!
jQuery
.
support
.
noCloneChecked
)
&&
if
(
(
!
jQuery
.
support
.
noCloneEvent
||
!
jQuery
.
support
.
noCloneChecked
)
&&
(
elem
.
nodeType
===
1
||
elem
.
nodeType
===
11
)
&&
!
jQuery
.
isXMLDoc
(
elem
)
)
{
(
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.
// We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
// We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
destElements
=
getAll
(
clone
);
destElements
=
getAll
(
clone
);
srcElements
=
getAll
(
elem
);
srcElements
=
getAll
(
elem
);
// Weird iteration because IE will replace the length property
// Fix all IE cloning issues
// 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
(
i
=
0
;
(
node
=
srcElements
[
i
])
!=
null
;
++
i
)
{
for
(
i
=
0
;
(
node
=
srcElements
[
i
])
!=
null
;
++
i
)
{
// Ensure that the destination node is not null; Fixes #9587
// Ensure that the destination node is not null; Fixes #9587
if
(
destElements
[
i
]
)
{
if
(
destElements
[
i
]
)
{
...
@@ -607,8 +596,8 @@ jQuery.extend({
...
@@ -607,8 +596,8 @@ jQuery.extend({
// Copy the events from the original to the clone
// Copy the events from the original to the clone
if
(
dataAndEvents
)
{
if
(
dataAndEvents
)
{
if
(
deepDataAndEvents
)
{
if
(
deepDataAndEvents
)
{
destElements
=
getAll
(
clone
);
srcElements
=
srcElements
||
getAll
(
elem
);
srcElements
=
getAll
(
elem
);
destElements
=
destElements
||
getAll
(
clone
);
for
(
i
=
0
;
(
node
=
srcElements
[
i
])
!=
null
;
i
++
)
{
for
(
i
=
0
;
(
node
=
srcElements
[
i
])
!=
null
;
i
++
)
{
cloneCopyEvent
(
node
,
destElements
[
i
]
);
cloneCopyEvent
(
node
,
destElements
[
i
]
);
...
...
test/unit/event.js
View file @
93e18922
...
@@ -3104,4 +3104,53 @@ test( "Namespace preserved when passed an Event (#12739)", function() {
...
@@ -3104,4 +3104,53 @@ test( "Namespace preserved when passed an Event (#12739)", function() {
equal
(
triggered
,
3
,
"foo.bar triggered"
);
equal
(
triggered
,
3
,
"foo.bar triggered"
);
});
});
test
(
"make sure events cloned correctly"
,
18
,
function
()
{
var
clone
,
fixture
=
jQuery
(
"#qunit-fixture"
),
checkbox
=
jQuery
(
"#check1"
),
p
=
jQuery
(
"#firstp"
);
fixture
.
on
(
"click change"
,
function
(
event
,
result
)
{
ok
(
result
,
event
.
type
+
" on original element is fired"
);
}).
on
(
"click"
,
"#firstp"
,
function
(
event
,
result
)
{
ok
(
result
,
"Click on original child element though delegation is fired"
);
}).
on
(
"change"
,
"#check1"
,
function
(
event
,
result
)
{
ok
(
result
,
"Change on original child element though delegation is fired"
);
});
p
.
on
(
"click"
,
function
(
event
,
result
)
{
ok
(
true
,
"Click on original child element is fired"
);
});
checkbox
.
on
(
"change"
,
function
(
event
,
result
)
{
ok
(
true
,
"Change on original child element is fired"
);
});
fixture
.
clone
().
click
().
change
();
// 0 events should be fired
clone
=
fixture
.
clone
(
true
);
clone
.
find
(
"p:first"
).
trigger
(
"click"
,
true
);
// 3 events should fire
clone
.
find
(
"#check1"
).
trigger
(
"change"
,
true
);
// 3 events should fire
clone
.
remove
();
clone
=
fixture
.
clone
(
true
,
true
);
clone
.
find
(
"p:first"
).
trigger
(
"click"
,
true
);
// 3 events should fire
clone
.
find
(
"#check1"
).
trigger
(
"change"
,
true
);
// 3 events should fire
fixture
.
off
();
p
.
off
();
checkbox
.
off
();
p
.
click
();
// 0 should be fired
checkbox
.
change
();
// 0 should be fired
clone
.
find
(
"p:first"
).
trigger
(
"click"
,
true
);
// 3 events should fire
clone
.
find
(
"#check1"
).
trigger
(
"change"
,
true
);
// 3 events should fire
clone
.
remove
();
clone
.
find
(
"p:first"
).
click
();
// 0 should be fired
clone
.
find
(
"#check1"
).
change
();
// 0 events should fire
});
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