Skip to content

Commit

Permalink
Additional reduction per @Raynos suggestion. Thanks!
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed May 7, 2012
1 parent 2af3642 commit df254d4
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/traversing.js
Expand Up @@ -174,14 +174,9 @@ function isDisconnected( node ) {
return !node || !node.parentNode || node.parentNode.nodeType === 11; return !node || !node.parentNode || node.parentNode.nodeType === 11;
} }


function nth( cur, dir ) { function sibling( cur, dir ) {
var num = 0; while ( cur = cur[ dir ], cur.nodeType !== 1 ) {}


for ( ; cur; cur = cur[dir] ) {
if ( cur.nodeType === 1 && num++ === 1 ) {
break;
}
}
return cur; return cur;
} }


Expand All @@ -197,10 +192,10 @@ jQuery.each({
return jQuery.dir( elem, "parentNode", until ); return jQuery.dir( elem, "parentNode", until );
}, },
next: function( elem ) { next: function( elem ) {
return nth( elem, "nextSibling" ); return sibling( elem, "nextSibling" );
}, },
prev: function( elem ) { prev: function( elem ) {
return nth( elem, "previousSibling" ); return sibling( elem, "previousSibling" );
}, },
nextAll: function( elem ) { nextAll: function( elem ) {
return jQuery.dir( elem, "nextSibling" ); return jQuery.dir( elem, "nextSibling" );
Expand Down

0 comments on commit df254d4

Please sign in to comment.