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