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 ) === 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 not: function( selector ) {
61 return this.pushStack( winnow(this, selector, false), "not", selector);
64 filter: function( selector ) {
65 return this.pushStack( winnow(this, selector, true), "filter", selector );
68 closest: function( selectors, context ) {
69 if ( jQuery.isArray( selectors ) ) {
70 var ret = [], cur = this[0], match, matches = {}, selector;
72 if ( cur && selectors.length ) {
73 for ( var i = 0, l = selectors.length; i < l; i++ ) {
74 selector = selectors[i];
76 if ( !matches[selector] ) {
77 matches[selector] = jQuery.expr.match.POS.test( selector ) ?
78 jQuery( selector, context || this.context ) :
83 while ( cur && cur.ownerDocument && cur !== context ) {
84 for ( selector in matches ) {
85 match = matches[selector];
87 if ( match.jquery ? match.index(cur) > -1 : jQuery(cur).is(match) ) {
88 ret.push({ selector: selector, elem: cur });
89 delete matches[selector];
99 var pos = jQuery.expr.match.POS.test( selectors ) ?
100 jQuery( selectors, context || this.context ) : null;
102 return this.map(function(i, cur){
103 while ( cur && cur.ownerDocument && cur !== context ) {
104 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selectors) ) {
107 cur = cur.parentNode;
113 add: function( selector, context ) {
114 var set = typeof selector === "string" ?
115 jQuery( selector, context || this.context ) :
116 jQuery.makeArray( selector ),
117 all = jQuery.merge( this.get(), set );
119 return this.pushStack( set[0] && (set[0].setInterval || set[0].nodeType === 9 || (set[0].parentNode && set[0].parentNode.nodeType !== 11)) ?
120 jQuery.unique( all ) :
127 this.slice( i, +i + 1 );
135 return this.eq( -1 );
139 return this.pushStack( slice.apply( this, arguments ),
140 "slice", slice.call(arguments).join(",") );
143 map: function( callback ) {
144 return this.pushStack( jQuery.map(this, function(elem, i){
145 return callback.call( elem, i, elem );
149 andSelf: function() {
150 return this.add( this.prevObject );
154 return this.prevObject || jQuery(null);
159 parent: function(elem){return elem.parentNode;},
160 parents: function(elem){return jQuery.dir(elem,"parentNode");},
161 parentsUntil: function(elem,i,until){return jQuery.dir(elem,"parentNode",until);},
162 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
163 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
164 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
165 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
166 nextUntil: function(elem,i,until){return jQuery.dir(elem,"nextSibling",until);},
167 prevUntil: function(elem,i,until){return jQuery.dir(elem,"previousSibling",until);},
168 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
169 children: function(elem){return jQuery.sibling(elem.firstChild);},
170 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
171 }, function(name, fn){
172 jQuery.fn[ name ] = function( until, selector ) {
173 var ret = jQuery.map( this, fn, until );
175 if ( !runtil.test( name ) ) {
179 if ( selector && typeof selector === "string" ) {
180 ret = jQuery.filter( selector, ret );
183 ret = this.length > 1 ? jQuery.unique( ret ) : ret;
185 if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) {
189 return this.pushStack( ret, name, slice.call(arguments).join(",") );
194 filter: function( expr, elems, not ) {
196 expr = ":not(" + expr + ")";
199 return jQuery.find.matches(expr, elems);
202 dir: function( elem, dir, until ) {
203 var matched = [], cur = elem[dir];
204 while ( cur && cur.nodeType !== 9 && (until === undefined || !jQuery( cur ).is( until )) ) {
205 if ( cur.nodeType === 1 ) {
213 nth: function( cur, result, dir, elem ) {
214 result = result || 1;
217 for ( ; cur; cur = cur[dir] ) {
218 if ( cur.nodeType === 1 && ++num === result ) {
226 sibling: function( n, elem ) {
229 for ( ; n; n = n.nextSibling ) {
230 if ( n.nodeType === 1 && n !== elem ) {