aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 a47b048ba..0d4c1c4c3 100644
--- a/src/traversing.js
+++ b/src/traversing.js
@@ -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
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;
+};
+
+} );