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
|
2010-03-23 16:12:16 +00:00
|
|
|
rmultiselector = /,/,
|
|
|
|
isSimple = /^.[^:#\[\.,]*$/,
|
|
|
|
slice = Array.prototype.slice;
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
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-10 17:25:25 +00:00
|
|
|
|
|
|
|
is: function( selector ) {
|
|
|
|
return !!selector && jQuery.filter( selector, this ).length > 0;
|
|
|
|
},
|
2009-03-18 21:15:38 +00:00
|
|
|
|
2009-12-03 00:05:51 +00:00
|
|
|
closest: function( selectors, context ) {
|
|
|
|
if ( jQuery.isArray( selectors ) ) {
|
2010-02-26 14:26:14 +00:00
|
|
|
var ret = [], cur = this[0], match, matches = {}, selector, level = 1;
|
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) ) {
|
2010-02-26 14:26:14 +00:00
|
|
|
ret.push({ selector: selector, elem: cur, level: level });
|
2009-12-03 00:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cur = cur.parentNode;
|
2010-02-26 14:26:14 +00:00
|
|
|
level++;
|
2009-12-03 00:05:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-22 00:58:13 +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-12-10 17:25:25 +00:00
|
|
|
|
|
|
|
// Determine the position of an element within
|
|
|
|
// the matched set of elements
|
|
|
|
index: function( elem ) {
|
|
|
|
if ( !elem || typeof elem === "string" ) {
|
|
|
|
return jQuery.inArray( this[0],
|
|
|
|
// If it receives a string, the selector is used
|
|
|
|
// If it receives nothing, the siblings are used
|
|
|
|
elem ? jQuery( elem ) : this.parent().children() );
|
|
|
|
}
|
|
|
|
// Locate the position of the desired element
|
|
|
|
return jQuery.inArray(
|
|
|
|
// If it receives a jQuery object, the first element is used
|
|
|
|
elem.jquery ? elem[0] : elem, this );
|
|
|
|
},
|
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 );
|
|
|
|
|
2010-01-13 05:12:18 +00:00
|
|
|
return this.pushStack( isDisconnected( set[0] ) || isDisconnected( all[0] ) ?
|
|
|
|
all :
|
|
|
|
jQuery.unique( all ) );
|
2009-03-18 21:15:38 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
andSelf: function() {
|
|
|
|
return this.add( this.prevObject );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-01-13 05:12:18 +00:00
|
|
|
// A painfully simple check to see if an element is disconnected
|
|
|
|
// from a document (should be improved, where feasible).
|
|
|
|
function isDisconnected( node ) {
|
|
|
|
return !node || !node.parentNode || node.parentNode.nodeType === 11;
|
|
|
|
}
|
|
|
|
|
2009-03-18 21:15:38 +00:00
|
|
|
jQuery.each({
|
2009-12-22 00:58:13 +00:00
|
|
|
parent: function( elem ) {
|
|
|
|
var parent = elem.parentNode;
|
|
|
|
return parent && parent.nodeType !== 11 ? parent : null;
|
|
|
|
},
|
|
|
|
parents: function( elem ) {
|
|
|
|
return jQuery.dir( elem, "parentNode" );
|
|
|
|
},
|
|
|
|
parentsUntil: function( elem, i, until ) {
|
|
|
|
return jQuery.dir( elem, "parentNode", until );
|
|
|
|
},
|
|
|
|
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" );
|
|
|
|
},
|
|
|
|
nextUntil: function( elem, i, until ) {
|
|
|
|
return jQuery.dir( elem, "nextSibling", until );
|
|
|
|
},
|
|
|
|
prevUntil: function( elem, i, until ) {
|
|
|
|
return jQuery.dir( elem, "previousSibling", until );
|
|
|
|
},
|
|
|
|
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];
|
2010-01-21 01:10:34 +00:00
|
|
|
while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !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
|
|
|
});
|
2010-03-23 16:12:16 +00:00
|
|
|
|
|
|
|
// Implement the identical functionality for filter and not
|
|
|
|
function winnow( elements, qualifier, keep ) {
|
|
|
|
if ( jQuery.isFunction( qualifier ) ) {
|
|
|
|
return jQuery.grep(elements, function( elem, i ) {
|
|
|
|
var retVal = !!qualifier.call( elem, i, elem );
|
|
|
|
return retVal === 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.filter(qualifier, filtered, !keep);
|
|
|
|
} else {
|
|
|
|
qualifier = jQuery.filter( qualifier, filtered );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return jQuery.grep(elements, function( elem, i ) {
|
|
|
|
return (jQuery.inArray( elem, qualifier ) >= 0) === keep;
|
|
|
|
});
|
2010-03-31 18:36:24 +00:00
|
|
|
}
|