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