Skip to content

Commit f9ef427

Browse files
committed
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
1 parent c161eec commit f9ef427

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

src/traversing.js

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
define( [
22
"./core",
33
"./var/indexOf",
4+
"./traversing/var/dir",
5+
"./traversing/var/siblings",
46
"./traversing/var/rneedsContext",
57
"./core/init",
68
"./traversing/findFilter",
79
"./selector"
8-
], function( jQuery, indexOf, rneedsContext ) {
10+
], function( jQuery, indexOf, dir, siblings, rneedsContext ) {
911

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

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

20-
jQuery.extend( {
21-
dir: function( elem, dir, until ) {
22-
var matched = [],
23-
truncate = until !== undefined;
24-
25-
while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) {
26-
if ( elem.nodeType === 1 ) {
27-
if ( truncate && jQuery( elem ).is( until ) ) {
28-
break;
29-
}
30-
matched.push( elem );
31-
}
32-
}
33-
return matched;
34-
},
35-
36-
sibling: function( n, elem ) {
37-
var matched = [];
38-
39-
for ( ; n; n = n.nextSibling ) {
40-
if ( n.nodeType === 1 && n !== elem ) {
41-
matched.push( n );
42-
}
43-
}
44-
45-
return matched;
46-
}
47-
} );
48-
4922
jQuery.fn.extend( {
5023
has: function( target ) {
5124
var targets = jQuery( target, this ),
@@ -137,10 +110,10 @@ jQuery.each( {
137110
return parent && parent.nodeType !== 11 ? parent : null;
138111
},
139112
parents: function( elem ) {
140-
return jQuery.dir( elem, "parentNode" );
113+
return dir( elem, "parentNode" );
141114
},
142115
parentsUntil: function( elem, i, until ) {
143-
return jQuery.dir( elem, "parentNode", until );
116+
return dir( elem, "parentNode", until );
144117
},
145118
next: function( elem ) {
146119
return sibling( elem, "nextSibling" );
@@ -149,22 +122,22 @@ jQuery.each( {
149122
return sibling( elem, "previousSibling" );
150123
},
151124
nextAll: function( elem ) {
152-
return jQuery.dir( elem, "nextSibling" );
125+
return dir( elem, "nextSibling" );
153126
},
154127
prevAll: function( elem ) {
155-
return jQuery.dir( elem, "previousSibling" );
128+
return dir( elem, "previousSibling" );
156129
},
157130
nextUntil: function( elem, i, until ) {
158-
return jQuery.dir( elem, "nextSibling", until );
131+
return dir( elem, "nextSibling", until );
159132
},
160133
prevUntil: function( elem, i, until ) {
161-
return jQuery.dir( elem, "previousSibling", until );
134+
return dir( elem, "previousSibling", until );
162135
},
163136
siblings: function( elem ) {
164-
return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
137+
return siblings( ( elem.parentNode || {} ).firstChild, elem );
165138
},
166139
children: function( elem ) {
167-
return jQuery.sibling( elem.firstChild );
140+
return siblings( elem.firstChild );
168141
},
169142
contents: function( elem ) {
170143
return elem.contentDocument || jQuery.merge( [], elem.childNodes );

src/traversing/var/dir.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
define( [
2+
"../../core"
3+
], function( jQuery ) {
4+
5+
return function( elem, dir, until ) {
6+
var matched = [],
7+
truncate = until !== undefined;
8+
9+
while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) {
10+
if ( elem.nodeType === 1 ) {
11+
if ( truncate && jQuery( elem ).is( until ) ) {
12+
break;
13+
}
14+
matched.push( elem );
15+
}
16+
}
17+
return matched;
18+
};
19+
20+
} );

src/traversing/var/siblings.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
define( function() {
2+
3+
return function( n, elem ) {
4+
var matched = [];
5+
6+
for ( ; n; n = n.nextSibling ) {
7+
if ( n.nodeType === 1 && n !== elem ) {
8+
matched.push( n );
9+
}
10+
}
11+
12+
return matched;
13+
};
14+
15+
} );

0 commit comments

Comments
 (0)