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
e09d8898
Commit
e09d8898
authored
Mar 22, 2011
by
timmywil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add node and jQuery object support to $.fn.closest
parent
eb1497c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
traversing.js
src/traversing.js
+12
-8
traversing.js
test/unit/traversing.js
+14
-0
No files found.
src/traversing.js
View file @
e09d8898
...
...
@@ -32,6 +32,7 @@ jQuery.fn.extend({
var
ret
=
this
.
pushStack
(
""
,
"find"
,
selector
),
length
,
n
,
r
;
for
(
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
length
=
ret
.
length
;
jQuery
.
find
(
selector
,
this
[
i
],
ret
);
...
...
@@ -77,7 +78,8 @@ jQuery.fn.extend({
closest
:
function
(
selectors
,
context
)
{
var
ret
=
[],
i
,
l
,
cur
=
this
[
0
];
// Array
if
(
jQuery
.
isArray
(
selectors
)
)
{
var
match
,
selector
,
matches
=
{},
...
...
@@ -87,8 +89,8 @@ jQuery.fn.extend({
for
(
i
=
0
,
l
=
selectors
.
length
;
i
<
l
;
i
++
)
{
selector
=
selectors
[
i
];
if
(
!
matches
[
selector
]
)
{
matches
[
selector
]
=
jQuery
.
expr
.
match
.
POS
.
test
(
selector
)
?
if
(
!
matches
[
selector
]
)
{
matches
[
selector
]
=
POS
.
test
(
selector
)
?
jQuery
(
selector
,
context
||
this
.
context
)
:
selector
;
}
...
...
@@ -96,9 +98,9 @@ jQuery.fn.extend({
while
(
cur
&&
cur
.
ownerDocument
&&
cur
!==
context
)
{
for
(
selector
in
matches
)
{
match
=
matches
[
selector
];
match
=
matches
[
selector
];
if
(
match
.
jquery
?
match
.
index
(
cur
)
>
-
1
:
jQuery
(
cur
).
is
(
match
)
)
{
if
(
match
.
jquery
?
match
.
index
(
cur
)
>
-
1
:
jQuery
(
cur
).
is
(
match
)
)
{
ret
.
push
({
selector
:
selector
,
elem
:
cur
,
level
:
level
});
}
}
...
...
@@ -110,9 +112,11 @@ jQuery.fn.extend({
return
ret
;
}
var
pos
=
POS
.
test
(
selectors
)
?
jQuery
(
selectors
,
context
||
this
.
context
)
:
null
;
// String
var
pos
=
POS
.
test
(
selectors
)
||
typeof
selectors
!==
"string"
?
jQuery
(
selectors
,
context
||
this
.
context
)
:
0
;
for
(
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
cur
=
this
[
i
];
...
...
test/unit/traversing.js
View file @
e09d8898
...
...
@@ -182,6 +182,20 @@ test("closest(Array)", function() {
same
(
jQuery
(
"body"
).
closest
([
"span"
,
"html"
]),
[{
selector
:
"html"
,
elem
:
document
.
documentElement
,
level
:
2
}],
"closest([body, html])"
);
});
test
(
"closest(jQuery)"
,
function
()
{
expect
(
7
);
var
$child
=
jQuery
(
"#nothiddendivchild"
),
$parent
=
jQuery
(
"#nothiddendiv"
),
$main
=
jQuery
(
"#main"
);
ok
(
$child
.
closest
(
$parent
).
is
(
'#nothiddendiv'
),
"closest( jQuery('#nothiddendiv') )"
);
ok
(
$child
.
closest
(
$parent
[
0
]
).
is
(
'#nothiddendiv'
),
"closest( jQuery('#nothiddendiv') ) :: node"
);
ok
(
$child
.
closest
(
$child
).
is
(
'#nothiddendivchild'
),
"child is included"
);
ok
(
$child
.
closest
(
$child
[
0
]
).
is
(
'#nothiddendivchild'
),
"child is included :: node"
);
equals
(
$child
.
closest
(
document
.
createElement
(
'div'
)
).
length
,
0
,
"created element is not related"
);
equals
(
$child
.
closest
(
$main
).
length
,
0
,
"Main not a parent of child"
);
equals
(
$child
.
closest
(
$main
[
0
]
).
length
,
0
,
"Main not a parent of child :: node"
);
});
test
(
"not(Selector)"
,
function
()
{
expect
(
7
);
equals
(
jQuery
(
"#main > p#ap > a"
).
not
(
"#google"
).
length
,
2
,
"not('selector')"
);
...
...
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