aboutsummaryrefslogtreecommitdiffstats
path: root/src/selector.js
diff options
context:
space:
mode:
authorDavid Serduke <davidserduke@gmail.com>2007-11-16 19:01:53 +0000
committerDavid Serduke <davidserduke@gmail.com>2007-11-16 19:01:53 +0000
commit084079d2fd1c7ed3582612cc32b01346b43fb415 (patch)
tree7cc1ca32d476a5ca782ce348a2a348b81283be7d /src/selector.js
parent0a0990485e5c1fd4b4fdcce7f7723d9e0a9dd16d (diff)
downloadjquery-084079d2fd1c7ed3582612cc32b01346b43fb415.tar.gz
jquery-084079d2fd1c7ed3582612cc32b01346b43fb415.zip
Fixed #1727 bug where :nth-child() was non-standard with CSS3 plus two minor white space changes in selector.js.
Diffstat (limited to 'src/selector.js')
-rw-r--r--src/selector.js21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/selector.js b/src/selector.js
index 82627e1cc..b272acd4f 100644
--- a/src/selector.js
+++ b/src/selector.js
@@ -192,7 +192,7 @@ jQuery.extend({
// Re-organize the results, so that they're consistent
if ( m ) {
- m = [ 0, m[2], m[3], m[1] ];
+ m = [ 0, m[2], m[3], m[1] ];
} else {
// Otherwise, do a traditional filter check for
@@ -297,7 +297,7 @@ jQuery.extend({
var last;
// Look for common filter expressions
- while ( t && t != last ) {
+ while ( t && t != last ) {
last = t;
var p = jQuery.parse, m;
@@ -349,11 +349,14 @@ jQuery.extend({
// We can get a speed boost by handling nth-child here
} else if ( m[1] == ":" && m[2] == "nth-child" ) {
var merge = {}, tmp = [],
- test = /(\d*)n\+?(\d*)/.exec(
+ // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
+ test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
m[3] == "even" && "2n" || m[3] == "odd" && "2n+1" ||
- !/\D/.test(m[3]) && "n+" + m[3] || m[3]),
- first = (test[1] || 1) - 0, last = test[2] - 0;
-
+ !/\D/.test(m[3]) && "0n+" + m[3] || m[3]),
+ // calculate the numbers (first)n+(last) including if they are negative
+ first = (test[1] + (test[2] || 1)) - 0, last = test[3] - 0;
+
+ // loop through all the elements left in the jQuery object
for ( var i = 0, rl = r.length; i < rl; i++ ) {
var node = r[i], parentNode = node.parentNode, id = jQuery.data(parentNode);
@@ -369,10 +372,10 @@ jQuery.extend({
var add = false;
- if ( first == 1 ) {
- if ( last == 0 || node.nodeIndex == last )
+ if ( first == 0 ) {
+ if ( node.nodeIndex == last )
add = true;
- } else if ( (node.nodeIndex + last) % first == 0 )
+ } else if ( (node.nodeIndex - last) % first == 0 && (node.nodeIndex - last) / first >= 0 )
add = true;
if ( add ^ not )