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
b75b9ef8
Commit
b75b9ef8
authored
Jan 14, 2013
by
Richard Gibson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #13180: don't delegate into SVG <use>
(cherry picked from commits
36457cb6..f860e0bd
)
parent
77672343
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
45 deletions
+66
-45
event.js
src/event.js
+47
-37
event.js
test/unit/event.js
+19
-8
No files found.
src/event.js
View file @
b75b9ef8
...
@@ -331,11 +331,10 @@ jQuery.event = {
...
@@ -331,11 +331,10 @@ jQuery.event = {
// Make a writable jQuery.Event from the native event object
// Make a writable jQuery.Event from the native event object
event
=
jQuery
.
event
.
fix
(
event
);
event
=
jQuery
.
event
.
fix
(
event
);
var
i
,
j
,
cur
,
ret
,
selMatch
,
matched
,
matches
,
handleObj
,
sel
,
var
i
,
j
,
ret
,
matched
,
handleObj
,
handlerQueue
=
[],
handlerQueue
=
[],
args
=
core_slice
.
call
(
arguments
),
args
=
core_slice
.
call
(
arguments
),
handlers
=
(
jQuery
.
_data
(
this
,
"events"
)
||
{}
)[
event
.
type
]
||
[],
handlers
=
(
jQuery
.
_data
(
this
,
"events"
)
||
{}
)[
event
.
type
]
||
[],
delegateCount
=
handlers
.
delegateCount
,
special
=
jQuery
.
event
.
special
[
event
.
type
]
||
{};
special
=
jQuery
.
event
.
special
[
event
.
type
]
||
{};
// Use the fix-ed jQuery.Event rather than the (read-only) native event
// Use the fix-ed jQuery.Event rather than the (read-only) native event
...
@@ -347,41 +346,8 @@ jQuery.event = {
...
@@ -347,41 +346,8 @@ jQuery.event = {
return
;
return
;
}
}
// Determine handlers that should run if there are delegated events
// Determine handlers
// Avoid non-left-click bubbling in Firefox (#3861)
handlerQueue
=
jQuery
.
event
.
handlers
.
call
(
this
,
event
,
handlers
);
if
(
delegateCount
&&
!
(
event
.
button
&&
event
.
type
===
"click"
)
)
{
for
(
cur
=
event
.
target
;
cur
!=
this
;
cur
=
cur
.
parentNode
||
this
)
{
// Ignore clicks (ONLY) on disabled elements (#6911, #8165, #11382, #11764)
if
(
cur
.
disabled
!==
true
||
event
.
type
!==
"click"
)
{
selMatch
=
{};
matches
=
[];
i
=
0
;
for
(
;
i
<
delegateCount
;
i
++
)
{
handleObj
=
handlers
[
i
];
sel
=
handleObj
.
selector
;
if
(
selMatch
[
sel
]
===
undefined
)
{
selMatch
[
sel
]
=
handleObj
.
needsContext
?
jQuery
(
sel
,
this
).
index
(
cur
)
>=
0
:
jQuery
.
find
(
sel
,
this
,
null
,
[
cur
]
).
length
;
}
if
(
selMatch
[
sel
]
)
{
matches
.
push
(
handleObj
);
}
}
if
(
matches
.
length
)
{
handlerQueue
.
push
({
elem
:
cur
,
handlers
:
matches
});
}
}
}
}
// Add the remaining (directly-bound) handlers
if
(
handlers
.
length
>
delegateCount
)
{
handlerQueue
.
push
({
elem
:
this
,
handlers
:
handlers
.
slice
(
delegateCount
)
});
}
// Run delegates first; they may want to stop propagation beneath us
// Run delegates first; they may want to stop propagation beneath us
i
=
0
;
i
=
0
;
...
@@ -419,6 +385,50 @@ jQuery.event = {
...
@@ -419,6 +385,50 @@ jQuery.event = {
return
event
.
result
;
return
event
.
result
;
},
},
handlers
:
function
(
event
,
handlers
)
{
var
i
,
matches
,
sel
,
handleObj
,
handlerQueue
=
[],
delegateCount
=
handlers
.
delegateCount
,
cur
=
event
.
target
;
// Find delegate handlers
// Black-hole SVG <use> instance trees (#13180)
// Avoid non-left-click bubbling in Firefox (#3861)
if
(
delegateCount
&&
cur
.
nodeType
&&
(
!
event
.
button
||
event
.
type
!==
"click"
)
)
{
for
(
;
cur
!=
this
;
cur
=
cur
.
parentNode
||
this
)
{
// Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
if
(
cur
.
disabled
!==
true
||
event
.
type
!==
"click"
)
{
matches
=
[];
for
(
i
=
0
;
i
<
delegateCount
;
i
++
)
{
handleObj
=
handlers
[
i
];
sel
=
handleObj
.
selector
;
if
(
matches
[
sel
]
===
undefined
)
{
matches
[
sel
]
=
handleObj
.
needsContext
?
jQuery
(
sel
,
this
).
index
(
cur
)
>=
0
:
jQuery
.
find
(
sel
,
this
,
null
,
[
cur
]
).
length
;
}
if
(
matches
[
sel
]
)
{
matches
.
push
(
handleObj
);
}
}
if
(
matches
.
length
)
{
handlerQueue
.
push
({
elem
:
cur
,
handlers
:
matches
});
}
}
}
}
// Add the remaining (directly-bound) handlers
if
(
delegateCount
<
handlers
.
length
)
{
handlerQueue
.
push
({
elem
:
this
,
handlers
:
handlers
.
slice
(
delegateCount
)
});
}
return
handlerQueue
;
},
// Includes some event props shared by KeyEvent and MouseEvent
// Includes some event props shared by KeyEvent and MouseEvent
props
:
"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which"
.
split
(
" "
),
props
:
"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which"
.
split
(
" "
),
...
...
test/unit/event.js
View file @
b75b9ef8
...
@@ -1231,17 +1231,21 @@ test(".trigger() doesn't bubble load event (#10717)", function() {
...
@@ -1231,17 +1231,21 @@ test(".trigger() doesn't bubble load event (#10717)", function() {
jQuery
(
window
).
off
(
"load"
);
jQuery
(
window
).
off
(
"load"
);
});
});
test
(
"Delegated events in SVG (#10791)"
,
function
()
{
test
(
"Delegated events in SVG (#10791
; #13180
)"
,
function
()
{
expect
(
2
);
expect
(
2
);
var
svg
=
jQuery
(
var
e
,
svg
=
jQuery
(
"<svg height='1' version='1.1' width='1' xmlns='http://www.w3.org/2000/svg'>"
+
"<svg height='1' version='1.1' width='1' xmlns='http://www.w3.org/2000/svg'>"
+
"<defs><rect id='ref' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect></defs>"
+
"<rect class='svg-by-class' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect>"
+
"<rect class='svg-by-class' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect>"
+
"<rect id='svg-by-id' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect>"
+
"<rect id='svg-by-id' x='10' y='20' width='100' height='60' r='10' rx='10' ry='10'></rect>"
+
"<use id='use' xlink:href='#ref'></use>"
+
"</svg>"
"</svg>"
)
.
appendTo
(
"body"
)
;
);
jQuery
(
"body"
)
jQuery
(
"#qunit-fixture"
)
.
append
(
svg
)
.
on
(
"click"
,
"#svg-by-id"
,
function
()
{
.
on
(
"click"
,
"#svg-by-id"
,
function
()
{
ok
(
true
,
"delegated id selector"
);
ok
(
true
,
"delegated id selector"
);
})
})
...
@@ -1249,11 +1253,18 @@ test("Delegated events in SVG (#10791)", function() {
...
@@ -1249,11 +1253,18 @@ test("Delegated events in SVG (#10791)", function() {
ok
(
true
,
"delegated class selector"
);
ok
(
true
,
"delegated class selector"
);
})
})
.
find
(
"#svg-by-id, [class~='svg-by-class']"
)
.
find
(
"#svg-by-id, [class~='svg-by-class']"
)
.
trigger
(
"click"
)
.
trigger
(
"click"
)
.
end
()
.
end
();
.
off
(
"click"
);
// Fire a native click on an SVGElementInstance (the instance tree of an SVG <use>)
// to confirm that it doesn't break our event delegation handling (#13180)
if
(
document
.
createEvent
)
{
e
=
document
.
createEvent
(
"MouseEvents"
);
e
.
initEvent
(
"click"
,
true
,
true
);
svg
.
find
(
"#use"
)[
0
].
instanceRoot
.
dispatchEvent
(
e
);
}
svg
.
remove
(
);
jQuery
(
"#qunit-fixture"
).
off
(
"click"
);
});
});
test
(
"Delegated events in forms (#10844; #11145; #8165; #11382, #11764)"
,
function
()
{
test
(
"Delegated events in forms (#10844; #11145; #8165; #11382, #11764)"
,
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