2013-08-15 18:15:49 +00:00
|
|
|
define([
|
|
|
|
"./core",
|
|
|
|
"./var/indexOf",
|
2013-09-10 00:13:01 +00:00
|
|
|
"./traversing/var/rneedsContext",
|
|
|
|
"./core/init",
|
|
|
|
"./traversing/findFilter",
|
2013-08-15 18:15:49 +00:00
|
|
|
"./selector"
|
2013-09-10 00:13:01 +00:00
|
|
|
], function( jQuery, indexOf, rneedsContext ) {
|
2013-09-09 15:26:21 +00:00
|
|
|
|
2013-09-10 00:13:01 +00:00
|
|
|
var rparentsprev = /^(?:parents|prev(?:Until|All))/,
|
2011-01-14 14:55:40 +00:00
|
|
|
// methods guaranteed to produce a unique set when starting from a unique set
|
|
|
|
guaranteedUnique = {
|
|
|
|
children: true,
|
|
|
|
contents: true,
|
|
|
|
next: true,
|
|
|
|
prev: true
|
|
|
|
};
|
2010-10-10 04:33:02 +00:00
|
|
|
|
2013-09-09 16:13:41 +00:00
|
|
|
jQuery.extend({
|
|
|
|
dir: function( elem, dir, until ) {
|
|
|
|
var matched = [],
|
|
|
|
truncate = until !== undefined;
|
|
|
|
|
|
|
|
while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
|
|
|
|
if ( elem.nodeType === 1 ) {
|
|
|
|
if ( truncate && jQuery( elem ).is( until ) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
matched.push( elem );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matched;
|
|
|
|
},
|
|
|
|
|
|
|
|
sibling: function( n, elem ) {
|
|
|
|
var matched = [];
|
|
|
|
|
|
|
|
for ( ; n; n = n.nextSibling ) {
|
|
|
|
if ( n.nodeType === 1 && n !== elem ) {
|
|
|
|
matched.push( n );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return matched;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2009-03-18 21:15:38 +00:00
|
|
|
jQuery.fn.extend({
|
2009-12-09 20:43:13 +00:00
|
|
|
has: function( target ) {
|
2012-12-18 11:29:04 +00:00
|
|
|
var targets = jQuery( target, this ),
|
|
|
|
l = targets.length;
|
2012-07-10 01:38:11 +00:00
|
|
|
|
2009-12-09 20:43:13 +00:00
|
|
|
return this.filter(function() {
|
2012-12-18 11:29:04 +00:00
|
|
|
var i = 0;
|
|
|
|
for ( ; i < l; i++ ) {
|
2009-12-09 20:43:13 +00:00
|
|
|
if ( jQuery.contains( this, targets[i] ) ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-12-03 00:05:51 +00:00
|
|
|
closest: function( selectors, context ) {
|
2012-12-19 15:38:33 +00:00
|
|
|
var cur,
|
|
|
|
i = 0,
|
2012-07-10 01:38:11 +00:00
|
|
|
l = this.length,
|
2012-12-18 11:29:04 +00:00
|
|
|
matched = [],
|
|
|
|
pos = ( rneedsContext.test( selectors ) || typeof selectors !== "string" ) ?
|
2011-03-22 00:59:20 +00:00
|
|
|
jQuery( selectors, context || this.context ) :
|
|
|
|
0;
|
2010-09-28 00:59:42 +00:00
|
|
|
|
2012-07-10 01:38:11 +00:00
|
|
|
for ( ; i < l; i++ ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
|
|
|
|
// Always skip document fragments
|
|
|
|
if ( cur.nodeType < 11 && (pos ?
|
|
|
|
pos.index(cur) > -1 :
|
2010-10-10 04:33:02 +00:00
|
|
|
|
2013-01-27 18:24:50 +00:00
|
|
|
// Don't pass non-elements to Sizzle
|
|
|
|
cur.nodeType === 1 &&
|
|
|
|
jQuery.find.matchesSelector(cur, selectors)) ) {
|
|
|
|
|
|
|
|
cur = matched.push( cur );
|
2010-10-10 17:37:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-28 00:59:42 +00:00
|
|
|
|
2012-12-18 11:29:04 +00:00
|
|
|
return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
|
2009-03-18 21:15:38 +00:00
|
|
|
},
|
2010-12-30 06:34:48 +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 ) {
|
2011-06-15 04:38:36 +00:00
|
|
|
|
|
|
|
// No argument, return index in parent
|
|
|
|
if ( !elem ) {
|
2012-12-18 11:29:04 +00:00
|
|
|
return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
|
2011-06-15 04:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// index in selector
|
|
|
|
if ( typeof elem === "string" ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
return indexOf.call( jQuery( elem ), this[ 0 ] );
|
2009-12-10 17:25:25 +00:00
|
|
|
}
|
2011-06-15 04:38:36 +00:00
|
|
|
|
2009-12-10 17:25:25 +00:00
|
|
|
// Locate the position of the desired element
|
2013-08-15 18:15:49 +00:00
|
|
|
return indexOf.call( this,
|
2012-12-18 11:29:04 +00:00
|
|
|
|
2009-12-10 17:25:25 +00:00
|
|
|
// If it receives a jQuery object, the first element is used
|
2012-12-18 11:29:04 +00:00
|
|
|
elem.jquery ? elem[ 0 ] : elem
|
|
|
|
);
|
2009-12-10 17:25:25 +00:00
|
|
|
},
|
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" ?
|
2010-12-29 02:07:04 +00:00
|
|
|
jQuery( selector, context ) :
|
2011-04-17 17:51:24 +00:00
|
|
|
jQuery.makeArray( selector && selector.nodeType ? [ selector ] : selector ),
|
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
|
|
|
all = jQuery.merge( this.get(), set );
|
|
|
|
|
2012-10-16 15:52:48 +00:00
|
|
|
return this.pushStack( jQuery.unique(all) );
|
2009-03-18 21:15:38 +00:00
|
|
|
},
|
|
|
|
|
2012-05-29 16:04:27 +00:00
|
|
|
addBack: function( selector ) {
|
2012-05-31 22:15:57 +00:00
|
|
|
return this.add( selector == null ?
|
2012-06-03 14:42:24 +00:00
|
|
|
this.prevObject : this.prevObject.filter(selector)
|
|
|
|
);
|
2009-03-18 21:15:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-01-27 18:24:50 +00:00
|
|
|
function sibling( cur, dir ) {
|
|
|
|
while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
2009-03-18 21:15:38 +00:00
|
|
|
jQuery.each({
|
2009-12-22 00:58:13 +00:00
|
|
|
parent: function( elem ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
var parent = elem.parentNode;
|
|
|
|
return parent && parent.nodeType !== 11 ? parent : null;
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
parents: function( elem ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
return jQuery.dir( elem, "parentNode" );
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
parentsUntil: function( elem, i, until ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
return jQuery.dir( elem, "parentNode", until );
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
next: function( elem ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
return sibling( elem, "nextSibling" );
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
prev: function( elem ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
return sibling( elem, "previousSibling" );
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
nextAll: function( elem ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
return jQuery.dir( elem, "nextSibling" );
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
prevAll: function( elem ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
return jQuery.dir( elem, "previousSibling" );
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
nextUntil: function( elem, i, until ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
return jQuery.dir( elem, "nextSibling", until );
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
prevUntil: function( elem, i, until ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
return jQuery.dir( elem, "previousSibling", until );
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
siblings: function( elem ) {
|
2012-02-22 05:21:18 +00:00
|
|
|
return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
children: function( elem ) {
|
2013-01-27 18:24:50 +00:00
|
|
|
return jQuery.sibling( elem.firstChild );
|
2009-12-22 00:58:13 +00:00
|
|
|
},
|
|
|
|
contents: function( elem ) {
|
2013-05-26 11:20:47 +00:00
|
|
|
return elem.contentDocument || jQuery.merge( [], elem.childNodes );
|
2009-12-22 00:58:13 +00:00
|
|
|
}
|
|
|
|
}, function( name, fn ) {
|
2009-12-04 17:28:47 +00:00
|
|
|
jQuery.fn[ name ] = function( until, selector ) {
|
2012-12-18 11:29:04 +00:00
|
|
|
var matched = jQuery.map( this, fn, until );
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2013-03-27 01:20:27 +00:00
|
|
|
if ( name.slice( -5 ) !== "Until" ) {
|
2009-12-04 17:28:47 +00:00
|
|
|
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" ) {
|
2012-12-18 11:29:04 +00:00
|
|
|
matched = jQuery.filter( selector, matched );
|
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
|
|
|
}
|
|
|
|
|
2012-12-18 11:29:04 +00:00
|
|
|
if ( this.length > 1 ) {
|
2013-03-27 01:20:27 +00:00
|
|
|
// Remove duplicates
|
2012-12-18 11:29:04 +00:00
|
|
|
if ( !guaranteedUnique[ name ] ) {
|
|
|
|
jQuery.unique( matched );
|
|
|
|
}
|
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
|
|
|
|
2013-05-01 15:33:06 +00:00
|
|
|
// Reverse order for parents* and prev-derivatives
|
|
|
|
if ( rparentsprev.test( name ) ) {
|
2012-12-18 11:29:04 +00:00
|
|
|
matched.reverse();
|
|
|
|
}
|
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
|
|
|
}
|
2009-03-18 21:15:38 +00:00
|
|
|
|
2012-12-18 11:29:04 +00:00
|
|
|
return this.pushStack( matched );
|
2009-03-18 21:15:38 +00:00
|
|
|
};
|
2009-07-25 21:31:59 +00:00
|
|
|
});
|
2009-10-26 22:07:57 +00:00
|
|
|
|
2013-09-09 01:25:27 +00:00
|
|
|
return jQuery;
|
2013-08-15 18:15:49 +00:00
|
|
|
});
|