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
4e27f170
Commit
4e27f170
authored
Dec 09, 2009
by
Yehuda Katz
Committed by
John Resig
Dec 09, 2009
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Landing in jQuery.contains, jQuery.fn.contains, and jQuery.fn.has support. Fixes #4101.
parent
9e60fec4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
1 deletion
+53
-1
sizzle-jquery.js
src/sizzle-jquery.js
+1
-0
traversing.js
src/traversing.js
+15
-0
traversing.js
test/unit/traversing.js
+37
-1
No files found.
src/sizzle-jquery.js
View file @
4e27f170
...
@@ -4,5 +4,6 @@ jQuery.expr[":"] = jQuery.expr.filters;
...
@@ -4,5 +4,6 @@ jQuery.expr[":"] = jQuery.expr.filters;
jQuery
.
unique
=
Sizzle
.
uniqueSort
;
jQuery
.
unique
=
Sizzle
.
uniqueSort
;
jQuery
.
getText
=
getText
;
jQuery
.
getText
=
getText
;
jQuery
.
isXMLDoc
=
isXML
;
jQuery
.
isXMLDoc
=
isXML
;
jQuery
.
contains
=
contains
;
return
;
return
;
src/traversing.js
View file @
4e27f170
...
@@ -57,6 +57,21 @@ jQuery.fn.extend({
...
@@ -57,6 +57,21 @@ jQuery.fn.extend({
return
ret
;
return
ret
;
},
},
has
:
function
(
target
)
{
var
targets
=
jQuery
(
target
);
return
this
.
filter
(
function
()
{
for
(
var
i
=
0
,
l
=
targets
.
length
;
i
<
l
;
i
++
)
{
if
(
jQuery
.
contains
(
this
,
targets
[
i
]
)
)
{
return
true
;
}
}
});
},
contains
:
function
(
target
)
{
return
this
.
has
(
target
).
length
>
0
;
},
not
:
function
(
selector
)
{
not
:
function
(
selector
)
{
return
this
.
pushStack
(
winnow
(
this
,
selector
,
false
),
"not"
,
selector
);
return
this
.
pushStack
(
winnow
(
this
,
selector
,
false
),
"not"
,
selector
);
},
},
...
...
test/unit/traversing.js
View file @
4e27f170
...
@@ -152,7 +152,43 @@ test("not(jQuery)", function() {
...
@@ -152,7 +152,43 @@ test("not(jQuery)", function() {
expect
(
1
);
expect
(
1
);
same
(
jQuery
(
"p"
).
not
(
jQuery
(
"#ap, #sndp, .result"
)).
get
(),
q
(
"firstp"
,
"en"
,
"sap"
,
"first"
),
"not(jQuery)"
);
same
(
jQuery
(
"p"
).
not
(
jQuery
(
"#ap, #sndp, .result"
)).
get
(),
q
(
"firstp"
,
"en"
,
"sap"
,
"first"
),
"not(jQuery)"
);
})
});
test
(
"has(Element)"
,
function
()
{
expect
(
2
);
var
obj
=
jQuery
(
"#main"
).
has
(
jQuery
(
"#sndp"
)[
0
]);
same
(
obj
.
get
(),
q
(
"main"
),
"Keeps elements that have the element as a descendant"
);
var
multipleParent
=
jQuery
(
"#main, #header"
).
has
(
jQuery
(
"#sndp"
)[
0
]);
same
(
obj
.
get
(),
q
(
"main"
),
"Does not include elements that do not have the element as a descendant"
);
});
test
(
"has(Selector)"
,
function
()
{
expect
(
3
);
var
obj
=
jQuery
(
"#main"
).
has
(
"#sndp"
);
same
(
obj
.
get
(),
q
(
"main"
),
"Keeps elements that have any element matching the selector as a descendant"
);
var
multipleParent
=
jQuery
(
"#main, #header"
).
has
(
"#sndp"
);
same
(
obj
.
get
(),
q
(
"main"
),
"Does not include elements that do not have the element as a descendant"
);
var
multipleHas
=
jQuery
(
"#main"
).
has
(
"#sndp, #first"
);
same
(
multipleHas
.
get
(),
q
(
"main"
),
"Only adds elements once"
);
});
test
(
"has(Arrayish)"
,
function
()
{
expect
(
3
);
var
simple
=
jQuery
(
"#main"
).
has
(
jQuery
(
"#sndp"
));
same
(
simple
.
get
(),
q
(
"main"
),
"Keeps elements that have any element in the jQuery list as a descendant"
);
var
multipleParent
=
jQuery
(
"#main, #header"
).
has
(
jQuery
(
"#sndp"
));
same
(
multipleParent
.
get
(),
q
(
"main"
),
"Does not include elements that do not have an element in the jQuery list as a descendant"
);
var
multipleHas
=
jQuery
(
"#main"
).
has
(
jQuery
(
"#sndp, #first"
));
same
(
simple
.
get
(),
q
(
"main"
),
"Only adds elements once"
);
});
test
(
"andSelf()"
,
function
()
{
test
(
"andSelf()"
,
function
()
{
expect
(
4
);
expect
(
4
);
...
...
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