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 contains: function( target ) {
72 return this.has( target ).length > 0;
75 not: function( selector ) {
76 return this.pushStack( winnow(this, selector, false), "not", selector);
79 filter: function( selector ) {
80 return this.pushStack( winnow(this, selector, true), "filter", selector );
83 is: function( selector ) {
84 return !!selector && jQuery.filter( selector, this ).length > 0;
87 closest: function( selectors, context ) {
88 if ( jQuery.isArray( selectors ) ) {
89 var ret = [], cur = this[0], match, matches = {}, selector;
91 if ( cur && selectors.length ) {
92 for ( var i = 0, l = selectors.length; i < l; i++ ) {
93 selector = selectors[i];
95 if ( !matches[selector] ) {
96 matches[selector] = jQuery.expr.match.POS.test( selector ) ?
97 jQuery( selector, context || this.context ) :
102 while ( cur && cur.ownerDocument && cur !== context ) {
103 for ( selector in matches ) {
104 match = matches[selector];
106 if ( match.jquery ? match.index(cur) > -1 : jQuery(cur).is(match) ) {
107 ret.push({ selector: selector, elem: cur });
108 delete matches[selector];
111 cur = cur.parentNode;
118 var pos = jQuery.expr.match.POS.test( selectors ) ?
119 jQuery( selectors, context || this.context ) : null;
121 return this.map(function(i, cur){
122 while ( cur && cur.ownerDocument && cur !== context ) {
123 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selectors) ) {
126 cur = cur.parentNode;
132 // Determine the position of an element within
133 // the matched set of elements
134 index: function( elem ) {
135 if ( !elem || typeof elem === "string" ) {
136 return jQuery.inArray( this[0],
137 // If it receives a string, the selector is used
138 // If it receives nothing, the siblings are used
139 elem ? jQuery( elem ) : this.parent().children() );
141 // Locate the position of the desired element
142 return jQuery.inArray(
143 // If it receives a jQuery object, the first element is used
144 elem.jquery ? elem[0] : elem, this );
147 add: function( selector, context ) {
148 var set = typeof selector === "string" ?
149 jQuery( selector, context || this.context ) :
150 jQuery.makeArray( selector ),
151 all = jQuery.merge( this.get(), set );
153 return this.pushStack( set[0] && (set[0].setInterval || set[0].nodeType === 9 || (set[0].parentNode && set[0].parentNode.nodeType !== 11)) ?
154 jQuery.unique( all ) :
158 andSelf: function() {
159 return this.add( this.prevObject );
164 parent: function(elem){return elem.parentNode;},
165 parents: function(elem){return jQuery.dir(elem,"parentNode");},
166 parentsUntil: function(elem,i,until){return jQuery.dir(elem,"parentNode",until);},
167 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
168 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
169 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
170 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
171 nextUntil: function(elem,i,until){return jQuery.dir(elem,"nextSibling",until);},
172 prevUntil: function(elem,i,until){return jQuery.dir(elem,"previousSibling",until);},
173 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
174 children: function(elem){return jQuery.sibling(elem.firstChild);},
175 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
176 }, function(name, fn){
177 jQuery.fn[ name ] = function( until, selector ) {
178 var ret = jQuery.map( this, fn, until );
180 if ( !runtil.test( name ) ) {
184 if ( selector && typeof selector === "string" ) {
185 ret = jQuery.filter( selector, ret );
188 ret = this.length > 1 ? jQuery.unique( ret ) : ret;
190 if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) {
194 return this.pushStack( ret, name, slice.call(arguments).join(",") );
199 filter: function( expr, elems, not ) {
201 expr = ":not(" + expr + ")";
204 return jQuery.find.matches(expr, elems);
207 dir: function( elem, dir, until ) {
208 var matched = [], cur = elem[dir];
209 while ( cur && cur.nodeType !== 9 && (until === undefined || !jQuery( cur ).is( until )) ) {
210 if ( cur.nodeType === 1 ) {
218 nth: function( cur, result, dir, elem ) {
219 result = result || 1;
222 for ( ; cur; cur = cur[dir] ) {
223 if ( cur.nodeType === 1 && ++num === result ) {
231 sibling: function( n, elem ) {
234 for ( ; n; n = n.nextSibling ) {
235 if ( n.nodeType === 1 && n !== elem ) {