ffffng/app/bower_components/jquery/src/traversing.js

192 lines
4.4 KiB
JavaScript
Raw Normal View History

2017-05-13 13:25:33 +02:00
define( [
2014-05-12 20:08:19 +02:00
"./core",
"./var/indexOf",
2017-05-13 13:25:33 +02:00
"./traversing/var/dir",
"./traversing/var/siblings",
2014-05-12 20:08:19 +02:00
"./traversing/var/rneedsContext",
2017-05-13 13:25:33 +02:00
"./core/nodeName",
2014-05-12 20:08:19 +02:00
"./core/init",
"./traversing/findFilter",
"./selector"
2017-05-13 13:25:33 +02:00
], function( jQuery, indexOf, dir, siblings, rneedsContext, nodeName ) {
"use strict";
2014-05-12 20:08:19 +02:00
var rparentsprev = /^(?:parents|prev(?:Until|All))/,
2017-05-13 13:25:33 +02:00
2016-05-16 13:33:49 +02:00
// Methods guaranteed to produce a unique set when starting from a unique set
2014-05-12 20:08:19 +02:00
guaranteedUnique = {
children: true,
contents: true,
next: true,
prev: true
};
2017-05-13 13:25:33 +02:00
jQuery.fn.extend( {
2014-05-12 20:08:19 +02:00
has: function( target ) {
var targets = jQuery( target, this ),
l = targets.length;
2017-05-13 13:25:33 +02:00
return this.filter( function() {
2014-05-12 20:08:19 +02:00
var i = 0;
for ( ; i < l; i++ ) {
2017-05-13 13:25:33 +02:00
if ( jQuery.contains( this, targets[ i ] ) ) {
2014-05-12 20:08:19 +02:00
return true;
}
}
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
},
closest: function( selectors, context ) {
var cur,
i = 0,
l = this.length,
matched = [],
2017-05-13 13:25:33 +02:00
targets = typeof selectors !== "string" && jQuery( selectors );
// Positional selectors never match, since there's no _selection_ context
if ( !rneedsContext.test( selectors ) ) {
for ( ; i < l; i++ ) {
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
cur.nodeType === 1 &&
jQuery.find.matchesSelector( cur, selectors ) ) ) {
matched.push( cur );
break;
}
2014-05-12 20:08:19 +02:00
}
}
}
2017-05-13 13:25:33 +02:00
return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
2014-05-12 20:08:19 +02:00
},
2016-05-16 13:33:49 +02:00
// Determine the position of an element within the set
2014-05-12 20:08:19 +02:00
index: function( elem ) {
// No argument, return index in parent
if ( !elem ) {
return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
}
2016-05-16 13:33:49 +02:00
// Index in selector
2014-05-12 20:08:19 +02:00
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(
2017-05-13 13:25:33 +02:00
jQuery.uniqueSort(
2014-05-12 20:08:19 +02:00
jQuery.merge( this.get(), jQuery( selector, context ) )
)
);
},
addBack: function( selector ) {
return this.add( selector == null ?
2017-05-13 13:25:33 +02:00
this.prevObject : this.prevObject.filter( selector )
2014-05-12 20:08:19 +02:00
);
}
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
function sibling( cur, dir ) {
2017-05-13 13:25:33 +02:00
while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {}
2014-05-12 20:08:19 +02:00
return cur;
}
2017-05-13 13:25:33 +02:00
jQuery.each( {
2014-05-12 20:08:19 +02:00
parent: function( elem ) {
var parent = elem.parentNode;
return parent && parent.nodeType !== 11 ? parent : null;
},
parents: function( elem ) {
2017-05-13 13:25:33 +02:00
return dir( elem, "parentNode" );
2014-05-12 20:08:19 +02:00
},
parentsUntil: function( elem, i, until ) {
2017-05-13 13:25:33 +02:00
return dir( elem, "parentNode", until );
2014-05-12 20:08:19 +02:00
},
next: function( elem ) {
return sibling( elem, "nextSibling" );
},
prev: function( elem ) {
return sibling( elem, "previousSibling" );
},
nextAll: function( elem ) {
2017-05-13 13:25:33 +02:00
return dir( elem, "nextSibling" );
2014-05-12 20:08:19 +02:00
},
prevAll: function( elem ) {
2017-05-13 13:25:33 +02:00
return dir( elem, "previousSibling" );
2014-05-12 20:08:19 +02:00
},
nextUntil: function( elem, i, until ) {
2017-05-13 13:25:33 +02:00
return dir( elem, "nextSibling", until );
2014-05-12 20:08:19 +02:00
},
prevUntil: function( elem, i, until ) {
2017-05-13 13:25:33 +02:00
return dir( elem, "previousSibling", until );
2014-05-12 20:08:19 +02:00
},
siblings: function( elem ) {
2017-05-13 13:25:33 +02:00
return siblings( ( elem.parentNode || {} ).firstChild, elem );
2014-05-12 20:08:19 +02:00
},
children: function( elem ) {
2017-05-13 13:25:33 +02:00
return siblings( elem.firstChild );
2014-05-12 20:08:19 +02:00
},
contents: function( elem ) {
2020-01-20 20:59:15 +01:00
if ( typeof elem.contentDocument !== "undefined" ) {
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
// don't support it.
if ( nodeName( elem, "template" ) ) {
elem = elem.content || elem;
}
return jQuery.merge( [], elem.childNodes );
2014-05-12 20:08:19 +02:00
}
}, 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 ) {
2017-05-13 13:25:33 +02:00
2014-05-12 20:08:19 +02:00
// Remove duplicates
if ( !guaranteedUnique[ name ] ) {
2017-05-13 13:25:33 +02:00
jQuery.uniqueSort( matched );
2014-05-12 20:08:19 +02:00
}
// Reverse order for parents* and prev-derivatives
if ( rparentsprev.test( name ) ) {
matched.reverse();
}
}
return this.pushStack( matched );
};
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
return jQuery;
2017-05-13 13:25:33 +02:00
} );