1 jQuery.winnow = function( elements, qualifier, keep ) {
2 if(jQuery.isFunction( qualifier )) {
3 return jQuery.grep(elements, function(elem, i) {
4 return !!qualifier.call( elem, i ) === keep;
6 } else if( qualifier.nodeType ) {
7 return jQuery.grep(elements, function(elem, i) {
8 return (elem === qualifier) === keep;
10 } else if( typeof qualifier === "string" ) {
11 var filtered = jQuery.grep(elements, function(elem) { return elem.nodeType === 1 });
13 if(isSimple.test( qualifier )) return jQuery.multiFilter(qualifier, filtered, !keep);
14 else qualifier = jQuery.multiFilter( qualifier, elements );
17 return jQuery.grep(elements, function(elem, i) {
18 return (jQuery.inArray( elem, qualifier ) >= 0) === keep;
23 find: function( selector ) {
24 var ret = this.pushStack( "", "find", selector ), length = 0;
26 for ( var i = 0, l = this.length; i < l; i++ ) {
28 jQuery.find( selector, this[i], ret );
31 // Make sure that the results are unique
32 for ( var n = length; n < ret.length; n++ ) {
33 for ( var r = 0; r < length; r++ ) {
34 if ( ret[r] === ret[n] ) {
46 not: function( selector ) {
47 return this.pushStack( jQuery.winnow(this, selector, false), "not", selector);
50 filter: function( selector ) {
51 return this.pushStack( jQuery.winnow(this, selector, true), "filter", selector );
54 closest: function( selector, context ) {
55 var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
58 return this.map(function(){
60 while ( cur && cur.ownerDocument && cur !== context ) {
61 if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
62 jQuery.data(cur, "closest", closer);
71 add: function( selector ) {
72 return this.pushStack( jQuery.unique( jQuery.merge(
74 typeof selector === "string" ?
76 jQuery.makeArray( selector )
81 return this.slice( i, +i + 1 );
85 return this.pushStack( Array.prototype.slice.apply( this, arguments ),
86 "slice", Array.prototype.slice.call(arguments).join(",") );
89 map: function( callback ) {
90 return this.pushStack( jQuery.map(this, function(elem, i){
91 return callback.call( elem, i, elem );
96 return this.add( this.prevObject );
100 return this.prevObject || jQuery(null);
105 parent: function(elem){return elem.parentNode;},
106 parents: function(elem){return jQuery.dir(elem,"parentNode");},
107 next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
108 prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
109 nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
110 prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
111 siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
112 children: function(elem){return jQuery.sibling(elem.firstChild);},
113 contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
114 }, function(name, fn){
115 jQuery.fn[ name ] = function( selector ) {
116 var ret = jQuery.map( this, fn );
118 if ( selector && typeof selector == "string" )
119 ret = jQuery.multiFilter( selector, ret );
121 return this.pushStack( jQuery.unique( ret ), name, selector );