3 "./traversing/var/rneedsContext",
5 "./traversing/findFilter",
7 ], function( jQuery, rneedsContext ) {
9 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
10 // methods guaranteed to produce a unique set when starting from a unique set
19 dir: function( elem, dir, until ) {
23 while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) {
24 if ( cur.nodeType === 1 ) {
32 sibling: function( n, elem ) {
35 for ( ; n; n = n.nextSibling ) {
36 if ( n.nodeType === 1 && n !== elem ) {
46 has: function( target ) {
48 targets = jQuery( target, this ),
51 return this.filter(function() {
52 for ( i = 0; i < len; i++ ) {
53 if ( jQuery.contains( this, targets[i] ) ) {
60 closest: function( selectors, context ) {
65 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
66 jQuery( selectors, context || this.context ) :
69 for ( ; i < l; i++ ) {
70 for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
71 // Always skip document fragments
72 if ( cur.nodeType < 11 && (pos ?
75 // Don't pass non-elements to Sizzle
77 jQuery.find.matchesSelector(cur, selectors)) ) {
85 return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
88 // Determine the position of an element within
89 // the matched set of elements
90 index: function( elem ) {
92 // No argument, return index in parent
94 return ( this[0] && this[0].parentNode ) ? this.first().prevAll().length : -1;
98 if ( typeof elem === "string" ) {
99 return jQuery.inArray( this[0], jQuery( elem ) );
102 // Locate the position of the desired element
103 return jQuery.inArray(
104 // If it receives a jQuery object, the first element is used
105 elem.jquery ? elem[0] : elem, this );
108 add: function( selector, context ) {
109 return this.pushStack(
111 jQuery.merge( this.get(), jQuery( selector, context ) )
116 addBack: function( selector ) {
117 return this.add( selector == null ?
118 this.prevObject : this.prevObject.filter(selector)
123 function sibling( cur, dir ) {
126 } while ( cur && cur.nodeType !== 1 );
132 parent: function( elem ) {
133 var parent = elem.parentNode;
134 return parent && parent.nodeType !== 11 ? parent : null;
136 parents: function( elem ) {
137 return jQuery.dir( elem, "parentNode" );
139 parentsUntil: function( elem, i, until ) {
140 return jQuery.dir( elem, "parentNode", until );
142 next: function( elem ) {
143 return sibling( elem, "nextSibling" );
145 prev: function( elem ) {
146 return sibling( elem, "previousSibling" );
148 nextAll: function( elem ) {
149 return jQuery.dir( elem, "nextSibling" );
151 prevAll: function( elem ) {
152 return jQuery.dir( elem, "previousSibling" );
154 nextUntil: function( elem, i, until ) {
155 return jQuery.dir( elem, "nextSibling", until );
157 prevUntil: function( elem, i, until ) {
158 return jQuery.dir( elem, "previousSibling", until );
160 siblings: function( elem ) {
161 return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
163 children: function( elem ) {
164 return jQuery.sibling( elem.firstChild );
166 contents: function( elem ) {
167 return jQuery.nodeName( elem, "iframe" ) ?
168 elem.contentDocument || elem.contentWindow.document :
169 jQuery.merge( [], elem.childNodes );
171 }, function( name, fn ) {
172 jQuery.fn[ name ] = function( until, selector ) {
173 var ret = jQuery.map( this, fn, until );
175 if ( name.slice( -5 ) !== "Until" ) {
179 if ( selector && typeof selector === "string" ) {
180 ret = jQuery.filter( selector, ret );
183 if ( this.length > 1 ) {
185 if ( !guaranteedUnique[ name ] ) {
186 ret = jQuery.unique( ret );
189 // Reverse order for parents* and prev-derivatives
190 if ( rparentsprev.test( name ) ) {
195 return this.pushStack( ret );