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
ffd457d4
Commit
ffd457d4
authored
May 02, 2009
by
Brandon Aaron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
index now works in reverse when passed a selector or undefined. fixes #3971
parent
cbda6c54
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
24 deletions
+40
-24
core.js
src/core.js
+9
-3
core.js
test/unit/core.js
+31
-21
No files found.
src/core.js
View file @
ffd457d4
...
@@ -182,10 +182,16 @@ jQuery.fn = jQuery.prototype = {
...
@@ -182,10 +182,16 @@ jQuery.fn = jQuery.prototype = {
// Determine the position of an element within
// Determine the position of an element within
// the matched set of elements
// the matched set of elements
index
:
function
(
elem
)
{
index
:
function
(
elem
)
{
if
(
!
elem
||
typeof
elem
===
"string"
)
{
return
jQuery
.
inArray
(
this
[
0
],
// If it receives a string, the selector is used
// If it receives nothing, the siblings are used
elem
?
jQuery
(
elem
)
:
this
.
parent
().
children
()
);
}
// Locate the position of the desired element
// Locate the position of the desired element
return
jQuery
.
inArray
(
return
jQuery
.
inArray
(
// If it receives a jQuery object, the first element is used
// If it receives a jQuery object, the first element is used
elem
&&
elem
.
jquery
?
elem
[
0
]
:
elem
,
this
);
elem
.
jquery
?
elem
[
0
]
:
elem
,
this
);
},
},
is
:
function
(
selector
)
{
is
:
function
(
selector
)
{
...
...
test/unit/core.js
View file @
ffd457d4
...
@@ -366,12 +366,13 @@ test("each(Function)", function() {
...
@@ -366,12 +366,13 @@ test("each(Function)", function() {
ok
(
pass
,
"Execute a function, Relative"
);
ok
(
pass
,
"Execute a function, Relative"
);
});
});
test
(
"index(Object)"
,
function
()
{
test
(
"index(Object
|String|undefined
)"
,
function
()
{
expect
(
1
0
);
expect
(
1
5
);
var
elements
=
jQuery
([
window
,
document
]),
var
elements
=
jQuery
([
window
,
document
]),
inputElements
=
jQuery
(
'#radio1,#radio2,#check1,#check2'
);
inputElements
=
jQuery
(
'#radio1,#radio2,#check1,#check2'
);
// Passing a node
equals
(
elements
.
index
(
window
),
0
,
"Check for index of elements"
);
equals
(
elements
.
index
(
window
),
0
,
"Check for index of elements"
);
equals
(
elements
.
index
(
document
),
1
,
"Check for index of elements"
);
equals
(
elements
.
index
(
document
),
1
,
"Check for index of elements"
);
equals
(
inputElements
.
index
(
document
.
getElementById
(
'radio1'
)),
0
,
"Check for index of elements"
);
equals
(
inputElements
.
index
(
document
.
getElementById
(
'radio1'
)),
0
,
"Check for index of elements"
);
...
@@ -381,9 +382,18 @@ test("index(Object)", function() {
...
@@ -381,9 +382,18 @@ test("index(Object)", function() {
equals
(
inputElements
.
index
(
window
),
-
1
,
"Check for not found index"
);
equals
(
inputElements
.
index
(
window
),
-
1
,
"Check for not found index"
);
equals
(
inputElements
.
index
(
document
),
-
1
,
"Check for not found index"
);
equals
(
inputElements
.
index
(
document
),
-
1
,
"Check for not found index"
);
// Passing a jQuery object
// enabled since [5500]
// enabled since [5500]
equals
(
elements
.
index
(
elements
),
0
,
"Pass in a jQuery object"
);
equals
(
elements
.
index
(
elements
),
0
,
"Pass in a jQuery object"
);
equals
(
elements
.
index
(
elements
.
eq
(
1
)
),
1
,
"Pass in a jQuery object"
);
equals
(
elements
.
index
(
elements
.
eq
(
1
)
),
1
,
"Pass in a jQuery object"
);
equals
(
jQuery
(
"#form :radio"
).
index
(
jQuery
(
"#radio2"
)
),
1
,
"Pass in a jQuery object"
);
// Passing a selector or nothing
// enabled since [6329]
equals
(
jQuery
(
'#text2'
).
index
(),
2
,
"Check for index amongst siblings"
);
equals
(
jQuery
(
'#form'
).
children
().
eq
(
4
).
index
(),
4
,
"Check for index amongst siblings"
);
equals
(
jQuery
(
'#radio2'
).
index
(
'#form :radio'
)
,
1
,
"Check for index within a selector"
);
equals
(
jQuery
(
'#radio2'
).
index
(
'#form :text'
)
,
-
1
,
"Check for index not found within a selector"
);
});
});
test
(
"jQuery.merge()"
,
function
()
{
test
(
"jQuery.merge()"
,
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