4 "./traversing/var/dir",
5 "./traversing/var/siblings",
6 "./traversing/var/rneedsContext",
10 "./traversing/findFilter",
12 ], function( jQuery, indexOf, dir, siblings, rneedsContext, nodeName ) {
16 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
18 // Methods guaranteed to produce a unique set when starting from a unique set
27 has: function( target ) {
28 var targets = jQuery( target, this ),
31 return this.filter( function() {
33 for ( ; i < l; i++ ) {
34 if ( jQuery.contains( this, targets[ i ] ) ) {
41 closest: function( selectors, context ) {
46 targets = typeof selectors !== "string" && jQuery( selectors );
48 // Positional selectors never match, since there's no _selection_ context
49 if ( !rneedsContext.test( selectors ) ) {
50 for ( ; i < l; i++ ) {
51 for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
53 // Always skip document fragments
54 if ( cur.nodeType < 11 && ( targets ?
55 targets.index( cur ) > -1 :
57 // Don't pass non-elements to Sizzle
59 jQuery.find.matchesSelector( cur, selectors ) ) ) {
68 return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
71 // Determine the position of an element within the set
72 index: function( elem ) {
74 // No argument, return index in parent
76 return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
80 if ( typeof elem === "string" ) {
81 return indexOf.call( jQuery( elem ), this[ 0 ] );
84 // Locate the position of the desired element
85 return indexOf.call( this,
87 // If it receives a jQuery object, the first element is used
88 elem.jquery ? elem[ 0 ] : elem
92 add: function( selector, context ) {
93 return this.pushStack(
95 jQuery.merge( this.get(), jQuery( selector, context ) )
100 addBack: function( selector ) {
101 return this.add( selector == null ?
102 this.prevObject : this.prevObject.filter( selector )
107 function sibling( cur, dir ) {
108 while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {}
113 parent: function( elem ) {
114 var parent = elem.parentNode;
115 return parent && parent.nodeType !== 11 ? parent : null;
117 parents: function( elem ) {
118 return dir( elem, "parentNode" );
120 parentsUntil: function( elem, i, until ) {
121 return dir( elem, "parentNode", until );
123 next: function( elem ) {
124 return sibling( elem, "nextSibling" );
126 prev: function( elem ) {
127 return sibling( elem, "previousSibling" );
129 nextAll: function( elem ) {
130 return dir( elem, "nextSibling" );
132 prevAll: function( elem ) {
133 return dir( elem, "previousSibling" );
135 nextUntil: function( elem, i, until ) {
136 return dir( elem, "nextSibling", until );
138 prevUntil: function( elem, i, until ) {
139 return dir( elem, "previousSibling", until );
141 siblings: function( elem ) {
142 return siblings( ( elem.parentNode || {} ).firstChild, elem );
144 children: function( elem ) {
145 return siblings( elem.firstChild );
147 contents: function( elem ) {
148 if ( nodeName( elem, "iframe" ) ) {
149 return elem.contentDocument;
152 // Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only
153 // Treat the template element as a regular one in browsers that
155 if ( nodeName( elem, "template" ) ) {
156 elem = elem.content || elem;
159 return jQuery.merge( [], elem.childNodes );
161 }, function( name, fn ) {
162 jQuery.fn[ name ] = function( until, selector ) {
163 var matched = jQuery.map( this, fn, until );
165 if ( name.slice( -5 ) !== "Until" ) {
169 if ( selector && typeof selector === "string" ) {
170 matched = jQuery.filter( selector, matched );
173 if ( this.length > 1 ) {
176 if ( !guaranteedUnique[ name ] ) {
177 jQuery.uniqueSort( matched );
180 // Reverse order for parents* and prev-derivatives
181 if ( rparentsprev.test( name ) ) {
186 return this.pushStack( matched );