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
e761e0c6
Commit
e761e0c6
authored
Jul 23, 2012
by
Richard Gibson
Committed by
Timmy Willison
Jul 23, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support event delegation with relative selectors. Fixes #10762. Closes gh-860.
parent
a08a18b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
11 deletions
+14
-11
traversing.js
src/traversing.js
+4
-4
event.js
test/unit/event.js
+10
-7
No files found.
src/traversing.js
View file @
e761e0c6
var
runtil
=
/Until$/
,
var
runtil
=
/Until$/
,
rparentsprev
=
/^
(?:
parents|prev
(?:
Until|All
))
/
,
rparentsprev
=
/^
(?:
parents|prev
(?:
Until|All
))
/
,
isSimple
=
/^.
[^
:#
\[\.
,
]
*$/
,
isSimple
=
/^.
[^
:#
\[\.
,
]
*$/
,
POS
=
jQuery
.
expr
.
match
.
globalPOS
,
rneedsContext
=
jQuery
.
expr
.
match
.
needsContext
,
// methods guaranteed to produce a unique set when starting from a unique set
// methods guaranteed to produce a unique set when starting from a unique set
guaranteedUnique
=
{
guaranteedUnique
=
{
children
:
true
,
children
:
true
,
...
@@ -72,9 +72,9 @@ jQuery.fn.extend({
...
@@ -72,9 +72,9 @@ jQuery.fn.extend({
is
:
function
(
selector
)
{
is
:
function
(
selector
)
{
return
!!
selector
&&
(
return
!!
selector
&&
(
typeof
selector
===
"string"
?
typeof
selector
===
"string"
?
// If this is a positional selector, check membership in the returned set
// If this is a positional
/relative
selector, check membership in the returned set
// so $("p:first").is("p:last") won't return true for a doc with two "p".
// so $("p:first").is("p:last") won't return true for a doc with two "p".
POS
.
test
(
selector
)
?
rneedsContext
.
test
(
selector
)
?
jQuery
(
selector
,
this
.
context
).
index
(
this
[
0
]
)
>=
0
:
jQuery
(
selector
,
this
.
context
).
index
(
this
[
0
]
)
>=
0
:
jQuery
.
filter
(
selector
,
this
).
length
>
0
:
jQuery
.
filter
(
selector
,
this
).
length
>
0
:
this
.
filter
(
selector
).
length
>
0
);
this
.
filter
(
selector
).
length
>
0
);
...
@@ -85,7 +85,7 @@ jQuery.fn.extend({
...
@@ -85,7 +85,7 @@ jQuery.fn.extend({
i
=
0
,
i
=
0
,
l
=
this
.
length
,
l
=
this
.
length
,
ret
=
[],
ret
=
[],
pos
=
POS
.
test
(
selectors
)
||
typeof
selectors
!==
"string"
?
pos
=
rneedsContext
.
test
(
selectors
)
||
typeof
selectors
!==
"string"
?
jQuery
(
selectors
,
context
||
this
.
context
)
:
jQuery
(
selectors
,
context
||
this
.
context
)
:
0
;
0
;
...
...
test/unit/event.js
View file @
e761e0c6
...
@@ -2342,17 +2342,20 @@ test("jQuery.off using dispatched jQuery.Event", function() {
...
@@ -2342,17 +2342,20 @@ test("jQuery.off using dispatched jQuery.Event", function() {
.
remove
();
.
remove
();
});
});
test
(
"delegated event with delegateTarget-relative selector
(#)
"
,
function
()
{
test
(
"delegated event with delegateTarget-relative selector"
,
function
()
{
expect
(
1
);
expect
(
2
);
var
markup
=
jQuery
(
'<ul><li><
ul id="u1"><li id="f1"></li></ul></li
>'
).
appendTo
(
"body"
);
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
(
"body"
);
markup
markup
.
find
(
"#u1"
)
.
on
(
"click"
,
">li>a"
,
function
()
{
.
on
(
"click"
,
"li:first"
,
function
()
{
ok
(
this
.
id
===
"a0"
,
"child li was clicked"
);
ok
(
this
.
id
===
"f1"
,
"first li under #u1 was clicked"
);
})
.
find
(
"#ul0"
)
.
on
(
"click"
,
"li:first>a"
,
function
()
{
ok
(
this
.
id
===
"a0_0"
,
"first li under #u10 was clicked"
);
})
})
.
find
(
"#f1"
).
click
().
end
()
.
end
()
.
end
()
.
find
(
"a"
).
click
().
end
()
.
remove
();
.
remove
();
});
});
...
...
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