Blame view

bower_components/jquery/src/selector-native.js 5.52 KB
a1a3bc73   Luigi Serra   graphs updates
1
2
3
4
5
6
7
  define( [
  	"./core",
  	"./var/document",
  	"./var/documentElement",
  	"./var/hasOwn",
  	"./var/indexOf"
  ], function( jQuery, document, documentElement, hasOwn, indexOf ) {
74249687   Luigi Serra   Cross browser con...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  
  /*
   * Optional (non-Sizzle) selector module for custom builds.
   *
   * Note that this DOES NOT SUPPORT many documented jQuery
   * features in exchange for its smaller size:
   *
   * Attribute not equal selector
   * Positional selectors (:first; :eq(n); :odd; etc.)
   * Type selectors (:input; :checkbox; :button; etc.)
   * State-based selectors (:animated; :visible; :hidden; etc.)
   * :has(selector)
   * :not(complex selector)
   * custom selectors via Sizzle extensions
   * Leading combinators (e.g., $collection.find("> *"))
   * Reliable functionality on XML fragments
   * Requiring all parts of a selector to match elements under context
   *   (e.g., $div.find("div > *") now matches children of $div)
   * Matching against non-elements
   * Reliable sorting of disconnected nodes
   * querySelectorAll bug fixes (e.g., unreliable :focus on WebKit)
   *
   * If any of these are unacceptable tradeoffs, either use Sizzle or
   * customize this stub for the project's specific needs.
   */
  
a1a3bc73   Luigi Serra   graphs updates
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  var hasDuplicate, sortInput,
  	sortStable = jQuery.expando.split( "" ).sort( sortOrder ).join( "" ) === jQuery.expando,
  	matches = documentElement.matches ||
  		documentElement.webkitMatchesSelector ||
  		documentElement.mozMatchesSelector ||
  		documentElement.oMatchesSelector ||
  		documentElement.msMatchesSelector;
  
  function sortOrder( a, b ) {
  
  	// Flag for duplicate removal
  	if ( a === b ) {
  		hasDuplicate = true;
  		return 0;
  	}
  
  	// Sort on method existence if only one input has compareDocumentPosition
  	var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
  	if ( compare ) {
  		return compare;
  	}
  
  	// Calculate position if both inputs belong to the same document
  	compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
  		a.compareDocumentPosition( b ) :
  
  		// Otherwise we know they are disconnected
  		1;
  
  	// Disconnected nodes
  	if ( compare & 1 ) {
  
  		// Choose the first element that is related to our preferred document
  		if ( a === document || a.ownerDocument === document &&
  			jQuery.contains( document, a ) ) {
  			return -1;
  		}
  		if ( b === document || b.ownerDocument === document &&
  			jQuery.contains( document, b ) ) {
  			return 1;
74249687   Luigi Serra   Cross browser con...
74
75
  		}
  
a1a3bc73   Luigi Serra   graphs updates
76
77
78
79
80
  		// Maintain original order
  		return sortInput ?
  			( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
  			0;
  	}
74249687   Luigi Serra   Cross browser con...
81
  
a1a3bc73   Luigi Serra   graphs updates
82
83
  	return compare & 4 ? -1 : 1;
  }
74249687   Luigi Serra   Cross browser con...
84
  
a1a3bc73   Luigi Serra   graphs updates
85
86
87
88
89
  function uniqueSort( results ) {
  	var elem,
  		duplicates = [],
  		j = 0,
  		i = 0;
74249687   Luigi Serra   Cross browser con...
90
  
a1a3bc73   Luigi Serra   graphs updates
91
92
93
  	hasDuplicate = false;
  	sortInput = !sortStable && results.slice( 0 );
  	results.sort( sortOrder );
74249687   Luigi Serra   Cross browser con...
94
  
a1a3bc73   Luigi Serra   graphs updates
95
96
97
98
99
  	if ( hasDuplicate ) {
  		while ( ( elem = results[ i++ ] ) ) {
  			if ( elem === results[ i ] ) {
  				j = duplicates.push( i );
  			}
74249687   Luigi Serra   Cross browser con...
100
  		}
a1a3bc73   Luigi Serra   graphs updates
101
102
103
104
  		while ( j-- ) {
  			results.splice( duplicates[ j ], 1 );
  		}
  	}
74249687   Luigi Serra   Cross browser con...
105
  
a1a3bc73   Luigi Serra   graphs updates
106
107
108
  	// Clear input after sorting to release objects
  	// See https://github.com/jquery/sizzle/pull/225
  	sortInput = null;
74249687   Luigi Serra   Cross browser con...
109
  
a1a3bc73   Luigi Serra   graphs updates
110
111
112
113
  	return results;
  }
  
  jQuery.extend( {
74249687   Luigi Serra   Cross browser con...
114
115
116
117
118
119
120
121
122
123
124
125
126
  	find: function( selector, context, results, seed ) {
  		var elem, nodeType,
  			i = 0;
  
  		results = results || [];
  		context = context || document;
  
  		// Same basic safeguard as Sizzle
  		if ( !selector || typeof selector !== "string" ) {
  			return results;
  		}
  
  		// Early return if context is not an element or document
a1a3bc73   Luigi Serra   graphs updates
127
  		if ( ( nodeType = context.nodeType ) !== 1 && nodeType !== 9 ) {
74249687   Luigi Serra   Cross browser con...
128
129
130
131
  			return [];
  		}
  
  		if ( seed ) {
a1a3bc73   Luigi Serra   graphs updates
132
133
  			while ( ( elem = seed[ i++ ] ) ) {
  				if ( jQuery.find.matchesSelector( elem, selector ) ) {
74249687   Luigi Serra   Cross browser con...
134
135
136
137
  					results.push( elem );
  				}
  			}
  		} else {
a1a3bc73   Luigi Serra   graphs updates
138
  			jQuery.merge( results, context.querySelectorAll( selector ) );
74249687   Luigi Serra   Cross browser con...
139
140
141
142
  		}
  
  		return results;
  	},
a1a3bc73   Luigi Serra   graphs updates
143
144
  	uniqueSort: uniqueSort,
  	unique: uniqueSort,
74249687   Luigi Serra   Cross browser con...
145
146
147
148
149
150
151
  	text: function( elem ) {
  		var node,
  			ret = "",
  			i = 0,
  			nodeType = elem.nodeType;
  
  		if ( !nodeType ) {
a1a3bc73   Luigi Serra   graphs updates
152
  
74249687   Luigi Serra   Cross browser con...
153
  			// If no nodeType, this is expected to be an array
a1a3bc73   Luigi Serra   graphs updates
154
155
  			while ( ( node = elem[ i++ ] ) ) {
  
74249687   Luigi Serra   Cross browser con...
156
157
158
159
  				// Do not traverse comment nodes
  				ret += jQuery.text( node );
  			}
  		} else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
a1a3bc73   Luigi Serra   graphs updates
160
  
74249687   Luigi Serra   Cross browser con...
161
162
163
164
165
  			// Use textContent for elements
  			return elem.textContent;
  		} else if ( nodeType === 3 || nodeType === 4 ) {
  			return elem.nodeValue;
  		}
a1a3bc73   Luigi Serra   graphs updates
166
  
74249687   Luigi Serra   Cross browser con...
167
168
169
170
171
172
173
  		// Do not include comment or processing instruction nodes
  
  		return ret;
  	},
  	contains: function( a, b ) {
  		var adown = a.nodeType === 9 ? a.documentElement : a,
  			bup = b && b.parentNode;
a1a3bc73   Luigi Serra   graphs updates
174
  		return a === bup || !!( bup && bup.nodeType === 1 && adown.contains( bup ) );
74249687   Luigi Serra   Cross browser con...
175
176
  	},
  	isXMLDoc: function( elem ) {
a1a3bc73   Luigi Serra   graphs updates
177
178
179
180
181
  
  		// documentElement is verified for cases where it doesn't yet exist
  		// (such as loading iframes in IE - #4833)
  		var documentElement = elem && ( elem.ownerDocument || elem ).documentElement;
  		return documentElement ? documentElement.nodeName !== "HTML" : false;
74249687   Luigi Serra   Cross browser con...
182
183
184
185
  	},
  	expr: {
  		attrHandle: {},
  		match: {
a1a3bc73   Luigi Serra   graphs updates
186
187
  			bool: new RegExp( "^(?:checked|selected|async|autofocus|autoplay|controls|defer" +
  				"|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped)$", "i" ),
74249687   Luigi Serra   Cross browser con...
188
189
190
  			needsContext: /^[\x20\t\r\n\f]*[>+~]/
  		}
  	}
a1a3bc73   Luigi Serra   graphs updates
191
  } );
74249687   Luigi Serra   Cross browser con...
192
193
194
195
196
197
198
199
200
  
  jQuery.extend( jQuery.find, {
  	matches: function( expr, elements ) {
  		return jQuery.find( expr, null, null, elements );
  	},
  	matchesSelector: function( elem, expr ) {
  		return matches.call( elem, expr );
  	},
  	attr: function( elem, name ) {
a1a3bc73   Luigi Serra   graphs updates
201
202
203
204
205
206
207
  		var fn = jQuery.expr.attrHandle[ name.toLowerCase() ],
  
  			// Don't get fooled by Object.prototype properties (jQuery #13807)
  			value = fn && hasOwn.call( jQuery.expr.attrHandle, name.toLowerCase() ) ?
  				fn( elem, name, jQuery.isXMLDoc( elem ) ) :
  				undefined;
  		return value !== undefined ? value : elem.getAttribute( name );
74249687   Luigi Serra   Cross browser con...
208
  	}
a1a3bc73   Luigi Serra   graphs updates
209
  } );
74249687   Luigi Serra   Cross browser con...
210
  
a1a3bc73   Luigi Serra   graphs updates
211
  } );