Traversing: Don't expose jQuery.dir & jQuery.sibling

jQuery.dir & jQuery.sibling are undocumented internal APIs; they shouldn't
be exposed.

Fixes gh-2512
Closes gh-2525
This commit is contained in:
Michał Gołębiowski 2015-08-03 19:45:26 +02:00
parent c161eecce0
commit f9ef427d35
3 changed files with 46 additions and 38 deletions

View File

@ -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))/,
@ -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 ),
@ -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" );
@ -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 );

20
src/traversing/var/dir.js Normal file
View File

@ -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;
};
} );

View File

@ -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;
};
} );