Skip to content

Commit

Permalink
Traversing: Don't expose jQuery.dir & jQuery.sibling
Browse files Browse the repository at this point in the history
jQuery.dir & jQuery.sibling are undocumented internal APIs; they shouldn't
be exposed.

Fixes gh-2512
Closes gh-2525
  • Loading branch information
mgol committed Sep 8, 2015
1 parent c161eec commit f9ef427
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
49 changes: 11 additions & 38 deletions src/traversing.js
@@ -1,11 +1,13 @@
define( [ define( [
"./core", "./core",
"./var/indexOf", "./var/indexOf",
"./traversing/var/dir",
"./traversing/var/siblings",
"./traversing/var/rneedsContext", "./traversing/var/rneedsContext",
"./core/init", "./core/init",
"./traversing/findFilter", "./traversing/findFilter",
"./selector" "./selector"
], function( jQuery, indexOf, rneedsContext ) { ], function( jQuery, indexOf, dir, siblings, rneedsContext ) {


var rparentsprev = /^(?:parents|prev(?:Until|All))/, var rparentsprev = /^(?:parents|prev(?:Until|All))/,


Expand All @@ -17,35 +19,6 @@ var rparentsprev = /^(?:parents|prev(?:Until|All))/,
prev: true prev: true
}; };


jQuery.extend( {
dir: function( elem, dir, until ) {
var matched = [],
truncate = until !== undefined;

while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) {
if ( elem.nodeType === 1 ) {
if ( truncate && jQuery( elem ).is( until ) ) {
break;
}
matched.push( elem );
}
}
return matched;
},

sibling: function( n, elem ) {
var matched = [];

for ( ; n; n = n.nextSibling ) {
if ( n.nodeType === 1 && n !== elem ) {
matched.push( n );
}
}

return matched;
}
} );

jQuery.fn.extend( { jQuery.fn.extend( {
has: function( target ) { has: function( target ) {
var targets = jQuery( target, this ), var targets = jQuery( target, this ),
Expand Down Expand Up @@ -137,10 +110,10 @@ jQuery.each( {
return parent && parent.nodeType !== 11 ? parent : null; return parent && parent.nodeType !== 11 ? parent : null;
}, },
parents: function( elem ) { parents: function( elem ) {
return jQuery.dir( elem, "parentNode" ); return dir( elem, "parentNode" );
}, },
parentsUntil: function( elem, i, until ) { parentsUntil: function( elem, i, until ) {
return jQuery.dir( elem, "parentNode", until ); return dir( elem, "parentNode", until );
}, },
next: function( elem ) { next: function( elem ) {
return sibling( elem, "nextSibling" ); return sibling( elem, "nextSibling" );
Expand All @@ -149,22 +122,22 @@ jQuery.each( {
return sibling( elem, "previousSibling" ); return sibling( elem, "previousSibling" );
}, },
nextAll: function( elem ) { nextAll: function( elem ) {
return jQuery.dir( elem, "nextSibling" ); return dir( elem, "nextSibling" );
}, },
prevAll: function( elem ) { prevAll: function( elem ) {
return jQuery.dir( elem, "previousSibling" ); return dir( elem, "previousSibling" );
}, },
nextUntil: function( elem, i, until ) { nextUntil: function( elem, i, until ) {
return jQuery.dir( elem, "nextSibling", until ); return dir( elem, "nextSibling", until );
}, },
prevUntil: function( elem, i, until ) { prevUntil: function( elem, i, until ) {
return jQuery.dir( elem, "previousSibling", until ); return dir( elem, "previousSibling", until );
}, },
siblings: function( elem ) { siblings: function( elem ) {
return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem ); return siblings( ( elem.parentNode || {} ).firstChild, elem );
}, },
children: function( elem ) { children: function( elem ) {
return jQuery.sibling( elem.firstChild ); return siblings( elem.firstChild );
}, },
contents: function( elem ) { contents: function( elem ) {
return elem.contentDocument || jQuery.merge( [], elem.childNodes ); return elem.contentDocument || jQuery.merge( [], elem.childNodes );
Expand Down
20 changes: 20 additions & 0 deletions src/traversing/var/dir.js
@@ -0,0 +1,20 @@
define( [
"../../core"
], function( jQuery ) {

return function( elem, dir, until ) {
var matched = [],
truncate = until !== undefined;

while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) {
if ( elem.nodeType === 1 ) {
if ( truncate && jQuery( elem ).is( until ) ) {
break;
}
matched.push( elem );
}
}
return matched;
};

} );
15 changes: 15 additions & 0 deletions src/traversing/var/siblings.js
@@ -0,0 +1,15 @@
define( function() {

return function( n, elem ) {
var matched = [];

for ( ; n; n = n.nextSibling ) {
if ( n.nodeType === 1 && n !== elem ) {
matched.push( n );
}
}

return matched;
};

} );

0 comments on commit f9ef427

Please sign in to comment.