4 "./traversing/var/dir",
5 "./traversing/var/siblings",
6 "./traversing/var/rneedsContext",
8 "./traversing/findFilter",
10 ], function( jQuery, indexOf, dir, siblings, rneedsContext ) {
12 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
14 // Methods guaranteed to produce a unique set when starting from a unique set
23 has: function( target ) {
24 var targets = jQuery( target, this ),
27 return this.filter( function() {
29 for ( ; i < l; i++ ) {
30 if ( jQuery.contains( this, targets[ i ] ) ) {
37 closest: function( selectors, context ) {
42 pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
43 jQuery( selectors, context || this.context ) :
46 for ( ; i < l; i++ ) {
47 for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
49 // Always skip document fragments
50 if ( cur.nodeType < 11 && ( pos ?
51 pos.index( cur ) > -1 :
53 // Don't pass non-elements to Sizzle
55 jQuery.find.matchesSelector( cur, selectors ) ) ) {
63 return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
66 // Determine the position of an element within the set
67 index: function( elem ) {
69 // No argument, return index in parent
71 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
75 if ( typeof elem === "string" ) {
76 return indexOf.call( jQuery( elem ), this[ 0 ] );
79 // Locate the position of the desired element
80 return indexOf.call( this,
82 // If it receives a jQuery object, the first element is used
83 elem.jquery ? elem[ 0 ] : elem
87 add: function( selector, context ) {
88 return this.pushStack(
90 jQuery.merge( this.get(), jQuery( selector, context ) )
95 addBack: function( selector ) {
96 return this.add( selector == null ?
97 this.prevObject : this.prevObject.filter( selector )
102 function sibling( cur, dir ) {
103 while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {}
108 parent: function( elem ) {
109 var parent = elem.parentNode;
110 return parent && parent.nodeType !== 11 ? parent : null;
112 parents: function( elem ) {
113 return dir( elem, "parentNode" );
115 parentsUntil: function( elem, i, until ) {
116 return dir( elem, "parentNode", until );
118 next: function( elem ) {
119 return sibling( elem, "nextSibling" );
121 prev: function( elem ) {
122 return sibling( elem, "previousSibling" );
124 nextAll: function( elem ) {
125 return dir( elem, "nextSibling" );
127 prevAll: function( elem ) {
128 return dir( elem, "previousSibling" );
130 nextUntil: function( elem, i, until ) {
131 return dir( elem, "nextSibling", until );
133 prevUntil: function( elem, i, until ) {
134 return dir( elem, "previousSibling", until );
136 siblings: function( elem ) {
137 return siblings( ( elem.parentNode || {} ).firstChild, elem );
139 children: function( elem ) {
140 return siblings( elem.firstChild );
142 contents: function( elem ) {
143 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
145 }, function( name, fn ) {
146 jQuery.fn[ name ] = function( until, selector ) {
147 var matched = jQuery.map( this, fn, until );
149 if ( name.slice( -5 ) !== "Until" ) {
153 if ( selector && typeof selector === "string" ) {
154 matched = jQuery.filter( selector, matched );
157 if ( this.length > 1 ) {
160 if ( !guaranteedUnique[ name ] ) {
161 jQuery.uniqueSort( matched );
164 // Reverse order for parents* and prev-derivatives
165 if ( rparentsprev.test( name ) ) {
170 return this.pushStack( matched );