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
afd717df
Commit
afd717df
authored
Aug 28, 2012
by
Dave Methvin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #12383. All selectors should be delegateTarget-relative
parent
c078b83b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
event.js
src/event.js
+2
-7
event.js
test/unit/event.js
+21
-3
No files found.
src/event.js
View file @
afd717df
...
@@ -361,7 +361,7 @@ jQuery.event = {
...
@@ -361,7 +361,7 @@ 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
||
window
.
event
);
event
=
jQuery
.
event
.
fix
(
event
||
window
.
event
);
var
i
,
j
,
cur
,
jqcur
,
ret
,
selMatch
,
matched
,
matches
,
handleObj
,
sel
,
related
,
var
i
,
j
,
cur
,
ret
,
selMatch
,
matched
,
matches
,
handleObj
,
sel
,
related
,
handlers
=
(
(
jQuery
.
_data
(
this
,
"events"
)
||
{}
)[
event
.
type
]
||
[]),
handlers
=
(
(
jQuery
.
_data
(
this
,
"events"
)
||
{}
)[
event
.
type
]
||
[]),
delegateCount
=
handlers
.
delegateCount
,
delegateCount
=
handlers
.
delegateCount
,
args
=
[].
slice
.
call
(
arguments
),
args
=
[].
slice
.
call
(
arguments
),
...
@@ -382,23 +382,18 @@ jQuery.event = {
...
@@ -382,23 +382,18 @@ jQuery.event = {
// Avoid non-left-click bubbling in Firefox (#3861)
// Avoid non-left-click bubbling in Firefox (#3861)
if
(
delegateCount
&&
!
(
event
.
button
&&
event
.
type
===
"click"
)
)
{
if
(
delegateCount
&&
!
(
event
.
button
&&
event
.
type
===
"click"
)
)
{
// Pregenerate a single jQuery object for reuse with .is()
jqcur
=
jQuery
(
this
);
jqcur
.
context
=
this
;
for
(
cur
=
event
.
target
;
cur
!=
this
;
cur
=
cur
.
parentNode
||
this
)
{
for
(
cur
=
event
.
target
;
cur
!=
this
;
cur
=
cur
.
parentNode
||
this
)
{
// Don't process clicks (ONLY) on disabled elements (#6911, #8165, #xxxx)
// Don't process clicks (ONLY) on disabled elements (#6911, #8165, #xxxx)
if
(
cur
.
disabled
!==
true
||
event
.
type
!==
"click"
)
{
if
(
cur
.
disabled
!==
true
||
event
.
type
!==
"click"
)
{
selMatch
=
{};
selMatch
=
{};
matches
=
[];
matches
=
[];
jqcur
[
0
]
=
cur
;
for
(
i
=
0
;
i
<
delegateCount
;
i
++
)
{
for
(
i
=
0
;
i
<
delegateCount
;
i
++
)
{
handleObj
=
handlers
[
i
];
handleObj
=
handlers
[
i
];
sel
=
handleObj
.
selector
;
sel
=
handleObj
.
selector
;
if
(
selMatch
[
sel
]
===
undefined
)
{
if
(
selMatch
[
sel
]
===
undefined
)
{
selMatch
[
sel
]
=
j
qcur
.
is
(
sel
)
;
selMatch
[
sel
]
=
j
Query
(
sel
,
this
).
index
(
cur
)
>=
0
;
}
}
if
(
selMatch
[
sel
]
)
{
if
(
selMatch
[
sel
]
)
{
matches
.
push
(
handleObj
);
matches
.
push
(
handleObj
);
...
...
test/unit/event.js
View file @
afd717df
...
@@ -2343,9 +2343,10 @@ test("jQuery.off using dispatched jQuery.Event", function() {
...
@@ -2343,9 +2343,10 @@ test("jQuery.off using dispatched jQuery.Event", function() {
});
});
test
(
"delegated event with delegateTarget-relative selector"
,
function
()
{
test
(
"delegated event with delegateTarget-relative selector"
,
function
()
{
expect
(
2
);
expect
(
3
);
var
markup
=
jQuery
(
"<ul><li><a id=
\"
a0
\"
></a><ul id=
\"
ul0
\"
><li><a id=
\"
a0_0
\"
></a></li><li><a id=
\"
a0_1
\"
></a></li></ul></li></ul>"
).
appendTo
(
"#qunit-fixture"
);
var
markup
=
jQuery
(
"<ul><li><a id=
\"
a0
\"
></a><ul id=
\"
ul0
\"
><li
class=test
><a id=
\"
a0_0
\"
></a></li><li><a id=
\"
a0_1
\"
></a></li></ul></li></ul>"
).
appendTo
(
"#qunit-fixture"
);
// Positional selector (#11315)
markup
markup
.
on
(
"click"
,
">li>a"
,
function
()
{
.
on
(
"click"
,
">li>a"
,
function
()
{
ok
(
this
.
id
===
"a0"
,
"child li was clicked"
);
ok
(
this
.
id
===
"a0"
,
"child li was clicked"
);
...
@@ -2356,7 +2357,24 @@ test( "delegated event with delegateTarget-relative selector", function() {
...
@@ -2356,7 +2357,24 @@ test( "delegated event with delegateTarget-relative selector", function() {
})
})
.
end
()
.
end
()
.
find
(
"a"
).
click
().
end
()
.
find
(
"a"
).
click
().
end
()
.
remove
();
.
find
(
"#ul0"
).
off
();
// Non-positional selector (#12383)
markup
=
markup
.
wrap
(
"<div />"
).
parent
();
markup
.
find
(
"#ul0"
)
.
on
(
"click"
,
"div li a"
,
function
()
{
ok
(
false
,
"div is ABOVE the delegation point!"
);
})
.
on
(
"click"
,
"ul a"
,
function
()
{
ok
(
false
,
"ul is the delegation point!"
);
})
.
on
(
"click"
,
"li.test a"
,
function
()
{
ok
(
true
,
"li.test is below the delegation point."
);
})
.
find
(
"#a0_0"
).
click
();
markup
.
remove
();
});
});
test
(
"stopPropagation() stops directly-bound events on delegated target"
,
function
()
{
test
(
"stopPropagation() stops directly-bound events on delegated target"
,
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