Skip to content

Commit 8c851bf

Browse files
committed
Traversing: Don't expose jQuery.dir & jQuery.sibling
jQuery.dir & jQuery.sibling are undocumented internal APIs; they shouldn't be exposed. (cherry-picked from f9ef427) Fixes gh-2512 Closes gh-2525
1 parent d8b7e7b commit 8c851bf

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,10 +1,12 @@
11
define( [
22
"./core",
3+
"./traversing/var/dir",
4+
"./traversing/var/siblings",
35
"./traversing/var/rneedsContext",
46
"./core/init",
57
"./traversing/findFilter",
68
"./selector"
7-
], function( jQuery, rneedsContext ) {
9+
], function( jQuery, dir, siblings, rneedsContext ) {
810

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

@@ -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-
cur = elem[ dir ];
23-
24-
while ( cur && cur.nodeType !== 9 &&
25-
( until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until ) ) ) {
26-
27-
if ( cur.nodeType === 1 ) {
28-
matched.push( cur );
29-
}
30-
cur = cur[ dir ];
31-
}
32-
return matched;
33-
},
34-
35-
sibling: function( n, elem ) {
36-
var r = [];
37-
38-
for ( ; n; n = n.nextSibling ) {
39-
if ( n.nodeType === 1 && n !== elem ) {
40-
r.push( n );
41-
}
42-
}
43-
44-
return r;
45-
}
46-
} );
47-
4821
jQuery.fn.extend( {
4922
has: function( target ) {
5023
var i,
@@ -139,10 +112,10 @@ jQuery.each( {
139112
return parent && parent.nodeType !== 11 ? parent : null;
140113
},
141114
parents: function( elem ) {
142-
return jQuery.dir( elem, "parentNode" );
115+
return dir( elem, "parentNode" );
143116
},
144117
parentsUntil: function( elem, i, until ) {
145-
return jQuery.dir( elem, "parentNode", until );
118+
return dir( elem, "parentNode", until );
146119
},
147120
next: function( elem ) {
148121
return sibling( elem, "nextSibling" );
@@ -151,22 +124,22 @@ jQuery.each( {
151124
return sibling( elem, "previousSibling" );
152125
},
153126
nextAll: function( elem ) {
154-
return jQuery.dir( elem, "nextSibling" );
127+
return dir( elem, "nextSibling" );
155128
},
156129
prevAll: function( elem ) {
157-
return jQuery.dir( elem, "previousSibling" );
130+
return dir( elem, "previousSibling" );
158131
},
159132
nextUntil: function( elem, i, until ) {
160-
return jQuery.dir( elem, "nextSibling", until );
133+
return dir( elem, "nextSibling", until );
161134
},
162135
prevUntil: function( elem, i, until ) {
163-
return jQuery.dir( elem, "previousSibling", until );
136+
return dir( elem, "previousSibling", until );
164137
},
165138
siblings: function( elem ) {
166-
return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
139+
return siblings( ( elem.parentNode || {} ).firstChild, elem );
167140
},
168141
children: function( elem ) {
169-
return jQuery.sibling( elem.firstChild );
142+
return siblings( elem.firstChild );
170143
},
171144
contents: function( elem ) {
172145
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)