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
6dc30ae7
Commit
6dc30ae7
authored
Jan 13, 2009
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged Sizzle changes back into jQuery.
parent
d5858c7c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
16 deletions
+47
-16
selector.js
src/selector.js
+26
-11
index.html
test/index.html
+1
-0
selector.js
test/unit/selector.js
+20
-5
No files found.
src/selector.js
View file @
6dc30ae7
...
@@ -45,7 +45,7 @@ var Sizzle = function(selector, context, results, seed) {
...
@@ -45,7 +45,7 @@ var Sizzle = function(selector, context, results, seed) {
selector
=
selector
.
replace
(
Expr
.
match
.
POS
,
""
);
selector
=
selector
.
replace
(
Expr
.
match
.
POS
,
""
);
}
}
set
=
Sizzle
.
filter
(
later
,
Sizzle
(
selector
,
context
)
);
set
=
Sizzle
.
filter
(
later
,
Sizzle
(
/
\s
$/
.
test
(
selector
)
?
selector
+
"*"
:
selector
,
context
)
);
}
else
{
}
else
{
set
=
Expr
.
relative
[
parts
[
0
]
]
?
set
=
Expr
.
relative
[
parts
[
0
]
]
?
[
context
]
:
[
context
]
:
...
@@ -259,7 +259,7 @@ var Expr = Sizzle.selectors = {
...
@@ -259,7 +259,7 @@ var Expr = Sizzle.selectors = {
ID: /#((?:[
\
w
\
u00c0-
\
uFFFF_-]|
\\
.)+)/,
ID: /#((?:[
\
w
\
u00c0-
\
uFFFF_-]|
\\
.)+)/,
CLASS: /
\
.((?:[
\
w
\
u00c0-
\
uFFFF_-]|
\\
.)+)/,
CLASS: /
\
.((?:[
\
w
\
u00c0-
\
uFFFF_-]|
\\
.)+)/,
NAME: /
\
[name=['"
]
*
((?:[
\
w
\
u00c0
-
\
uFFFF_
-
]
|
\\
.)
+
)[
'"]*
\
]/,
NAME: /
\
[name=['"
]
*
((?:[
\
w
\
u00c0
-
\
uFFFF_
-
]
|
\\
.)
+
)[
'"]*
\
]/,
ATTR: /
\
[
((?:[
\
w
\
u00c0-
\
uFFFF_-]|
\\
.)+)
\
s*(?:(
\
S?=)
\
s*(['
"]*)(.*?)
\
3|)
\
]/,
ATTR: /
\
[
\
s*((?:[
\
w
\
u00c0-
\
uFFFF_-]|
\\
.)+)
\
s*(?:(
\
S?=)
\
s*(['
"]*)(.*?)
\
3|)
\
s*
\
]/,
TAG: /^((?:[
\
w
\
u00c0-
\
uFFFF
\
*_-]|
\\
.)+)/,
TAG: /^((?:[
\
w
\
u00c0-
\
uFFFF
\
*_-]|
\\
.)+)/,
CHILD: /:(only|nth|last|first)-child(?:
\
((even|odd|[
\
dn+-]*)
\
))?/,
CHILD: /:(only|nth|last|first)-child(?:
\
((even|odd|[
\
dn+-]*)
\
))?/,
POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:
\
((
\
d*)
\
))?(?=[^-]|$)/,
POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:
\
((
\
d*)
\
))?(?=[^-]|$)/,
...
@@ -269,6 +269,11 @@ var Expr = Sizzle.selectors = {
...
@@ -269,6 +269,11 @@ var Expr = Sizzle.selectors = {
"class"
:
"className"
,
"class"
:
"className"
,
"for"
:
"htmlFor"
"for"
:
"htmlFor"
},
},
attrHandle
:
{
href
:
function
(
elem
){
return
elem
.
getAttribute
(
"href"
);
}
},
relative
:
{
relative
:
{
"+"
:
function
(
checkSet
,
part
){
"+"
:
function
(
checkSet
,
part
){
for
(
var
i
=
0
,
l
=
checkSet
.
length
;
i
<
l
;
i
++
)
{
for
(
var
i
=
0
,
l
=
checkSet
.
length
;
i
<
l
;
i
++
)
{
...
@@ -322,7 +327,7 @@ var Expr = Sizzle.selectors = {
...
@@ -322,7 +327,7 @@ var Expr = Sizzle.selectors = {
checkFn
=
dirNodeCheck
;
checkFn
=
dirNodeCheck
;
}
}
checkFn
(
"parentNode"
,
part
,
doneName
,
checkSet
,
nodeCheck
);
checkFn
(
"parentNode"
,
part
,
doneName
,
checkSet
,
nodeCheck
,
isXML
);
},
},
"~"
:
function
(
checkSet
,
part
,
isXML
){
"~"
:
function
(
checkSet
,
part
,
isXML
){
var
doneName
=
"done"
+
(
done
++
),
checkFn
=
dirCheck
;
var
doneName
=
"done"
+
(
done
++
),
checkFn
=
dirCheck
;
...
@@ -332,7 +337,7 @@ var Expr = Sizzle.selectors = {
...
@@ -332,7 +337,7 @@ var Expr = Sizzle.selectors = {
checkFn
=
dirNodeCheck
;
checkFn
=
dirNodeCheck
;
}
}
checkFn
(
"previousSibling"
,
part
,
doneName
,
checkSet
,
nodeCheck
);
checkFn
(
"previousSibling"
,
part
,
doneName
,
checkSet
,
nodeCheck
,
isXML
);
}
}
},
},
find
:
{
find
:
{
...
@@ -580,7 +585,7 @@ var Expr = Sizzle.selectors = {
...
@@ -580,7 +585,7 @@ var Expr = Sizzle.selectors = {
return
match
.
test
(
elem
.
className
);
return
match
.
test
(
elem
.
className
);
},
},
ATTR
:
function
(
elem
,
match
){
ATTR
:
function
(
elem
,
match
){
var
result
=
elem
[
match
[
1
]
]
||
elem
.
getAttribute
(
match
[
1
]
),
value
=
result
+
""
,
type
=
match
[
2
],
check
=
match
[
4
];
var
result
=
Expr
.
attrHandle
[
match
[
1
]
]
?
Expr
.
attrHandle
[
match
[
1
]
](
elem
)
:
elem
[
match
[
1
]
]
||
elem
.
getAttribute
(
match
[
1
]
),
value
=
result
+
""
,
type
=
match
[
2
],
check
=
match
[
4
];
return
result
==
null
?
return
result
==
null
?
false
:
false
:
type
===
"="
?
type
===
"="
?
...
@@ -685,9 +690,10 @@ try {
...
@@ -685,9 +690,10 @@ try {
root
.
removeChild
(
form
);
root
.
removeChild
(
form
);
})();
})();
// Check to see if the browser returns only elements
// when doing getElementsByTagName("*")
(
function
(){
(
function
(){
// Check to see if the browser returns only elements
// when doing getElementsByTagName("*")
// Create a fake element
// Create a fake element
var
div
=
document
.
createElement
(
"div"
);
var
div
=
document
.
createElement
(
"div"
);
div
.
appendChild
(
document
.
createComment
(
""
)
);
div
.
appendChild
(
document
.
createComment
(
""
)
);
...
@@ -713,6 +719,14 @@ try {
...
@@ -713,6 +719,14 @@ try {
return
results
;
return
results
;
};
};
}
}
// Check to see if an attribute returns normalized href attributes
div
.
innerHTML
=
"<a href='#'></a>"
;
if
(
div
.
firstChild
.
getAttribute
(
"href"
)
!==
"#"
)
{
Expr
.
attrHandle
.
href
=
function
(
elem
){
return
elem
.
getAttribute
(
"href"
,
2
);
};
}
})();
})();
if
(
document
.
querySelectorAll
)
(
function
(){
if
(
document
.
querySelectorAll
)
(
function
(){
...
@@ -743,7 +757,7 @@ if ( document.documentElement.getElementsByClassName ) {
...
@@ -743,7 +757,7 @@ if ( document.documentElement.getElementsByClassName ) {
};
};
}
}
function
dirNodeCheck
(
dir
,
cur
,
doneName
,
checkSet
,
nodeCheck
)
{
function
dirNodeCheck
(
dir
,
cur
,
doneName
,
checkSet
,
nodeCheck
,
isXML
)
{
for
(
var
i
=
0
,
l
=
checkSet
.
length
;
i
<
l
;
i
++
)
{
for
(
var
i
=
0
,
l
=
checkSet
.
length
;
i
<
l
;
i
++
)
{
var
elem
=
checkSet
[
i
];
var
elem
=
checkSet
[
i
];
if
(
elem
)
{
if
(
elem
)
{
...
@@ -757,7 +771,7 @@ function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck ) {
...
@@ -757,7 +771,7 @@ function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck ) {
break
;
break
;
}
}
if
(
elem
.
nodeType
===
1
)
if
(
elem
.
nodeType
===
1
&&
!
isXML
)
elem
[
doneName
]
=
i
;
elem
[
doneName
]
=
i
;
if
(
elem
.
nodeName
===
cur
)
{
if
(
elem
.
nodeName
===
cur
)
{
...
@@ -773,7 +787,7 @@ function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck ) {
...
@@ -773,7 +787,7 @@ function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck ) {
}
}
}
}
function
dirCheck
(
dir
,
cur
,
doneName
,
checkSet
,
nodeCheck
)
{
function
dirCheck
(
dir
,
cur
,
doneName
,
checkSet
,
nodeCheck
,
isXML
)
{
for
(
var
i
=
0
,
l
=
checkSet
.
length
;
i
<
l
;
i
++
)
{
for
(
var
i
=
0
,
l
=
checkSet
.
length
;
i
<
l
;
i
++
)
{
var
elem
=
checkSet
[
i
];
var
elem
=
checkSet
[
i
];
if
(
elem
)
{
if
(
elem
)
{
...
@@ -787,7 +801,8 @@ function dirCheck( dir, cur, doneName, checkSet, nodeCheck ) {
...
@@ -787,7 +801,8 @@ function dirCheck( dir, cur, doneName, checkSet, nodeCheck ) {
}
}
if
(
elem
.
nodeType
===
1
)
{
if
(
elem
.
nodeType
===
1
)
{
elem
[
doneName
]
=
i
;
if
(
!
isXML
)
elem
[
doneName
]
=
i
;
if
(
typeof
cur
!==
"string"
)
{
if
(
typeof
cur
!==
"string"
)
{
if
(
elem
===
cur
)
{
if
(
elem
===
cur
)
{
...
...
test/index.html
View file @
6dc30ae7
...
@@ -54,6 +54,7 @@
...
@@ -54,6 +54,7 @@
<ul
id=
"firstUL"
></ul>
<ul
id=
"firstUL"
></ul>
<ol
id=
"empty"
></ol>
<ol
id=
"empty"
></ol>
<form
id=
"form"
action=
"formaction"
>
<form
id=
"form"
action=
"formaction"
>
<label
for=
"action"
id=
"label-for"
>
Action:
</label>
<input
type=
"text"
name=
"action"
value=
"Test"
id=
"text1"
maxlength=
"30"
/>
<input
type=
"text"
name=
"action"
value=
"Test"
id=
"text1"
maxlength=
"30"
/>
<input
type=
"text"
name=
"text2"
value=
"Test"
id=
"text2"
disabled=
"disabled"
/>
<input
type=
"text"
name=
"text2"
value=
"Test"
id=
"text2"
disabled=
"disabled"
/>
<input
type=
"radio"
name=
"radio1"
id=
"radio1"
value=
"on"
/>
<input
type=
"radio"
name=
"radio1"
id=
"radio1"
value=
"on"
/>
...
...
test/unit/selector.js
View file @
6dc30ae7
...
@@ -2,6 +2,8 @@ module("selector");
...
@@ -2,6 +2,8 @@ module("selector");
test
(
"element"
,
function
()
{
test
(
"element"
,
function
()
{
expect
(
9
);
expect
(
9
);
reset
();
ok
(
jQuery
(
"*"
).
size
()
>=
30
,
"Select all"
);
ok
(
jQuery
(
"*"
).
size
()
>=
30
,
"Select all"
);
var
all
=
jQuery
(
"*"
),
good
=
true
;
var
all
=
jQuery
(
"*"
),
good
=
true
;
for
(
var
i
=
0
;
i
<
all
.
length
;
i
++
)
for
(
var
i
=
0
;
i
<
all
.
length
;
i
++
)
...
@@ -39,7 +41,7 @@ test("broken", function() {
...
@@ -39,7 +41,7 @@ test("broken", function() {
name
+
": "
+
selector
);
name
+
": "
+
selector
);
}
}
}
}
broken
(
"Broken Selector"
,
"["
,
[]
);
broken
(
"Broken Selector"
,
"["
,
[]
);
broken
(
"Broken Selector"
,
"("
,
[]
);
broken
(
"Broken Selector"
,
"("
,
[]
);
broken
(
"Broken Selector"
,
"{"
,
[]
);
broken
(
"Broken Selector"
,
"{"
,
[]
);
...
@@ -139,7 +141,7 @@ test("multiple", function() {
...
@@ -139,7 +141,7 @@ test("multiple", function() {
});
});
test
(
"child and adjacent"
,
function
()
{
test
(
"child and adjacent"
,
function
()
{
expect
(
38
);
expect
(
41
);
t
(
"Child"
,
"p > a"
,
[
"simon1"
,
"google"
,
"groups"
,
"mark"
,
"yahoo"
,
"simon"
]
);
t
(
"Child"
,
"p > a"
,
[
"simon1"
,
"google"
,
"groups"
,
"mark"
,
"yahoo"
,
"simon"
]
);
t
(
"Child"
,
"p> a"
,
[
"simon1"
,
"google"
,
"groups"
,
"mark"
,
"yahoo"
,
"simon"
]
);
t
(
"Child"
,
"p> a"
,
[
"simon1"
,
"google"
,
"groups"
,
"mark"
,
"yahoo"
,
"simon"
]
);
t
(
"Child"
,
"p >a"
,
[
"simon1"
,
"google"
,
"groups"
,
"mark"
,
"yahoo"
,
"simon"
]
);
t
(
"Child"
,
"p >a"
,
[
"simon1"
,
"google"
,
"groups"
,
"mark"
,
"yahoo"
,
"simon"
]
);
...
@@ -154,6 +156,10 @@ test("child and adjacent", function() {
...
@@ -154,6 +156,10 @@ test("child and adjacent", function() {
t
(
"Adjacent"
,
"p + p"
,
[
"ap"
,
"en"
,
"sap"
]
);
t
(
"Adjacent"
,
"p + p"
,
[
"ap"
,
"en"
,
"sap"
]
);
t
(
"Comma, Child, and Adjacent"
,
"a + a, code > a"
,
[
"groups"
,
"anchor1"
,
"anchor2"
]
);
t
(
"Comma, Child, and Adjacent"
,
"a + a, code > a"
,
[
"groups"
,
"anchor1"
,
"anchor2"
]
);
isSet
(
jQuery
(
"> :first"
,
document
.
getElementById
(
"nothiddendiv"
)),
q
(
"nothiddendivchild"
),
"Verify child context positional selctor"
);
isSet
(
jQuery
(
"> :eq(0)"
,
document
.
getElementById
(
"nothiddendiv"
)),
q
(
"nothiddendivchild"
),
"Verify child context positional selctor"
);
isSet
(
jQuery
(
"> *:first"
,
document
.
getElementById
(
"nothiddendiv"
)),
q
(
"nothiddendivchild"
),
"Verify child context positional selctor"
);
t
(
"Non-existant ancestors"
,
".fototab > .thumbnails > a"
,
[]
);
t
(
"Non-existant ancestors"
,
".fototab > .thumbnails > a"
,
[]
);
t
(
"First Child"
,
"p:first-child"
,
[
"firstp"
,
"sndp"
]
);
t
(
"First Child"
,
"p:first-child"
,
[
"firstp"
,
"sndp"
]
);
...
@@ -162,8 +168,8 @@ test("child and adjacent", function() {
...
@@ -162,8 +168,8 @@ test("child and adjacent", function() {
t
(
"Last Child"
,
"p:last-child"
,
[
"sap"
]
);
t
(
"Last Child"
,
"p:last-child"
,
[
"sap"
]
);
t
(
"Last Child"
,
"a:last-child"
,
[
"simon1"
,
"anchor1"
,
"mark"
,
"yahoo"
,
"anchor2"
,
"simon"
]
);
t
(
"Last Child"
,
"a:last-child"
,
[
"simon1"
,
"anchor1"
,
"mark"
,
"yahoo"
,
"anchor2"
,
"simon"
]
);
t
(
"Nth-child"
,
"#main form#form > *:nth-child(2)"
,
[
"text
2
"
]
);
t
(
"Nth-child"
,
"#main form#form > *:nth-child(2)"
,
[
"text
1
"
]
);
t
(
"Nth-child"
,
"#main form#form > :nth-child(2)"
,
[
"text
2
"
]
);
t
(
"Nth-child"
,
"#main form#form > :nth-child(2)"
,
[
"text
1
"
]
);
t
(
"Nth-child"
,
"#form select:first option:nth-child(3)"
,
[
"option1c"
]
);
t
(
"Nth-child"
,
"#form select:first option:nth-child(3)"
,
[
"option1c"
]
);
t
(
"Nth-child"
,
"#form select:first option:nth-child(0n+3)"
,
[
"option1c"
]
);
t
(
"Nth-child"
,
"#form select:first option:nth-child(0n+3)"
,
[
"option1c"
]
);
...
@@ -186,15 +192,24 @@ test("child and adjacent", function() {
...
@@ -186,15 +192,24 @@ test("child and adjacent", function() {
});
});
test
(
"attributes"
,
function
()
{
test
(
"attributes"
,
function
()
{
expect
(
2
1
);
expect
(
2
7
);
t
(
"Attribute Exists"
,
"a[title]"
,
[
"google"
]
);
t
(
"Attribute Exists"
,
"a[title]"
,
[
"google"
]
);
t
(
"Attribute Exists"
,
"*[title]"
,
[
"google"
]
);
t
(
"Attribute Exists"
,
"*[title]"
,
[
"google"
]
);
t
(
"Attribute Exists"
,
"[title]"
,
[
"google"
]
);
t
(
"Attribute Exists"
,
"[title]"
,
[
"google"
]
);
t
(
"Attribute Exists"
,
"a[ title ]"
,
[
"google"
]
);
t
(
"Attribute Equals"
,
"a[rel='bookmark']"
,
[
"simon1"
]
);
t
(
"Attribute Equals"
,
"a[rel='bookmark']"
,
[
"simon1"
]
);
t
(
"Attribute Equals"
,
'a[rel="bookmark"]'
,
[
"simon1"
]
);
t
(
"Attribute Equals"
,
'a[rel="bookmark"]'
,
[
"simon1"
]
);
t
(
"Attribute Equals"
,
"a[rel=bookmark]"
,
[
"simon1"
]
);
t
(
"Attribute Equals"
,
"a[rel=bookmark]"
,
[
"simon1"
]
);
t
(
"Attribute Equals"
,
"a[href='http://www.google.com/']"
,
[
"google"
]
);
t
(
"Attribute Equals"
,
"a[href='http://www.google.com/']"
,
[
"google"
]
);
t
(
"Attribute Equals"
,
"a[ rel = 'bookmark' ]"
,
[
"simon1"
]
);
document
.
getElementById
(
"anchor2"
).
href
=
"#2"
;
t
(
"href Attribute"
,
"p a[href^=#]"
,
[
"anchor2"
]
);
t
(
"href Attribute"
,
"p a[href*=#]"
,
[
"simon1"
,
"anchor2"
]
);
t
(
"for Attribute"
,
"form label[for]"
,
[
"label-for"
]
);
t
(
"for Attribute in form"
,
"#form [for=action]"
,
[
"label-for"
]
);
var
results
=
[
"hidden1"
,
"radio1"
,
"radio2"
];
var
results
=
[
"hidden1"
,
"radio1"
,
"radio2"
];
...
...
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