This project is archived and is in readonly mode.

#528 ✓resolved
JeanLucPicard2

nth-child pseudo-class selector problem

Reported by JeanLucPicard2 | December 21st, 2008 @ 06:15 PM | in 2.0 (closed)

The nth-child pseudo-class of Selectors.js doesn’t work correctly in all cases. (and I a puzzled a while over it to find out what was wrong with the selector I passed as argument ;-)

According to the CSS spec (http://www.w3.org/TR/css3-select...) :nth-child(10n-1) represents the 9th, 19th, 29th, etc, element and :nth-child(-n+6) represents the 6 first elements.

In such cases the MooTools nth-child selection fails. I would suggest the following changes:


parseNthArgument: function(argument){
[…]
/* – var a = (inta || inta === 0) ? inta : 1; */
/* + */ var a = (inta || inta === 0) ? inta : (parsed[1] == "-" ? -1 : 1);
[…]
/* - if (a != 0){
   - 	b--;
   - 	while (b < 1) b += a;
   - 	while (b >= a) b -= a;
   - } else {
   - 	a = b;
   - 	special = 'index';
   - }*/
/* + */ if (a == 0){
/* + */ 	a = b;
/* + */ 	special = 'index';
/* + */ }
/* + */ else b--;
[…]
}

[…]

'nth-child': function(argument, local){
[…]
/* – return (local.positions[uid] % parsed.a == parsed.b);*/
/* + */ parsed=(local.positions[uid] – parsed.b) / parsed.a;
/* + */ return  parsed-Math.abs(Math.floor(parsed)) == 0;
}

That schould work (although a bit more testing would’nt be amiss ;-)

Hope that helps…

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages