]> source.dussan.org Git - jquery.git/commitdiff
Traversing: Don't expose jQuery.dir & jQuery.sibling
authorMichał Gołębiowski <m.goleb@gmail.com>
Mon, 3 Aug 2015 17:45:26 +0000 (19:45 +0200)
committerMichał Gołębiowski <m.goleb@gmail.com>
Tue, 8 Sep 2015 15:32:07 +0000 (17:32 +0200)
jQuery.dir & jQuery.sibling are undocumented internal APIs; they shouldn't
be exposed.

Fixes gh-2512
Closes gh-2525

src/traversing.js
src/traversing/var/dir.js [new file with mode: 0644]
src/traversing/var/siblings.js [new file with mode: 0644]

index a47b048ba709075e4a07bb9b43667f4fb1507c74..0d4c1c4c36cb47f1988f5812b7bb740c73974148 100644 (file)
@@ -1,11 +1,13 @@
 define( [
        "./core",
        "./var/indexOf",
+       "./traversing/var/dir",
+       "./traversing/var/siblings",
        "./traversing/var/rneedsContext",
        "./core/init",
        "./traversing/findFilter",
        "./selector"
-], function( jQuery, indexOf, rneedsContext ) {
+], function( jQuery, indexOf, dir, siblings, rneedsContext ) {
 
 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
 
@@ -17,35 +19,6 @@ var rparentsprev = /^(?:parents|prev(?:Until|All))/,
                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( {
        has: function( target ) {
                var targets = jQuery( target, this ),
@@ -137,10 +110,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" );
@@ -149,22 +122,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 (file)
index 0000000..b98fdca
--- /dev/null
@@ -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 (file)
index 0000000..8a8880b
--- /dev/null
@@ -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;
+};
+
+} );