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
7a69e34a
Commit
7a69e34a
authored
Mar 16, 2011
by
timmywil
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
2773: first pass adding node/jQuery object support to jQuery.fn.find; unit tests added
parent
8246347b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
11 deletions
+39
-11
core.js
src/core.js
+1
-1
traversing.js
src/traversing.js
+18
-5
traversing.js
test/unit/traversing.js
+20
-5
No files found.
src/core.js
View file @
7a69e34a
...
@@ -88,7 +88,7 @@ jQuery.fn = jQuery.prototype = {
...
@@ -88,7 +88,7 @@ jQuery.fn = jQuery.prototype = {
if
(
selector
===
"body"
&&
!
context
&&
document
.
body
)
{
if
(
selector
===
"body"
&&
!
context
&&
document
.
body
)
{
this
.
context
=
document
;
this
.
context
=
document
;
this
[
0
]
=
document
.
body
;
this
[
0
]
=
document
.
body
;
this
.
selector
=
"body"
;
this
.
selector
=
selector
;
this
.
length
=
1
;
this
.
length
=
1
;
return
this
;
return
this
;
}
}
...
...
src/traversing.js
View file @
7a69e34a
...
@@ -17,17 +17,30 @@ var runtil = /Until$/,
...
@@ -17,17 +17,30 @@ var runtil = /Until$/,
jQuery
.
fn
.
extend
({
jQuery
.
fn
.
extend
({
find
:
function
(
selector
)
{
find
:
function
(
selector
)
{
var
ret
=
this
.
pushStack
(
""
,
"find"
,
selector
),
var
self
=
this
,
length
=
0
;
ret
,
i
,
l
;
if
(
typeof
selector
!==
"string"
)
{
return
jQuery
(
selector
).
filter
(
function
()
{
for
(
i
=
0
,
l
=
self
.
length
;
i
<
l
;
i
++
)
{
if
(
jQuery
.
contains
(
self
[
i
],
this
)
)
{
return
true
;
}
}
});
}
for
(
var
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
ret
=
this
.
pushStack
(
""
,
"find"
,
selector
);
var
length
,
n
,
r
;
for
(
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
length
=
ret
.
length
;
length
=
ret
.
length
;
jQuery
.
find
(
selector
,
this
[
i
],
ret
);
jQuery
.
find
(
selector
,
this
[
i
],
ret
);
if
(
i
>
0
)
{
if
(
i
>
0
)
{
// Make sure that the results are unique
// Make sure that the results are unique
for
(
var
n
=
length
;
n
<
ret
.
length
;
n
++
)
{
for
(
n
=
length
;
n
<
ret
.
length
;
n
++
)
{
for
(
var
r
=
0
;
r
<
length
;
r
++
)
{
for
(
r
=
0
;
r
<
length
;
r
++
)
{
if
(
ret
[
r
]
===
ret
[
n
]
)
{
if
(
ret
[
r
]
===
ret
[
n
]
)
{
ret
.
splice
(
n
--
,
1
);
ret
.
splice
(
n
--
,
1
);
break
;
break
;
...
...
test/unit/traversing.js
View file @
7a69e34a
...
@@ -14,12 +14,27 @@ test("find(String)", function() {
...
@@ -14,12 +14,27 @@ test("find(String)", function() {
});
});
test
(
"find(node|jQuery object)"
,
function
()
{
test
(
"find(node|jQuery object)"
,
function
()
{
expect
(
2
);
expect
(
11
);
var
$foo
=
jQuery
(
'#foo'
),
$blog
=
jQuery
(
'.blogTest'
),
$first
=
jQuery
(
'#first'
),
$two
=
$blog
.
add
(
$first
),
$fooTwo
=
$foo
.
add
(
$blog
);
equals
(
$foo
.
find
(
$blog
).
text
(),
'Yahoo'
,
'Find with blog jQuery object'
);
equals
(
$foo
.
find
(
$blog
[
0
]
).
text
(),
'Yahoo'
,
'Find with blog node'
);
equals
(
$foo
.
find
(
$first
).
length
,
0
,
'#first is not in #foo'
);
equals
(
$foo
.
find
(
$first
[
0
]).
length
,
0
,
'#first not in #foo (node)'
);
ok
(
$foo
.
find
(
$two
).
is
(
'.blogTest'
),
'Find returns only nodes within #foo'
);
ok
(
$fooTwo
.
find
(
$blog
).
is
(
'.blogTest'
),
'Blog is part of the collection, but also within foo'
);
ok
(
$fooTwo
.
find
(
$blog
[
0
]
).
is
(
'.blogTest'
),
'Blog is part of the collection, but also within foo(node)'
);
equals
(
$two
.
find
(
$foo
).
length
,
0
,
'Foo is not in two elements'
);
equals
(
$two
.
find
(
$foo
[
0
]
).
length
,
0
,
'Foo is not in two elements(node)'
);
equals
(
$two
.
find
(
$first
).
length
,
0
,
'first is in the collection and not within two'
);
equals
(
$two
.
find
(
$first
).
length
,
0
,
'first is in the collection and not within two(node)'
);
var
$blog
=
jQuery
(
'.blogTest'
),
blog
=
$blog
[
0
];
equals
(
jQuery
(
'#foo'
).
find
(
$blog
).
text
(),
'Yahoo'
,
'Find with blog jQuery object'
);
equals
(
jQuery
(
'#foo'
).
find
(
blog
).
text
(),
'Yahoo'
,
'Find with blog node'
);
});
});
test
(
"is(String)"
,
function
()
{
test
(
"is(String)"
,
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