aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Gołębiowski <m.goleb@gmail.com>2015-08-03 19:45:26 +0200
committerMichał Gołębiowski <m.goleb@gmail.com>2015-09-08 17:39:28 +0200
commit8c851bfdb952f2aa0b71bf30194184f954af2215 (patch)
tree86732f736231781674ddd7e3fc73a36c6426b400
parentd8b7e7b0bd047f02890de2874cafdd3e0f8dd608 (diff)
downloadjquery-8c851bfdb952f2aa0b71bf30194184f954af2215.tar.gz
jquery-8c851bfdb952f2aa0b71bf30194184f954af2215.zip
Traversing: Don't expose jQuery.dir & jQuery.sibling
jQuery.dir & jQuery.sibling are undocumented internal APIs; they shouldn't be exposed. (cherry-picked from f9ef427d355a8a2b531aed5d112dfa4f9692105c) Fixes gh-2512 Closes gh-2525
-rw-r--r--src/traversing.js49
-rw-r--r--src/traversing/var/dir.js20
-rw-r--r--src/traversing/var/siblings.js15
3 files changed, 46 insertions, 38 deletions
diff --git a/src/traversing.js b/src/traversing.js
index ad041821b..addc79080 100644
--- a/src/traversing.js
+++ b/src/traversing.js
@@ -1,10 +1,12 @@
define( [
"./core",
+ "./traversing/var/dir",
+ "./traversing/var/siblings",
"./traversing/var/rneedsContext",
"./core/init",
"./traversing/findFilter",
"./selector"
-], function( jQuery, rneedsContext ) {
+], function( jQuery, dir, siblings, rneedsContext ) {
var rparentsprev = /^(?:parents|prev(?:Until|All))/,
@@ -16,35 +18,6 @@ var rparentsprev = /^(?:parents|prev(?:Until|All))/,
prev: true
};
-jQuery.extend( {
- dir: function( elem, dir, until ) {
- var matched = [],
- cur = elem[ dir ];
-
- while ( cur && cur.nodeType !== 9 &&
- ( until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until ) ) ) {
-
- if ( cur.nodeType === 1 ) {
- matched.push( cur );
- }
- cur = cur[ dir ];
- }
- return matched;
- },
-
- sibling: function( n, elem ) {
- var r = [];
-
- for ( ; n; n = n.nextSibling ) {
- if ( n.nodeType === 1 && n !== elem ) {
- r.push( n );
- }
- }
-
- return r;
- }
-} );
-
jQuery.fn.extend( {
has: function( target ) {
var i,
@@ -139,10 +112,10 @@ jQuery.each( {
return parent && parent.nodeType !== 11 ? parent : null;
},
parents: function( elem ) {
- return jQuery.dir( elem, "parentNode" );
+ return dir( elem, "parentNode" );
},
parentsUntil: function( elem, i, until ) {
- return jQuery.dir( elem, "parentNode", until );
+ return dir( elem, "parentNode", until );
},
next: function( elem ) {
return sibling( elem, "nextSibling" );
@@ -151,22 +124,22 @@ jQuery.each( {
return sibling( elem, "previousSibling" );
},
nextAll: function( elem ) {
- return jQuery.dir( elem, "nextSibling" );
+ return dir( elem, "nextSibling" );
},
prevAll: function( elem ) {
- return jQuery.dir( elem, "previousSibling" );
+ return dir( elem, "previousSibling" );
},
nextUntil: function( elem, i, until ) {
- return jQuery.dir( elem, "nextSibling", until );
+ return dir( elem, "nextSibling", until );
},
prevUntil: function( elem, i, until ) {
- return jQuery.dir( elem, "previousSibling", until );
+ return dir( elem, "previousSibling", until );
},
siblings: function( elem ) {
- return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
+ return siblings( ( elem.parentNode || {} ).firstChild, elem );
},
children: function( elem ) {
- return jQuery.sibling( elem.firstChild );
+ return siblings( elem.firstChild );
},
contents: function( elem ) {
return elem.contentDocument || jQuery.merge( [], elem.childNodes );
diff --git a/src/traversing/var/dir.js b/src/traversing/var/dir.js
new file mode 100644
index 000000000..b98fdca0e
--- /dev/null
+++ b/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;
+};
+
+} );
diff --git a/src/traversing/var/siblings.js b/src/traversing/var/siblings.js
new file mode 100644
index 000000000..8a8880bf7
--- /dev/null
+++ b/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;
+};
+
+} );