nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jquery / src / traversing.js
1 define( [
2         "./core",
3         "./var/indexOf",
4         "./traversing/var/dir",
5         "./traversing/var/siblings",
6         "./traversing/var/rneedsContext",
7         "./core/init",
8         "./traversing/findFilter",
9         "./selector"
10 ], function( jQuery, indexOf, dir, siblings, rneedsContext ) {
11
12 var rparentsprev = /^(?:parents|prev(?:Until|All))/,
13
14         // Methods guaranteed to produce a unique set when starting from a unique set
15         guaranteedUnique = {
16                 children: true,
17                 contents: true,
18                 next: true,
19                 prev: true
20         };
21
22 jQuery.fn.extend( {
23         has: function( target ) {
24                 var targets = jQuery( target, this ),
25                         l = targets.length;
26
27                 return this.filter( function() {
28                         var i = 0;
29                         for ( ; i < l; i++ ) {
30                                 if ( jQuery.contains( this, targets[ i ] ) ) {
31                                         return true;
32                                 }
33                         }
34                 } );
35         },
36
37         closest: function( selectors, context ) {
38                 var cur,
39                         i = 0,
40                         l = this.length,
41                         matched = [],
42                         pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
43                                 jQuery( selectors, context || this.context ) :
44                                 0;
45
46                 for ( ; i < l; i++ ) {
47                         for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
48
49                                 // Always skip document fragments
50                                 if ( cur.nodeType < 11 && ( pos ?
51                                         pos.index( cur ) > -1 :
52
53                                         // Don't pass non-elements to Sizzle
54                                         cur.nodeType === 1 &&
55                                                 jQuery.find.matchesSelector( cur, selectors ) ) ) {
56
57                                         matched.push( cur );
58                                         break;
59                                 }
60                         }
61                 }
62
63                 return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
64         },
65
66         // Determine the position of an element within the set
67         index: function( elem ) {
68
69                 // No argument, return index in parent
70                 if ( !elem ) {
71                         return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
72                 }
73
74                 // Index in selector
75                 if ( typeof elem === "string" ) {
76                         return indexOf.call( jQuery( elem ), this[ 0 ] );
77                 }
78
79                 // Locate the position of the desired element
80                 return indexOf.call( this,
81
82                         // If it receives a jQuery object, the first element is used
83                         elem.jquery ? elem[ 0 ] : elem
84                 );
85         },
86
87         add: function( selector, context ) {
88                 return this.pushStack(
89                         jQuery.uniqueSort(
90                                 jQuery.merge( this.get(), jQuery( selector, context ) )
91                         )
92                 );
93         },
94
95         addBack: function( selector ) {
96                 return this.add( selector == null ?
97                         this.prevObject : this.prevObject.filter( selector )
98                 );
99         }
100 } );
101
102 function sibling( cur, dir ) {
103         while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {}
104         return cur;
105 }
106
107 jQuery.each( {
108         parent: function( elem ) {
109                 var parent = elem.parentNode;
110                 return parent && parent.nodeType !== 11 ? parent : null;
111         },
112         parents: function( elem ) {
113                 return dir( elem, "parentNode" );
114         },
115         parentsUntil: function( elem, i, until ) {
116                 return dir( elem, "parentNode", until );
117         },
118         next: function( elem ) {
119                 return sibling( elem, "nextSibling" );
120         },
121         prev: function( elem ) {
122                 return sibling( elem, "previousSibling" );
123         },
124         nextAll: function( elem ) {
125                 return dir( elem, "nextSibling" );
126         },
127         prevAll: function( elem ) {
128                 return dir( elem, "previousSibling" );
129         },
130         nextUntil: function( elem, i, until ) {
131                 return dir( elem, "nextSibling", until );
132         },
133         prevUntil: function( elem, i, until ) {
134                 return dir( elem, "previousSibling", until );
135         },
136         siblings: function( elem ) {
137                 return siblings( ( elem.parentNode || {} ).firstChild, elem );
138         },
139         children: function( elem ) {
140                 return siblings( elem.firstChild );
141         },
142         contents: function( elem ) {
143                 return elem.contentDocument || jQuery.merge( [], elem.childNodes );
144         }
145 }, function( name, fn ) {
146         jQuery.fn[ name ] = function( until, selector ) {
147                 var matched = jQuery.map( this, fn, until );
148
149                 if ( name.slice( -5 ) !== "Until" ) {
150                         selector = until;
151                 }
152
153                 if ( selector && typeof selector === "string" ) {
154                         matched = jQuery.filter( selector, matched );
155                 }
156
157                 if ( this.length > 1 ) {
158
159                         // Remove duplicates
160                         if ( !guaranteedUnique[ name ] ) {
161                                 jQuery.uniqueSort( matched );
162                         }
163
164                         // Reverse order for parents* and prev-derivatives
165                         if ( rparentsprev.test( name ) ) {
166                                 matched.reverse();
167                         }
168                 }
169
170                 return this.pushStack( matched );
171         };
172 } );
173
174 return jQuery;
175 } );