2009-07-16 07:32:11 +00:00
|
|
|
jQuery.winnow = function( elements, qualifier, keep ) {
|
|
|
|
if(jQuery.isFunction( qualifier )) {
|
|
|
|
return jQuery.grep(elements, function(elem, i) {
|
|
|
|
return !!qualifier.call( elem, i ) === keep;
|
|
|
|
});
|
|
|
|
} else if( qualifier.nodeType ) {
|
|
|
|
return jQuery.grep(elements, function(elem, i) {
|
|
|
|
return (elem === qualifier) === keep;
|
|
|
|
})
|
|
|
|
} else if( typeof qualifier === "string" ) {
|
|
|
|
var filtered = jQuery.grep(elements, function(elem) { return elem.nodeType === 1 });
|
|
|
|
|
|
|
|
if(isSimple.test( qualifier )) return jQuery.multiFilter(qualifier, filtered, !keep);
|
|
|
|
else qualifier = jQuery.multiFilter( qualifier, elements );
|
|
|
|
}
|
|
|
|
|
|
|
|
return jQuery.grep(elements, function(elem, i) {
|
|
|
|
return (jQuery.inArray( elem, qualifier ) >= 0) === keep;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-03-18 21:15:38 +00:00
|
|
|
jQuery.fn.extend({
|
|
|
|
find: function( selector ) {
|
|
|
|
var ret = this.pushStack( "", "find", selector ), length = 0;
|
|
|
|
|
|
|
|
for ( var i = 0, l = this.length; i < l; i++ ) {
|
|
|
|
length = ret.length;
|
|
|
|
jQuery.find( selector, this[i], ret );
|
|
|
|
|
|
|
|
if ( i > 0 ) {
|
|
|
|
// Make sure that the results are unique
|
|
|
|
for ( var n = length; n < ret.length; n++ ) {
|
|
|
|
for ( var r = 0; r < length; r++ ) {
|
|
|
|
if ( ret[r] === ret[n] ) {
|
|
|
|
ret.splice(n--, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
2009-07-16 07:32:11 +00:00
|
|
|
not: function( selector ) {
|
|
|
|
return this.pushStack( jQuery.winnow(this, selector, false), "not", selector);
|
|
|
|
},
|
|
|
|
|
2009-03-18 21:15:38 +00:00
|
|
|
filter: function( selector ) {
|
2009-07-16 07:32:11 +00:00
|
|
|
return this.pushStack( jQuery.winnow(this, selector, true), "filter", selector );
|
2009-03-18 21:15:38 +00:00
|
|
|
},
|
|
|
|
|
2009-07-28 12:28:59 +00:00
|
|
|
closest: function( selector, context ) {
|
2009-03-18 21:15:38 +00:00
|
|
|
var pos = jQuery.expr.match.POS.test( selector ) ? jQuery(selector) : null,
|
2009-07-28 12:22:10 +00:00
|
|
|
closer = 0;
|
2009-03-18 21:15:38 +00:00
|
|
|
|
|
|
|
return this.map(function(){
|
|
|
|
var cur = this;
|
2009-07-28 12:28:59 +00:00
|
|
|
while ( cur && cur.ownerDocument && cur !== context ) {
|
2009-03-18 21:15:38 +00:00
|
|
|
if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selector) ) {
|
|
|
|
jQuery.data(cur, "closest", closer);
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
cur = cur.parentNode;
|
|
|
|
closer++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
add: function( selector ) {
|
|
|
|
return this.pushStack( jQuery.unique( jQuery.merge(
|
|
|
|
this.get(),
|
|
|
|
typeof selector === "string" ?
|
|
|
|
jQuery( selector ) :
|
|
|
|
jQuery.makeArray( selector )
|
|
|
|
)));
|
|
|
|
},
|
|
|
|
|
|
|
|
eq: function( i ) {
|
|
|
|
return this.slice( i, +i + 1 );
|
|
|
|
},
|
|
|
|
|
|
|
|
slice: function() {
|
|
|
|
return this.pushStack( Array.prototype.slice.apply( this, arguments ),
|
|
|
|
"slice", Array.prototype.slice.call(arguments).join(",") );
|
|
|
|
},
|
|
|
|
|
|
|
|
map: function( callback ) {
|
|
|
|
return this.pushStack( jQuery.map(this, function(elem, i){
|
|
|
|
return callback.call( elem, i, elem );
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
|
|
|
andSelf: function() {
|
|
|
|
return this.add( this.prevObject );
|
|
|
|
},
|
|
|
|
|
|
|
|
end: function() {
|
|
|
|
return this.prevObject || jQuery(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.each({
|
|
|
|
parent: function(elem){return elem.parentNode;},
|
|
|
|
parents: function(elem){return jQuery.dir(elem,"parentNode");},
|
|
|
|
next: function(elem){return jQuery.nth(elem,2,"nextSibling");},
|
|
|
|
prev: function(elem){return jQuery.nth(elem,2,"previousSibling");},
|
|
|
|
nextAll: function(elem){return jQuery.dir(elem,"nextSibling");},
|
|
|
|
prevAll: function(elem){return jQuery.dir(elem,"previousSibling");},
|
|
|
|
siblings: function(elem){return jQuery.sibling(elem.parentNode.firstChild,elem);},
|
|
|
|
children: function(elem){return jQuery.sibling(elem.firstChild);},
|
|
|
|
contents: function(elem){return jQuery.nodeName(elem,"iframe")?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes);}
|
|
|
|
}, function(name, fn){
|
|
|
|
jQuery.fn[ name ] = function( selector ) {
|
|
|
|
var ret = jQuery.map( this, fn );
|
|
|
|
|
|
|
|
if ( selector && typeof selector == "string" )
|
|
|
|
ret = jQuery.multiFilter( selector, ret );
|
|
|
|
|
|
|
|
return this.pushStack( jQuery.unique( ret ), name, selector );
|
|
|
|
};
|
2009-07-25 21:31:59 +00:00
|
|
|
});
|