2009-12-04 17:28:47 +00:00
|
|
|
var runtil = /Until$/,
|
|
|
|
rparentsprev = /^(?:parents|prevUntil|prevAll)/,
|
|
|
|
// Note: This RegExp should be improved, or likely pulled from Sizzle
|
|
|
|
rmultiselector = /,/,
|
2009-12-04 17:36:24 +00:00
|
|
|
slice = Array.prototype.slice;
|
2009-12-04 17:28:47 +00:00
|
|
|
|
2009-12-03 19:20:06 +00:00
|
|
|
// Implement the identical functionality for filter and not
|
2009-09-15 00:35:35 +00:00
|
|
|
var winnow = function( elements, qualifier, keep ) {
|
2009-12-03 19:20:06 +00:00
|
|
|
if ( jQuery.isFunction( qualifier ) ) {
|
2009-07-16 07:32:11 +00:00
|
|
|
return jQuery.grep(elements, function(elem, i) {
|
|
|
|
return !!qualifier.call( elem, i ) === keep;
|
|
|
|
});
|
2009-12-03 19:20:06 +00:00
|
|
|
|
|
|
|
} else if ( qualifier.nodeType ) {
|
2009-07-16 07:32:11 +00:00
|
|
|
return jQuery.grep(elements, function(elem, i) {
|
|
|
|
return (elem === qualifier) === keep;
|
2009-11-27 19:31:28 +00:00
|
|
|
});
|
2009-07-16 07:32:11 +00:00
|
|
|
|
2009-12-03 19:20:06 +00:00
|
|
|
} else if ( typeof qualifier === "string" ) {
|
|
|
|
var filtered = jQuery.grep(elements, function(elem) {
|
|
|
|
return elem.nodeType === 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
if ( isSimple.test( qualifier ) ) {
|
2009-11-27 19:28:42 +00:00
|
|
|
return jQuery.filter(qualifier, filtered, !keep);
|
|
|
|
} else {
|
|
|
|
qualifier = jQuery.filter( qualifier, elements );
|
|
|
|
}
|
2009-07-16 07:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return jQuery.grep(elements, function(elem, i) {
|
|
|
|
return (jQuery.inArray( elem, qualifier ) >= 0) === keep;
|
|
|
|
});
|
2009-11-27 19:31:28 +00:00
|
|
|
};
|
2009-07-16 07:32:11 +00:00
|
|
|
|
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-12-09 20:43:13 +00:00
|
|
|
has: function( target ) {
|
|
|
|
var targets = jQuery( target );
|
|
|
|
return this.filter(function() {
|
|
|
|
for ( var i = 0, l = targets.length; i < l; i++ ) {
|
|
|
|
if ( jQuery.contains( this, targets[i] ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
contains: function( target ) {
|
|
|
|
return this.has( target ).length > 0;
|
|
|
|
},
|
|
|
|
|
2009-07-16 07:32:11 +00:00
|
|
|
not: function( selector ) {
|
2009-09-15 00:35:35 +00:00
|
|
|
return this.pushStack( winnow(this, selector, false), "not", selector);
|
2009-07-16 07:32:11 +00:00
|
|
|
},
|
|
|
|
|
2009-03-18 21:15:38 +00:00
|
|
|
filter: function( selector ) {
|
2009-09-15 00:35:35 +00:00
|
|
|
return this.pushStack( winnow(this, selector, true), "filter", selector );
|
2009-03-18 21:15:38 +00:00
|
|
|
},
|
|
|
|
|
2009-12-03 00:05:51 +00:00
|
|
|
closest: function( selectors, context ) {
|
|
|
|
if ( jQuery.isArray( selectors ) ) {
|
2009-12-03 16:14:10 +00:00
|
|
|
var ret = [], cur = this[0], match, matches = {}, selector;
|
2009-12-03 00:05:51 +00:00
|
|
|
|
2009-12-03 15:51:04 +00:00
|
|
|
if ( cur && selectors.length ) {
|
2009-12-03 00:05:51 +00:00
|
|
|
for ( var i = 0, l = selectors.length; i < l; i++ ) {
|
2009-12-03 16:14:10 +00:00
|
|
|
selector = selectors[i];
|
|
|
|
|
|
|
|
if ( !matches[selector] ) {
|
|
|
|
matches[selector] = jQuery.expr.match.POS.test( selector ) ?
|
|
|
|
jQuery( selector, context || this.context ) :
|
|
|
|
selector;
|
|
|
|
}
|
2009-12-03 00:05:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while ( cur && cur.ownerDocument && cur !== context ) {
|
2009-12-03 16:14:10 +00:00
|
|
|
for ( selector in matches ) {
|
|
|
|
match = matches[selector];
|
2009-12-03 16:05:12 +00:00
|
|
|
|
2009-12-03 16:14:10 +00:00
|
|
|
if ( match.jquery ? match.index(cur) > -1 : jQuery(cur).is(match) ) {
|
2009-12-03 00:05:51 +00:00
|
|
|
ret.push({ selector: selector, elem: cur });
|
2009-12-03 16:14:10 +00:00
|
|
|
delete matches[selector];
|
2009-12-03 00:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cur = cur.parentNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
var pos = jQuery.expr.match.POS.test( selectors ) ?
|
|
|
|
jQuery( selectors, context || this.context ) : null;
|
2009-03-18 21:15:38 +00:00
|
|
|
|
2009-12-03 00:05:51 +00:00
|
|
|
return this.map(function(i, cur){
|
2009-07-28 12:28:59 +00:00
|
|
|
while ( cur && cur.ownerDocument && cur !== context ) {
|
2009-12-03 00:05:51 +00:00
|
|
|
if ( pos ? pos.index(cur) > -1 : jQuery(cur).is(selectors) ) {
|
2009-03-18 21:15:38 +00:00
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
cur = cur.parentNode;
|
|
|
|
}
|
2009-11-07 16:40:47 +00:00
|
|
|
return null;
|
2009-03-18 21:15:38 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-11-07 15:43:31 +00:00
|
|
|
add: function( selector, context ) {
|
A follow-up to [6578] (which stopped adding expandos to elements that didn't have data). That broke jQuery.unique() (so we're now using the unique from Sizzle). Using Sizzle's unique (which also sorts in document order) changed how add, andSelf, parents, nextAll, prevAll, and siblings work. after and before were changed to not use .add() (in order to guarantee their position in the jQuery set). Also, jQuery.data(elem) was updated to return that element's data object (instead of its ID).
$("<div/>").after("<span/>")
=> [ div, span ]
(calling after on a disconnected DOM node adds the nodes to the end of the jQuery set)
$("<div/>").before("<span/>")
=> [ span, div ]
(calling before on a disconnected DOM node adds the nodes to the beginning of the jQuery set)
$("div").add("span")
=> [ div, span, span, div, span ]
(results now come out in document order)
$("div").find("code").andSelf();
=> [ div, code, code ]
(results now come out in document order)
Same goes for .parents(), .nextAll(), .prevAll(), and .siblings().
Exception: .parents() will still return the results in reverse document order.
jQuery.data(elem)
=> { object of data }
(no longer returns the unique ID assigned to the node)
2009-09-25 17:55:20 +00:00
|
|
|
var set = typeof selector === "string" ?
|
2009-11-07 15:43:31 +00:00
|
|
|
jQuery( selector, context || this.context ) :
|
A follow-up to [6578] (which stopped adding expandos to elements that didn't have data). That broke jQuery.unique() (so we're now using the unique from Sizzle). Using Sizzle's unique (which also sorts in document order) changed how add, andSelf, parents, nextAll, prevAll, and siblings work. after and before were changed to not use .add() (in order to guarantee their position in the jQuery set). Also, jQuery.data(elem) was updated to return that element's data object (instead of its ID).
$("<div/>").after("<span/>")
=> [ div, span ]
(calling after on a disconnected DOM node adds the nodes to the end of the jQuery set)
$("<div/>").before("<span/>")
=> [ span, div ]
(calling before on a disconnected DOM node adds the nodes to the beginning of the jQuery set)
$("div").add("span")
=> [ div, span, span, div, span ]
(results now come out in document order)
$("div").find("code").andSelf();
=> [ div, code, code ]
(results now come out in document order)
Same goes for .parents(), .nextAll(), .prevAll(), and .siblings().
Exception: .parents() will still return the results in reverse document order.
jQuery.data(elem)
=> { object of data }
(no longer returns the unique ID assigned to the node)
2009-09-25 17:55:20 +00:00
|
|
|
jQuery.makeArray( selector ),
|
|
|
|
all = jQuery.merge( this.get(), set );
|
|
|
|
|
|
|
|
return this.pushStack( set[0] && (set[0].setInterval || set[0].nodeType === 9 || (set[0].parentNode && set[0].parentNode.nodeType !== 11)) ?
|
|
|
|
jQuery.unique( all ) :
|
|
|
|
all );
|
2009-03-18 21:15:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
eq: function( i ) {
|
2009-09-09 00:21:21 +00:00
|
|
|
return i === -1 ?
|
|
|
|
this.slice( i ) :
|
|
|
|
this.slice( i, +i + 1 );
|
|
|
|
},
|
|
|
|
|
|
|
|
first: function() {
|
|
|
|
return this.eq( 0 );
|
|
|
|
},
|
|
|
|
|
|
|
|
last: function() {
|
|
|
|
return this.eq( -1 );
|
2009-03-18 21:15:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
slice: function() {
|
2009-12-04 17:28:47 +00:00
|
|
|
return this.pushStack( slice.apply( this, arguments ),
|
2009-12-04 17:36:24 +00:00
|
|
|
"slice", slice.call(arguments).join(",") );
|
2009-03-18 21:15:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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");},
|
2009-12-04 17:28:47 +00:00
|
|
|
parentsUntil: function(elem,i,until){return jQuery.dir(elem,"parentNode",until);},
|
2009-03-18 21:15:38 +00:00
|
|
|
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");},
|
2009-12-04 17:28:47 +00:00
|
|
|
nextUntil: function(elem,i,until){return jQuery.dir(elem,"nextSibling",until);},
|
|
|
|
prevUntil: function(elem,i,until){return jQuery.dir(elem,"previousSibling",until);},
|
2009-03-18 21:15:38 +00:00
|
|
|
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){
|
2009-12-04 17:28:47 +00:00
|
|
|
jQuery.fn[ name ] = function( until, selector ) {
|
|
|
|
var ret = jQuery.map( this, fn, until );
|
|
|
|
|
|
|
|
if ( !runtil.test( name ) ) {
|
|
|
|
selector = until;
|
|
|
|
}
|
2009-03-18 21:15:38 +00:00
|
|
|
|
A follow-up to [6578] (which stopped adding expandos to elements that didn't have data). That broke jQuery.unique() (so we're now using the unique from Sizzle). Using Sizzle's unique (which also sorts in document order) changed how add, andSelf, parents, nextAll, prevAll, and siblings work. after and before were changed to not use .add() (in order to guarantee their position in the jQuery set). Also, jQuery.data(elem) was updated to return that element's data object (instead of its ID).
$("<div/>").after("<span/>")
=> [ div, span ]
(calling after on a disconnected DOM node adds the nodes to the end of the jQuery set)
$("<div/>").before("<span/>")
=> [ span, div ]
(calling before on a disconnected DOM node adds the nodes to the beginning of the jQuery set)
$("div").add("span")
=> [ div, span, span, div, span ]
(results now come out in document order)
$("div").find("code").andSelf();
=> [ div, code, code ]
(results now come out in document order)
Same goes for .parents(), .nextAll(), .prevAll(), and .siblings().
Exception: .parents() will still return the results in reverse document order.
jQuery.data(elem)
=> { object of data }
(no longer returns the unique ID assigned to the node)
2009-09-25 17:55:20 +00:00
|
|
|
if ( selector && typeof selector === "string" ) {
|
2009-10-26 22:07:57 +00:00
|
|
|
ret = jQuery.filter( selector, ret );
|
A follow-up to [6578] (which stopped adding expandos to elements that didn't have data). That broke jQuery.unique() (so we're now using the unique from Sizzle). Using Sizzle's unique (which also sorts in document order) changed how add, andSelf, parents, nextAll, prevAll, and siblings work. after and before were changed to not use .add() (in order to guarantee their position in the jQuery set). Also, jQuery.data(elem) was updated to return that element's data object (instead of its ID).
$("<div/>").after("<span/>")
=> [ div, span ]
(calling after on a disconnected DOM node adds the nodes to the end of the jQuery set)
$("<div/>").before("<span/>")
=> [ span, div ]
(calling before on a disconnected DOM node adds the nodes to the beginning of the jQuery set)
$("div").add("span")
=> [ div, span, span, div, span ]
(results now come out in document order)
$("div").find("code").andSelf();
=> [ div, code, code ]
(results now come out in document order)
Same goes for .parents(), .nextAll(), .prevAll(), and .siblings().
Exception: .parents() will still return the results in reverse document order.
jQuery.data(elem)
=> { object of data }
(no longer returns the unique ID assigned to the node)
2009-09-25 17:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = this.length > 1 ? jQuery.unique( ret ) : ret;
|
|
|
|
|
2009-12-04 17:28:47 +00:00
|
|
|
if ( (this.length > 1 || rmultiselector.test( selector )) && rparentsprev.test( name ) ) {
|
A follow-up to [6578] (which stopped adding expandos to elements that didn't have data). That broke jQuery.unique() (so we're now using the unique from Sizzle). Using Sizzle's unique (which also sorts in document order) changed how add, andSelf, parents, nextAll, prevAll, and siblings work. after and before were changed to not use .add() (in order to guarantee their position in the jQuery set). Also, jQuery.data(elem) was updated to return that element's data object (instead of its ID).
$("<div/>").after("<span/>")
=> [ div, span ]
(calling after on a disconnected DOM node adds the nodes to the end of the jQuery set)
$("<div/>").before("<span/>")
=> [ span, div ]
(calling before on a disconnected DOM node adds the nodes to the beginning of the jQuery set)
$("div").add("span")
=> [ div, span, span, div, span ]
(results now come out in document order)
$("div").find("code").andSelf();
=> [ div, code, code ]
(results now come out in document order)
Same goes for .parents(), .nextAll(), .prevAll(), and .siblings().
Exception: .parents() will still return the results in reverse document order.
jQuery.data(elem)
=> { object of data }
(no longer returns the unique ID assigned to the node)
2009-09-25 17:55:20 +00:00
|
|
|
ret = ret.reverse();
|
|
|
|
}
|
2009-03-18 21:15:38 +00:00
|
|
|
|
2009-12-04 17:36:24 +00:00
|
|
|
return this.pushStack( ret, name, slice.call(arguments).join(",") );
|
2009-03-18 21:15:38 +00:00
|
|
|
};
|
2009-07-25 21:31:59 +00:00
|
|
|
});
|
2009-10-26 22:07:57 +00:00
|
|
|
|
|
|
|
jQuery.extend({
|
|
|
|
filter: function( expr, elems, not ) {
|
|
|
|
if ( not ) {
|
|
|
|
expr = ":not(" + expr + ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
return jQuery.find.matches(expr, elems);
|
|
|
|
},
|
|
|
|
|
2009-12-04 17:28:47 +00:00
|
|
|
dir: function( elem, dir, until ) {
|
2009-10-26 22:07:57 +00:00
|
|
|
var matched = [], cur = elem[dir];
|
2009-12-04 17:28:47 +00:00
|
|
|
while ( cur && cur.nodeType !== 9 && (until === undefined || !jQuery( cur ).is( until )) ) {
|
2009-10-26 22:07:57 +00:00
|
|
|
if ( cur.nodeType === 1 ) {
|
|
|
|
matched.push( cur );
|
|
|
|
}
|
|
|
|
cur = cur[dir];
|
|
|
|
}
|
|
|
|
return matched;
|
|
|
|
},
|
|
|
|
|
|
|
|
nth: function( cur, result, dir, elem ) {
|
|
|
|
result = result || 1;
|
|
|
|
var num = 0;
|
|
|
|
|
|
|
|
for ( ; cur; cur = cur[dir] ) {
|
|
|
|
if ( cur.nodeType === 1 && ++num === result ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cur;
|
|
|
|
},
|
|
|
|
|
|
|
|
sibling: function( n, elem ) {
|
|
|
|
var r = [];
|
|
|
|
|
|
|
|
for ( ; n; n = n.nextSibling ) {
|
|
|
|
if ( n.nodeType === 1 && n !== elem ) {
|
|
|
|
r.push( n );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2009-11-07 15:43:31 +00:00
|
|
|
});
|