var siblings = function( n, elem ) {
for ( ; n; n = n.nextSibling ) {
if ( n.nodeType === 1 && n !== elem ) {
var rneedsContext = jQuery.expr.match.needsContext;
function nodeName( elem, name ) {
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
var rsingleTag = ( /^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i );
// Implement the identical functionality for filter and not
function winnow( elements, qualifier, not ) {
if ( isFunction( qualifier ) ) {
return jQuery.grep( elements, function( elem, i ) {
return !!qualifier.call( elem, i, elem ) !== not;
if ( qualifier.nodeType ) {
return jQuery.grep( elements, function( elem ) {
return ( elem === qualifier ) !== not;
// Arraylike of elements (jQuery, arguments, Array)
if ( typeof qualifier !== "string" ) {
return jQuery.grep( elements, function( elem ) {
return ( indexOf.call( qualifier, elem ) > -1 ) !== not;
// Filtered directly for both simple and complex selectors
return jQuery.filter( qualifier, elements, not );
jQuery.filter = function( expr, elems, not ) {
expr = ":not(" + expr + ")";
if ( elems.length === 1 && elem.nodeType === 1 ) {
return jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [];
return jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
return elem.nodeType === 1;
find: function( selector ) {
if ( typeof selector !== "string" ) {
return this.pushStack( jQuery( selector ).filter( function() {
for ( i = 0; i < len; i++ ) {
if ( jQuery.contains( self[ i ], this ) ) {
ret = this.pushStack( [] );
for ( i = 0; i < len; i++ ) {
jQuery.find( selector, self[ i ], ret );
return len > 1 ? jQuery.uniqueSort( ret ) : ret;
filter: function( selector ) {
return this.pushStack( winnow( this, selector || [], false ) );
not: function( selector ) {
return this.pushStack( winnow( this, selector || [], true ) );
is: function( selector ) {
// If this is a positional/relative selector, check membership in the returned set
// so $("p:first").is("p:last") won't return true for a doc with two "p".
typeof selector === "string" && rneedsContext.test( selector ) ?
// Initialize a jQuery object
// A central reference to the root jQuery(document)
// A simple way to check for HTML strings
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
// Strict HTML recognition (#11290: must start with <)
// Shortcut simple #id case for speed
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,
init = jQuery.fn.init = function( selector, context, root ) {
// HANDLE: $(""), $(null), $(undefined), $(false)
// Method init() accepts an alternate rootjQuery
// so migrate can support jQuery.sub (gh-2101)
root = root || rootjQuery;
if ( typeof selector === "string" ) {
if ( selector[ 0 ] === "<" &&
selector[ selector.length - 1 ] === ">" &&
// Assume that strings that start and end with <> are HTML and skip the regex check
match = [ null, selector, null ];
match = rquickExpr.exec( selector );
// Match html or make sure no context is specified for #id
if ( match && ( match[ 1 ] || !context ) ) {
// HANDLE: $(html) -> $(array)
context = context instanceof jQuery ? context[ 0 ] : context;
// Option to run scripts is true for back-compat
// Intentionally let the error be thrown if parseHTML is not present
jQuery.merge( this, jQuery.parseHTML(
context && context.nodeType ? context.ownerDocument || context : document,
// HANDLE: $(html, props)
if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
for ( match in context ) {
// Properties of context are called as methods if possible
if ( isFunction( this[ match ] ) ) {
this[ match ]( context[ match ] );
// ...and otherwise set as attributes
this.attr( match, context[ match ] );
elem = document.getElementById( match[ 2 ] );
// Inject the element directly into the jQuery object
// HANDLE: $(expr, $(...))
} else if ( !context || context.jquery ) {
return ( context || root ).find( selector );
// HANDLE: $(expr, context)
// (which is just equivalent to: $(context).find(expr)
return this.constructor( context ).find( selector );
} else if ( selector.nodeType ) {
// Shortcut for document ready
} else if ( isFunction( selector ) ) {
return root.ready !== undefined ?
// Execute immediately if ready is not present
return jQuery.makeArray( selector, this );
// Give the init function the jQuery prototype for later instantiation
init.prototype = jQuery.fn;
// Initialize central reference
rootjQuery = jQuery( document );
var rparentsprev = /^(?:parents|prev(?:Until|All))/,
// Methods guaranteed to produce a unique set when starting from a unique set
has: function( target ) {
var targets = jQuery( target, this ),
return this.filter( function() {
if ( jQuery.contains( this, targets[ i ] ) ) {
closest: function( selectors, context ) {
targets = typeof selectors !== "string" && jQuery( selectors );
// Positional selectors never match, since there's no _selection_ context
if ( !rneedsContext.test( selectors ) ) {
for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
// Always skip document fragments
if ( cur.nodeType < 11 && ( targets ?
targets.index( cur ) > -1 :
// Don't pass non-elements to Sizzle
jQuery.find.matchesSelector( cur, selectors ) ) ) {
return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
// Determine the position of an element within the set
index: function( elem ) {
// No argument, return index in parent
return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
if ( typeof elem === "string" ) {
return indexOf.call( jQuery( elem ), this[ 0 ] );
// Locate the position of the desired element
return indexOf.call( this,
// If it receives a jQuery object, the first element is used
elem.jquery ? elem[ 0 ] : elem
add: function( selector, context ) {
jQuery.merge( this.get(), jQuery( selector, context ) )
addBack: function( selector ) {
return this.add( selector == null ?
this.prevObject : this.prevObject.filter( selector )
function sibling( cur, dir ) {
while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {}
parent: function( elem ) {
var parent = elem.parentNode;
return parent && parent.nodeType !== 11 ? parent : null;
parents: function( elem ) {
return dir( elem, "parentNode" );
parentsUntil: function( elem, _i, until ) {
return dir( elem, "parentNode", until );
return sibling( elem, "nextSibling" );
return sibling( elem, "previousSibling" );
nextAll: function( elem ) {
return dir( elem, "nextSibling" );
prevAll: function( elem ) {
return dir( elem, "previousSibling" );
nextUntil: function( elem, _i, until ) {
return dir( elem, "nextSibling", until );
prevUntil: function( elem, _i, until ) {
return dir( elem, "previousSibling", until );
siblings: function( elem ) {
return siblings( ( elem.parentNode || {} ).firstChild, elem );
children: function( elem ) {
return siblings( elem.firstChild );
contents: function( elem ) {
if ( elem.contentDocument != null &&
// <object> elements with no `data` attribute has an object
// `contentDocument` with a `null` prototype.
getProto( elem.contentDocument ) ) {
return elem.contentDocument;
// Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only
// Treat the template element as a regular one in browsers that
if ( nodeName( elem, "template" ) ) {
elem = elem.content || elem;
return jQuery.merge( [], elem.childNodes );
}, function( name, fn ) {
jQuery.fn[ name ] = function( until, selector ) {
var matched = jQuery.map( this, fn, until );
if ( name.slice( -5 ) !== "Until" ) {
if ( selector && typeof selector === "string" ) {
matched = jQuery.filter( selector, matched );
if ( !guaranteedUnique[ name ] ) {
jQuery.uniqueSort( matched );
// Reverse order for parents* and prev-derivatives
if ( rparentsprev.test( name ) ) {
return this.pushStack( matched );
var rnothtmlwhite = ( /[^\x20\t\r\n\f]+/g );
// Convert String-formatted options into Object-formatted ones
function createOptions( options ) {
jQuery.each( options.match( rnothtmlwhite ) || [], function( _, flag ) {
* Create a callback list using the following parameters:
* options: an optional list of space-separated options that will change how
* the callback list behaves or a more traditional option object
* By default a callback list will act like an event callback list and can be
* "fired" multiple times.
* once: will ensure the callback list can only be fired once (like a Deferred)
* memory: will keep track of previous values and will call any callback added
* after the list has been fired right away with the latest "memorized"
* values (like a Deferred)
* unique: will ensure a callback can only be added once (no duplicate in the list)
* stopOnFalse: interrupt callings when a callback returns false
jQuery.Callbacks = function( options ) {
// Convert options from String-formatted to Object-formatted if needed
// (we check in cache first)
options = typeof options === "string" ?
createOptions( options ) :
jQuery.extend( {}, options );
var // Flag to know if list is currently firing
// Last fire value for non-forgettable lists
// Flag to know if list was already fired
// Flag to prevent firing
// Queue of execution data for repeatable lists
// Index of currently firing callback (modified by add/remove as needed)
locked = locked || options.once;
// Execute callbacks for all pending executions,
// respecting firingIndex overrides and runtime changes
for ( ; queue.length; firingIndex = -1 ) {
while ( ++firingIndex < list.length ) {
// Run callback and check for early termination
if ( list[ firingIndex ].apply( memory[ 0 ], memory[ 1 ] ) === false &&
// Jump to end and forget the data so .add doesn't re-fire
firingIndex = list.length;