Blame view

bower_components/jquery/src/traversing.js 4.43 KB
c5169e0e   Renato De Donato   a new hope
1
  define([
74249687   Luigi Serra   Cross browser con...
2
3
  	"./core",
  	"./var/indexOf",
74249687   Luigi Serra   Cross browser con...
4
5
6
7
  	"./traversing/var/rneedsContext",
  	"./core/init",
  	"./traversing/findFilter",
  	"./selector"
c5169e0e   Renato De Donato   a new hope
8
  ], function( jQuery, indexOf, rneedsContext ) {
74249687   Luigi Serra   Cross browser con...
9
10
  
  var rparentsprev = /^(?:parents|prev(?:Until|All))/,
74249687   Luigi Serra   Cross browser con...
11
12
13
14
15
16
17
18
  	// Methods guaranteed to produce a unique set when starting from a unique set
  	guaranteedUnique = {
  		children: true,
  		contents: true,
  		next: true,
  		prev: true
  	};
  
c5169e0e   Renato De Donato   a new hope
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  jQuery.extend({
  	dir: function( elem, dir, until ) {
  		var matched = [],
  			truncate = until !== undefined;
  
  		while ( (elem = elem[ dir ]) && elem.nodeType !== 9 ) {
  			if ( elem.nodeType === 1 ) {
  				if ( truncate && jQuery( elem ).is( until ) ) {
  					break;
  				}
  				matched.push( elem );
  			}
  		}
  		return matched;
  	},
  
  	sibling: function( n, elem ) {
  		var matched = [];
  
  		for ( ; n; n = n.nextSibling ) {
  			if ( n.nodeType === 1 && n !== elem ) {
  				matched.push( n );
  			}
  		}
  
  		return matched;
  	}
  });
  
  jQuery.fn.extend({
74249687   Luigi Serra   Cross browser con...
49
50
51
52
  	has: function( target ) {
  		var targets = jQuery( target, this ),
  			l = targets.length;
  
c5169e0e   Renato De Donato   a new hope
53
  		return this.filter(function() {
74249687   Luigi Serra   Cross browser con...
54
55
  			var i = 0;
  			for ( ; i < l; i++ ) {
c5169e0e   Renato De Donato   a new hope
56
  				if ( jQuery.contains( this, targets[i] ) ) {
74249687   Luigi Serra   Cross browser con...
57
58
59
  					return true;
  				}
  			}
c5169e0e   Renato De Donato   a new hope
60
  		});
74249687   Luigi Serra   Cross browser con...
61
62
63
64
65
66
67
68
69
70
71
72
  	},
  
  	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++ ) {
c5169e0e   Renato De Donato   a new hope
73
  			for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) {
74249687   Luigi Serra   Cross browser con...
74
  				// Always skip document fragments
c5169e0e   Renato De Donato   a new hope
75
76
  				if ( cur.nodeType < 11 && (pos ?
  					pos.index(cur) > -1 :
74249687   Luigi Serra   Cross browser con...
77
78
79
  
  					// Don't pass non-elements to Sizzle
  					cur.nodeType === 1 &&
c5169e0e   Renato De Donato   a new hope
80
  						jQuery.find.matchesSelector(cur, selectors)) ) {
74249687   Luigi Serra   Cross browser con...
81
82
83
84
85
86
87
  
  					matched.push( cur );
  					break;
  				}
  			}
  		}
  
c5169e0e   Renato De Donato   a new hope
88
  		return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched );
74249687   Luigi Serra   Cross browser con...
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  	},
  
  	// 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(
c5169e0e   Renato De Donato   a new hope
114
  			jQuery.unique(
74249687   Luigi Serra   Cross browser con...
115
116
117
118
119
120
121
  				jQuery.merge( this.get(), jQuery( selector, context ) )
  			)
  		);
  	},
  
  	addBack: function( selector ) {
  		return this.add( selector == null ?
c5169e0e   Renato De Donato   a new hope
122
  			this.prevObject : this.prevObject.filter(selector)
74249687   Luigi Serra   Cross browser con...
123
124
  		);
  	}
c5169e0e   Renato De Donato   a new hope
125
  });
74249687   Luigi Serra   Cross browser con...
126
127
  
  function sibling( cur, dir ) {
c5169e0e   Renato De Donato   a new hope
128
  	while ( (cur = cur[dir]) && cur.nodeType !== 1 ) {}
74249687   Luigi Serra   Cross browser con...
129
130
131
  	return cur;
  }
  
c5169e0e   Renato De Donato   a new hope
132
  jQuery.each({
74249687   Luigi Serra   Cross browser con...
133
134
135
136
137
  	parent: function( elem ) {
  		var parent = elem.parentNode;
  		return parent && parent.nodeType !== 11 ? parent : null;
  	},
  	parents: function( elem ) {
c5169e0e   Renato De Donato   a new hope
138
  		return jQuery.dir( elem, "parentNode" );
74249687   Luigi Serra   Cross browser con...
139
140
  	},
  	parentsUntil: function( elem, i, until ) {
c5169e0e   Renato De Donato   a new hope
141
  		return jQuery.dir( elem, "parentNode", until );
74249687   Luigi Serra   Cross browser con...
142
143
144
145
146
147
148
149
  	},
  	next: function( elem ) {
  		return sibling( elem, "nextSibling" );
  	},
  	prev: function( elem ) {
  		return sibling( elem, "previousSibling" );
  	},
  	nextAll: function( elem ) {
c5169e0e   Renato De Donato   a new hope
150
  		return jQuery.dir( elem, "nextSibling" );
74249687   Luigi Serra   Cross browser con...
151
152
  	},
  	prevAll: function( elem ) {
c5169e0e   Renato De Donato   a new hope
153
  		return jQuery.dir( elem, "previousSibling" );
74249687   Luigi Serra   Cross browser con...
154
155
  	},
  	nextUntil: function( elem, i, until ) {
c5169e0e   Renato De Donato   a new hope
156
  		return jQuery.dir( elem, "nextSibling", until );
74249687   Luigi Serra   Cross browser con...
157
158
  	},
  	prevUntil: function( elem, i, until ) {
c5169e0e   Renato De Donato   a new hope
159
  		return jQuery.dir( elem, "previousSibling", until );
74249687   Luigi Serra   Cross browser con...
160
161
  	},
  	siblings: function( elem ) {
c5169e0e   Renato De Donato   a new hope
162
  		return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem );
74249687   Luigi Serra   Cross browser con...
163
164
  	},
  	children: function( elem ) {
c5169e0e   Renato De Donato   a new hope
165
  		return jQuery.sibling( elem.firstChild );
74249687   Luigi Serra   Cross browser con...
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  	},
  	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 ) {
74249687   Luigi Serra   Cross browser con...
183
184
  			// Remove duplicates
  			if ( !guaranteedUnique[ name ] ) {
c5169e0e   Renato De Donato   a new hope
185
  				jQuery.unique( matched );
74249687   Luigi Serra   Cross browser con...
186
187
188
189
190
191
192
193
194
195
  			}
  
  			// Reverse order for parents* and prev-derivatives
  			if ( rparentsprev.test( name ) ) {
  				matched.reverse();
  			}
  		}
  
  		return this.pushStack( matched );
  	};
c5169e0e   Renato De Donato   a new hope
196
  });
74249687   Luigi Serra   Cross browser con...
197
198
  
  return jQuery;
c5169e0e   Renato De Donato   a new hope
199
  });