Commit | Line | Data |
---|---|---|
63c88397 | 1 | /*! |
f0c0c1ea | 2 | * jQuery JavaScript Library v1.12.1 |
63c88397 PS |
3 | * http://jquery.com/ |
4 | * | |
5 | * Includes Sizzle.js | |
6 | * http://sizzlejs.com/ | |
7 | * | |
f0c0c1ea | 8 | * Copyright jQuery Foundation and other contributors |
63c88397 PS |
9 | * Released under the MIT license |
10 | * http://jquery.org/license | |
11 | * | |
f0c0c1ea | 12 | * Date: 2016-02-22T19:07Z |
63c88397 | 13 | */ |
fa71f84f PŠ |
14 | |
15 | (function( global, factory ) { | |
16 | ||
17 | if ( typeof module === "object" && typeof module.exports === "object" ) { | |
f0c0c1ea SL |
18 | // For CommonJS and CommonJS-like environments where a proper `window` |
19 | // is present, execute the factory and get jQuery. | |
20 | // For environments that do not have a `window` with a `document` | |
21 | // (such as Node.js), expose a factory as module.exports. | |
22 | // This accentuates the need for the creation of a real `window`. | |
fa71f84f | 23 | // e.g. var jQuery = require("jquery")(window); |
f0c0c1ea | 24 | // See ticket #14549 for more info. |
fa71f84f PŠ |
25 | module.exports = global.document ? |
26 | factory( global, true ) : | |
27 | function( w ) { | |
28 | if ( !w.document ) { | |
29 | throw new Error( "jQuery requires a window with a document" ); | |
30 | } | |
31 | return factory( w ); | |
32 | }; | |
33 | } else { | |
34 | factory( global ); | |
35 | } | |
36 | ||
37 | // Pass this if window is not defined yet | |
38 | }(typeof window !== "undefined" ? window : this, function( window, noGlobal ) { | |
63c88397 | 39 | |
f0c0c1ea SL |
40 | // Support: Firefox 18+ |
41 | // Can't be in strict mode, several libs including ASP.NET trace | |
63c88397 PS |
42 | // the stack via arguments.caller.callee and Firefox dies if |
43 | // you try to trace through "use strict" call chains. (#13335) | |
f0c0c1ea | 44 | //"use strict"; |
fa71f84f | 45 | var deletedIds = []; |
63c88397 | 46 | |
f0c0c1ea SL |
47 | var document = window.document; |
48 | ||
fa71f84f | 49 | var slice = deletedIds.slice; |
63c88397 | 50 | |
fa71f84f | 51 | var concat = deletedIds.concat; |
63c88397 | 52 | |
fa71f84f | 53 | var push = deletedIds.push; |
63c88397 | 54 | |
fa71f84f PŠ |
55 | var indexOf = deletedIds.indexOf; |
56 | ||
57 | var class2type = {}; | |
58 | ||
59 | var toString = class2type.toString; | |
60 | ||
61 | var hasOwn = class2type.hasOwnProperty; | |
62 | ||
fa71f84f | 63 | var support = {}; |
63c88397 | 64 | |
63c88397 | 65 | |
63c88397 | 66 | |
fa71f84f | 67 | var |
f0c0c1ea | 68 | version = "1.12.1", |
63c88397 PS |
69 | |
70 | // Define a local copy of jQuery | |
71 | jQuery = function( selector, context ) { | |
f0c0c1ea | 72 | |
63c88397 | 73 | // The jQuery object is actually just the init constructor 'enhanced' |
fa71f84f PŠ |
74 | // Need init if jQuery is called (just allow error to be thrown if not included) |
75 | return new jQuery.fn.init( selector, context ); | |
63c88397 PS |
76 | }, |
77 | ||
5a53b77f PS |
78 | // Support: Android<4.1, IE<9 |
79 | // Make sure we trim BOM and NBSP | |
63c88397 PS |
80 | rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, |
81 | ||
63c88397 PS |
82 | // Matches dashed string for camelizing |
83 | rmsPrefix = /^-ms-/, | |
84 | rdashAlpha = /-([\da-z])/gi, | |
85 | ||
86 | // Used by jQuery.camelCase as callback to replace() | |
87 | fcamelCase = function( all, letter ) { | |
88 | return letter.toUpperCase(); | |
63c88397 PS |
89 | }; |
90 | ||
91 | jQuery.fn = jQuery.prototype = { | |
f0c0c1ea | 92 | |
63c88397 | 93 | // The current version of jQuery being used |
fa71f84f | 94 | jquery: version, |
63c88397 PS |
95 | |
96 | constructor: jQuery, | |
63c88397 PS |
97 | |
98 | // Start with an empty selector | |
99 | selector: "", | |
100 | ||
101 | // The default length of a jQuery object is 0 | |
102 | length: 0, | |
103 | ||
63c88397 | 104 | toArray: function() { |
fa71f84f | 105 | return slice.call( this ); |
63c88397 PS |
106 | }, |
107 | ||
108 | // Get the Nth element in the matched element set OR | |
109 | // Get the whole matched element set as a clean array | |
110 | get: function( num ) { | |
fa71f84f | 111 | return num != null ? |
63c88397 | 112 | |
5a53b77f | 113 | // Return just the one element from the set |
fa71f84f | 114 | ( num < 0 ? this[ num + this.length ] : this[ num ] ) : |
63c88397 | 115 | |
5a53b77f | 116 | // Return all the elements in a clean array |
fa71f84f | 117 | slice.call( this ); |
63c88397 PS |
118 | }, |
119 | ||
120 | // Take an array of elements and push it onto the stack | |
121 | // (returning the new matched element set) | |
122 | pushStack: function( elems ) { | |
123 | ||
124 | // Build a new jQuery matched element set | |
125 | var ret = jQuery.merge( this.constructor(), elems ); | |
126 | ||
127 | // Add the old object onto the stack (as a reference) | |
128 | ret.prevObject = this; | |
129 | ret.context = this.context; | |
130 | ||
131 | // Return the newly-formed element set | |
132 | return ret; | |
133 | }, | |
134 | ||
135 | // Execute a callback for every element in the matched set. | |
f0c0c1ea SL |
136 | each: function( callback ) { |
137 | return jQuery.each( this, callback ); | |
63c88397 PS |
138 | }, |
139 | ||
fa71f84f | 140 | map: function( callback ) { |
f0c0c1ea | 141 | return this.pushStack( jQuery.map( this, function( elem, i ) { |
fa71f84f | 142 | return callback.call( elem, i, elem ); |
f0c0c1ea | 143 | } ) ); |
63c88397 PS |
144 | }, |
145 | ||
146 | slice: function() { | |
fa71f84f | 147 | return this.pushStack( slice.apply( this, arguments ) ); |
63c88397 PS |
148 | }, |
149 | ||
150 | first: function() { | |
151 | return this.eq( 0 ); | |
152 | }, | |
153 | ||
154 | last: function() { | |
155 | return this.eq( -1 ); | |
156 | }, | |
157 | ||
158 | eq: function( i ) { | |
159 | var len = this.length, | |
160 | j = +i + ( i < 0 ? len : 0 ); | |
f0c0c1ea | 161 | return this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] ); |
63c88397 PS |
162 | }, |
163 | ||
63c88397 | 164 | end: function() { |
f0c0c1ea | 165 | return this.prevObject || this.constructor(); |
63c88397 PS |
166 | }, |
167 | ||
168 | // For internal use only. | |
169 | // Behaves like an Array's method, not like a jQuery method. | |
fa71f84f PŠ |
170 | push: push, |
171 | sort: deletedIds.sort, | |
172 | splice: deletedIds.splice | |
63c88397 PS |
173 | }; |
174 | ||
63c88397 PS |
175 | jQuery.extend = jQuery.fn.extend = function() { |
176 | var src, copyIsArray, copy, name, options, clone, | |
f0c0c1ea | 177 | target = arguments[ 0 ] || {}, |
63c88397 PS |
178 | i = 1, |
179 | length = arguments.length, | |
180 | deep = false; | |
181 | ||
182 | // Handle a deep copy situation | |
183 | if ( typeof target === "boolean" ) { | |
184 | deep = target; | |
fa71f84f | 185 | |
63c88397 | 186 | // skip the boolean and the target |
fa71f84f PŠ |
187 | target = arguments[ i ] || {}; |
188 | i++; | |
63c88397 PS |
189 | } |
190 | ||
191 | // Handle case when target is a string or something (possible in deep copy) | |
f0c0c1ea | 192 | if ( typeof target !== "object" && !jQuery.isFunction( target ) ) { |
63c88397 PS |
193 | target = {}; |
194 | } | |
195 | ||
196 | // extend jQuery itself if only one argument is passed | |
fa71f84f | 197 | if ( i === length ) { |
63c88397 | 198 | target = this; |
fa71f84f | 199 | i--; |
63c88397 PS |
200 | } |
201 | ||
202 | for ( ; i < length; i++ ) { | |
f0c0c1ea | 203 | |
63c88397 | 204 | // Only deal with non-null/undefined values |
f0c0c1ea SL |
205 | if ( ( options = arguments[ i ] ) != null ) { |
206 | ||
63c88397 PS |
207 | // Extend the base object |
208 | for ( name in options ) { | |
209 | src = target[ name ]; | |
210 | copy = options[ name ]; | |
211 | ||
212 | // Prevent never-ending loop | |
213 | if ( target === copy ) { | |
214 | continue; | |
215 | } | |
216 | ||
217 | // Recurse if we're merging plain objects or arrays | |
f0c0c1ea SL |
218 | if ( deep && copy && ( jQuery.isPlainObject( copy ) || |
219 | ( copyIsArray = jQuery.isArray( copy ) ) ) ) { | |
220 | ||
63c88397 PS |
221 | if ( copyIsArray ) { |
222 | copyIsArray = false; | |
f0c0c1ea | 223 | clone = src && jQuery.isArray( src ) ? src : []; |
63c88397 PS |
224 | |
225 | } else { | |
f0c0c1ea | 226 | clone = src && jQuery.isPlainObject( src ) ? src : {}; |
63c88397 PS |
227 | } |
228 | ||
229 | // Never move original objects, clone them | |
230 | target[ name ] = jQuery.extend( deep, clone, copy ); | |
231 | ||
232 | // Don't bring in undefined values | |
233 | } else if ( copy !== undefined ) { | |
234 | target[ name ] = copy; | |
235 | } | |
236 | } | |
237 | } | |
238 | } | |
239 | ||
240 | // Return the modified object | |
241 | return target; | |
242 | }; | |
243 | ||
f0c0c1ea SL |
244 | jQuery.extend( { |
245 | ||
09bacfd7 | 246 | // Unique for each copy of jQuery on the page |
fa71f84f | 247 | expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ), |
63c88397 | 248 | |
fa71f84f PŠ |
249 | // Assume jQuery is ready without the ready module |
250 | isReady: true, | |
63c88397 | 251 | |
fa71f84f PŠ |
252 | error: function( msg ) { |
253 | throw new Error( msg ); | |
63c88397 PS |
254 | }, |
255 | ||
fa71f84f | 256 | noop: function() {}, |
63c88397 PS |
257 | |
258 | // See test/unit/core.js for details concerning isFunction. | |
259 | // Since version 1.3, DOM methods and functions like alert | |
260 | // aren't supported. They return false on IE (#2968). | |
261 | isFunction: function( obj ) { | |
f0c0c1ea | 262 | return jQuery.type( obj ) === "function"; |
63c88397 PS |
263 | }, |
264 | ||
265 | isArray: Array.isArray || function( obj ) { | |
f0c0c1ea | 266 | return jQuery.type( obj ) === "array"; |
63c88397 PS |
267 | }, |
268 | ||
269 | isWindow: function( obj ) { | |
09bacfd7 | 270 | /* jshint eqeqeq: false */ |
63c88397 PS |
271 | return obj != null && obj == obj.window; |
272 | }, | |
273 | ||
274 | isNumeric: function( obj ) { | |
f0c0c1ea | 275 | |
fa71f84f PŠ |
276 | // parseFloat NaNs numeric-cast false positives (null|true|false|"") |
277 | // ...but misinterprets leading-number strings, particularly hex literals ("0x...") | |
278 | // subtraction forces infinities to NaN | |
c2260ade | 279 | // adding 1 corrects loss of precision from parseFloat (#15100) |
f0c0c1ea SL |
280 | var realStringObj = obj && obj.toString(); |
281 | return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0; | |
63c88397 PS |
282 | }, |
283 | ||
fa71f84f PŠ |
284 | isEmptyObject: function( obj ) { |
285 | var name; | |
286 | for ( name in obj ) { | |
287 | return false; | |
63c88397 | 288 | } |
fa71f84f | 289 | return true; |
63c88397 PS |
290 | }, |
291 | ||
292 | isPlainObject: function( obj ) { | |
09bacfd7 PS |
293 | var key; |
294 | ||
63c88397 PS |
295 | // Must be an Object. |
296 | // Because of IE, we also have to check the presence of the constructor property. | |
297 | // Make sure that DOM nodes and window objects don't pass through, as well | |
f0c0c1ea | 298 | if ( !obj || jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) { |
63c88397 PS |
299 | return false; |
300 | } | |
301 | ||
302 | try { | |
f0c0c1ea | 303 | |
63c88397 PS |
304 | // Not own constructor property must be Object |
305 | if ( obj.constructor && | |
f0c0c1ea SL |
306 | !hasOwn.call( obj, "constructor" ) && |
307 | !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) { | |
63c88397 PS |
308 | return false; |
309 | } | |
310 | } catch ( e ) { | |
f0c0c1ea | 311 | |
63c88397 PS |
312 | // IE8,9 Will throw exceptions on certain host objects #9897 |
313 | return false; | |
314 | } | |
315 | ||
09bacfd7 PS |
316 | // Support: IE<9 |
317 | // Handle iteration over inherited properties before own properties. | |
f0c0c1ea | 318 | if ( !support.ownFirst ) { |
09bacfd7 | 319 | for ( key in obj ) { |
fa71f84f | 320 | return hasOwn.call( obj, key ); |
09bacfd7 PS |
321 | } |
322 | } | |
323 | ||
63c88397 PS |
324 | // Own properties are enumerated firstly, so to speed up, |
325 | // if last one is own, then all properties are own. | |
63c88397 PS |
326 | for ( key in obj ) {} |
327 | ||
fa71f84f | 328 | return key === undefined || hasOwn.call( obj, key ); |
63c88397 PS |
329 | }, |
330 | ||
fa71f84f PŠ |
331 | type: function( obj ) { |
332 | if ( obj == null ) { | |
333 | return obj + ""; | |
63c88397 | 334 | } |
fa71f84f | 335 | return typeof obj === "object" || typeof obj === "function" ? |
f0c0c1ea | 336 | class2type[ toString.call( obj ) ] || "object" : |
fa71f84f | 337 | typeof obj; |
63c88397 PS |
338 | }, |
339 | ||
fa71f84f PŠ |
340 | // Workarounds based on findings by Jim Driscoll |
341 | // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context | |
342 | globalEval: function( data ) { | |
343 | if ( data && jQuery.trim( data ) ) { | |
f0c0c1ea | 344 | |
fa71f84f PŠ |
345 | // We use execScript on Internet Explorer |
346 | // We use an anonymous function so that context is window | |
347 | // rather than jQuery in Firefox | |
348 | ( window.execScript || function( data ) { | |
f0c0c1ea | 349 | window[ "eval" ].call( window, data ); // jscs:ignore requireDotNotation |
fa71f84f | 350 | } )( data ); |
63c88397 | 351 | } |
fa71f84f | 352 | }, |
63c88397 | 353 | |
fa71f84f PŠ |
354 | // Convert dashed to camelCase; used by the css and data modules |
355 | // Microsoft forgot to hump their vendor prefix (#9572) | |
356 | camelCase: function( string ) { | |
357 | return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); | |
63c88397 PS |
358 | }, |
359 | ||
fa71f84f PŠ |
360 | nodeName: function( elem, name ) { |
361 | return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); | |
362 | }, | |
63c88397 | 363 | |
f0c0c1ea SL |
364 | each: function( obj, callback ) { |
365 | var length, i = 0; | |
63c88397 | 366 | |
f0c0c1ea SL |
367 | if ( isArrayLike( obj ) ) { |
368 | length = obj.length; | |
369 | for ( ; i < length; i++ ) { | |
370 | if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) { | |
371 | break; | |
63c88397 PS |
372 | } |
373 | } | |
63c88397 | 374 | } else { |
f0c0c1ea SL |
375 | for ( i in obj ) { |
376 | if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) { | |
377 | break; | |
63c88397 PS |
378 | } |
379 | } | |
380 | } | |
381 | ||
382 | return obj; | |
383 | }, | |
384 | ||
5a53b77f PS |
385 | // Support: Android<4.1, IE<9 |
386 | trim: function( text ) { | |
387 | return text == null ? | |
388 | "" : | |
389 | ( text + "" ).replace( rtrim, "" ); | |
390 | }, | |
63c88397 PS |
391 | |
392 | // results is for internal usage only | |
393 | makeArray: function( arr, results ) { | |
394 | var ret = results || []; | |
395 | ||
396 | if ( arr != null ) { | |
f0c0c1ea | 397 | if ( isArrayLike( Object( arr ) ) ) { |
63c88397 PS |
398 | jQuery.merge( ret, |
399 | typeof arr === "string" ? | |
400 | [ arr ] : arr | |
401 | ); | |
402 | } else { | |
fa71f84f | 403 | push.call( ret, arr ); |
63c88397 PS |
404 | } |
405 | } | |
406 | ||
407 | return ret; | |
408 | }, | |
409 | ||
410 | inArray: function( elem, arr, i ) { | |
411 | var len; | |
412 | ||
413 | if ( arr ) { | |
fa71f84f PŠ |
414 | if ( indexOf ) { |
415 | return indexOf.call( arr, elem, i ); | |
63c88397 PS |
416 | } |
417 | ||
418 | len = arr.length; | |
419 | i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0; | |
420 | ||
421 | for ( ; i < len; i++ ) { | |
f0c0c1ea | 422 | |
63c88397 PS |
423 | // Skip accessing in sparse arrays |
424 | if ( i in arr && arr[ i ] === elem ) { | |
425 | return i; | |
426 | } | |
427 | } | |
428 | } | |
429 | ||
430 | return -1; | |
431 | }, | |
432 | ||
433 | merge: function( first, second ) { | |
fa71f84f PŠ |
434 | var len = +second.length, |
435 | j = 0, | |
436 | i = first.length; | |
63c88397 | 437 | |
fa71f84f PŠ |
438 | while ( j < len ) { |
439 | first[ i++ ] = second[ j++ ]; | |
440 | } | |
441 | ||
442 | // Support: IE<9 | |
443 | // Workaround casting of .length to NaN on otherwise arraylike objects (e.g., NodeLists) | |
444 | if ( len !== len ) { | |
f0c0c1ea | 445 | while ( second[ j ] !== undefined ) { |
63c88397 PS |
446 | first[ i++ ] = second[ j++ ]; |
447 | } | |
448 | } | |
449 | ||
450 | first.length = i; | |
451 | ||
452 | return first; | |
453 | }, | |
454 | ||
fa71f84f PŠ |
455 | grep: function( elems, callback, invert ) { |
456 | var callbackInverse, | |
457 | matches = [], | |
63c88397 | 458 | i = 0, |
fa71f84f PŠ |
459 | length = elems.length, |
460 | callbackExpect = !invert; | |
63c88397 PS |
461 | |
462 | // Go through the array, only saving the items | |
463 | // that pass the validator function | |
464 | for ( ; i < length; i++ ) { | |
fa71f84f PŠ |
465 | callbackInverse = !callback( elems[ i ], i ); |
466 | if ( callbackInverse !== callbackExpect ) { | |
467 | matches.push( elems[ i ] ); | |
63c88397 PS |
468 | } |
469 | } | |
470 | ||
fa71f84f | 471 | return matches; |
63c88397 PS |
472 | }, |
473 | ||
474 | // arg is for internal usage only | |
475 | map: function( elems, callback, arg ) { | |
f0c0c1ea | 476 | var length, value, |
63c88397 | 477 | i = 0, |
63c88397 PS |
478 | ret = []; |
479 | ||
fa71f84f | 480 | // Go through the array, translating each of the items to their new values |
f0c0c1ea SL |
481 | if ( isArrayLike( elems ) ) { |
482 | length = elems.length; | |
63c88397 PS |
483 | for ( ; i < length; i++ ) { |
484 | value = callback( elems[ i ], i, arg ); | |
485 | ||
486 | if ( value != null ) { | |
fa71f84f | 487 | ret.push( value ); |
63c88397 PS |
488 | } |
489 | } | |
490 | ||
491 | // Go through every key on the object, | |
492 | } else { | |
493 | for ( i in elems ) { | |
494 | value = callback( elems[ i ], i, arg ); | |
495 | ||
496 | if ( value != null ) { | |
fa71f84f | 497 | ret.push( value ); |
63c88397 PS |
498 | } |
499 | } | |
500 | } | |
501 | ||
502 | // Flatten any nested arrays | |
fa71f84f | 503 | return concat.apply( [], ret ); |
63c88397 PS |
504 | }, |
505 | ||
506 | // A global GUID counter for objects | |
507 | guid: 1, | |
508 | ||
509 | // Bind a function to a context, optionally partially applying any | |
510 | // arguments. | |
511 | proxy: function( fn, context ) { | |
512 | var args, proxy, tmp; | |
513 | ||
514 | if ( typeof context === "string" ) { | |
515 | tmp = fn[ context ]; | |
516 | context = fn; | |
517 | fn = tmp; | |
518 | } | |
519 | ||
520 | // Quick check to determine if target is callable, in the spec | |
521 | // this throws a TypeError, but we will just return undefined. | |
522 | if ( !jQuery.isFunction( fn ) ) { | |
523 | return undefined; | |
524 | } | |
525 | ||
526 | // Simulated bind | |
fa71f84f | 527 | args = slice.call( arguments, 2 ); |
63c88397 | 528 | proxy = function() { |
fa71f84f | 529 | return fn.apply( context || this, args.concat( slice.call( arguments ) ) ); |
63c88397 PS |
530 | }; |
531 | ||
532 | // Set the guid of unique handler to the same of original handler, so it can be removed | |
533 | proxy.guid = fn.guid = fn.guid || jQuery.guid++; | |
534 | ||
535 | return proxy; | |
536 | }, | |
537 | ||
63c88397 | 538 | now: function() { |
fa71f84f | 539 | return +( new Date() ); |
09bacfd7 PS |
540 | }, |
541 | ||
fa71f84f PŠ |
542 | // jQuery.support is not used in Core but other projects attach their |
543 | // properties to it so it needs to exist. | |
544 | support: support | |
f0c0c1ea SL |
545 | } ); |
546 | ||
547 | // JSHint would error on this code due to the Symbol not being defined in ES5. | |
548 | // Defining this global in .jshintrc would create a danger of using the global | |
549 | // unguarded in another place, it seems safer to just disable JSHint for these | |
550 | // three lines. | |
551 | /* jshint ignore: start */ | |
552 | if ( typeof Symbol === "function" ) { | |
553 | jQuery.fn[ Symbol.iterator ] = deletedIds[ Symbol.iterator ]; | |
554 | } | |
555 | /* jshint ignore: end */ | |
63c88397 | 556 | |
63c88397 | 557 | // Populate the class2type map |
f0c0c1ea SL |
558 | jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ), |
559 | function( i, name ) { | |
63c88397 | 560 | class2type[ "[object " + name + "]" ] = name.toLowerCase(); |
f0c0c1ea | 561 | } ); |
63c88397 | 562 | |
f0c0c1ea | 563 | function isArrayLike( obj ) { |
d463b9c1 JP |
564 | |
565 | // Support: iOS 8.2 (not reproducible in simulator) | |
566 | // `in` check used to prevent JIT error (gh-2145) | |
567 | // hasOwn isn't used here due to false negatives | |
568 | // regarding Nodelist length in IE | |
f0c0c1ea | 569 | var length = !!obj && "length" in obj && obj.length, |
63c88397 PS |
570 | type = jQuery.type( obj ); |
571 | ||
fa71f84f | 572 | if ( type === "function" || jQuery.isWindow( obj ) ) { |
63c88397 PS |
573 | return false; |
574 | } | |
575 | ||
fa71f84f PŠ |
576 | return type === "array" || length === 0 || |
577 | typeof length === "number" && length > 0 && ( length - 1 ) in obj; | |
63c88397 | 578 | } |
fa71f84f | 579 | var Sizzle = |
09bacfd7 | 580 | /*! |
f0c0c1ea | 581 | * Sizzle CSS Selector Engine v2.2.1 |
09bacfd7 | 582 | * http://sizzlejs.com/ |
63c88397 | 583 | * |
f0c0c1ea | 584 | * Copyright jQuery Foundation and other contributors |
09bacfd7 PS |
585 | * Released under the MIT license |
586 | * http://jquery.org/license | |
63c88397 | 587 | * |
f0c0c1ea | 588 | * Date: 2015-10-17 |
63c88397 | 589 | */ |
fa71f84f | 590 | (function( window ) { |
63c88397 | 591 | |
09bacfd7 PS |
592 | var i, |
593 | support, | |
09bacfd7 PS |
594 | Expr, |
595 | getText, | |
596 | isXML, | |
5a53b77f | 597 | tokenize, |
09bacfd7 | 598 | compile, |
5a53b77f | 599 | select, |
09bacfd7 PS |
600 | outermostContext, |
601 | sortInput, | |
fa71f84f | 602 | hasDuplicate, |
63c88397 | 603 | |
09bacfd7 PS |
604 | // Local document vars |
605 | setDocument, | |
606 | document, | |
607 | docElem, | |
608 | documentIsHTML, | |
609 | rbuggyQSA, | |
610 | rbuggyMatches, | |
611 | matches, | |
612 | contains, | |
63c88397 | 613 | |
09bacfd7 | 614 | // Instance-specific data |
c2260ade | 615 | expando = "sizzle" + 1 * new Date(), |
09bacfd7 PS |
616 | preferredDoc = window.document, |
617 | dirruns = 0, | |
618 | done = 0, | |
619 | classCache = createCache(), | |
620 | tokenCache = createCache(), | |
621 | compilerCache = createCache(), | |
09bacfd7 PS |
622 | sortOrder = function( a, b ) { |
623 | if ( a === b ) { | |
624 | hasDuplicate = true; | |
09bacfd7 PS |
625 | } |
626 | return 0; | |
627 | }, | |
63c88397 | 628 | |
09bacfd7 | 629 | // General-purpose constants |
09bacfd7 | 630 | MAX_NEGATIVE = 1 << 31, |
63c88397 | 631 | |
09bacfd7 PS |
632 | // Instance methods |
633 | hasOwn = ({}).hasOwnProperty, | |
634 | arr = [], | |
635 | pop = arr.pop, | |
636 | push_native = arr.push, | |
637 | push = arr.push, | |
638 | slice = arr.slice, | |
c2260ade JO |
639 | // Use a stripped-down indexOf as it's faster than native |
640 | // http://jsperf.com/thor-indexof-vs-for/5 | |
641 | indexOf = function( list, elem ) { | |
09bacfd7 | 642 | var i = 0, |
c2260ade | 643 | len = list.length; |
09bacfd7 | 644 | for ( ; i < len; i++ ) { |
c2260ade | 645 | if ( list[i] === elem ) { |
09bacfd7 PS |
646 | return i; |
647 | } | |
648 | } | |
649 | return -1; | |
650 | }, | |
63c88397 | 651 | |
09bacfd7 | 652 | booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped", |
63c88397 | 653 | |
09bacfd7 | 654 | // Regular expressions |
63c88397 | 655 | |
f0c0c1ea | 656 | // http://www.w3.org/TR/css3-selectors/#whitespace |
09bacfd7 | 657 | whitespace = "[\\x20\\t\\r\\n\\f]", |
63c88397 | 658 | |
f0c0c1ea SL |
659 | // http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier |
660 | identifier = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+", | |
63c88397 | 661 | |
5a53b77f | 662 | // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors |
f0c0c1ea | 663 | attributes = "\\[" + whitespace + "*(" + identifier + ")(?:" + whitespace + |
5a53b77f PS |
664 | // Operator (capture 2) |
665 | "*([*^$|!~]?=)" + whitespace + | |
666 | // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]" | |
667 | "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace + | |
668 | "*\\]", | |
669 | ||
f0c0c1ea | 670 | pseudos = ":(" + identifier + ")(?:\\((" + |
5a53b77f PS |
671 | // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments: |
672 | // 1. quoted (capture 3; capture 4 or capture 5) | |
673 | "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" + | |
674 | // 2. simple (capture 6) | |
675 | "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" + | |
676 | // 3. anything else (capture 2) | |
677 | ".*" + | |
678 | ")\\)|)", | |
63c88397 | 679 | |
09bacfd7 | 680 | // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter |
c2260ade | 681 | rwhitespace = new RegExp( whitespace + "+", "g" ), |
09bacfd7 | 682 | rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ), |
63c88397 | 683 | |
09bacfd7 PS |
684 | rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ), |
685 | rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ), | |
63c88397 | 686 | |
fa71f84f | 687 | rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ), |
63c88397 | 688 | |
09bacfd7 PS |
689 | rpseudo = new RegExp( pseudos ), |
690 | ridentifier = new RegExp( "^" + identifier + "$" ), | |
63c88397 | 691 | |
09bacfd7 | 692 | matchExpr = { |
f0c0c1ea SL |
693 | "ID": new RegExp( "^#(" + identifier + ")" ), |
694 | "CLASS": new RegExp( "^\\.(" + identifier + ")" ), | |
695 | "TAG": new RegExp( "^(" + identifier + "|[*])" ), | |
09bacfd7 PS |
696 | "ATTR": new RegExp( "^" + attributes ), |
697 | "PSEUDO": new RegExp( "^" + pseudos ), | |
698 | "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace + | |
699 | "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace + | |
700 | "*(\\d+)|))" + whitespace + "*\\)|)", "i" ), | |
701 | "bool": new RegExp( "^(?:" + booleans + ")$", "i" ), | |
702 | // For use in libraries implementing .is() | |
703 | // We use this for POS matching in `select` | |
704 | "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" + | |
705 | whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" ) | |
706 | }, | |
63c88397 | 707 | |
fa71f84f PŠ |
708 | rinputs = /^(?:input|select|textarea|button)$/i, |
709 | rheader = /^h\d$/i, | |
710 | ||
09bacfd7 | 711 | rnative = /^[^{]+\{\s*\[native \w/, |
63c88397 | 712 | |
09bacfd7 PS |
713 | // Easily-parseable/retrievable ID or TAG or CLASS selectors |
714 | rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, | |
63c88397 | 715 | |
fa71f84f | 716 | rsibling = /[+~]/, |
09bacfd7 | 717 | rescape = /'|\\/g, |
63c88397 | 718 | |
09bacfd7 PS |
719 | // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters |
720 | runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ), | |
721 | funescape = function( _, escaped, escapedWhitespace ) { | |
722 | var high = "0x" + escaped - 0x10000; | |
723 | // NaN means non-codepoint | |
5a53b77f | 724 | // Support: Firefox<24 |
09bacfd7 PS |
725 | // Workaround erroneous numeric interpretation of +"0x" |
726 | return high !== high || escapedWhitespace ? | |
727 | escaped : | |
09bacfd7 | 728 | high < 0 ? |
fa71f84f | 729 | // BMP codepoint |
09bacfd7 PS |
730 | String.fromCharCode( high + 0x10000 ) : |
731 | // Supplemental Plane codepoint (surrogate pair) | |
732 | String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 ); | |
c2260ade JO |
733 | }, |
734 | ||
735 | // Used for iframes | |
736 | // See setDocument() | |
737 | // Removing the function wrapper causes a "Permission Denied" | |
738 | // error in IE | |
739 | unloadHandler = function() { | |
740 | setDocument(); | |
09bacfd7 | 741 | }; |
63c88397 | 742 | |
09bacfd7 PS |
743 | // Optimize for push.apply( _, NodeList ) |
744 | try { | |
745 | push.apply( | |
746 | (arr = slice.call( preferredDoc.childNodes )), | |
747 | preferredDoc.childNodes | |
748 | ); | |
749 | // Support: Android<4.0 | |
750 | // Detect silently failing push.apply | |
751 | arr[ preferredDoc.childNodes.length ].nodeType; | |
752 | } catch ( e ) { | |
753 | push = { apply: arr.length ? | |
63c88397 | 754 | |
09bacfd7 PS |
755 | // Leverage slice if possible |
756 | function( target, els ) { | |
757 | push_native.apply( target, slice.call(els) ); | |
758 | } : | |
63c88397 | 759 | |
09bacfd7 PS |
760 | // Support: IE<9 |
761 | // Otherwise append directly | |
762 | function( target, els ) { | |
763 | var j = target.length, | |
764 | i = 0; | |
765 | // Can't trust NodeList.length | |
766 | while ( (target[j++] = els[i++]) ) {} | |
767 | target.length = j - 1; | |
768 | } | |
63c88397 | 769 | }; |
09bacfd7 | 770 | } |
63c88397 | 771 | |
09bacfd7 | 772 | function Sizzle( selector, context, results, seed ) { |
f0c0c1ea SL |
773 | var m, i, elem, nid, nidselect, match, groups, newSelector, |
774 | newContext = context && context.ownerDocument, | |
63c88397 | 775 | |
f0c0c1ea SL |
776 | // nodeType defaults to 9, since context defaults to document |
777 | nodeType = context ? context.nodeType : 9; | |
63c88397 | 778 | |
09bacfd7 | 779 | results = results || []; |
63c88397 | 780 | |
f0c0c1ea | 781 | // Return early from calls with invalid selector or context |
c2260ade JO |
782 | if ( typeof selector !== "string" || !selector || |
783 | nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) { | |
63c88397 | 784 | |
c2260ade | 785 | return results; |
09bacfd7 | 786 | } |
63c88397 | 787 | |
f0c0c1ea SL |
788 | // Try to shortcut find operations (as opposed to filters) in HTML documents |
789 | if ( !seed ) { | |
63c88397 | 790 | |
f0c0c1ea SL |
791 | if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) { |
792 | setDocument( context ); | |
793 | } | |
794 | context = context || document; | |
795 | ||
796 | if ( documentIsHTML ) { | |
797 | ||
798 | // If the selector is sufficiently simple, try using a "get*By*" DOM method | |
799 | // (excepting DocumentFragment context, where the methods don't exist) | |
800 | if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) { | |
801 | ||
802 | // ID selector | |
803 | if ( (m = match[1]) ) { | |
804 | ||
805 | // Document context | |
806 | if ( nodeType === 9 ) { | |
807 | if ( (elem = context.getElementById( m )) ) { | |
808 | ||
809 | // Support: IE, Opera, Webkit | |
810 | // TODO: identify versions | |
811 | // getElementById can match elements by name instead of ID | |
812 | if ( elem.id === m ) { | |
813 | results.push( elem ); | |
814 | return results; | |
815 | } | |
816 | } else { | |
09bacfd7 PS |
817 | return results; |
818 | } | |
f0c0c1ea SL |
819 | |
820 | // Element context | |
09bacfd7 | 821 | } else { |
f0c0c1ea SL |
822 | |
823 | // Support: IE, Opera, Webkit | |
824 | // TODO: identify versions | |
825 | // getElementById can match elements by name instead of ID | |
826 | if ( newContext && (elem = newContext.getElementById( m )) && | |
827 | contains( context, elem ) && | |
828 | elem.id === m ) { | |
829 | ||
830 | results.push( elem ); | |
831 | return results; | |
832 | } | |
09bacfd7 | 833 | } |
63c88397 | 834 | |
f0c0c1ea SL |
835 | // Type selector |
836 | } else if ( match[2] ) { | |
837 | push.apply( results, context.getElementsByTagName( selector ) ); | |
838 | return results; | |
63c88397 | 839 | |
f0c0c1ea SL |
840 | // Class selector |
841 | } else if ( (m = match[3]) && support.getElementsByClassName && | |
842 | context.getElementsByClassName ) { | |
843 | ||
844 | push.apply( results, context.getElementsByClassName( m ) ); | |
845 | return results; | |
846 | } | |
09bacfd7 | 847 | } |
63c88397 | 848 | |
f0c0c1ea SL |
849 | // Take advantage of querySelectorAll |
850 | if ( support.qsa && | |
851 | !compilerCache[ selector + " " ] && | |
852 | (!rbuggyQSA || !rbuggyQSA.test( selector )) ) { | |
63c88397 | 853 | |
f0c0c1ea SL |
854 | if ( nodeType !== 1 ) { |
855 | newContext = context; | |
856 | newSelector = selector; | |
63c88397 | 857 | |
f0c0c1ea SL |
858 | // qSA looks outside Element context, which is not what we want |
859 | // Thanks to Andrew Dupont for this workaround technique | |
860 | // Support: IE <=8 | |
861 | // Exclude object elements | |
862 | } else if ( context.nodeName.toLowerCase() !== "object" ) { | |
63c88397 | 863 | |
f0c0c1ea SL |
864 | // Capture the context ID, setting it first if necessary |
865 | if ( (nid = context.getAttribute( "id" )) ) { | |
866 | nid = nid.replace( rescape, "\\$&" ); | |
867 | } else { | |
868 | context.setAttribute( "id", (nid = expando) ); | |
869 | } | |
870 | ||
871 | // Prefix every selector in the list | |
872 | groups = tokenize( selector ); | |
873 | i = groups.length; | |
874 | nidselect = ridentifier.test( nid ) ? "#" + nid : "[id='" + nid + "']"; | |
875 | while ( i-- ) { | |
876 | groups[i] = nidselect + " " + toSelector( groups[i] ); | |
877 | } | |
878 | newSelector = groups.join( "," ); | |
879 | ||
880 | // Expand context for sibling selectors | |
881 | newContext = rsibling.test( selector ) && testContext( context.parentNode ) || | |
882 | context; | |
09bacfd7 | 883 | } |
63c88397 | 884 | |
f0c0c1ea SL |
885 | if ( newSelector ) { |
886 | try { | |
887 | push.apply( results, | |
888 | newContext.querySelectorAll( newSelector ) | |
889 | ); | |
890 | return results; | |
891 | } catch ( qsaError ) { | |
892 | } finally { | |
893 | if ( nid === expando ) { | |
894 | context.removeAttribute( "id" ); | |
895 | } | |
09bacfd7 PS |
896 | } |
897 | } | |
63c88397 PS |
898 | } |
899 | } | |
09bacfd7 | 900 | } |
63c88397 | 901 | |
09bacfd7 PS |
902 | // All others |
903 | return select( selector.replace( rtrim, "$1" ), context, results, seed ); | |
904 | } | |
63c88397 | 905 | |
09bacfd7 PS |
906 | /** |
907 | * Create key-value caches of limited size | |
f0c0c1ea | 908 | * @returns {function(string, object)} Returns the Object data after storing it on itself with |
09bacfd7 PS |
909 | * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength) |
910 | * deleting the oldest entry | |
911 | */ | |
912 | function createCache() { | |
913 | var keys = []; | |
63c88397 | 914 | |
09bacfd7 PS |
915 | function cache( key, value ) { |
916 | // Use (key + " ") to avoid collision with native prototype properties (see Issue #157) | |
fa71f84f | 917 | if ( keys.push( key + " " ) > Expr.cacheLength ) { |
09bacfd7 PS |
918 | // Only keep the most recent entries |
919 | delete cache[ keys.shift() ]; | |
920 | } | |
fa71f84f | 921 | return (cache[ key + " " ] = value); |
09bacfd7 PS |
922 | } |
923 | return cache; | |
924 | } | |
63c88397 | 925 | |
09bacfd7 PS |
926 | /** |
927 | * Mark a function for special use by Sizzle | |
928 | * @param {Function} fn The function to mark | |
929 | */ | |
930 | function markFunction( fn ) { | |
931 | fn[ expando ] = true; | |
932 | return fn; | |
933 | } | |
63c88397 | 934 | |
09bacfd7 PS |
935 | /** |
936 | * Support testing using an element | |
937 | * @param {Function} fn Passed the created div and expects a boolean result | |
938 | */ | |
939 | function assert( fn ) { | |
940 | var div = document.createElement("div"); | |
63c88397 | 941 | |
09bacfd7 PS |
942 | try { |
943 | return !!fn( div ); | |
944 | } catch (e) { | |
945 | return false; | |
946 | } finally { | |
947 | // Remove from its parent by default | |
948 | if ( div.parentNode ) { | |
949 | div.parentNode.removeChild( div ); | |
950 | } | |
951 | // release memory in IE | |
952 | div = null; | |
63c88397 | 953 | } |
09bacfd7 | 954 | } |
63c88397 | 955 | |
09bacfd7 PS |
956 | /** |
957 | * Adds the same handler for all of the specified attrs | |
958 | * @param {String} attrs Pipe-separated list of attributes | |
959 | * @param {Function} handler The method that will be applied | |
960 | */ | |
961 | function addHandle( attrs, handler ) { | |
962 | var arr = attrs.split("|"), | |
f0c0c1ea | 963 | i = arr.length; |
63c88397 | 964 | |
09bacfd7 PS |
965 | while ( i-- ) { |
966 | Expr.attrHandle[ arr[i] ] = handler; | |
967 | } | |
968 | } | |
63c88397 | 969 | |
09bacfd7 PS |
970 | /** |
971 | * Checks document order of two siblings | |
972 | * @param {Element} a | |
973 | * @param {Element} b | |
974 | * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b | |
975 | */ | |
976 | function siblingCheck( a, b ) { | |
977 | var cur = b && a, | |
978 | diff = cur && a.nodeType === 1 && b.nodeType === 1 && | |
979 | ( ~b.sourceIndex || MAX_NEGATIVE ) - | |
980 | ( ~a.sourceIndex || MAX_NEGATIVE ); | |
63c88397 | 981 | |
09bacfd7 PS |
982 | // Use IE sourceIndex if available on both nodes |
983 | if ( diff ) { | |
984 | return diff; | |
63c88397 PS |
985 | } |
986 | ||
09bacfd7 PS |
987 | // Check if b follows a |
988 | if ( cur ) { | |
989 | while ( (cur = cur.nextSibling) ) { | |
990 | if ( cur === b ) { | |
991 | return -1; | |
992 | } | |
63c88397 PS |
993 | } |
994 | } | |
995 | ||
09bacfd7 PS |
996 | return a ? 1 : -1; |
997 | } | |
63c88397 | 998 | |
09bacfd7 PS |
999 | /** |
1000 | * Returns a function to use in pseudos for input types | |
1001 | * @param {String} type | |
1002 | */ | |
1003 | function createInputPseudo( type ) { | |
1004 | return function( elem ) { | |
1005 | var name = elem.nodeName.toLowerCase(); | |
1006 | return name === "input" && elem.type === type; | |
1007 | }; | |
1008 | } | |
63c88397 | 1009 | |
09bacfd7 PS |
1010 | /** |
1011 | * Returns a function to use in pseudos for buttons | |
1012 | * @param {String} type | |
1013 | */ | |
1014 | function createButtonPseudo( type ) { | |
1015 | return function( elem ) { | |
1016 | var name = elem.nodeName.toLowerCase(); | |
1017 | return (name === "input" || name === "button") && elem.type === type; | |
1018 | }; | |
1019 | } | |
63c88397 | 1020 | |
09bacfd7 PS |
1021 | /** |
1022 | * Returns a function to use in pseudos for positionals | |
1023 | * @param {Function} fn | |
1024 | */ | |
1025 | function createPositionalPseudo( fn ) { | |
1026 | return markFunction(function( argument ) { | |
1027 | argument = +argument; | |
1028 | return markFunction(function( seed, matches ) { | |
1029 | var j, | |
1030 | matchIndexes = fn( [], seed.length, argument ), | |
1031 | i = matchIndexes.length; | |
63c88397 | 1032 | |
09bacfd7 PS |
1033 | // Match elements found at the specified indexes |
1034 | while ( i-- ) { | |
1035 | if ( seed[ (j = matchIndexes[i]) ] ) { | |
1036 | seed[j] = !(matches[j] = seed[j]); | |
1037 | } | |
1038 | } | |
1039 | }); | |
1040 | }); | |
1041 | } | |
63c88397 | 1042 | |
09bacfd7 | 1043 | /** |
fa71f84f PŠ |
1044 | * Checks a node for validity as a Sizzle context |
1045 | * @param {Element|Object=} context | |
1046 | * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value | |
1047 | */ | |
1048 | function testContext( context ) { | |
c2260ade | 1049 | return context && typeof context.getElementsByTagName !== "undefined" && context; |
fa71f84f PŠ |
1050 | } |
1051 | ||
1052 | // Expose support vars for convenience | |
1053 | support = Sizzle.support = {}; | |
1054 | ||
1055 | /** | |
1056 | * Detects XML nodes | |
09bacfd7 | 1057 | * @param {Element|Object} elem An element or a document |
fa71f84f | 1058 | * @returns {Boolean} True iff elem is a non-HTML XML node |
09bacfd7 PS |
1059 | */ |
1060 | isXML = Sizzle.isXML = function( elem ) { | |
1061 | // documentElement is verified for cases where it doesn't yet exist | |
1062 | // (such as loading iframes in IE - #4833) | |
1063 | var documentElement = elem && (elem.ownerDocument || elem).documentElement; | |
1064 | return documentElement ? documentElement.nodeName !== "HTML" : false; | |
1065 | }; | |
63c88397 | 1066 | |
09bacfd7 PS |
1067 | /** |
1068 | * Sets document-related variables once based on the current document | |
1069 | * @param {Element|Object} [doc] An element or document object to use to set the document | |
1070 | * @returns {Object} Returns the current document | |
1071 | */ | |
1072 | setDocument = Sizzle.setDocument = function( node ) { | |
c2260ade JO |
1073 | var hasCompare, parent, |
1074 | doc = node ? node.ownerDocument || node : preferredDoc; | |
63c88397 | 1075 | |
f0c0c1ea | 1076 | // Return early if doc is invalid or already selected |
09bacfd7 PS |
1077 | if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) { |
1078 | return document; | |
63c88397 PS |
1079 | } |
1080 | ||
f0c0c1ea | 1081 | // Update global variables |
09bacfd7 | 1082 | document = doc; |
f0c0c1ea SL |
1083 | docElem = document.documentElement; |
1084 | documentIsHTML = !isXML( document ); | |
1085 | ||
1086 | // Support: IE 9-11, Edge | |
1087 | // Accessing iframe documents after unload throws "permission denied" errors (jQuery #13936) | |
1088 | if ( (parent = document.defaultView) && parent.top !== parent ) { | |
1089 | // Support: IE 11 | |
fa71f84f | 1090 | if ( parent.addEventListener ) { |
c2260ade | 1091 | parent.addEventListener( "unload", unloadHandler, false ); |
f0c0c1ea SL |
1092 | |
1093 | // Support: IE 9 - 10 only | |
fa71f84f | 1094 | } else if ( parent.attachEvent ) { |
c2260ade | 1095 | parent.attachEvent( "onunload", unloadHandler ); |
fa71f84f | 1096 | } |
63c88397 PS |
1097 | } |
1098 | ||
09bacfd7 PS |
1099 | /* Attributes |
1100 | ---------------------------------------------------------------------- */ | |
63c88397 | 1101 | |
09bacfd7 | 1102 | // Support: IE<8 |
c2260ade JO |
1103 | // Verify that getAttribute really returns attributes and not properties |
1104 | // (excepting IE8 booleans) | |
09bacfd7 PS |
1105 | support.attributes = assert(function( div ) { |
1106 | div.className = "i"; | |
1107 | return !div.getAttribute("className"); | |
1108 | }); | |
63c88397 | 1109 | |
09bacfd7 PS |
1110 | /* getElement(s)By* |
1111 | ---------------------------------------------------------------------- */ | |
63c88397 | 1112 | |
09bacfd7 PS |
1113 | // Check if getElementsByTagName("*") returns only elements |
1114 | support.getElementsByTagName = assert(function( div ) { | |
f0c0c1ea | 1115 | div.appendChild( document.createComment("") ); |
09bacfd7 PS |
1116 | return !div.getElementsByTagName("*").length; |
1117 | }); | |
63c88397 | 1118 | |
c2260ade | 1119 | // Support: IE<9 |
f0c0c1ea | 1120 | support.getElementsByClassName = rnative.test( document.getElementsByClassName ); |
63c88397 | 1121 | |
09bacfd7 PS |
1122 | // Support: IE<10 |
1123 | // Check if getElementById returns elements by name | |
1124 | // The broken getElementById methods don't pick up programatically-set names, | |
1125 | // so use a roundabout getElementsByName test | |
1126 | support.getById = assert(function( div ) { | |
1127 | docElem.appendChild( div ).id = expando; | |
f0c0c1ea | 1128 | return !document.getElementsByName || !document.getElementsByName( expando ).length; |
09bacfd7 | 1129 | }); |
63c88397 | 1130 | |
09bacfd7 PS |
1131 | // ID find and filter |
1132 | if ( support.getById ) { | |
1133 | Expr.find["ID"] = function( id, context ) { | |
c2260ade | 1134 | if ( typeof context.getElementById !== "undefined" && documentIsHTML ) { |
09bacfd7 | 1135 | var m = context.getElementById( id ); |
f0c0c1ea | 1136 | return m ? [ m ] : []; |
09bacfd7 PS |
1137 | } |
1138 | }; | |
1139 | Expr.filter["ID"] = function( id ) { | |
1140 | var attrId = id.replace( runescape, funescape ); | |
1141 | return function( elem ) { | |
1142 | return elem.getAttribute("id") === attrId; | |
1143 | }; | |
1144 | }; | |
1145 | } else { | |
1146 | // Support: IE6/7 | |
1147 | // getElementById is not reliable as a find shortcut | |
1148 | delete Expr.find["ID"]; | |
63c88397 | 1149 | |
09bacfd7 PS |
1150 | Expr.filter["ID"] = function( id ) { |
1151 | var attrId = id.replace( runescape, funescape ); | |
1152 | return function( elem ) { | |
f0c0c1ea SL |
1153 | var node = typeof elem.getAttributeNode !== "undefined" && |
1154 | elem.getAttributeNode("id"); | |
09bacfd7 PS |
1155 | return node && node.value === attrId; |
1156 | }; | |
1157 | }; | |
1158 | } | |
63c88397 | 1159 | |
09bacfd7 PS |
1160 | // Tag |
1161 | Expr.find["TAG"] = support.getElementsByTagName ? | |
1162 | function( tag, context ) { | |
c2260ade | 1163 | if ( typeof context.getElementsByTagName !== "undefined" ) { |
09bacfd7 | 1164 | return context.getElementsByTagName( tag ); |
c2260ade JO |
1165 | |
1166 | // DocumentFragment nodes don't have gEBTN | |
1167 | } else if ( support.qsa ) { | |
1168 | return context.querySelectorAll( tag ); | |
09bacfd7 PS |
1169 | } |
1170 | } : | |
c2260ade | 1171 | |
09bacfd7 PS |
1172 | function( tag, context ) { |
1173 | var elem, | |
1174 | tmp = [], | |
1175 | i = 0, | |
c2260ade | 1176 | // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too |
09bacfd7 PS |
1177 | results = context.getElementsByTagName( tag ); |
1178 | ||
1179 | // Filter out possible comments | |
1180 | if ( tag === "*" ) { | |
1181 | while ( (elem = results[i++]) ) { | |
1182 | if ( elem.nodeType === 1 ) { | |
1183 | tmp.push( elem ); | |
63c88397 PS |
1184 | } |
1185 | } | |
63c88397 | 1186 | |
09bacfd7 | 1187 | return tmp; |
63c88397 | 1188 | } |
09bacfd7 PS |
1189 | return results; |
1190 | }; | |
63c88397 | 1191 | |
09bacfd7 PS |
1192 | // Class |
1193 | Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) { | |
f0c0c1ea | 1194 | if ( typeof context.getElementsByClassName !== "undefined" && documentIsHTML ) { |
09bacfd7 | 1195 | return context.getElementsByClassName( className ); |
63c88397 | 1196 | } |
09bacfd7 | 1197 | }; |
63c88397 | 1198 | |
09bacfd7 PS |
1199 | /* QSA/matchesSelector |
1200 | ---------------------------------------------------------------------- */ | |
63c88397 | 1201 | |
09bacfd7 | 1202 | // QSA and matchesSelector support |
63c88397 | 1203 | |
09bacfd7 PS |
1204 | // matchesSelector(:active) reports false when true (IE9/Opera 11.5) |
1205 | rbuggyMatches = []; | |
63c88397 | 1206 | |
09bacfd7 PS |
1207 | // qSa(:focus) reports false when true (Chrome 21) |
1208 | // We allow this because of a bug in IE8/9 that throws an error | |
1209 | // whenever `document.activeElement` is accessed on an iframe | |
1210 | // So, we allow :focus to pass through QSA all the time to avoid the IE error | |
1211 | // See http://bugs.jquery.com/ticket/13378 | |
1212 | rbuggyQSA = []; | |
63c88397 | 1213 | |
f0c0c1ea | 1214 | if ( (support.qsa = rnative.test( document.querySelectorAll )) ) { |
09bacfd7 PS |
1215 | // Build QSA regex |
1216 | // Regex strategy adopted from Diego Perini | |
1217 | assert(function( div ) { | |
1218 | // Select is set to empty string on purpose | |
1219 | // This is to test IE's treatment of not explicitly | |
1220 | // setting a boolean content attribute, | |
1221 | // since its presence should be enough | |
1222 | // http://bugs.jquery.com/ticket/12359 | |
c2260ade | 1223 | docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" + |
f0c0c1ea | 1224 | "<select id='" + expando + "-\r\\' msallowcapture=''>" + |
c2260ade | 1225 | "<option selected=''></option></select>"; |
fa71f84f | 1226 | |
5a53b77f | 1227 | // Support: IE8, Opera 11-12.16 |
fa71f84f | 1228 | // Nothing should be selected when empty strings follow ^= or $= or *= |
5a53b77f PS |
1229 | // The test attribute must be unknown in Opera but "safe" for WinRT |
1230 | // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section | |
c2260ade | 1231 | if ( div.querySelectorAll("[msallowcapture^='']").length ) { |
fa71f84f PŠ |
1232 | rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" ); |
1233 | } | |
63c88397 | 1234 | |
09bacfd7 PS |
1235 | // Support: IE8 |
1236 | // Boolean attributes and "value" are not treated correctly | |
1237 | if ( !div.querySelectorAll("[selected]").length ) { | |
1238 | rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" ); | |
1239 | } | |
63c88397 | 1240 | |
f0c0c1ea | 1241 | // Support: Chrome<29, Android<4.4, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.8+ |
c2260ade JO |
1242 | if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) { |
1243 | rbuggyQSA.push("~="); | |
1244 | } | |
1245 | ||
09bacfd7 PS |
1246 | // Webkit/Opera - :checked should return selected option elements |
1247 | // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked | |
1248 | // IE8 throws error here and will not see later tests | |
1249 | if ( !div.querySelectorAll(":checked").length ) { | |
1250 | rbuggyQSA.push(":checked"); | |
1251 | } | |
c2260ade JO |
1252 | |
1253 | // Support: Safari 8+, iOS 8+ | |
1254 | // https://bugs.webkit.org/show_bug.cgi?id=136851 | |
1255 | // In-page `selector#id sibing-combinator selector` fails | |
1256 | if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) { | |
1257 | rbuggyQSA.push(".#.+[+~]"); | |
1258 | } | |
09bacfd7 | 1259 | }); |
63c88397 | 1260 | |
09bacfd7 | 1261 | assert(function( div ) { |
09bacfd7 | 1262 | // Support: Windows 8 Native Apps |
fa71f84f | 1263 | // The type and name attributes are restricted during .innerHTML assignment |
f0c0c1ea | 1264 | var input = document.createElement("input"); |
09bacfd7 | 1265 | input.setAttribute( "type", "hidden" ); |
fa71f84f | 1266 | div.appendChild( input ).setAttribute( "name", "D" ); |
63c88397 | 1267 | |
fa71f84f PŠ |
1268 | // Support: IE8 |
1269 | // Enforce case-sensitivity of name attribute | |
1270 | if ( div.querySelectorAll("[name=d]").length ) { | |
1271 | rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" ); | |
09bacfd7 | 1272 | } |
63c88397 | 1273 | |
09bacfd7 PS |
1274 | // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled) |
1275 | // IE8 throws error here and will not see later tests | |
1276 | if ( !div.querySelectorAll(":enabled").length ) { | |
1277 | rbuggyQSA.push( ":enabled", ":disabled" ); | |
1278 | } | |
63c88397 | 1279 | |
09bacfd7 PS |
1280 | // Opera 10-11 does not throw on post-comma invalid pseudos |
1281 | div.querySelectorAll("*,:x"); | |
1282 | rbuggyQSA.push(",.*:"); | |
1283 | }); | |
1284 | } | |
63c88397 | 1285 | |
5a53b77f PS |
1286 | if ( (support.matchesSelector = rnative.test( (matches = docElem.matches || |
1287 | docElem.webkitMatchesSelector || | |
09bacfd7 PS |
1288 | docElem.mozMatchesSelector || |
1289 | docElem.oMatchesSelector || | |
1290 | docElem.msMatchesSelector) )) ) { | |
63c88397 | 1291 | |
09bacfd7 PS |
1292 | assert(function( div ) { |
1293 | // Check to see if it's possible to do matchesSelector | |
1294 | // on a disconnected node (IE 9) | |
1295 | support.disconnectedMatch = matches.call( div, "div" ); | |
63c88397 | 1296 | |
09bacfd7 PS |
1297 | // This should fail with an exception |
1298 | // Gecko does not error, returns false instead | |
1299 | matches.call( div, "[s!='']:x" ); | |
1300 | rbuggyMatches.push( "!=", pseudos ); | |
1301 | }); | |
63c88397 | 1302 | } |
63c88397 | 1303 | |
09bacfd7 PS |
1304 | rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") ); |
1305 | rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") ); | |
63c88397 | 1306 | |
09bacfd7 PS |
1307 | /* Contains |
1308 | ---------------------------------------------------------------------- */ | |
fa71f84f | 1309 | hasCompare = rnative.test( docElem.compareDocumentPosition ); |
63c88397 | 1310 | |
09bacfd7 | 1311 | // Element contains another |
f0c0c1ea | 1312 | // Purposefully self-exclusive |
09bacfd7 | 1313 | // As in, an element does not contain itself |
fa71f84f | 1314 | contains = hasCompare || rnative.test( docElem.contains ) ? |
09bacfd7 PS |
1315 | function( a, b ) { |
1316 | var adown = a.nodeType === 9 ? a.documentElement : a, | |
1317 | bup = b && b.parentNode; | |
1318 | return a === bup || !!( bup && bup.nodeType === 1 && ( | |
1319 | adown.contains ? | |
1320 | adown.contains( bup ) : | |
1321 | a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16 | |
1322 | )); | |
1323 | } : | |
1324 | function( a, b ) { | |
1325 | if ( b ) { | |
1326 | while ( (b = b.parentNode) ) { | |
1327 | if ( b === a ) { | |
1328 | return true; | |
63c88397 | 1329 | } |
63c88397 PS |
1330 | } |
1331 | } | |
09bacfd7 PS |
1332 | return false; |
1333 | }; | |
63c88397 | 1334 | |
09bacfd7 PS |
1335 | /* Sorting |
1336 | ---------------------------------------------------------------------- */ | |
63c88397 | 1337 | |
09bacfd7 | 1338 | // Document order sorting |
fa71f84f | 1339 | sortOrder = hasCompare ? |
09bacfd7 | 1340 | function( a, b ) { |
63c88397 | 1341 | |
09bacfd7 PS |
1342 | // Flag for duplicate removal |
1343 | if ( a === b ) { | |
1344 | hasDuplicate = true; | |
1345 | return 0; | |
1346 | } | |
63c88397 | 1347 | |
fa71f84f PŠ |
1348 | // Sort on method existence if only one input has compareDocumentPosition |
1349 | var compare = !a.compareDocumentPosition - !b.compareDocumentPosition; | |
09bacfd7 | 1350 | if ( compare ) { |
fa71f84f PŠ |
1351 | return compare; |
1352 | } | |
63c88397 | 1353 | |
fa71f84f PŠ |
1354 | // Calculate position if both inputs belong to the same document |
1355 | compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ? | |
1356 | a.compareDocumentPosition( b ) : | |
1357 | ||
1358 | // Otherwise we know they are disconnected | |
1359 | 1; | |
63c88397 | 1360 | |
fa71f84f PŠ |
1361 | // Disconnected nodes |
1362 | if ( compare & 1 || | |
1363 | (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) { | |
1364 | ||
1365 | // Choose the first element that is related to our preferred document | |
f0c0c1ea | 1366 | if ( a === document || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) { |
fa71f84f PŠ |
1367 | return -1; |
1368 | } | |
f0c0c1ea | 1369 | if ( b === document || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) { |
fa71f84f | 1370 | return 1; |
09bacfd7 | 1371 | } |
63c88397 | 1372 | |
fa71f84f PŠ |
1373 | // Maintain original order |
1374 | return sortInput ? | |
c2260ade | 1375 | ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) : |
fa71f84f | 1376 | 0; |
09bacfd7 | 1377 | } |
63c88397 | 1378 | |
fa71f84f | 1379 | return compare & 4 ? -1 : 1; |
09bacfd7 PS |
1380 | } : |
1381 | function( a, b ) { | |
fa71f84f PŠ |
1382 | // Exit early if the nodes are identical |
1383 | if ( a === b ) { | |
1384 | hasDuplicate = true; | |
1385 | return 0; | |
1386 | } | |
1387 | ||
09bacfd7 PS |
1388 | var cur, |
1389 | i = 0, | |
1390 | aup = a.parentNode, | |
1391 | bup = b.parentNode, | |
1392 | ap = [ a ], | |
1393 | bp = [ b ]; | |
63c88397 | 1394 | |
09bacfd7 | 1395 | // Parentless nodes are either documents or disconnected |
fa71f84f | 1396 | if ( !aup || !bup ) { |
f0c0c1ea SL |
1397 | return a === document ? -1 : |
1398 | b === document ? 1 : | |
09bacfd7 PS |
1399 | aup ? -1 : |
1400 | bup ? 1 : | |
1401 | sortInput ? | |
c2260ade | 1402 | ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) : |
09bacfd7 | 1403 | 0; |
63c88397 | 1404 | |
09bacfd7 PS |
1405 | // If the nodes are siblings, we can do a quick check |
1406 | } else if ( aup === bup ) { | |
1407 | return siblingCheck( a, b ); | |
63c88397 | 1408 | } |
63c88397 | 1409 | |
09bacfd7 PS |
1410 | // Otherwise we need full lists of their ancestors for comparison |
1411 | cur = a; | |
1412 | while ( (cur = cur.parentNode) ) { | |
1413 | ap.unshift( cur ); | |
63c88397 | 1414 | } |
09bacfd7 PS |
1415 | cur = b; |
1416 | while ( (cur = cur.parentNode) ) { | |
1417 | bp.unshift( cur ); | |
63c88397 | 1418 | } |
63c88397 | 1419 | |
09bacfd7 PS |
1420 | // Walk down the tree looking for a discrepancy |
1421 | while ( ap[i] === bp[i] ) { | |
1422 | i++; | |
63c88397 | 1423 | } |
63c88397 | 1424 | |
09bacfd7 PS |
1425 | return i ? |
1426 | // Do a sibling check if the nodes have a common ancestor | |
1427 | siblingCheck( ap[i], bp[i] ) : | |
63c88397 | 1428 | |
09bacfd7 PS |
1429 | // Otherwise nodes in our document sort first |
1430 | ap[i] === preferredDoc ? -1 : | |
1431 | bp[i] === preferredDoc ? 1 : | |
1432 | 0; | |
1433 | }; | |
63c88397 | 1434 | |
f0c0c1ea | 1435 | return document; |
09bacfd7 | 1436 | }; |
63c88397 | 1437 | |
09bacfd7 PS |
1438 | Sizzle.matches = function( expr, elements ) { |
1439 | return Sizzle( expr, null, null, elements ); | |
1440 | }; | |
63c88397 | 1441 | |
09bacfd7 PS |
1442 | Sizzle.matchesSelector = function( elem, expr ) { |
1443 | // Set document vars if needed | |
1444 | if ( ( elem.ownerDocument || elem ) !== document ) { | |
1445 | setDocument( elem ); | |
1446 | } | |
63c88397 | 1447 | |
09bacfd7 PS |
1448 | // Make sure that attribute selectors are quoted |
1449 | expr = expr.replace( rattributeQuotes, "='$1']" ); | |
63c88397 | 1450 | |
09bacfd7 | 1451 | if ( support.matchesSelector && documentIsHTML && |
f0c0c1ea | 1452 | !compilerCache[ expr + " " ] && |
09bacfd7 PS |
1453 | ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) && |
1454 | ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) { | |
63c88397 | 1455 | |
09bacfd7 PS |
1456 | try { |
1457 | var ret = matches.call( elem, expr ); | |
1458 | ||
1459 | // IE 9's matchesSelector returns false on disconnected nodes | |
1460 | if ( ret || support.disconnectedMatch || | |
1461 | // As well, disconnected nodes are said to be in a document | |
1462 | // fragment in IE 9 | |
1463 | elem.document && elem.document.nodeType !== 11 ) { | |
1464 | return ret; | |
1465 | } | |
c2260ade | 1466 | } catch (e) {} |
63c88397 | 1467 | } |
63c88397 | 1468 | |
5a53b77f | 1469 | return Sizzle( expr, document, null, [ elem ] ).length > 0; |
09bacfd7 | 1470 | }; |
63c88397 | 1471 | |
09bacfd7 PS |
1472 | Sizzle.contains = function( context, elem ) { |
1473 | // Set document vars if needed | |
1474 | if ( ( context.ownerDocument || context ) !== document ) { | |
1475 | setDocument( context ); | |
1476 | } | |
1477 | return contains( context, elem ); | |
1478 | }; | |
63c88397 | 1479 | |
09bacfd7 PS |
1480 | Sizzle.attr = function( elem, name ) { |
1481 | // Set document vars if needed | |
1482 | if ( ( elem.ownerDocument || elem ) !== document ) { | |
1483 | setDocument( elem ); | |
1484 | } | |
63c88397 | 1485 | |
09bacfd7 PS |
1486 | var fn = Expr.attrHandle[ name.toLowerCase() ], |
1487 | // Don't get fooled by Object.prototype properties (jQuery #13807) | |
1488 | val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ? | |
1489 | fn( elem, name, !documentIsHTML ) : | |
1490 | undefined; | |
63c88397 | 1491 | |
fa71f84f PŠ |
1492 | return val !== undefined ? |
1493 | val : | |
09bacfd7 PS |
1494 | support.attributes || !documentIsHTML ? |
1495 | elem.getAttribute( name ) : | |
1496 | (val = elem.getAttributeNode(name)) && val.specified ? | |
1497 | val.value : | |
fa71f84f | 1498 | null; |
09bacfd7 | 1499 | }; |
63c88397 | 1500 | |
09bacfd7 PS |
1501 | Sizzle.error = function( msg ) { |
1502 | throw new Error( "Syntax error, unrecognized expression: " + msg ); | |
1503 | }; | |
63c88397 | 1504 | |
09bacfd7 PS |
1505 | /** |
1506 | * Document sorting and removing duplicates | |
1507 | * @param {ArrayLike} results | |
1508 | */ | |
1509 | Sizzle.uniqueSort = function( results ) { | |
1510 | var elem, | |
1511 | duplicates = [], | |
1512 | j = 0, | |
1513 | i = 0; | |
63c88397 | 1514 | |
09bacfd7 PS |
1515 | // Unless we *know* we can detect duplicates, assume their presence |
1516 | hasDuplicate = !support.detectDuplicates; | |
1517 | sortInput = !support.sortStable && results.slice( 0 ); | |
1518 | results.sort( sortOrder ); | |
63c88397 | 1519 | |
09bacfd7 PS |
1520 | if ( hasDuplicate ) { |
1521 | while ( (elem = results[i++]) ) { | |
1522 | if ( elem === results[ i ] ) { | |
1523 | j = duplicates.push( i ); | |
63c88397 PS |
1524 | } |
1525 | } | |
09bacfd7 PS |
1526 | while ( j-- ) { |
1527 | results.splice( duplicates[ j ], 1 ); | |
1528 | } | |
63c88397 | 1529 | } |
63c88397 | 1530 | |
fa71f84f PŠ |
1531 | // Clear input after sorting to release objects |
1532 | // See https://github.com/jquery/sizzle/pull/225 | |
1533 | sortInput = null; | |
1534 | ||
09bacfd7 PS |
1535 | return results; |
1536 | }; | |
63c88397 | 1537 | |
09bacfd7 PS |
1538 | /** |
1539 | * Utility function for retrieving the text value of an array of DOM nodes | |
1540 | * @param {Array|Element} elem | |
1541 | */ | |
1542 | getText = Sizzle.getText = function( elem ) { | |
1543 | var node, | |
1544 | ret = "", | |
1545 | i = 0, | |
1546 | nodeType = elem.nodeType; | |
63c88397 | 1547 | |
09bacfd7 PS |
1548 | if ( !nodeType ) { |
1549 | // If no nodeType, this is expected to be an array | |
fa71f84f | 1550 | while ( (node = elem[i++]) ) { |
09bacfd7 PS |
1551 | // Do not traverse comment nodes |
1552 | ret += getText( node ); | |
1553 | } | |
1554 | } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) { | |
1555 | // Use textContent for elements | |
fa71f84f | 1556 | // innerText usage removed for consistency of new lines (jQuery #11153) |
09bacfd7 PS |
1557 | if ( typeof elem.textContent === "string" ) { |
1558 | return elem.textContent; | |
1559 | } else { | |
1560 | // Traverse its children | |
1561 | for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { | |
1562 | ret += getText( elem ); | |
1563 | } | |
1564 | } | |
1565 | } else if ( nodeType === 3 || nodeType === 4 ) { | |
1566 | return elem.nodeValue; | |
1567 | } | |
1568 | // Do not include comment or processing instruction nodes | |
63c88397 | 1569 | |
09bacfd7 PS |
1570 | return ret; |
1571 | }; | |
63c88397 | 1572 | |
09bacfd7 | 1573 | Expr = Sizzle.selectors = { |
63c88397 | 1574 | |
09bacfd7 PS |
1575 | // Can be adjusted by the user |
1576 | cacheLength: 50, | |
63c88397 | 1577 | |
09bacfd7 | 1578 | createPseudo: markFunction, |
63c88397 | 1579 | |
09bacfd7 | 1580 | match: matchExpr, |
63c88397 | 1581 | |
09bacfd7 | 1582 | attrHandle: {}, |
63c88397 | 1583 | |
09bacfd7 | 1584 | find: {}, |
63c88397 | 1585 | |
09bacfd7 PS |
1586 | relative: { |
1587 | ">": { dir: "parentNode", first: true }, | |
1588 | " ": { dir: "parentNode" }, | |
1589 | "+": { dir: "previousSibling", first: true }, | |
1590 | "~": { dir: "previousSibling" } | |
63c88397 PS |
1591 | }, |
1592 | ||
09bacfd7 PS |
1593 | preFilter: { |
1594 | "ATTR": function( match ) { | |
1595 | match[1] = match[1].replace( runescape, funescape ); | |
63c88397 | 1596 | |
09bacfd7 | 1597 | // Move the given value to match[3] whether quoted or unquoted |
5a53b77f | 1598 | match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape ); |
63c88397 | 1599 | |
09bacfd7 PS |
1600 | if ( match[2] === "~=" ) { |
1601 | match[3] = " " + match[3] + " "; | |
1602 | } | |
63c88397 | 1603 | |
09bacfd7 PS |
1604 | return match.slice( 0, 4 ); |
1605 | }, | |
63c88397 | 1606 | |
09bacfd7 PS |
1607 | "CHILD": function( match ) { |
1608 | /* matches from matchExpr["CHILD"] | |
1609 | 1 type (only|nth|...) | |
1610 | 2 what (child|of-type) | |
1611 | 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...) | |
1612 | 4 xn-component of xn+y argument ([+-]?\d*n|) | |
1613 | 5 sign of xn-component | |
1614 | 6 x of xn-component | |
1615 | 7 sign of y-component | |
1616 | 8 y of y-component | |
1617 | */ | |
1618 | match[1] = match[1].toLowerCase(); | |
63c88397 | 1619 | |
09bacfd7 PS |
1620 | if ( match[1].slice( 0, 3 ) === "nth" ) { |
1621 | // nth-* requires argument | |
1622 | if ( !match[3] ) { | |
1623 | Sizzle.error( match[0] ); | |
63c88397 PS |
1624 | } |
1625 | ||
09bacfd7 PS |
1626 | // numeric x and y parameters for Expr.filter.CHILD |
1627 | // remember that false/true cast respectively to 0/1 | |
1628 | match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) ); | |
1629 | match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" ); | |
63c88397 | 1630 | |
09bacfd7 PS |
1631 | // other types prohibit arguments |
1632 | } else if ( match[3] ) { | |
1633 | Sizzle.error( match[0] ); | |
63c88397 | 1634 | } |
63c88397 | 1635 | |
09bacfd7 PS |
1636 | return match; |
1637 | }, | |
63c88397 | 1638 | |
09bacfd7 PS |
1639 | "PSEUDO": function( match ) { |
1640 | var excess, | |
5a53b77f | 1641 | unquoted = !match[6] && match[2]; |
63c88397 | 1642 | |
09bacfd7 PS |
1643 | if ( matchExpr["CHILD"].test( match[0] ) ) { |
1644 | return null; | |
1645 | } | |
63c88397 | 1646 | |
09bacfd7 | 1647 | // Accept quoted arguments as-is |
5a53b77f PS |
1648 | if ( match[3] ) { |
1649 | match[2] = match[4] || match[5] || ""; | |
63c88397 | 1650 | |
09bacfd7 PS |
1651 | // Strip excess characters from unquoted arguments |
1652 | } else if ( unquoted && rpseudo.test( unquoted ) && | |
1653 | // Get excess from tokenize (recursively) | |
1654 | (excess = tokenize( unquoted, true )) && | |
1655 | // advance to the next closing parenthesis | |
1656 | (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) { | |
63c88397 | 1657 | |
09bacfd7 PS |
1658 | // excess is a negative index |
1659 | match[0] = match[0].slice( 0, excess ); | |
1660 | match[2] = unquoted.slice( 0, excess ); | |
63c88397 PS |
1661 | } |
1662 | ||
09bacfd7 PS |
1663 | // Return only captures needed by the pseudo filter method (type and argument) |
1664 | return match.slice( 0, 3 ); | |
63c88397 | 1665 | } |
09bacfd7 | 1666 | }, |
63c88397 | 1667 | |
09bacfd7 | 1668 | filter: { |
63c88397 | 1669 | |
09bacfd7 PS |
1670 | "TAG": function( nodeNameSelector ) { |
1671 | var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase(); | |
1672 | return nodeNameSelector === "*" ? | |
1673 | function() { return true; } : | |
1674 | function( elem ) { | |
1675 | return elem.nodeName && elem.nodeName.toLowerCase() === nodeName; | |
1676 | }; | |
1677 | }, | |
63c88397 | 1678 | |
09bacfd7 PS |
1679 | "CLASS": function( className ) { |
1680 | var pattern = classCache[ className + " " ]; | |
63c88397 | 1681 | |
09bacfd7 PS |
1682 | return pattern || |
1683 | (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) && | |
1684 | classCache( className, function( elem ) { | |
c2260ade | 1685 | return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" ); |
63c88397 | 1686 | }); |
09bacfd7 | 1687 | }, |
63c88397 | 1688 | |
09bacfd7 PS |
1689 | "ATTR": function( name, operator, check ) { |
1690 | return function( elem ) { | |
1691 | var result = Sizzle.attr( elem, name ); | |
63c88397 | 1692 | |
09bacfd7 PS |
1693 | if ( result == null ) { |
1694 | return operator === "!="; | |
1695 | } | |
1696 | if ( !operator ) { | |
1697 | return true; | |
1698 | } | |
63c88397 | 1699 | |
09bacfd7 PS |
1700 | result += ""; |
1701 | ||
1702 | return operator === "=" ? result === check : | |
1703 | operator === "!=" ? result !== check : | |
1704 | operator === "^=" ? check && result.indexOf( check ) === 0 : | |
1705 | operator === "*=" ? check && result.indexOf( check ) > -1 : | |
1706 | operator === "$=" ? check && result.slice( -check.length ) === check : | |
c2260ade | 1707 | operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 : |
09bacfd7 PS |
1708 | operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" : |
1709 | false; | |
1710 | }; | |
63c88397 | 1711 | }, |
63c88397 | 1712 | |
09bacfd7 PS |
1713 | "CHILD": function( type, what, argument, first, last ) { |
1714 | var simple = type.slice( 0, 3 ) !== "nth", | |
1715 | forward = type.slice( -4 ) !== "last", | |
1716 | ofType = what === "of-type"; | |
63c88397 | 1717 | |
09bacfd7 | 1718 | return first === 1 && last === 0 ? |
63c88397 | 1719 | |
09bacfd7 PS |
1720 | // Shortcut for :nth-*(n) |
1721 | function( elem ) { | |
1722 | return !!elem.parentNode; | |
1723 | } : | |
63c88397 | 1724 | |
09bacfd7 | 1725 | function( elem, context, xml ) { |
f0c0c1ea | 1726 | var cache, uniqueCache, outerCache, node, nodeIndex, start, |
09bacfd7 PS |
1727 | dir = simple !== forward ? "nextSibling" : "previousSibling", |
1728 | parent = elem.parentNode, | |
1729 | name = ofType && elem.nodeName.toLowerCase(), | |
f0c0c1ea SL |
1730 | useCache = !xml && !ofType, |
1731 | diff = false; | |
63c88397 | 1732 | |
09bacfd7 | 1733 | if ( parent ) { |
63c88397 | 1734 | |
09bacfd7 PS |
1735 | // :(first|last|only)-(child|of-type) |
1736 | if ( simple ) { | |
1737 | while ( dir ) { | |
1738 | node = elem; | |
1739 | while ( (node = node[ dir ]) ) { | |
f0c0c1ea SL |
1740 | if ( ofType ? |
1741 | node.nodeName.toLowerCase() === name : | |
1742 | node.nodeType === 1 ) { | |
1743 | ||
09bacfd7 PS |
1744 | return false; |
1745 | } | |
1746 | } | |
1747 | // Reverse direction for :only-* (if we haven't yet done so) | |
1748 | start = dir = type === "only" && !start && "nextSibling"; | |
1749 | } | |
1750 | return true; | |
1751 | } | |
63c88397 | 1752 | |
09bacfd7 | 1753 | start = [ forward ? parent.firstChild : parent.lastChild ]; |
63c88397 | 1754 | |
09bacfd7 PS |
1755 | // non-xml :nth-child(...) stores cache data on `parent` |
1756 | if ( forward && useCache ) { | |
f0c0c1ea | 1757 | |
09bacfd7 | 1758 | // Seek `elem` from a previously-cached index |
f0c0c1ea SL |
1759 | |
1760 | // ...in a gzip-friendly way | |
1761 | node = parent; | |
1762 | outerCache = node[ expando ] || (node[ expando ] = {}); | |
1763 | ||
1764 | // Support: IE <9 only | |
1765 | // Defend against cloned attroperties (jQuery gh-1709) | |
1766 | uniqueCache = outerCache[ node.uniqueID ] || | |
1767 | (outerCache[ node.uniqueID ] = {}); | |
1768 | ||
1769 | cache = uniqueCache[ type ] || []; | |
1770 | nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ]; | |
1771 | diff = nodeIndex && cache[ 2 ]; | |
09bacfd7 | 1772 | node = nodeIndex && parent.childNodes[ nodeIndex ]; |
63c88397 | 1773 | |
09bacfd7 | 1774 | while ( (node = ++nodeIndex && node && node[ dir ] || |
63c88397 | 1775 | |
09bacfd7 PS |
1776 | // Fallback to seeking `elem` from the start |
1777 | (diff = nodeIndex = 0) || start.pop()) ) { | |
63c88397 | 1778 | |
09bacfd7 PS |
1779 | // When found, cache indexes on `parent` and break |
1780 | if ( node.nodeType === 1 && ++diff && node === elem ) { | |
f0c0c1ea | 1781 | uniqueCache[ type ] = [ dirruns, nodeIndex, diff ]; |
09bacfd7 PS |
1782 | break; |
1783 | } | |
1784 | } | |
63c88397 | 1785 | |
09bacfd7 | 1786 | } else { |
f0c0c1ea SL |
1787 | // Use previously-cached element index if available |
1788 | if ( useCache ) { | |
1789 | // ...in a gzip-friendly way | |
1790 | node = elem; | |
1791 | outerCache = node[ expando ] || (node[ expando ] = {}); | |
63c88397 | 1792 | |
f0c0c1ea SL |
1793 | // Support: IE <9 only |
1794 | // Defend against cloned attroperties (jQuery gh-1709) | |
1795 | uniqueCache = outerCache[ node.uniqueID ] || | |
1796 | (outerCache[ node.uniqueID ] = {}); | |
63c88397 | 1797 | |
f0c0c1ea SL |
1798 | cache = uniqueCache[ type ] || []; |
1799 | nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ]; | |
1800 | diff = nodeIndex; | |
1801 | } | |
1802 | ||
1803 | // xml :nth-child(...) | |
1804 | // or :nth-last-child(...) or :nth(-last)?-of-type(...) | |
1805 | if ( diff === false ) { | |
1806 | // Use the same loop as above to seek `elem` from the start | |
1807 | while ( (node = ++nodeIndex && node && node[ dir ] || | |
1808 | (diff = nodeIndex = 0) || start.pop()) ) { | |
1809 | ||
1810 | if ( ( ofType ? | |
1811 | node.nodeName.toLowerCase() === name : | |
1812 | node.nodeType === 1 ) && | |
1813 | ++diff ) { | |
1814 | ||
1815 | // Cache the index of each encountered element | |
1816 | if ( useCache ) { | |
1817 | outerCache = node[ expando ] || (node[ expando ] = {}); | |
1818 | ||
1819 | // Support: IE <9 only | |
1820 | // Defend against cloned attroperties (jQuery gh-1709) | |
1821 | uniqueCache = outerCache[ node.uniqueID ] || | |
1822 | (outerCache[ node.uniqueID ] = {}); | |
1823 | ||
1824 | uniqueCache[ type ] = [ dirruns, diff ]; | |
1825 | } | |
1826 | ||
1827 | if ( node === elem ) { | |
1828 | break; | |
1829 | } | |
09bacfd7 PS |
1830 | } |
1831 | } | |
1832 | } | |
1833 | } | |
63c88397 | 1834 | |
09bacfd7 PS |
1835 | // Incorporate the offset, then check against cycle size |
1836 | diff -= last; | |
1837 | return diff === first || ( diff % first === 0 && diff / first >= 0 ); | |
1838 | } | |
1839 | }; | |
1840 | }, | |
63c88397 | 1841 | |
09bacfd7 PS |
1842 | "PSEUDO": function( pseudo, argument ) { |
1843 | // pseudo-class names are case-insensitive | |
1844 | // http://www.w3.org/TR/selectors/#pseudo-classes | |
1845 | // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters | |
1846 | // Remember that setFilters inherits from pseudos | |
1847 | var args, | |
1848 | fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] || | |
1849 | Sizzle.error( "unsupported pseudo: " + pseudo ); | |
63c88397 | 1850 | |
09bacfd7 PS |
1851 | // The user may use createPseudo to indicate that |
1852 | // arguments are needed to create the filter function | |
1853 | // just as Sizzle does | |
1854 | if ( fn[ expando ] ) { | |
1855 | return fn( argument ); | |
63c88397 PS |
1856 | } |
1857 | ||
09bacfd7 PS |
1858 | // But maintain support for old signatures |
1859 | if ( fn.length > 1 ) { | |
1860 | args = [ pseudo, pseudo, "", argument ]; | |
1861 | return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ? | |
1862 | markFunction(function( seed, matches ) { | |
1863 | var idx, | |
1864 | matched = fn( seed, argument ), | |
1865 | i = matched.length; | |
1866 | while ( i-- ) { | |
c2260ade | 1867 | idx = indexOf( seed, matched[i] ); |
09bacfd7 PS |
1868 | seed[ idx ] = !( matches[ idx ] = matched[i] ); |
1869 | } | |
1870 | }) : | |
1871 | function( elem ) { | |
1872 | return fn( elem, 0, args ); | |
1873 | }; | |
63c88397 PS |
1874 | } |
1875 | ||
09bacfd7 | 1876 | return fn; |
63c88397 PS |
1877 | } |
1878 | }, | |
1879 | ||
09bacfd7 PS |
1880 | pseudos: { |
1881 | // Potentially complex pseudos | |
1882 | "not": markFunction(function( selector ) { | |
1883 | // Trim the selector passed to compile | |
1884 | // to avoid treating leading and trailing | |
1885 | // spaces as combinators | |
1886 | var input = [], | |
1887 | results = [], | |
1888 | matcher = compile( selector.replace( rtrim, "$1" ) ); | |
63c88397 | 1889 | |
09bacfd7 PS |
1890 | return matcher[ expando ] ? |
1891 | markFunction(function( seed, matches, context, xml ) { | |
1892 | var elem, | |
1893 | unmatched = matcher( seed, null, xml, [] ), | |
1894 | i = seed.length; | |
63c88397 | 1895 | |
09bacfd7 PS |
1896 | // Match elements unmatched by `matcher` |
1897 | while ( i-- ) { | |
1898 | if ( (elem = unmatched[i]) ) { | |
1899 | seed[i] = !(matches[i] = elem); | |
1900 | } | |
63c88397 | 1901 | } |
09bacfd7 PS |
1902 | }) : |
1903 | function( elem, context, xml ) { | |
1904 | input[0] = elem; | |
1905 | matcher( input, null, xml, results ); | |
c2260ade JO |
1906 | // Don't keep the element (issue #299) |
1907 | input[0] = null; | |
09bacfd7 PS |
1908 | return !results.pop(); |
1909 | }; | |
1910 | }), | |
63c88397 | 1911 | |
09bacfd7 PS |
1912 | "has": markFunction(function( selector ) { |
1913 | return function( elem ) { | |
1914 | return Sizzle( selector, elem ).length > 0; | |
1915 | }; | |
1916 | }), | |
63c88397 | 1917 | |
09bacfd7 | 1918 | "contains": markFunction(function( text ) { |
c2260ade | 1919 | text = text.replace( runescape, funescape ); |
09bacfd7 PS |
1920 | return function( elem ) { |
1921 | return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1; | |
1922 | }; | |
1923 | }), | |
1924 | ||
1925 | // "Whether an element is represented by a :lang() selector | |
1926 | // is based solely on the element's language value | |
1927 | // being equal to the identifier C, | |
1928 | // or beginning with the identifier C immediately followed by "-". | |
1929 | // The matching of C against the element's language value is performed case-insensitively. | |
1930 | // The identifier C does not have to be a valid language name." | |
1931 | // http://www.w3.org/TR/selectors/#lang-pseudo | |
1932 | "lang": markFunction( function( lang ) { | |
1933 | // lang value must be a valid identifier | |
1934 | if ( !ridentifier.test(lang || "") ) { | |
1935 | Sizzle.error( "unsupported lang: " + lang ); | |
63c88397 | 1936 | } |
09bacfd7 PS |
1937 | lang = lang.replace( runescape, funescape ).toLowerCase(); |
1938 | return function( elem ) { | |
1939 | var elemLang; | |
1940 | do { | |
1941 | if ( (elemLang = documentIsHTML ? | |
1942 | elem.lang : | |
1943 | elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) { | |
63c88397 | 1944 | |
09bacfd7 PS |
1945 | elemLang = elemLang.toLowerCase(); |
1946 | return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0; | |
63c88397 | 1947 | } |
09bacfd7 PS |
1948 | } while ( (elem = elem.parentNode) && elem.nodeType === 1 ); |
1949 | return false; | |
1950 | }; | |
1951 | }), | |
63c88397 | 1952 | |
09bacfd7 PS |
1953 | // Miscellaneous |
1954 | "target": function( elem ) { | |
1955 | var hash = window.location && window.location.hash; | |
1956 | return hash && hash.slice( 1 ) === elem.id; | |
1957 | }, | |
63c88397 | 1958 | |
09bacfd7 PS |
1959 | "root": function( elem ) { |
1960 | return elem === docElem; | |
1961 | }, | |
63c88397 | 1962 | |
09bacfd7 PS |
1963 | "focus": function( elem ) { |
1964 | return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex); | |
1965 | }, | |
63c88397 | 1966 | |
09bacfd7 PS |
1967 | // Boolean properties |
1968 | "enabled": function( elem ) { | |
1969 | return elem.disabled === false; | |
1970 | }, | |
63c88397 | 1971 | |
09bacfd7 PS |
1972 | "disabled": function( elem ) { |
1973 | return elem.disabled === true; | |
1974 | }, | |
63c88397 | 1975 | |
09bacfd7 PS |
1976 | "checked": function( elem ) { |
1977 | // In CSS3, :checked should return both checked and selected elements | |
1978 | // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked | |
1979 | var nodeName = elem.nodeName.toLowerCase(); | |
1980 | return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected); | |
1981 | }, | |
63c88397 | 1982 | |
09bacfd7 PS |
1983 | "selected": function( elem ) { |
1984 | // Accessing this property makes selected-by-default | |
1985 | // options in Safari work properly | |
1986 | if ( elem.parentNode ) { | |
1987 | elem.parentNode.selectedIndex; | |
63c88397 PS |
1988 | } |
1989 | ||
09bacfd7 PS |
1990 | return elem.selected === true; |
1991 | }, | |
63c88397 | 1992 | |
09bacfd7 PS |
1993 | // Contents |
1994 | "empty": function( elem ) { | |
1995 | // http://www.w3.org/TR/selectors/#empty-pseudo | |
fa71f84f PŠ |
1996 | // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5), |
1997 | // but not by others (comment: 8; processing instruction: 7; etc.) | |
1998 | // nodeType < 6 works because attributes (2) do not appear as children | |
09bacfd7 | 1999 | for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { |
fa71f84f | 2000 | if ( elem.nodeType < 6 ) { |
09bacfd7 PS |
2001 | return false; |
2002 | } | |
63c88397 | 2003 | } |
09bacfd7 PS |
2004 | return true; |
2005 | }, | |
63c88397 | 2006 | |
09bacfd7 PS |
2007 | "parent": function( elem ) { |
2008 | return !Expr.pseudos["empty"]( elem ); | |
2009 | }, | |
63c88397 | 2010 | |
09bacfd7 PS |
2011 | // Element/input types |
2012 | "header": function( elem ) { | |
2013 | return rheader.test( elem.nodeName ); | |
2014 | }, | |
63c88397 | 2015 | |
09bacfd7 PS |
2016 | "input": function( elem ) { |
2017 | return rinputs.test( elem.nodeName ); | |
63c88397 | 2018 | }, |
63c88397 | 2019 | |
09bacfd7 PS |
2020 | "button": function( elem ) { |
2021 | var name = elem.nodeName.toLowerCase(); | |
2022 | return name === "input" && elem.type === "button" || name === "button"; | |
2023 | }, | |
63c88397 | 2024 | |
09bacfd7 PS |
2025 | "text": function( elem ) { |
2026 | var attr; | |
09bacfd7 PS |
2027 | return elem.nodeName.toLowerCase() === "input" && |
2028 | elem.type === "text" && | |
fa71f84f PŠ |
2029 | |
2030 | // Support: IE<8 | |
2031 | // New HTML5 attribute values (e.g., "search") appear with elem.type === "text" | |
2032 | ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" ); | |
63c88397 | 2033 | }, |
63c88397 | 2034 | |
09bacfd7 PS |
2035 | // Position-in-collection |
2036 | "first": createPositionalPseudo(function() { | |
2037 | return [ 0 ]; | |
2038 | }), | |
63c88397 | 2039 | |
09bacfd7 PS |
2040 | "last": createPositionalPseudo(function( matchIndexes, length ) { |
2041 | return [ length - 1 ]; | |
2042 | }), | |
63c88397 | 2043 | |
09bacfd7 PS |
2044 | "eq": createPositionalPseudo(function( matchIndexes, length, argument ) { |
2045 | return [ argument < 0 ? argument + length : argument ]; | |
2046 | }), | |
63c88397 | 2047 | |
09bacfd7 PS |
2048 | "even": createPositionalPseudo(function( matchIndexes, length ) { |
2049 | var i = 0; | |
2050 | for ( ; i < length; i += 2 ) { | |
2051 | matchIndexes.push( i ); | |
63c88397 | 2052 | } |
09bacfd7 PS |
2053 | return matchIndexes; |
2054 | }), | |
63c88397 | 2055 | |
09bacfd7 PS |
2056 | "odd": createPositionalPseudo(function( matchIndexes, length ) { |
2057 | var i = 1; | |
2058 | for ( ; i < length; i += 2 ) { | |
2059 | matchIndexes.push( i ); | |
2060 | } | |
2061 | return matchIndexes; | |
2062 | }), | |
63c88397 | 2063 | |
09bacfd7 PS |
2064 | "lt": createPositionalPseudo(function( matchIndexes, length, argument ) { |
2065 | var i = argument < 0 ? argument + length : argument; | |
2066 | for ( ; --i >= 0; ) { | |
2067 | matchIndexes.push( i ); | |
63c88397 | 2068 | } |
09bacfd7 PS |
2069 | return matchIndexes; |
2070 | }), | |
63c88397 | 2071 | |
09bacfd7 PS |
2072 | "gt": createPositionalPseudo(function( matchIndexes, length, argument ) { |
2073 | var i = argument < 0 ? argument + length : argument; | |
2074 | for ( ; ++i < length; ) { | |
2075 | matchIndexes.push( i ); | |
63c88397 | 2076 | } |
09bacfd7 PS |
2077 | return matchIndexes; |
2078 | }) | |
2079 | } | |
2080 | }; | |
63c88397 | 2081 | |
09bacfd7 PS |
2082 | Expr.pseudos["nth"] = Expr.pseudos["eq"]; |
2083 | ||
2084 | // Add button/input type pseudos | |
2085 | for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) { | |
2086 | Expr.pseudos[ i ] = createInputPseudo( i ); | |
2087 | } | |
2088 | for ( i in { submit: true, reset: true } ) { | |
2089 | Expr.pseudos[ i ] = createButtonPseudo( i ); | |
63c88397 PS |
2090 | } |
2091 | ||
09bacfd7 PS |
2092 | // Easy API for creating new setFilters |
2093 | function setFilters() {} | |
2094 | setFilters.prototype = Expr.filters = Expr.pseudos; | |
2095 | Expr.setFilters = new setFilters(); | |
63c88397 | 2096 | |
5a53b77f | 2097 | tokenize = Sizzle.tokenize = function( selector, parseOnly ) { |
09bacfd7 PS |
2098 | var matched, match, tokens, type, |
2099 | soFar, groups, preFilters, | |
2100 | cached = tokenCache[ selector + " " ]; | |
63c88397 | 2101 | |
09bacfd7 PS |
2102 | if ( cached ) { |
2103 | return parseOnly ? 0 : cached.slice( 0 ); | |
2104 | } | |
63c88397 | 2105 | |
09bacfd7 PS |
2106 | soFar = selector; |
2107 | groups = []; | |
2108 | preFilters = Expr.preFilter; | |
63c88397 | 2109 | |
09bacfd7 PS |
2110 | while ( soFar ) { |
2111 | ||
2112 | // Comma and first run | |
2113 | if ( !matched || (match = rcomma.exec( soFar )) ) { | |
2114 | if ( match ) { | |
2115 | // Don't consume trailing commas as valid | |
2116 | soFar = soFar.slice( match[0].length ) || soFar; | |
63c88397 | 2117 | } |
fa71f84f | 2118 | groups.push( (tokens = []) ); |
63c88397 | 2119 | } |
63c88397 | 2120 | |
09bacfd7 | 2121 | matched = false; |
63c88397 | 2122 | |
09bacfd7 PS |
2123 | // Combinators |
2124 | if ( (match = rcombinators.exec( soFar )) ) { | |
2125 | matched = match.shift(); | |
2126 | tokens.push({ | |
2127 | value: matched, | |
2128 | // Cast descendant combinators to space | |
2129 | type: match[0].replace( rtrim, " " ) | |
2130 | }); | |
2131 | soFar = soFar.slice( matched.length ); | |
2132 | } | |
63c88397 | 2133 | |
09bacfd7 PS |
2134 | // Filters |
2135 | for ( type in Expr.filter ) { | |
2136 | if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] || | |
2137 | (match = preFilters[ type ]( match ))) ) { | |
2138 | matched = match.shift(); | |
2139 | tokens.push({ | |
2140 | value: matched, | |
2141 | type: type, | |
2142 | matches: match | |
2143 | }); | |
2144 | soFar = soFar.slice( matched.length ); | |
2145 | } | |
63c88397 PS |
2146 | } |
2147 | ||
09bacfd7 PS |
2148 | if ( !matched ) { |
2149 | break; | |
63c88397 | 2150 | } |
09bacfd7 | 2151 | } |
63c88397 | 2152 | |
09bacfd7 PS |
2153 | // Return the length of the invalid excess |
2154 | // if we're just parsing | |
2155 | // Otherwise, throw an error or return tokens | |
2156 | return parseOnly ? | |
2157 | soFar.length : | |
2158 | soFar ? | |
2159 | Sizzle.error( selector ) : | |
2160 | // Cache the tokens | |
2161 | tokenCache( selector, groups ).slice( 0 ); | |
5a53b77f | 2162 | }; |
63c88397 | 2163 | |
09bacfd7 PS |
2164 | function toSelector( tokens ) { |
2165 | var i = 0, | |
2166 | len = tokens.length, | |
2167 | selector = ""; | |
2168 | for ( ; i < len; i++ ) { | |
2169 | selector += tokens[i].value; | |
2170 | } | |
2171 | return selector; | |
2172 | } | |
63c88397 | 2173 | |
09bacfd7 PS |
2174 | function addCombinator( matcher, combinator, base ) { |
2175 | var dir = combinator.dir, | |
2176 | checkNonElements = base && dir === "parentNode", | |
2177 | doneName = done++; | |
63c88397 | 2178 | |
09bacfd7 PS |
2179 | return combinator.first ? |
2180 | // Check against closest ancestor/preceding element | |
2181 | function( elem, context, xml ) { | |
2182 | while ( (elem = elem[ dir ]) ) { | |
2183 | if ( elem.nodeType === 1 || checkNonElements ) { | |
2184 | return matcher( elem, context, xml ); | |
2185 | } | |
2186 | } | |
2187 | } : | |
63c88397 | 2188 | |
09bacfd7 PS |
2189 | // Check against all ancestor/preceding elements |
2190 | function( elem, context, xml ) { | |
f0c0c1ea | 2191 | var oldCache, uniqueCache, outerCache, |
fa71f84f | 2192 | newCache = [ dirruns, doneName ]; |
63c88397 | 2193 | |
f0c0c1ea | 2194 | // We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching |
09bacfd7 PS |
2195 | if ( xml ) { |
2196 | while ( (elem = elem[ dir ]) ) { | |
2197 | if ( elem.nodeType === 1 || checkNonElements ) { | |
2198 | if ( matcher( elem, context, xml ) ) { | |
2199 | return true; | |
2200 | } | |
2201 | } | |
2202 | } | |
2203 | } else { | |
2204 | while ( (elem = elem[ dir ]) ) { | |
2205 | if ( elem.nodeType === 1 || checkNonElements ) { | |
2206 | outerCache = elem[ expando ] || (elem[ expando ] = {}); | |
f0c0c1ea SL |
2207 | |
2208 | // Support: IE <9 only | |
2209 | // Defend against cloned attroperties (jQuery gh-1709) | |
2210 | uniqueCache = outerCache[ elem.uniqueID ] || (outerCache[ elem.uniqueID ] = {}); | |
2211 | ||
2212 | if ( (oldCache = uniqueCache[ dir ]) && | |
fa71f84f PŠ |
2213 | oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) { |
2214 | ||
2215 | // Assign to newCache so results back-propagate to previous elements | |
2216 | return (newCache[ 2 ] = oldCache[ 2 ]); | |
09bacfd7 | 2217 | } else { |
fa71f84f | 2218 | // Reuse newcache so results back-propagate to previous elements |
f0c0c1ea | 2219 | uniqueCache[ dir ] = newCache; |
fa71f84f PŠ |
2220 | |
2221 | // A match means we're done; a fail means we have to keep checking | |
2222 | if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) { | |
09bacfd7 PS |
2223 | return true; |
2224 | } | |
2225 | } | |
63c88397 PS |
2226 | } |
2227 | } | |
2228 | } | |
09bacfd7 PS |
2229 | }; |
2230 | } | |
63c88397 | 2231 | |
09bacfd7 PS |
2232 | function elementMatcher( matchers ) { |
2233 | return matchers.length > 1 ? | |
2234 | function( elem, context, xml ) { | |
2235 | var i = matchers.length; | |
2236 | while ( i-- ) { | |
2237 | if ( !matchers[i]( elem, context, xml ) ) { | |
2238 | return false; | |
63c88397 PS |
2239 | } |
2240 | } | |
09bacfd7 PS |
2241 | return true; |
2242 | } : | |
2243 | matchers[0]; | |
2244 | } | |
63c88397 | 2245 | |
5a53b77f PS |
2246 | function multipleContexts( selector, contexts, results ) { |
2247 | var i = 0, | |
2248 | len = contexts.length; | |
2249 | for ( ; i < len; i++ ) { | |
2250 | Sizzle( selector, contexts[i], results ); | |
2251 | } | |
2252 | return results; | |
2253 | } | |
2254 | ||
09bacfd7 PS |
2255 | function condense( unmatched, map, filter, context, xml ) { |
2256 | var elem, | |
2257 | newUnmatched = [], | |
2258 | i = 0, | |
2259 | len = unmatched.length, | |
2260 | mapped = map != null; | |
63c88397 | 2261 | |
09bacfd7 PS |
2262 | for ( ; i < len; i++ ) { |
2263 | if ( (elem = unmatched[i]) ) { | |
2264 | if ( !filter || filter( elem, context, xml ) ) { | |
2265 | newUnmatched.push( elem ); | |
2266 | if ( mapped ) { | |
2267 | map.push( i ); | |
2268 | } | |
2269 | } | |
63c88397 | 2270 | } |
09bacfd7 | 2271 | } |
63c88397 | 2272 | |
09bacfd7 PS |
2273 | return newUnmatched; |
2274 | } | |
63c88397 | 2275 | |
09bacfd7 PS |
2276 | function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) { |
2277 | if ( postFilter && !postFilter[ expando ] ) { | |
2278 | postFilter = setMatcher( postFilter ); | |
2279 | } | |
2280 | if ( postFinder && !postFinder[ expando ] ) { | |
2281 | postFinder = setMatcher( postFinder, postSelector ); | |
2282 | } | |
2283 | return markFunction(function( seed, results, context, xml ) { | |
2284 | var temp, i, elem, | |
2285 | preMap = [], | |
2286 | postMap = [], | |
2287 | preexisting = results.length, | |
63c88397 | 2288 | |
09bacfd7 PS |
2289 | // Get initial elements from seed or context |
2290 | elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ), | |
63c88397 | 2291 | |
09bacfd7 PS |
2292 | // Prefilter to get matcher input, preserving a map for seed-results synchronization |
2293 | matcherIn = preFilter && ( seed || !selector ) ? | |
2294 | condense( elems, preMap, preFilter, context, xml ) : | |
2295 | elems, | |
63c88397 | 2296 | |
09bacfd7 PS |
2297 | matcherOut = matcher ? |
2298 | // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results, | |
2299 | postFinder || ( seed ? preFilter : preexisting || postFilter ) ? | |
63c88397 | 2300 | |
09bacfd7 PS |
2301 | // ...intermediate processing is necessary |
2302 | [] : | |
63c88397 | 2303 | |
09bacfd7 PS |
2304 | // ...otherwise use results directly |
2305 | results : | |
2306 | matcherIn; | |
63c88397 | 2307 | |
09bacfd7 PS |
2308 | // Find primary matches |
2309 | if ( matcher ) { | |
2310 | matcher( matcherIn, matcherOut, context, xml ); | |
2311 | } | |
63c88397 | 2312 | |
09bacfd7 PS |
2313 | // Apply postFilter |
2314 | if ( postFilter ) { | |
2315 | temp = condense( matcherOut, postMap ); | |
2316 | postFilter( temp, [], context, xml ); | |
2317 | ||
2318 | // Un-match failing elements by moving them back to matcherIn | |
2319 | i = temp.length; | |
2320 | while ( i-- ) { | |
2321 | if ( (elem = temp[i]) ) { | |
2322 | matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem); | |
63c88397 PS |
2323 | } |
2324 | } | |
09bacfd7 | 2325 | } |
63c88397 | 2326 | |
09bacfd7 PS |
2327 | if ( seed ) { |
2328 | if ( postFinder || preFilter ) { | |
2329 | if ( postFinder ) { | |
2330 | // Get the final matcherOut by condensing this intermediate into postFinder contexts | |
2331 | temp = []; | |
2332 | i = matcherOut.length; | |
2333 | while ( i-- ) { | |
2334 | if ( (elem = matcherOut[i]) ) { | |
2335 | // Restore matcherIn since elem is not yet a final match | |
2336 | temp.push( (matcherIn[i] = elem) ); | |
2337 | } | |
2338 | } | |
2339 | postFinder( null, (matcherOut = []), temp, xml ); | |
63c88397 PS |
2340 | } |
2341 | ||
09bacfd7 PS |
2342 | // Move matched elements from seed to results to keep them synchronized |
2343 | i = matcherOut.length; | |
2344 | while ( i-- ) { | |
2345 | if ( (elem = matcherOut[i]) && | |
c2260ade | 2346 | (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) { |
09bacfd7 PS |
2347 | |
2348 | seed[temp] = !(results[temp] = elem); | |
2349 | } | |
2350 | } | |
2351 | } | |
2352 | ||
2353 | // Add elements to results, through postFinder if defined | |
2354 | } else { | |
2355 | matcherOut = condense( | |
2356 | matcherOut === results ? | |
2357 | matcherOut.splice( preexisting, matcherOut.length ) : | |
2358 | matcherOut | |
2359 | ); | |
2360 | if ( postFinder ) { | |
2361 | postFinder( null, results, matcherOut, xml ); | |
2362 | } else { | |
2363 | push.apply( results, matcherOut ); | |
63c88397 PS |
2364 | } |
2365 | } | |
09bacfd7 PS |
2366 | }); |
2367 | } | |
63c88397 | 2368 | |
09bacfd7 PS |
2369 | function matcherFromTokens( tokens ) { |
2370 | var checkContext, matcher, j, | |
2371 | len = tokens.length, | |
2372 | leadingRelative = Expr.relative[ tokens[0].type ], | |
2373 | implicitRelative = leadingRelative || Expr.relative[" "], | |
2374 | i = leadingRelative ? 1 : 0, | |
63c88397 | 2375 | |
09bacfd7 PS |
2376 | // The foundational matcher ensures that elements are reachable from top-level context(s) |
2377 | matchContext = addCombinator( function( elem ) { | |
2378 | return elem === checkContext; | |
2379 | }, implicitRelative, true ), | |
2380 | matchAnyContext = addCombinator( function( elem ) { | |
c2260ade | 2381 | return indexOf( checkContext, elem ) > -1; |
09bacfd7 PS |
2382 | }, implicitRelative, true ), |
2383 | matchers = [ function( elem, context, xml ) { | |
c2260ade | 2384 | var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( |
09bacfd7 PS |
2385 | (checkContext = context).nodeType ? |
2386 | matchContext( elem, context, xml ) : | |
2387 | matchAnyContext( elem, context, xml ) ); | |
c2260ade JO |
2388 | // Avoid hanging onto element (issue #299) |
2389 | checkContext = null; | |
2390 | return ret; | |
09bacfd7 PS |
2391 | } ]; |
2392 | ||
2393 | for ( ; i < len; i++ ) { | |
2394 | if ( (matcher = Expr.relative[ tokens[i].type ]) ) { | |
2395 | matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; | |
2396 | } else { | |
2397 | matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); | |
2398 | ||
2399 | // Return special upon seeing a positional matcher | |
2400 | if ( matcher[ expando ] ) { | |
2401 | // Find the next relative operator (if any) for proper handling | |
2402 | j = ++i; | |
2403 | for ( ; j < len; j++ ) { | |
2404 | if ( Expr.relative[ tokens[j].type ] ) { | |
2405 | break; | |
2406 | } | |
2407 | } | |
2408 | return setMatcher( | |
2409 | i > 1 && elementMatcher( matchers ), | |
2410 | i > 1 && toSelector( | |
2411 | // If the preceding token was a descendant combinator, insert an implicit any-element `*` | |
2412 | tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" }) | |
2413 | ).replace( rtrim, "$1" ), | |
2414 | matcher, | |
2415 | i < j && matcherFromTokens( tokens.slice( i, j ) ), | |
2416 | j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), | |
2417 | j < len && toSelector( tokens ) | |
2418 | ); | |
2419 | } | |
2420 | matchers.push( matcher ); | |
63c88397 | 2421 | } |
09bacfd7 | 2422 | } |
63c88397 | 2423 | |
09bacfd7 PS |
2424 | return elementMatcher( matchers ); |
2425 | } | |
63c88397 | 2426 | |
09bacfd7 | 2427 | function matcherFromGroupMatchers( elementMatchers, setMatchers ) { |
fa71f84f | 2428 | var bySet = setMatchers.length > 0, |
09bacfd7 | 2429 | byElement = elementMatchers.length > 0, |
fa71f84f | 2430 | superMatcher = function( seed, context, xml, results, outermost ) { |
09bacfd7 | 2431 | var elem, j, matcher, |
09bacfd7 PS |
2432 | matchedCount = 0, |
2433 | i = "0", | |
2434 | unmatched = seed && [], | |
fa71f84f | 2435 | setMatched = [], |
09bacfd7 | 2436 | contextBackup = outermostContext, |
fa71f84f PŠ |
2437 | // We must always have either seed elements or outermost context |
2438 | elems = seed || byElement && Expr.find["TAG"]( "*", outermost ), | |
09bacfd7 | 2439 | // Use integer dirruns iff this is the outermost matcher |
fa71f84f PŠ |
2440 | dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1), |
2441 | len = elems.length; | |
63c88397 | 2442 | |
09bacfd7 | 2443 | if ( outermost ) { |
f0c0c1ea | 2444 | outermostContext = context === document || context || outermost; |
09bacfd7 | 2445 | } |
63c88397 | 2446 | |
09bacfd7 | 2447 | // Add elements passing elementMatchers directly to results |
fa71f84f PŠ |
2448 | // Support: IE<9, Safari |
2449 | // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id | |
2450 | for ( ; i !== len && (elem = elems[i]) != null; i++ ) { | |
09bacfd7 PS |
2451 | if ( byElement && elem ) { |
2452 | j = 0; | |
f0c0c1ea SL |
2453 | if ( !context && elem.ownerDocument !== document ) { |
2454 | setDocument( elem ); | |
2455 | xml = !documentIsHTML; | |
2456 | } | |
09bacfd7 | 2457 | while ( (matcher = elementMatchers[j++]) ) { |
f0c0c1ea | 2458 | if ( matcher( elem, context || document, xml) ) { |
09bacfd7 PS |
2459 | results.push( elem ); |
2460 | break; | |
2461 | } | |
2462 | } | |
2463 | if ( outermost ) { | |
2464 | dirruns = dirrunsUnique; | |
09bacfd7 PS |
2465 | } |
2466 | } | |
63c88397 | 2467 | |
09bacfd7 PS |
2468 | // Track unmatched elements for set filters |
2469 | if ( bySet ) { | |
2470 | // They will have gone through all possible matchers | |
2471 | if ( (elem = !matcher && elem) ) { | |
2472 | matchedCount--; | |
2473 | } | |
63c88397 | 2474 | |
09bacfd7 PS |
2475 | // Lengthen the array for every element, matched or not |
2476 | if ( seed ) { | |
2477 | unmatched.push( elem ); | |
2478 | } | |
2479 | } | |
2480 | } | |
63c88397 | 2481 | |
f0c0c1ea SL |
2482 | // `i` is now the count of elements visited above, and adding it to `matchedCount` |
2483 | // makes the latter nonnegative. | |
09bacfd7 | 2484 | matchedCount += i; |
f0c0c1ea SL |
2485 | |
2486 | // Apply set filters to unmatched elements | |
2487 | // NOTE: This can be skipped if there are no unmatched elements (i.e., `matchedCount` | |
2488 | // equals `i`), unless we didn't visit _any_ elements in the above loop because we have | |
2489 | // no element matchers and no seed. | |
2490 | // Incrementing an initially-string "0" `i` allows `i` to remain a string only in that | |
2491 | // case, which will result in a "00" `matchedCount` that differs from `i` but is also | |
2492 | // numerically zero. | |
09bacfd7 PS |
2493 | if ( bySet && i !== matchedCount ) { |
2494 | j = 0; | |
2495 | while ( (matcher = setMatchers[j++]) ) { | |
2496 | matcher( unmatched, setMatched, context, xml ); | |
2497 | } | |
63c88397 | 2498 | |
09bacfd7 PS |
2499 | if ( seed ) { |
2500 | // Reintegrate element matches to eliminate the need for sorting | |
2501 | if ( matchedCount > 0 ) { | |
2502 | while ( i-- ) { | |
2503 | if ( !(unmatched[i] || setMatched[i]) ) { | |
2504 | setMatched[i] = pop.call( results ); | |
2505 | } | |
2506 | } | |
2507 | } | |
63c88397 | 2508 | |
09bacfd7 PS |
2509 | // Discard index placeholder values to get only actual matches |
2510 | setMatched = condense( setMatched ); | |
2511 | } | |
2512 | ||
2513 | // Add matches to results | |
2514 | push.apply( results, setMatched ); | |
2515 | ||
2516 | // Seedless set matches succeeding multiple successful matchers stipulate sorting | |
2517 | if ( outermost && !seed && setMatched.length > 0 && | |
2518 | ( matchedCount + setMatchers.length ) > 1 ) { | |
2519 | ||
2520 | Sizzle.uniqueSort( results ); | |
2521 | } | |
2522 | } | |
2523 | ||
2524 | // Override manipulation of globals by nested matchers | |
2525 | if ( outermost ) { | |
2526 | dirruns = dirrunsUnique; | |
2527 | outermostContext = contextBackup; | |
2528 | } | |
2529 | ||
2530 | return unmatched; | |
2531 | }; | |
2532 | ||
2533 | return bySet ? | |
2534 | markFunction( superMatcher ) : | |
2535 | superMatcher; | |
2536 | } | |
2537 | ||
5a53b77f | 2538 | compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) { |
09bacfd7 PS |
2539 | var i, |
2540 | setMatchers = [], | |
2541 | elementMatchers = [], | |
2542 | cached = compilerCache[ selector + " " ]; | |
2543 | ||
2544 | if ( !cached ) { | |
2545 | // Generate a function of recursive functions that can be used to check each element | |
5a53b77f PS |
2546 | if ( !match ) { |
2547 | match = tokenize( selector ); | |
09bacfd7 | 2548 | } |
5a53b77f | 2549 | i = match.length; |
09bacfd7 | 2550 | while ( i-- ) { |
5a53b77f | 2551 | cached = matcherFromTokens( match[i] ); |
09bacfd7 PS |
2552 | if ( cached[ expando ] ) { |
2553 | setMatchers.push( cached ); | |
2554 | } else { | |
2555 | elementMatchers.push( cached ); | |
2556 | } | |
2557 | } | |
2558 | ||
2559 | // Cache the compiled function | |
2560 | cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) ); | |
5a53b77f PS |
2561 | |
2562 | // Save selector and tokenization | |
2563 | cached.selector = selector; | |
09bacfd7 PS |
2564 | } |
2565 | return cached; | |
2566 | }; | |
2567 | ||
5a53b77f PS |
2568 | /** |
2569 | * A low-level selection function that works with Sizzle's compiled | |
2570 | * selector functions | |
2571 | * @param {String|Function} selector A selector or a pre-compiled | |
2572 | * selector function built with Sizzle.compile | |
2573 | * @param {Element} context | |
2574 | * @param {Array} [results] | |
2575 | * @param {Array} [seed] A set of elements to match against | |
2576 | */ | |
2577 | select = Sizzle.select = function( selector, context, results, seed ) { | |
09bacfd7 | 2578 | var i, tokens, token, type, find, |
5a53b77f PS |
2579 | compiled = typeof selector === "function" && selector, |
2580 | match = !seed && tokenize( (selector = compiled.selector || selector) ); | |
2581 | ||
2582 | results = results || []; | |
09bacfd7 | 2583 | |
f0c0c1ea SL |
2584 | // Try to minimize operations if there is only one selector in the list and no seed |
2585 | // (the latter of which guarantees us context) | |
5a53b77f | 2586 | if ( match.length === 1 ) { |
09bacfd7 | 2587 | |
f0c0c1ea | 2588 | // Reduce context if the leading compound selector is an ID |
5a53b77f PS |
2589 | tokens = match[0] = match[0].slice( 0 ); |
2590 | if ( tokens.length > 2 && (token = tokens[0]).type === "ID" && | |
2591 | support.getById && context.nodeType === 9 && documentIsHTML && | |
2592 | Expr.relative[ tokens[1].type ] ) { | |
09bacfd7 | 2593 | |
5a53b77f PS |
2594 | context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0]; |
2595 | if ( !context ) { | |
2596 | return results; | |
2597 | ||
2598 | // Precompiled matchers will still verify ancestry, so step up a level | |
2599 | } else if ( compiled ) { | |
2600 | context = context.parentNode; | |
09bacfd7 PS |
2601 | } |
2602 | ||
5a53b77f PS |
2603 | selector = selector.slice( tokens.shift().value.length ); |
2604 | } | |
09bacfd7 | 2605 | |
5a53b77f PS |
2606 | // Fetch a seed set for right-to-left matching |
2607 | i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length; | |
2608 | while ( i-- ) { | |
2609 | token = tokens[i]; | |
09bacfd7 | 2610 | |
5a53b77f PS |
2611 | // Abort if we hit a combinator |
2612 | if ( Expr.relative[ (type = token.type) ] ) { | |
2613 | break; | |
2614 | } | |
2615 | if ( (find = Expr.find[ type ]) ) { | |
2616 | // Search, expanding context for leading sibling combinators | |
2617 | if ( (seed = find( | |
2618 | token.matches[0].replace( runescape, funescape ), | |
2619 | rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context | |
2620 | )) ) { | |
2621 | ||
2622 | // If seed is empty or no tokens remain, we can return early | |
2623 | tokens.splice( i, 1 ); | |
2624 | selector = seed.length && toSelector( tokens ); | |
2625 | if ( !selector ) { | |
2626 | push.apply( results, seed ); | |
2627 | return results; | |
09bacfd7 | 2628 | } |
5a53b77f PS |
2629 | |
2630 | break; | |
09bacfd7 PS |
2631 | } |
2632 | } | |
2633 | } | |
2634 | } | |
2635 | ||
5a53b77f | 2636 | // Compile and execute a filtering function if one is not provided |
09bacfd7 | 2637 | // Provide `match` to avoid retokenization if we modified the selector above |
5a53b77f | 2638 | ( compiled || compile( selector, match ) )( |
09bacfd7 PS |
2639 | seed, |
2640 | context, | |
2641 | !documentIsHTML, | |
2642 | results, | |
f0c0c1ea | 2643 | !context || rsibling.test( selector ) && testContext( context.parentNode ) || context |
09bacfd7 PS |
2644 | ); |
2645 | return results; | |
5a53b77f | 2646 | }; |
09bacfd7 PS |
2647 | |
2648 | // One-time assignments | |
2649 | ||
2650 | // Sort stability | |
2651 | support.sortStable = expando.split("").sort( sortOrder ).join("") === expando; | |
2652 | ||
c2260ade | 2653 | // Support: Chrome 14-35+ |
09bacfd7 | 2654 | // Always assume duplicates if they aren't passed to the comparison function |
fa71f84f | 2655 | support.detectDuplicates = !!hasDuplicate; |
09bacfd7 PS |
2656 | |
2657 | // Initialize against the default document | |
2658 | setDocument(); | |
2659 | ||
2660 | // Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27) | |
2661 | // Detached nodes confoundingly follow *each other* | |
2662 | support.sortDetached = assert(function( div1 ) { | |
2663 | // Should return 1, but returns 4 (following) | |
2664 | return div1.compareDocumentPosition( document.createElement("div") ) & 1; | |
2665 | }); | |
2666 | ||
2667 | // Support: IE<8 | |
2668 | // Prevent attribute/property "interpolation" | |
2669 | // http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx | |
2670 | if ( !assert(function( div ) { | |
2671 | div.innerHTML = "<a href='#'></a>"; | |
2672 | return div.firstChild.getAttribute("href") === "#" ; | |
2673 | }) ) { | |
2674 | addHandle( "type|href|height|width", function( elem, name, isXML ) { | |
2675 | if ( !isXML ) { | |
2676 | return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 ); | |
2677 | } | |
2678 | }); | |
2679 | } | |
2680 | ||
2681 | // Support: IE<9 | |
2682 | // Use defaultValue in place of getAttribute("value") | |
2683 | if ( !support.attributes || !assert(function( div ) { | |
2684 | div.innerHTML = "<input/>"; | |
2685 | div.firstChild.setAttribute( "value", "" ); | |
2686 | return div.firstChild.getAttribute( "value" ) === ""; | |
2687 | }) ) { | |
2688 | addHandle( "value", function( elem, name, isXML ) { | |
2689 | if ( !isXML && elem.nodeName.toLowerCase() === "input" ) { | |
2690 | return elem.defaultValue; | |
2691 | } | |
2692 | }); | |
2693 | } | |
2694 | ||
2695 | // Support: IE<9 | |
2696 | // Use getAttributeNode to fetch booleans when getAttribute lies | |
2697 | if ( !assert(function( div ) { | |
2698 | return div.getAttribute("disabled") == null; | |
2699 | }) ) { | |
2700 | addHandle( booleans, function( elem, name, isXML ) { | |
2701 | var val; | |
2702 | if ( !isXML ) { | |
fa71f84f PŠ |
2703 | return elem[ name ] === true ? name.toLowerCase() : |
2704 | (val = elem.getAttributeNode( name )) && val.specified ? | |
2705 | val.value : | |
2706 | null; | |
09bacfd7 PS |
2707 | } |
2708 | }); | |
2709 | } | |
2710 | ||
fa71f84f PŠ |
2711 | return Sizzle; |
2712 | ||
2713 | })( window ); | |
2714 | ||
2715 | ||
2716 | ||
09bacfd7 PS |
2717 | jQuery.find = Sizzle; |
2718 | jQuery.expr = Sizzle.selectors; | |
f0c0c1ea SL |
2719 | jQuery.expr[ ":" ] = jQuery.expr.pseudos; |
2720 | jQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort; | |
09bacfd7 PS |
2721 | jQuery.text = Sizzle.getText; |
2722 | jQuery.isXMLDoc = Sizzle.isXML; | |
2723 | jQuery.contains = Sizzle.contains; | |
2724 | ||
2725 | ||
09bacfd7 | 2726 | |
f0c0c1ea SL |
2727 | var dir = function( elem, dir, until ) { |
2728 | var matched = [], | |
2729 | truncate = until !== undefined; | |
2730 | ||
2731 | while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) { | |
2732 | if ( elem.nodeType === 1 ) { | |
2733 | if ( truncate && jQuery( elem ).is( until ) ) { | |
2734 | break; | |
2735 | } | |
2736 | matched.push( elem ); | |
2737 | } | |
2738 | } | |
2739 | return matched; | |
2740 | }; | |
2741 | ||
2742 | ||
2743 | var siblings = function( n, elem ) { | |
2744 | var matched = []; | |
2745 | ||
2746 | for ( ; n; n = n.nextSibling ) { | |
2747 | if ( n.nodeType === 1 && n !== elem ) { | |
2748 | matched.push( n ); | |
2749 | } | |
2750 | } | |
2751 | ||
2752 | return matched; | |
2753 | }; | |
2754 | ||
2755 | ||
fa71f84f | 2756 | var rneedsContext = jQuery.expr.match.needsContext; |
09bacfd7 | 2757 | |
f0c0c1ea | 2758 | var rsingleTag = ( /^<([\w-]+)\s*\/?>(?:<\/\1>|)$/ ); |
09bacfd7 | 2759 | |
09bacfd7 | 2760 | |
fa71f84f PŠ |
2761 | |
2762 | var risSimple = /^.[^:#\[\.,]*$/; | |
2763 | ||
2764 | // Implement the identical functionality for filter and not | |
2765 | function winnow( elements, qualifier, not ) { | |
2766 | if ( jQuery.isFunction( qualifier ) ) { | |
2767 | return jQuery.grep( elements, function( elem, i ) { | |
2768 | /* jshint -W018 */ | |
2769 | return !!qualifier.call( elem, i, elem ) !== not; | |
f0c0c1ea | 2770 | } ); |
fa71f84f PŠ |
2771 | |
2772 | } | |
2773 | ||
2774 | if ( qualifier.nodeType ) { | |
2775 | return jQuery.grep( elements, function( elem ) { | |
2776 | return ( elem === qualifier ) !== not; | |
f0c0c1ea | 2777 | } ); |
fa71f84f PŠ |
2778 | |
2779 | } | |
2780 | ||
2781 | if ( typeof qualifier === "string" ) { | |
2782 | if ( risSimple.test( qualifier ) ) { | |
2783 | return jQuery.filter( qualifier, elements, not ); | |
2784 | } | |
2785 | ||
2786 | qualifier = jQuery.filter( qualifier, elements ); | |
2787 | } | |
2788 | ||
2789 | return jQuery.grep( elements, function( elem ) { | |
f0c0c1ea SL |
2790 | return ( jQuery.inArray( elem, qualifier ) > -1 ) !== not; |
2791 | } ); | |
fa71f84f PŠ |
2792 | } |
2793 | ||
2794 | jQuery.filter = function( expr, elems, not ) { | |
2795 | var elem = elems[ 0 ]; | |
2796 | ||
2797 | if ( not ) { | |
2798 | expr = ":not(" + expr + ")"; | |
2799 | } | |
2800 | ||
2801 | return elems.length === 1 && elem.nodeType === 1 ? | |
2802 | jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] : | |
2803 | jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) { | |
2804 | return elem.nodeType === 1; | |
f0c0c1ea | 2805 | } ) ); |
fa71f84f PŠ |
2806 | }; |
2807 | ||
f0c0c1ea | 2808 | jQuery.fn.extend( { |
fa71f84f PŠ |
2809 | find: function( selector ) { |
2810 | var i, | |
2811 | ret = [], | |
2812 | self = this, | |
2813 | len = self.length; | |
2814 | ||
2815 | if ( typeof selector !== "string" ) { | |
f0c0c1ea | 2816 | return this.pushStack( jQuery( selector ).filter( function() { |
fa71f84f PŠ |
2817 | for ( i = 0; i < len; i++ ) { |
2818 | if ( jQuery.contains( self[ i ], this ) ) { | |
2819 | return true; | |
09bacfd7 | 2820 | } |
09bacfd7 | 2821 | } |
f0c0c1ea | 2822 | } ) ); |
fa71f84f PŠ |
2823 | } |
2824 | ||
2825 | for ( i = 0; i < len; i++ ) { | |
2826 | jQuery.find( selector, self[ i ], ret ); | |
2827 | } | |
2828 | ||
2829 | // Needed because $( selector, context ) becomes $( context ).find( selector ) | |
2830 | ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret ); | |
2831 | ret.selector = this.selector ? this.selector + " " + selector : selector; | |
2832 | return ret; | |
2833 | }, | |
2834 | filter: function( selector ) { | |
f0c0c1ea | 2835 | return this.pushStack( winnow( this, selector || [], false ) ); |
fa71f84f PŠ |
2836 | }, |
2837 | not: function( selector ) { | |
f0c0c1ea | 2838 | return this.pushStack( winnow( this, selector || [], true ) ); |
fa71f84f PŠ |
2839 | }, |
2840 | is: function( selector ) { | |
2841 | return !!winnow( | |
2842 | this, | |
2843 | ||
2844 | // If this is a positional/relative selector, check membership in the returned set | |
2845 | // so $("p:first").is("p:last") won't return true for a doc with two "p". | |
2846 | typeof selector === "string" && rneedsContext.test( selector ) ? | |
2847 | jQuery( selector ) : | |
2848 | selector || [], | |
2849 | false | |
2850 | ).length; | |
2851 | } | |
f0c0c1ea | 2852 | } ); |
fa71f84f PŠ |
2853 | |
2854 | ||
2855 | // Initialize a jQuery object | |
2856 | ||
2857 | ||
2858 | // A central reference to the root jQuery(document) | |
2859 | var rootjQuery, | |
2860 | ||
fa71f84f PŠ |
2861 | // A simple way to check for HTML strings |
2862 | // Prioritize #id over <tag> to avoid XSS via location.hash (#9521) | |
2863 | // Strict HTML recognition (#11290: must start with <) | |
2864 | rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/, | |
2865 | ||
f0c0c1ea | 2866 | init = jQuery.fn.init = function( selector, context, root ) { |
fa71f84f PŠ |
2867 | var match, elem; |
2868 | ||
2869 | // HANDLE: $(""), $(null), $(undefined), $(false) | |
2870 | if ( !selector ) { | |
2871 | return this; | |
2872 | } | |
2873 | ||
f0c0c1ea SL |
2874 | // init accepts an alternate rootjQuery |
2875 | // so migrate can support jQuery.sub (gh-2101) | |
2876 | root = root || rootjQuery; | |
2877 | ||
fa71f84f PŠ |
2878 | // Handle HTML strings |
2879 | if ( typeof selector === "string" ) { | |
f0c0c1ea SL |
2880 | if ( selector.charAt( 0 ) === "<" && |
2881 | selector.charAt( selector.length - 1 ) === ">" && | |
2882 | selector.length >= 3 ) { | |
2883 | ||
fa71f84f PŠ |
2884 | // Assume that strings that start and end with <> are HTML and skip the regex check |
2885 | match = [ null, selector, null ]; | |
2886 | ||
2887 | } else { | |
2888 | match = rquickExpr.exec( selector ); | |
09bacfd7 | 2889 | } |
fa71f84f PŠ |
2890 | |
2891 | // Match html or make sure no context is specified for #id | |
f0c0c1ea | 2892 | if ( match && ( match[ 1 ] || !context ) ) { |
fa71f84f PŠ |
2893 | |
2894 | // HANDLE: $(html) -> $(array) | |
f0c0c1ea SL |
2895 | if ( match[ 1 ] ) { |
2896 | context = context instanceof jQuery ? context[ 0 ] : context; | |
fa71f84f PŠ |
2897 | |
2898 | // scripts is true for back-compat | |
2899 | // Intentionally let the error be thrown if parseHTML is not present | |
2900 | jQuery.merge( this, jQuery.parseHTML( | |
f0c0c1ea | 2901 | match[ 1 ], |
fa71f84f PŠ |
2902 | context && context.nodeType ? context.ownerDocument || context : document, |
2903 | true | |
2904 | ) ); | |
2905 | ||
2906 | // HANDLE: $(html, props) | |
f0c0c1ea | 2907 | if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) { |
fa71f84f | 2908 | for ( match in context ) { |
f0c0c1ea | 2909 | |
fa71f84f PŠ |
2910 | // Properties of context are called as methods if possible |
2911 | if ( jQuery.isFunction( this[ match ] ) ) { | |
2912 | this[ match ]( context[ match ] ); | |
2913 | ||
2914 | // ...and otherwise set as attributes | |
2915 | } else { | |
2916 | this.attr( match, context[ match ] ); | |
09bacfd7 | 2917 | } |
fa71f84f | 2918 | } |
09bacfd7 | 2919 | } |
fa71f84f PŠ |
2920 | |
2921 | return this; | |
2922 | ||
2923 | // HANDLE: $(#id) | |
2924 | } else { | |
f0c0c1ea | 2925 | elem = document.getElementById( match[ 2 ] ); |
fa71f84f PŠ |
2926 | |
2927 | // Check parentNode to catch when Blackberry 4.6 returns | |
2928 | // nodes that are no longer in the document #6963 | |
2929 | if ( elem && elem.parentNode ) { | |
f0c0c1ea | 2930 | |
fa71f84f PŠ |
2931 | // Handle the case where IE and Opera return items |
2932 | // by name instead of ID | |
f0c0c1ea | 2933 | if ( elem.id !== match[ 2 ] ) { |
fa71f84f | 2934 | return rootjQuery.find( selector ); |
09bacfd7 | 2935 | } |
fa71f84f PŠ |
2936 | |
2937 | // Otherwise, we inject the element directly into the jQuery object | |
2938 | this.length = 1; | |
f0c0c1ea | 2939 | this[ 0 ] = elem; |
fa71f84f PŠ |
2940 | } |
2941 | ||
2942 | this.context = document; | |
2943 | this.selector = selector; | |
2944 | return this; | |
2945 | } | |
2946 | ||
2947 | // HANDLE: $(expr, $(...)) | |
2948 | } else if ( !context || context.jquery ) { | |
f0c0c1ea | 2949 | return ( context || root ).find( selector ); |
fa71f84f PŠ |
2950 | |
2951 | // HANDLE: $(expr, context) | |
2952 | // (which is just equivalent to: $(context).find(expr) | |
2953 | } else { | |
2954 | return this.constructor( context ).find( selector ); | |
2955 | } | |
2956 | ||
2957 | // HANDLE: $(DOMElement) | |
2958 | } else if ( selector.nodeType ) { | |
f0c0c1ea | 2959 | this.context = this[ 0 ] = selector; |
fa71f84f PŠ |
2960 | this.length = 1; |
2961 | return this; | |
2962 | ||
2963 | // HANDLE: $(function) | |
2964 | // Shortcut for document ready | |
2965 | } else if ( jQuery.isFunction( selector ) ) { | |
f0c0c1ea SL |
2966 | return typeof root.ready !== "undefined" ? |
2967 | root.ready( selector ) : | |
2968 | ||
fa71f84f PŠ |
2969 | // Execute immediately if ready is not present |
2970 | selector( jQuery ); | |
2971 | } | |
2972 | ||
2973 | if ( selector.selector !== undefined ) { | |
2974 | this.selector = selector.selector; | |
2975 | this.context = selector.context; | |
2976 | } | |
2977 | ||
2978 | return jQuery.makeArray( selector, this ); | |
2979 | }; | |
2980 | ||
2981 | // Give the init function the jQuery prototype for later instantiation | |
2982 | init.prototype = jQuery.fn; | |
2983 | ||
2984 | // Initialize central reference | |
2985 | rootjQuery = jQuery( document ); | |
2986 | ||
2987 | ||
2988 | var rparentsprev = /^(?:parents|prev(?:Until|All))/, | |
f0c0c1ea | 2989 | |
fa71f84f PŠ |
2990 | // methods guaranteed to produce a unique set when starting from a unique set |
2991 | guaranteedUnique = { | |
2992 | children: true, | |
2993 | contents: true, | |
2994 | next: true, | |
2995 | prev: true | |
2996 | }; | |
2997 | ||
f0c0c1ea | 2998 | jQuery.fn.extend( { |
fa71f84f PŠ |
2999 | has: function( target ) { |
3000 | var i, | |
3001 | targets = jQuery( target, this ), | |
3002 | len = targets.length; | |
3003 | ||
f0c0c1ea | 3004 | return this.filter( function() { |
fa71f84f | 3005 | for ( i = 0; i < len; i++ ) { |
f0c0c1ea | 3006 | if ( jQuery.contains( this, targets[ i ] ) ) { |
fa71f84f PŠ |
3007 | return true; |
3008 | } | |
3009 | } | |
f0c0c1ea | 3010 | } ); |
fa71f84f PŠ |
3011 | }, |
3012 | ||
3013 | closest: function( selectors, context ) { | |
3014 | var cur, | |
3015 | i = 0, | |
3016 | l = this.length, | |
3017 | matched = [], | |
3018 | pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ? | |
3019 | jQuery( selectors, context || this.context ) : | |
3020 | 0; | |
3021 | ||
3022 | for ( ; i < l; i++ ) { | |
f0c0c1ea SL |
3023 | for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) { |
3024 | ||
fa71f84f | 3025 | // Always skip document fragments |
f0c0c1ea SL |
3026 | if ( cur.nodeType < 11 && ( pos ? |
3027 | pos.index( cur ) > -1 : | |
fa71f84f PŠ |
3028 | |
3029 | // Don't pass non-elements to Sizzle | |
3030 | cur.nodeType === 1 && | |
f0c0c1ea | 3031 | jQuery.find.matchesSelector( cur, selectors ) ) ) { |
fa71f84f PŠ |
3032 | |
3033 | matched.push( cur ); | |
3034 | break; | |
3035 | } | |
3036 | } | |
3037 | } | |
3038 | ||
f0c0c1ea | 3039 | return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched ); |
fa71f84f PŠ |
3040 | }, |
3041 | ||
3042 | // Determine the position of an element within | |
3043 | // the matched set of elements | |
3044 | index: function( elem ) { | |
3045 | ||
3046 | // No argument, return index in parent | |
3047 | if ( !elem ) { | |
f0c0c1ea | 3048 | return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1; |
fa71f84f PŠ |
3049 | } |
3050 | ||
3051 | // index in selector | |
3052 | if ( typeof elem === "string" ) { | |
f0c0c1ea | 3053 | return jQuery.inArray( this[ 0 ], jQuery( elem ) ); |
fa71f84f PŠ |
3054 | } |
3055 | ||
3056 | // Locate the position of the desired element | |
3057 | return jQuery.inArray( | |
f0c0c1ea | 3058 | |
fa71f84f | 3059 | // If it receives a jQuery object, the first element is used |
f0c0c1ea | 3060 | elem.jquery ? elem[ 0 ] : elem, this ); |
fa71f84f PŠ |
3061 | }, |
3062 | ||
3063 | add: function( selector, context ) { | |
3064 | return this.pushStack( | |
f0c0c1ea | 3065 | jQuery.uniqueSort( |
fa71f84f PŠ |
3066 | jQuery.merge( this.get(), jQuery( selector, context ) ) |
3067 | ) | |
3068 | ); | |
3069 | }, | |
3070 | ||
3071 | addBack: function( selector ) { | |
3072 | return this.add( selector == null ? | |
f0c0c1ea | 3073 | this.prevObject : this.prevObject.filter( selector ) |
fa71f84f PŠ |
3074 | ); |
3075 | } | |
f0c0c1ea | 3076 | } ); |
fa71f84f PŠ |
3077 | |
3078 | function sibling( cur, dir ) { | |
3079 | do { | |
3080 | cur = cur[ dir ]; | |
3081 | } while ( cur && cur.nodeType !== 1 ); | |
3082 | ||
3083 | return cur; | |
3084 | } | |
3085 | ||
f0c0c1ea | 3086 | jQuery.each( { |
fa71f84f PŠ |
3087 | parent: function( elem ) { |
3088 | var parent = elem.parentNode; | |
3089 | return parent && parent.nodeType !== 11 ? parent : null; | |
3090 | }, | |
3091 | parents: function( elem ) { | |
f0c0c1ea | 3092 | return dir( elem, "parentNode" ); |
fa71f84f PŠ |
3093 | }, |
3094 | parentsUntil: function( elem, i, until ) { | |
f0c0c1ea | 3095 | return dir( elem, "parentNode", until ); |
fa71f84f PŠ |
3096 | }, |
3097 | next: function( elem ) { | |
3098 | return sibling( elem, "nextSibling" ); | |
3099 | }, | |
3100 | prev: function( elem ) { | |
3101 | return sibling( elem, "previousSibling" ); | |
3102 | }, | |
3103 | nextAll: function( elem ) { | |
f0c0c1ea | 3104 | return dir( elem, "nextSibling" ); |
fa71f84f PŠ |
3105 | }, |
3106 | prevAll: function( elem ) { | |
f0c0c1ea | 3107 | return dir( elem, "previousSibling" ); |
fa71f84f PŠ |
3108 | }, |
3109 | nextUntil: function( elem, i, until ) { | |
f0c0c1ea | 3110 | return dir( elem, "nextSibling", until ); |
fa71f84f PŠ |
3111 | }, |
3112 | prevUntil: function( elem, i, until ) { | |
f0c0c1ea | 3113 | return dir( elem, "previousSibling", until ); |
fa71f84f PŠ |
3114 | }, |
3115 | siblings: function( elem ) { | |
f0c0c1ea | 3116 | return siblings( ( elem.parentNode || {} ).firstChild, elem ); |
fa71f84f PŠ |
3117 | }, |
3118 | children: function( elem ) { | |
f0c0c1ea | 3119 | return siblings( elem.firstChild ); |
fa71f84f PŠ |
3120 | }, |
3121 | contents: function( elem ) { | |
3122 | return jQuery.nodeName( elem, "iframe" ) ? | |
3123 | elem.contentDocument || elem.contentWindow.document : | |
3124 | jQuery.merge( [], elem.childNodes ); | |
3125 | } | |
3126 | }, function( name, fn ) { | |
3127 | jQuery.fn[ name ] = function( until, selector ) { | |
3128 | var ret = jQuery.map( this, fn, until ); | |
3129 | ||
3130 | if ( name.slice( -5 ) !== "Until" ) { | |
3131 | selector = until; | |
3132 | } | |
3133 | ||
3134 | if ( selector && typeof selector === "string" ) { | |
3135 | ret = jQuery.filter( selector, ret ); | |
3136 | } | |
3137 | ||
3138 | if ( this.length > 1 ) { | |
f0c0c1ea | 3139 | |
fa71f84f PŠ |
3140 | // Remove duplicates |
3141 | if ( !guaranteedUnique[ name ] ) { | |
f0c0c1ea | 3142 | ret = jQuery.uniqueSort( ret ); |
fa71f84f PŠ |
3143 | } |
3144 | ||
3145 | // Reverse order for parents* and prev-derivatives | |
3146 | if ( rparentsprev.test( name ) ) { | |
3147 | ret = ret.reverse(); | |
3148 | } | |
3149 | } | |
3150 | ||
3151 | return this.pushStack( ret ); | |
3152 | }; | |
f0c0c1ea SL |
3153 | } ); |
3154 | var rnotwhite = ( /\S+/g ); | |
fa71f84f PŠ |
3155 | |
3156 | ||
fa71f84f | 3157 | |
f0c0c1ea | 3158 | // Convert String-formatted options into Object-formatted ones |
fa71f84f | 3159 | function createOptions( options ) { |
f0c0c1ea | 3160 | var object = {}; |
fa71f84f PŠ |
3161 | jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) { |
3162 | object[ flag ] = true; | |
f0c0c1ea | 3163 | } ); |
fa71f84f PŠ |
3164 | return object; |
3165 | } | |
3166 | ||
3167 | /* | |
3168 | * Create a callback list using the following parameters: | |
3169 | * | |
3170 | * options: an optional list of space-separated options that will change how | |
3171 | * the callback list behaves or a more traditional option object | |
3172 | * | |
3173 | * By default a callback list will act like an event callback list and can be | |
3174 | * "fired" multiple times. | |
3175 | * | |
3176 | * Possible options: | |
3177 | * | |
3178 | * once: will ensure the callback list can only be fired once (like a Deferred) | |
3179 | * | |
3180 | * memory: will keep track of previous values and will call any callback added | |
3181 | * after the list has been fired right away with the latest "memorized" | |
3182 | * values (like a Deferred) | |
3183 | * | |
3184 | * unique: will ensure a callback can only be added once (no duplicate in the list) | |
3185 | * | |
3186 | * stopOnFalse: interrupt callings when a callback returns false | |
3187 | * | |
3188 | */ | |
3189 | jQuery.Callbacks = function( options ) { | |
3190 | ||
3191 | // Convert options from String-formatted to Object-formatted if needed | |
3192 | // (we check in cache first) | |
3193 | options = typeof options === "string" ? | |
f0c0c1ea | 3194 | createOptions( options ) : |
fa71f84f PŠ |
3195 | jQuery.extend( {}, options ); |
3196 | ||
3197 | var // Flag to know if list is currently firing | |
3198 | firing, | |
f0c0c1ea SL |
3199 | |
3200 | // Last fire value for non-forgettable lists | |
fa71f84f | 3201 | memory, |
f0c0c1ea | 3202 | |
fa71f84f PŠ |
3203 | // Flag to know if list was already fired |
3204 | fired, | |
f0c0c1ea SL |
3205 | |
3206 | // Flag to prevent firing | |
3207 | locked, | |
3208 | ||
fa71f84f PŠ |
3209 | // Actual callback list |
3210 | list = [], | |
f0c0c1ea SL |
3211 | |
3212 | // Queue of execution data for repeatable lists | |
3213 | queue = [], | |
3214 | ||
3215 | // Index of currently firing callback (modified by add/remove as needed) | |
3216 | firingIndex = -1, | |
3217 | ||
fa71f84f | 3218 | // Fire callbacks |
f0c0c1ea SL |
3219 | fire = function() { |
3220 | ||
3221 | // Enforce single-firing | |
3222 | locked = options.once; | |
3223 | ||
3224 | // Execute callbacks for all pending executions, | |
3225 | // respecting firingIndex overrides and runtime changes | |
3226 | fired = firing = true; | |
3227 | for ( ; queue.length; firingIndex = -1 ) { | |
3228 | memory = queue.shift(); | |
3229 | while ( ++firingIndex < list.length ) { | |
3230 | ||
3231 | // Run callback and check for early termination | |
3232 | if ( list[ firingIndex ].apply( memory[ 0 ], memory[ 1 ] ) === false && | |
3233 | options.stopOnFalse ) { | |
3234 | ||
3235 | // Jump to end and forget the data so .add doesn't re-fire | |
3236 | firingIndex = list.length; | |
3237 | memory = false; | |
3238 | } | |
fa71f84f PŠ |
3239 | } |
3240 | } | |
f0c0c1ea SL |
3241 | |
3242 | // Forget the data if we're done with it |