jellyfish-web/dashboard-ui/bower_components/jquery/src/traversing.js

176 lines
4 KiB
JavaScript
Raw Normal View History

2016-01-09 13:36:35 -05:00
define( [
2015-06-26 11:53:49 -04:00
"./core",
"./var/indexOf",
2016-01-09 13:36:35 -05:00
"./traversing/var/dir",
"./traversing/var/siblings",
2015-06-26 11:53:49 -04:00
"./traversing/var/rneedsContext",
"./core/init",
"./traversing/findFilter",
"./selector"
2016-01-09 13:36:35 -05:00
], function( jQuery, indexOf, dir, siblings, rneedsContext ) {
2015-06-26 11:53:49 -04:00
var rparentsprev = /^(?:parents|prev(?:Until|All))/,
2016-01-09 13:36:35 -05:00
2015-06-26 11:53:49 -04:00
// Methods guaranteed to produce a unique set when starting from a unique set
guaranteedUnique = {
children: true,
contents: true,
next: true,
prev: true
};
2016-01-09 13:36:35 -05:00
jQuery.fn.extend( {
2015-06-26 11:53:49 -04:00
has: function( target ) {
var targets = jQuery( target, this ),
l = targets.length;
2016-01-09 13:36:35 -05:00
return this.filter( function() {
2015-06-26 11:53:49 -04:00
var i = 0;
for ( ; i < l; i++ ) {
2016-01-09 13:36:35 -05:00
if ( jQuery.contains( this, targets[ i ] ) ) {
2015-06-26 11:53:49 -04:00
return true;
}
}
2016-01-09 13:36:35 -05:00
} );
2015-06-26 11:53:49 -04:00
},
closest: function( selectors, context ) {
var cur,
i = 0,
l = this.length,
matched = [],
pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
jQuery( selectors, context || this.context ) :
0;
for ( ; i < l; i++ ) {
2016-01-09 13:36:35 -05:00
for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
2015-06-26 11:53:49 -04:00
// Always skip document fragments
2016-01-09 13:36:35 -05:00
if ( cur.nodeType < 11 && ( pos ?
pos.index( cur ) > -1 :
2015-06-26 11:53:49 -04:00
// Don't pass non-elements to Sizzle
cur.nodeType === 1 &&
2016-01-09 13:36:35 -05:00
jQuery.find.matchesSelector( cur, selectors ) ) ) {
2015-06-26 11:53:49 -04:00
matched.push( cur );
break;
}
}
}
2016-01-09 13:36:35 -05:00
return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
2015-06-26 11:53:49 -04:00
},
// Determine the position of an element within the set
index: function( elem ) {
// No argument, return index in parent
if ( !elem ) {
return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
}
// Index in selector
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 ) {
return this.pushStack(
2016-01-09 13:36:35 -05:00
jQuery.uniqueSort(
2015-06-26 11:53:49 -04:00
jQuery.merge( this.get(), jQuery( selector, context ) )
)
);
},
addBack: function( selector ) {
return this.add( selector == null ?
2016-01-09 13:36:35 -05:00
this.prevObject : this.prevObject.filter( selector )
2015-06-26 11:53:49 -04:00
);
}
2016-01-09 13:36:35 -05:00
} );
2015-06-26 11:53:49 -04:00
function sibling( cur, dir ) {
2016-01-09 13:36:35 -05:00
while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {}
2015-06-26 11:53:49 -04:00
return cur;
}
2016-01-09 13:36:35 -05:00
jQuery.each( {
2015-06-26 11:53:49 -04:00
parent: function( elem ) {
var parent = elem.parentNode;
return parent && parent.nodeType !== 11 ? parent : null;
},
parents: function( elem ) {
2016-01-09 13:36:35 -05:00
return dir( elem, "parentNode" );
2015-06-26 11:53:49 -04:00
},
parentsUntil: function( elem, i, until ) {
2016-01-09 13:36:35 -05:00
return dir( elem, "parentNode", until );
2015-06-26 11:53:49 -04:00
},
next: function( elem ) {
return sibling( elem, "nextSibling" );
},
prev: function( elem ) {
return sibling( elem, "previousSibling" );
},
nextAll: function( elem ) {
2016-01-09 13:36:35 -05:00
return dir( elem, "nextSibling" );
2015-06-26 11:53:49 -04:00
},
prevAll: function( elem ) {
2016-01-09 13:36:35 -05:00
return dir( elem, "previousSibling" );
2015-06-26 11:53:49 -04:00
},
nextUntil: function( elem, i, until ) {
2016-01-09 13:36:35 -05:00
return dir( elem, "nextSibling", until );
2015-06-26 11:53:49 -04:00
},
prevUntil: function( elem, i, until ) {
2016-01-09 13:36:35 -05:00
return dir( elem, "previousSibling", until );
2015-06-26 11:53:49 -04:00
},
siblings: function( elem ) {
2016-01-09 13:36:35 -05:00
return siblings( ( elem.parentNode || {} ).firstChild, elem );
2015-06-26 11:53:49 -04:00
},
children: function( elem ) {
2016-01-09 13:36:35 -05:00
return siblings( elem.firstChild );
2015-06-26 11:53:49 -04:00
},
contents: function( elem ) {
return elem.contentDocument || 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" ) {
selector = until;
}
if ( selector && typeof selector === "string" ) {
matched = jQuery.filter( selector, matched );
}
if ( this.length > 1 ) {
2016-01-09 13:36:35 -05:00
2015-06-26 11:53:49 -04:00
// Remove duplicates
if ( !guaranteedUnique[ name ] ) {
2016-01-09 13:36:35 -05:00
jQuery.uniqueSort( matched );
2015-06-26 11:53:49 -04:00
}
// Reverse order for parents* and prev-derivatives
if ( rparentsprev.test( name ) ) {
matched.reverse();
}
}
return this.pushStack( matched );
};
2016-01-09 13:36:35 -05:00
} );
2015-06-26 11:53:49 -04:00
return jQuery;
2016-01-09 13:36:35 -05:00
} );