Skip to content

Commit ae320b5

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 669cb16 commit ae320b5

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
// Methods guaranteed to produce a unique set when starting from a unique set
@@ -16,35 +18,6 @@ var rparentsprev = /^(?:parents|prev(?:Until|All))/,
1618
prev: true
1719
};
1820

19-
jQuery.extend({
20-
dir: function( elem, dir, until ) {
21-
var matched = [],
22-
truncate = until !== undefined;
23-
24-
while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
25-
if ( elem.nodeType === 1 ) {
26-
if ( truncate && jQuery( elem ).is( until ) ) {
27-
break;
28-
}
29-
matched.push( elem );
30-
}
31-
}
32-
return matched;
33-
},
34-
35-
sibling: function( n, elem ) {
36-
var matched = [];
37-
38-
for ( ; n; n = n.nextSibling ) {
39-
if ( n.nodeType === 1 && n !== elem ) {
40-
matched.push( n );
41-
}
42-
}
43-
44-
return matched;
45-
}
46-
});
47-
4821
jQuery.fn.extend({
4922
has: function( target ) {
5023
var targets = jQuery( target, this ),
@@ -135,10 +108,10 @@ jQuery.each({
135108
return parent && parent.nodeType !== 11 ? parent : null;
136109
},
137110
parents: function( elem ) {
138-
return jQuery.dir( elem, "parentNode" );
111+
return dir( elem, "parentNode" );
139112
},
140113
parentsUntil: function( elem, i, until ) {
141-
return jQuery.dir( elem, "parentNode", until );
114+
return dir( elem, "parentNode", until );
142115
},
143116
next: function( elem ) {
144117
return sibling( elem, "nextSibling" );
@@ -147,22 +120,22 @@ jQuery.each({
147120
return sibling( elem, "previousSibling" );
148121
},
149122
nextAll: function( elem ) {
150-
return jQuery.dir( elem, "nextSibling" );
123+
return dir( elem, "nextSibling" );
151124
},
152125
prevAll: function( elem ) {
153-
return jQuery.dir( elem, "previousSibling" );
126+
return dir( elem, "previousSibling" );
154127
},
155128
nextUntil: function( elem, i, until ) {
156-
return jQuery.dir( elem, "nextSibling", until );
129+
return dir( elem, "nextSibling", until );
157130
},
158131
prevUntil: function( elem, i, until ) {
159-
return jQuery.dir( elem, "previousSibling", until );
132+
return dir( elem, "previousSibling", until );
160133
},
161134
siblings: function( elem ) {
162-
return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
135+
return siblings( ( elem.parentNode || {} ).firstChild, elem );
163136
},
164137
children: function( elem ) {
165-
return jQuery.sibling( elem.firstChild );
138+
return siblings( elem.firstChild );
166139
},
167140
contents: function( elem ) {
168141
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)