2 rparentsprev = /^(?:parents|prevUntil|prevAll)/,
3 // Note: This RegExp should be improved, or likely pulled from Sizzle
5 slice = Array.prototype.slice;
7 // Implement the identical functionality for filter and not
8 var winnow = function( elements, qualifier, keep ) {
9 if ( jQuery.isFunction( qualifier ) ) {
10 return jQuery.grep(elements, function( elem, i ) {
11 return !!qualifier.call( elem, i, elem ) === keep;
14 } else if ( qualifier.nodeType ) {
15 return jQuery.grep(elements, function( elem, i ) {
16 return (elem === qualifier) === keep;
19 } else if ( typeof qualifier === "string" ) {
20 var filtered = jQuery.grep(elements, function( elem ) {
21 return elem.nodeType === 1;
24 if ( isSimple.test( qualifier ) ) {
25 return jQuery.filter(qualifier, filtered, !keep);
27 qualifier = jQuery.filter( qualifier, elements );
31 return jQuery.grep(elements, function( elem, i ) {
32 return (jQuery.inArray( elem, qualifier ) >= 0) === keep;
37 find: function( selector ) {
38 var ret = this.pushStack( "", "find", selector ), length = 0;
40 for ( var i = 0, l = this.length; i < l; i++ ) {
42 jQuery.find( selector, this[i], ret );
45 // Make sure that the results are unique
46 for ( var n = length; n < ret.length; n++ ) {
47 for ( var r = 0; r < length; r++ ) {
48 if ( ret[r] === ret[n] ) {
60 has: function( target ) {
61 var targets = jQuery( target );
62 return this.filter(function() {
63 for ( var i = 0, l = targets.length; i < l; i++ ) {
64 if ( jQuery.contains( this, targets[i] ) ) {
71 not: function( selector ) {
72 return this.pushStack( winnow(this, selector, false), "not", selector);
75 filter: function( selector ) {
76 return this.pushStack( winnow(this, selector, true), "filter", selector );
79 is: function( selector ) {
80 return !!selector && jQuery.filter( selector, this ).length > 0;
83 closest: function( selectors, context ) {
84 if ( jQuery.isArray( selectors ) ) {
85 var ret = [], cur = this[0], match, matches = {}, selector;
87 if ( cur && selectors.length ) {
88 for ( var i = 0, l = selectors.length; i < l; i++ ) {
89 selector = selectors[i];
91 if ( !matches[selector] ) {
92 matches[selector] = jQuery.expr.match.POS.test( selector ) ?
93 jQuery( selector, context || this.context ) :
98 while ( cur && cur.ownerDocument && cur !== context ) {
99 for ( selector in matches ) {
100 match = matches[selector];
102 if ( match.jquery ? match.index(cur) > -1 : jQuery(cur).is(match) ) {
103 ret.push({ selector: selector, elem: cur });
104 delete matches[selector];
107 cur = cur.parentNode;
114 var pos = jQuery.expr.match.POS.test( selectors ) ?
115 jQuery( selectors, context || this.context ) : null;
117 return this.map(function( i, cur ) {
118 while ( cur && cur.ownerDocument && cur !== context ) {
119 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selectors) ) {
122 cur = cur.parentNode;
128 // Determine the position of an element within
129 // the matched set of elements
130 index: function( elem ) {
131 if ( !elem || typeof elem === "string" ) {
132 return jQuery.inArray( this[0],
133 // If it receives a string, the selector is used
134 // If it receives nothing, the siblings are used
135 elem ? jQuery( elem ) : this.parent().children() );
137 // Locate the position of the desired element
138 return jQuery.inArray(
139 // If it receives a jQuery object, the first element is used
140 elem.jquery ? elem[0] : elem, this );
143 add: function( selector, context ) {
144 var set = typeof selector === "string" ?
145 jQuery( selector, context || this.context ) :
146 jQuery.makeArray( selector ),
147 all = jQuery.merge( this.get(), set );
149 return this.pushStack( set[0] && (set[0].setInterval || set[0].nodeType === 9 || (set[0].parentNode && set[0].parentNode.nodeType !== 11)) ?
150 jQuery.unique( all ) :
154 andSelf: function() {
155 return this.add( this.prevObject );
160 parent: function( elem ) {
161 var parent = elem.parentNode;
162 return parent && parent.nodeType !== 11 ? parent : null;
164 parents: function( elem ) {
165 return jQuery.dir( elem, "parentNode" );
167 parentsUntil: function( elem, i, until ) {
168 return jQuery.dir( elem, "parentNode", until );
170 next: function( elem ) {
171 return jQuery.nth( elem, 2, "nextSibling" );
173 prev: function( elem ) {
174 return jQuery.nth( elem, 2, "previousSibling" );
176 nextAll: function( elem ) {
177 return jQuery.dir( elem, "nextSibling" );
179 prevAll: function( elem ) {
180 return jQuery.dir( elem, "previousSibling" );
182 nextUntil: function( elem, i, until ) {
183 return jQuery.dir( elem, "nextSibling", until );
185 prevUntil: function( elem, i, until ) {
186 return jQuery.dir( elem, "previousSibling", until );
188 siblings: function( elem ) {
189 return jQuery.sibling( elem.parentNode.firstChild, elem );
191 children: function( elem ) {
192 return jQuery.sibling( elem.firstChild );
194 contents: function( elem ) {
195 return jQuery.nodeName( elem, "iframe" ) ?
196 elem.contentDocument || elem.contentWindow.document :
197 jQuery.makeArray( elem.childNodes );
199 }, function( name, fn ) {
200 jQuery.fn[ name ] = function( until, selector ) {
201 var ret = jQuery.map( this, fn, until );
203 if ( !runtil.test( name ) ) {
207 if ( selector && typeof selector === "string" ) {
208 ret = jQuery.filter( selector, ret );
211 ret = this.length > 1 ? jQuery.unique( ret ) : ret;
213 if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) {
217 return this.pushStack( ret, name, slice.call(arguments).join(",") );
222 filter: function( expr, elems, not ) {
224 expr = ":not(" + expr + ")";
227 return jQuery.find.matches(expr, elems);
230 dir: function( elem, dir, until ) {
231 var matched = [], cur = elem[dir];
232 while ( cur && cur.nodeType !== 9 && (until === undefined || !jQuery( cur ).is( until )) ) {
233 if ( cur.nodeType === 1 ) {
241 nth: function( cur, result, dir, elem ) {
242 result = result || 1;
245 for ( ; cur; cur = cur[dir] ) {
246 if ( cur.nodeType === 1 && ++num === result ) {
254 sibling: function( n, elem ) {
257 for ( ; n; n = n.nextSibling ) {
258 if ( n.nodeType === 1 && n !== elem ) {