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
e8f91514
Commit
e8f91514
authored
Oct 30, 2012
by
Mike Sherov
Committed by
Dave Methvin
Oct 30, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #12009. $().find( DOMElement ) should pushStack properly. Close gh-927.
parent
c78a3ba6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
28 deletions
+37
-28
traversing.js
src/traversing.js
+24
-17
traversing.js
test/unit/traversing.js
+13
-11
No files found.
src/traversing.js
View file @
e8f91514
...
@@ -12,39 +12,46 @@ var runtil = /Until$/,
...
@@ -12,39 +12,46 @@ var runtil = /Until$/,
jQuery
.
fn
.
extend
({
jQuery
.
fn
.
extend
({
find
:
function
(
selector
)
{
find
:
function
(
selector
)
{
var
i
,
l
,
length
,
n
,
r
,
ret
,
var
prevLength
,
n
,
r
,
ret
,
self
=
this
;
i
=
0
,
self
=
this
,
selfLength
=
this
.
length
;
if
(
typeof
selector
!==
"string"
)
{
if
(
typeof
selector
!==
"string"
)
{
return
jQuery
(
selector
).
filter
(
function
()
{
for
(
i
=
0
,
l
=
self
.
length
;
i
<
l
;
i
++
)
{
ret
=
jQuery
(
selector
).
filter
(
function
()
{
for
(
;
i
<
selfLength
;
i
++
)
{
if
(
jQuery
.
contains
(
self
[
i
],
this
)
)
{
if
(
jQuery
.
contains
(
self
[
i
],
this
)
)
{
return
true
;
return
true
;
}
}
}
}
});
});
}
ret
=
this
.
pushStack
(
[]
);
}
else
{
for
(
i
=
0
,
l
=
this
.
length
;
i
<
l
;
i
++
)
{
length
=
ret
.
length
;
jQuery
.
find
(
selector
,
this
[
i
],
ret
);
if
(
i
>
0
)
{
ret
=
[];
// Make sure that the results are unique
for
(
;
i
<
selfLength
;
i
++
)
{
for
(
n
=
length
;
n
<
ret
.
length
;
n
++
)
{
prevLength
=
ret
.
length
;
for
(
r
=
0
;
r
<
length
;
r
++
)
{
jQuery
.
find
(
selector
,
this
[
i
],
ret
);
if
(
ret
[
r
]
===
ret
[
n
]
)
{
ret
.
splice
(
n
--
,
1
);
if
(
i
>
0
)
{
// Make sure that the results are unique
// by comparing the newly added elements on the ith
// iteration to the elements added by the previous iterations
for
(
n
=
prevLength
;
n
<
ret
.
length
;
n
++
)
{
for
(
r
=
0
;
r
<
prevLength
;
r
++
)
{
if
(
ret
[
r
]
===
ret
[
n
]
)
{
ret
.
splice
(
n
--
,
1
);
break
;
break
;
}
}
}
}
}
}
}
}
}
}
}
// Needed because $( "selector", context ) becomes $( context ).find( "selector" )
// Needed because $( selector, context ) becomes $( context ).find( selector )
ret
=
this
.
pushStack
(
ret
);
ret
.
selector
=
(
this
.
selector
?
this
.
selector
+
" "
:
""
)
+
selector
;
ret
.
selector
=
(
this
.
selector
?
this
.
selector
+
" "
:
""
)
+
selector
;
return
ret
;
return
ret
;
},
},
...
...
test/unit/traversing.js
View file @
e8f91514
module
(
"traversing"
,
{
teardown
:
moduleTeardown
});
module
(
"traversing"
,
{
teardown
:
moduleTeardown
});
test
(
"find(String)"
,
function
()
{
test
(
"find(String)"
,
function
()
{
expect
(
5
);
expect
(
6
);
equal
(
"Yahoo"
,
jQuery
(
"#foo"
).
find
(
".blogTest"
).
text
(),
"Check for find"
);
equal
(
"Yahoo"
,
jQuery
(
"#foo"
).
find
(
".blogTest"
).
text
(),
"Check for find"
);
// using contents will get comments regular, text, and comment nodes
// using contents will get comments regular, text, and comment nodes
var
j
=
jQuery
(
"#nonnodes"
).
contents
();
var
j
=
jQuery
(
"#nonnodes"
).
contents
();
equal
(
j
.
find
(
"div"
).
length
,
0
,
"Check node,textnode,comment to find zero divs"
);
equal
(
j
.
find
(
"div"
).
length
,
0
,
"Check node,textnode,comment to find zero divs"
);
equal
(
j
.
find
(
"div"
).
andSelf
().
length
,
3
,
"Check node,textnode,comment to find zero divs, but preserves pushStack"
);
deepEqual
(
jQuery
(
"#qunit-fixture"
).
find
(
"> div"
).
get
(),
q
(
"foo"
,
"moretests"
,
"tabindex-tests"
,
"liveHandlerOrder"
,
"siblingTest"
,
"fx-test-group"
),
"find child elements"
);
deepEqual
(
jQuery
(
"#qunit-fixture"
).
find
(
"> div"
).
get
(),
q
(
"foo"
,
"moretests"
,
"tabindex-tests"
,
"liveHandlerOrder"
,
"siblingTest"
,
"fx-test-group"
),
"find child elements"
);
deepEqual
(
jQuery
(
"#qunit-fixture"
).
find
(
"> #foo, > #moretests"
).
get
(),
q
(
"foo"
,
"moretests"
),
"find child elements"
);
deepEqual
(
jQuery
(
"#qunit-fixture"
).
find
(
"> #foo, > #moretests"
).
get
(),
q
(
"foo"
,
"moretests"
),
"find child elements"
);
deepEqual
(
jQuery
(
"#qunit-fixture"
).
find
(
"> #foo > p"
).
get
(),
q
(
"sndp"
,
"en"
,
"sap"
),
"find child elements"
);
deepEqual
(
jQuery
(
"#qunit-fixture"
).
find
(
"> #foo > p"
).
get
(),
q
(
"sndp"
,
"en"
,
"sap"
),
"find child elements"
);
});
});
test
(
"find(node|jQuery object)"
,
function
()
{
test
(
"find(node|jQuery object)"
,
function
()
{
expect
(
1
1
);
expect
(
1
2
);
var
$foo
=
jQuery
(
"#foo"
),
var
$foo
=
jQuery
(
"#foo"
),
$blog
=
jQuery
(
".blogTest"
),
$blog
=
jQuery
(
".blogTest"
),
...
@@ -23,18 +24,19 @@ test("find(node|jQuery object)", function() {
...
@@ -23,18 +24,19 @@ test("find(node|jQuery object)", function() {
$fooTwo
=
$foo
.
add
(
$blog
);
$fooTwo
=
$foo
.
add
(
$blog
);
equal
(
$foo
.
find
(
$blog
).
text
(),
"Yahoo"
,
"Find with blog jQuery object"
);
equal
(
$foo
.
find
(
$blog
).
text
(),
"Yahoo"
,
"Find with blog jQuery object"
);
equal
(
$foo
.
find
(
$blog
[
0
]
).
text
(),
"Yahoo"
,
"Find with blog node"
);
equal
(
$foo
.
find
(
$blog
[
0
]
).
text
(),
"Yahoo"
,
"Find with blog node"
);
equal
(
$foo
.
find
(
$first
).
length
,
0
,
"#first is not in #foo"
);
equal
(
$foo
.
find
(
$first
).
length
,
0
,
"#first is not in #foo"
);
equal
(
$foo
.
find
(
$first
[
0
]).
length
,
0
,
"#first not in #foo (node)"
);
equal
(
$foo
.
find
(
$first
[
0
]).
length
,
0
,
"#first not in #foo (node)"
);
ok
(
$foo
.
find
(
$two
).
is
(
".blogTest"
),
"Find returns only nodes within #foo"
);
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
).
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)"
);
ok
(
$fooTwo
.
find
(
$blog
[
0
]
).
is
(
".blogTest"
),
"Blog is part of the collection, but also within foo(node)"
);
equal
(
$two
.
find
(
$foo
).
length
,
0
,
"Foo is not in two elements"
);
equal
(
$two
.
find
(
$foo
).
length
,
0
,
"Foo is not in two elements"
);
equal
(
$two
.
find
(
$foo
[
0
]
).
length
,
0
,
"Foo is not in two elements(node)"
);
equal
(
$two
.
find
(
$foo
[
0
]
).
length
,
0
,
"Foo is not in two elements(node)"
);
equal
(
$two
.
find
(
$first
).
length
,
0
,
"first is in the collection and not within two"
);
equal
(
$two
.
find
(
$first
).
length
,
0
,
"first is in the collection and not within two"
);
equal
(
$two
.
find
(
$first
).
length
,
0
,
"first is in the collection and not within two(node)"
);
equal
(
$two
.
find
(
$first
).
length
,
0
,
"first is in the collection and not within two(node)"
);
equal
(
$two
.
find
(
$foo
[
0
]
).
andSelf
().
length
,
2
,
"find preserves the pushStack, see #12009"
);
});
});
test
(
"is(String|undefined)"
,
function
()
{
test
(
"is(String|undefined)"
,
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