4 rparentsprev = /^(?:parents|prevUntil|prevAll)/,
5 // Note: This RegExp should be improved, or likely pulled from Sizzle
7 isSimple = /^.[^:#\[\.,]*$/,
8 slice = Array.prototype.slice,
9 POS = jQuery.expr.match.POS,
10 // methods guaranteed to produce a unique set when starting from a unique set
19 find: function( selector ) {
20 var ret = this.pushStack( "", "find", selector ),
23 for ( var i = 0, l = this.length; i < l; i++ ) {
25 jQuery.find( selector, this[i], ret );
28 // Make sure that the results are unique
29 for ( var n = length; n < ret.length; n++ ) {
30 for ( var r = 0; r < length; r++ ) {
31 if ( ret[r] === ret[n] ) {
43 has: function( target ) {
44 var targets = jQuery( target );
45 return this.filter(function() {
46 for ( var i = 0, l = targets.length; i < l; i++ ) {
47 if ( jQuery.contains( this, targets[i] ) ) {
54 not: function( selector ) {
55 return this.pushStack( winnow(this, selector, false), "not", selector);
58 filter: function( selector ) {
59 return this.pushStack( winnow(this, selector, true), "filter", selector );
62 is: function( selector ) {
63 return !!selector && jQuery.filter( selector, this ).length > 0;
66 closest: function( selectors, context ) {
67 var ret = [], i, l, cur = this[0];
69 if ( jQuery.isArray( selectors ) ) {
74 if ( cur && selectors.length ) {
75 for ( i = 0, l = selectors.length; i < l; i++ ) {
76 selector = selectors[i];
78 if ( !matches[selector] ) {
79 matches[selector] = jQuery.expr.match.POS.test( selector ) ?
80 jQuery( selector, context || this.context ) :
85 while ( cur && cur.ownerDocument && cur !== context ) {
86 for ( selector in matches ) {
87 match = matches[selector];
89 if ( match.jquery ? match.index(cur) > -1 : jQuery(cur).is(match) ) {
90 ret.push({ selector: selector, elem: cur, level: level });
102 var pos = POS.test( selectors ) ?
103 jQuery( selectors, context || this.context ) : null;
105 for ( i = 0, l = this.length; i < l; i++ ) {
109 if ( pos ? pos.index(cur) > -1 : jQuery.find.matchesSelector(cur, selectors) ) {
114 cur = cur.parentNode;
115 if ( !cur || !cur.ownerDocument || cur === context ) {
122 ret = ret.length > 1 ? jQuery.unique(ret) : ret;
124 return this.pushStack( ret, "closest", selectors );
127 // Determine the position of an element within
128 // the matched set of elements
129 index: function( elem ) {
130 if ( !elem || typeof elem === "string" ) {
131 return jQuery.inArray( this[0],
132 // If it receives a string, the selector is used
133 // If it receives nothing, the siblings are used
134 elem ? jQuery( elem ) : this.parent().children() );
136 // Locate the position of the desired element
137 return jQuery.inArray(
138 // If it receives a jQuery object, the first element is used
139 elem.jquery ? elem[0] : elem, this );
142 add: function( selector, context ) {
143 var set = typeof selector === "string" ?
144 jQuery( selector, context || this.context ) :
145 jQuery.makeArray( selector ),
146 all = jQuery.merge( this.get(), set );
148 return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ?
150 jQuery.unique( all ) );
153 andSelf: function() {
154 return this.add( this.prevObject );
158 // A painfully simple check to see if an element is disconnected
159 // from a document (should be improved, where feasible).
160 function isDisconnected( node ) {
161 return !node || !node.parentNode || node.parentNode.nodeType === 11;
165 parent: function( elem ) {
166 var parent = elem.parentNode;
167 return parent && parent.nodeType !== 11 ? parent : null;
169 parents: function( elem ) {
170 return jQuery.dir( elem, "parentNode" );
172 parentsUntil: function( elem, i, until ) {
173 return jQuery.dir( elem, "parentNode", until );
175 next: function( elem ) {
176 return jQuery.nth( elem, 2, "nextSibling" );
178 prev: function( elem ) {
179 return jQuery.nth( elem, 2, "previousSibling" );
181 nextAll: function( elem ) {
182 return jQuery.dir( elem, "nextSibling" );
184 prevAll: function( elem ) {
185 return jQuery.dir( elem, "previousSibling" );
187 nextUntil: function( elem, i, until ) {
188 return jQuery.dir( elem, "nextSibling", until );
190 prevUntil: function( elem, i, until ) {
191 return jQuery.dir( elem, "previousSibling", until );
193 siblings: function( elem ) {
194 return jQuery.sibling( elem.parentNode.firstChild, elem );
196 children: function( elem ) {
197 return jQuery.sibling( elem.firstChild );
199 contents: function( elem ) {
200 return jQuery.nodeName( elem, "iframe" ) ?
201 elem.contentDocument || elem.contentWindow.document :
202 jQuery.makeArray( elem.childNodes );
204 }, function( name, fn ) {
205 jQuery.fn[ name ] = function( until, selector ) {
206 var ret = jQuery.map( this, fn, until ),
207 args = slice.call(arguments);
209 if ( !runtil.test( name ) ) {
213 if ( selector && typeof selector === "string" ) {
214 ret = jQuery.filter( selector, ret );
217 ret = this.length > 1 && !guaranteedUnique[ name ] ? jQuery.unique( ret ) : ret;
219 if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) {
223 return this.pushStack( ret, name, args.join(",") );
228 filter: function( expr, elems, not ) {
230 expr = ":not(" + expr + ")";
233 return elems.length === 1 ?
234 jQuery.find.matchesSelector(elems[0], expr) ? [ elems[0] ] : [] :
235 jQuery.find.matches(expr, elems);
238 dir: function( elem, dir, until ) {
242 while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) {
243 if ( cur.nodeType === 1 ) {
251 nth: function( cur, result, dir, elem ) {
252 result = result || 1;
255 for ( ; cur; cur = cur[dir] ) {
256 if ( cur.nodeType === 1 && ++num === result ) {
264 sibling: function( n, elem ) {
267 for ( ; n; n = n.nextSibling ) {
268 if ( n.nodeType === 1 && n !== elem ) {
277 // Implement the identical functionality for filter and not
278 function winnow( elements, qualifier, keep ) {
279 if ( jQuery.isFunction( qualifier ) ) {
280 return jQuery.grep(elements, function( elem, i ) {
281 var retVal = !!qualifier.call( elem, i, elem );
282 return retVal === keep;
285 } else if ( qualifier.nodeType ) {
286 return jQuery.grep(elements, function( elem, i ) {
287 return (elem === qualifier) === keep;
290 } else if ( typeof qualifier === "string" ) {
291 var filtered = jQuery.grep(elements, function( elem ) {
292 return elem.nodeType === 1;
295 if ( isSimple.test( qualifier ) ) {
296 return jQuery.filter(qualifier, filtered, !keep);
298 qualifier = jQuery.filter( qualifier, filtered );
302 return jQuery.grep(elements, function( elem, i ) {
303 return (jQuery.inArray( elem, qualifier ) >= 0) === keep;