4 "./traversing/var/rneedsContext",
6 "./traversing/findFilter",
8 ], function( jQuery, indexOf, rneedsContext ) {
10 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
11 // methods guaranteed to produce a unique set when starting from a unique set
20 dir: function( elem, dir, until ) {
22 truncate = until !== undefined;
24 while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
25 if ( elem.nodeType === 1 ) {
26 if ( truncate && jQuery( elem ).is( until ) ) {
35 sibling: function( n, elem ) {
38 for ( ; n; n = n.nextSibling ) {
39 if ( n.nodeType === 1 && n !== elem ) {
49 has: function( target ) {
50 var targets = jQuery( target, this ),
53 return this.filter(function() {
55 for ( ; i < l; i++ ) {
56 if ( jQuery.contains( this, targets[i] ) ) {
63 closest: function( selectors, context ) {
68 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
69 jQuery( selectors, context || this.context ) :
72 for ( ; i < l; i++ ) {
73 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
74 // Always skip document fragments
75 if ( cur.nodeType < 11 && (pos ?
78 // Don't pass non-elements to Sizzle
80 jQuery.find.matchesSelector(cur, selectors)) ) {
88 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
91 // Determine the position of an element within
92 // the matched set of elements
93 index: function( elem ) {
95 // No argument, return index in parent
97 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
101 if ( typeof elem === "string" ) {
102 return indexOf.call( jQuery( elem ), this[ 0 ] );
105 // Locate the position of the desired element
106 return indexOf.call( this,
108 // If it receives a jQuery object, the first element is used
109 elem.jquery ? elem[ 0 ] : elem
113 add: function( selector, context ) {
114 return this.pushStack(
116 jQuery.merge( this.get(), jQuery( selector, context ) )
121 addBack: function( selector ) {
122 return this.add( selector == null ?
123 this.prevObject : this.prevObject.filter(selector)
128 function sibling( cur, dir ) {
129 while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
134 parent: function( elem ) {
135 var parent = elem.parentNode;
136 return parent && parent.nodeType !== 11 ? parent : null;
138 parents: function( elem ) {
139 return jQuery.dir( elem, "parentNode" );
141 parentsUntil: function( elem, i, until ) {
142 return jQuery.dir( elem, "parentNode", until );
144 next: function( elem ) {
145 return sibling( elem, "nextSibling" );
147 prev: function( elem ) {
148 return sibling( elem, "previousSibling" );
150 nextAll: function( elem ) {
151 return jQuery.dir( elem, "nextSibling" );
153 prevAll: function( elem ) {
154 return jQuery.dir( elem, "previousSibling" );
156 nextUntil: function( elem, i, until ) {
157 return jQuery.dir( elem, "nextSibling", until );
159 prevUntil: function( elem, i, until ) {
160 return jQuery.dir( elem, "previousSibling", until );
162 siblings: function( elem ) {
163 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
165 children: function( elem ) {
166 return jQuery.sibling( elem.firstChild );
168 contents: function( elem ) {
169 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
171 }, function( name, fn ) {
172 jQuery.fn[ name ] = function( until, selector ) {
173 var matched = jQuery.map( this, fn, until );
175 if ( name.slice( -5 ) !== "Until" ) {
179 if ( selector && typeof selector === "string" ) {
180 matched = jQuery.filter( selector, matched );
183 if ( this.length > 1 ) {
185 if ( !guaranteedUnique[ name ] ) {
186 jQuery.unique( matched );
189 // Reverse order for parents* and prev-derivatives
190 if ( rparentsprev.test( name ) ) {
195 return this.pushStack( matched );