selector.js 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112
  1. define( [
  2. "./core",
  3. "./core/nodeName",
  4. "./var/arr",
  5. "./var/document",
  6. "./var/indexOf",
  7. "./var/hasOwn",
  8. "./var/pop",
  9. "./var/push",
  10. "./var/slice",
  11. "./var/sort",
  12. "./var/splice",
  13. "./var/whitespace",
  14. "./var/rtrimCSS",
  15. "./var/support",
  16. // The following utils are attached directly to the jQuery object.
  17. "./selector/contains",
  18. "./selector/escapeSelector"
  19. ], function( jQuery, nodeName, arr, document, indexOf, hasOwn, pop, push,
  20. slice, sort, splice, whitespace, rtrimCSS, support ) {
  21. "use strict";
  22. var preferredDoc = document,
  23. pushNative = push;
  24. ( function() {
  25. var i,
  26. Expr,
  27. outermostContext,
  28. sortInput,
  29. hasDuplicate,
  30. push = pushNative,
  31. // Local document vars
  32. document,
  33. documentElement,
  34. documentIsHTML,
  35. rbuggyQSA,
  36. matches,
  37. // Instance-specific data
  38. expando = jQuery.expando,
  39. dirruns = 0,
  40. done = 0,
  41. classCache = createCache(),
  42. tokenCache = createCache(),
  43. compilerCache = createCache(),
  44. nonnativeSelectorCache = createCache(),
  45. sortOrder = function( a, b ) {
  46. if ( a === b ) {
  47. hasDuplicate = true;
  48. }
  49. return 0;
  50. },
  51. booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|" +
  52. "loop|multiple|open|readonly|required|scoped",
  53. // Regular expressions
  54. // https://www.w3.org/TR/css-syntax-3/#ident-token-diagram
  55. identifier = "(?:\\\\[\\da-fA-F]{1,6}" + whitespace +
  56. "?|\\\\[^\\r\\n\\f]|[\\w-]|[^\0-\\x7f])+",
  57. // Attribute selectors: https://www.w3.org/TR/selectors/#attribute-selectors
  58. attributes = "\\[" + whitespace + "*(" + identifier + ")(?:" + whitespace +
  59. // Operator (capture 2)
  60. "*([*^$|!~]?=)" + whitespace +
  61. // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
  62. "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" +
  63. whitespace + "*\\]",
  64. pseudos = ":(" + identifier + ")(?:\\((" +
  65. // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
  66. // 1. quoted (capture 3; capture 4 or capture 5)
  67. "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
  68. // 2. simple (capture 6)
  69. "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
  70. // 3. anything else (capture 2)
  71. ".*" +
  72. ")\\)|)",
  73. // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
  74. rwhitespace = new RegExp( whitespace + "+", "g" ),
  75. rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
  76. rleadingCombinator = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" +
  77. whitespace + "*" ),
  78. rdescend = new RegExp( whitespace + "|>" ),
  79. rpseudo = new RegExp( pseudos ),
  80. ridentifier = new RegExp( "^" + identifier + "$" ),
  81. matchExpr = {
  82. ID: new RegExp( "^#(" + identifier + ")" ),
  83. CLASS: new RegExp( "^\\.(" + identifier + ")" ),
  84. TAG: new RegExp( "^(" + identifier + "|[*])" ),
  85. ATTR: new RegExp( "^" + attributes ),
  86. PSEUDO: new RegExp( "^" + pseudos ),
  87. CHILD: new RegExp(
  88. "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" +
  89. whitespace + "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" +
  90. whitespace + "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
  91. bool: new RegExp( "^(?:" + booleans + ")$", "i" ),
  92. // For use in libraries implementing .is()
  93. // We use this for POS matching in `select`
  94. needsContext: new RegExp( "^" + whitespace +
  95. "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" + whitespace +
  96. "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
  97. },
  98. rinputs = /^(?:input|select|textarea|button)$/i,
  99. rheader = /^h\d$/i,
  100. // Easily-parseable/retrievable ID or TAG or CLASS selectors
  101. rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
  102. rsibling = /[+~]/,
  103. // CSS escapes
  104. // https://www.w3.org/TR/CSS21/syndata.html#escaped-characters
  105. runescape = new RegExp( "\\\\[\\da-fA-F]{1,6}" + whitespace +
  106. "?|\\\\([^\\r\\n\\f])", "g" ),
  107. funescape = function( escape, nonHex ) {
  108. var high = "0x" + escape.slice( 1 ) - 0x10000;
  109. if ( nonHex ) {
  110. // Strip the backslash prefix from a non-hex escape sequence
  111. return nonHex;
  112. }
  113. // Replace a hexadecimal escape sequence with the encoded Unicode code point
  114. // Support: IE <=11+
  115. // For values outside the Basic Multilingual Plane (BMP), manually construct a
  116. // surrogate pair
  117. return high < 0 ?
  118. String.fromCharCode( high + 0x10000 ) :
  119. String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
  120. },
  121. // Used for iframes; see `setDocument`.
  122. // Support: IE 9 - 11+, Edge 12 - 18+
  123. // Removing the function wrapper causes a "Permission Denied"
  124. // error in IE/Edge.
  125. unloadHandler = function() {
  126. setDocument();
  127. },
  128. inDisabledFieldset = addCombinator(
  129. function( elem ) {
  130. return elem.disabled === true && nodeName( elem, "fieldset" );
  131. },
  132. { dir: "parentNode", next: "legend" }
  133. );
  134. // Support: IE <=9 only
  135. // Accessing document.activeElement can throw unexpectedly
  136. // https://bugs.jquery.com/ticket/13393
  137. function safeActiveElement() {
  138. try {
  139. return document.activeElement;
  140. } catch ( err ) { }
  141. }
  142. // Optimize for push.apply( _, NodeList )
  143. try {
  144. push.apply(
  145. ( arr = slice.call( preferredDoc.childNodes ) ),
  146. preferredDoc.childNodes
  147. );
  148. // Support: Android <=4.0
  149. // Detect silently failing push.apply
  150. // eslint-disable-next-line no-unused-expressions
  151. arr[ preferredDoc.childNodes.length ].nodeType;
  152. } catch ( e ) {
  153. push = {
  154. apply: function( target, els ) {
  155. pushNative.apply( target, slice.call( els ) );
  156. },
  157. call: function( target ) {
  158. pushNative.apply( target, slice.call( arguments, 1 ) );
  159. }
  160. };
  161. }
  162. function find( selector, context, results, seed ) {
  163. var m, i, elem, nid, match, groups, newSelector,
  164. newContext = context && context.ownerDocument,
  165. // nodeType defaults to 9, since context defaults to document
  166. nodeType = context ? context.nodeType : 9;
  167. results = results || [];
  168. // Return early from calls with invalid selector or context
  169. if ( typeof selector !== "string" || !selector ||
  170. nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
  171. return results;
  172. }
  173. // Try to shortcut find operations (as opposed to filters) in HTML documents
  174. if ( !seed ) {
  175. setDocument( context );
  176. context = context || document;
  177. if ( documentIsHTML ) {
  178. // If the selector is sufficiently simple, try using a "get*By*" DOM method
  179. // (excepting DocumentFragment context, where the methods don't exist)
  180. if ( nodeType !== 11 && ( match = rquickExpr.exec( selector ) ) ) {
  181. // ID selector
  182. if ( ( m = match[ 1 ] ) ) {
  183. // Document context
  184. if ( nodeType === 9 ) {
  185. if ( ( elem = context.getElementById( m ) ) ) {
  186. // Support: IE 9 only
  187. // getElementById can match elements by name instead of ID
  188. if ( elem.id === m ) {
  189. push.call( results, elem );
  190. return results;
  191. }
  192. } else {
  193. return results;
  194. }
  195. // Element context
  196. } else {
  197. // Support: IE 9 only
  198. // getElementById can match elements by name instead of ID
  199. if ( newContext && ( elem = newContext.getElementById( m ) ) &&
  200. find.contains( context, elem ) &&
  201. elem.id === m ) {
  202. push.call( results, elem );
  203. return results;
  204. }
  205. }
  206. // Type selector
  207. } else if ( match[ 2 ] ) {
  208. push.apply( results, context.getElementsByTagName( selector ) );
  209. return results;
  210. // Class selector
  211. } else if ( ( m = match[ 3 ] ) && context.getElementsByClassName ) {
  212. push.apply( results, context.getElementsByClassName( m ) );
  213. return results;
  214. }
  215. }
  216. // Take advantage of querySelectorAll
  217. if ( !nonnativeSelectorCache[ selector + " " ] &&
  218. ( !rbuggyQSA || !rbuggyQSA.test( selector ) ) ) {
  219. newSelector = selector;
  220. newContext = context;
  221. // qSA considers elements outside a scoping root when evaluating child or
  222. // descendant combinators, which is not what we want.
  223. // In such cases, we work around the behavior by prefixing every selector in the
  224. // list with an ID selector referencing the scope context.
  225. // The technique has to be used as well when a leading combinator is used
  226. // as such selectors are not recognized by querySelectorAll.
  227. // Thanks to Andrew Dupont for this technique.
  228. if ( nodeType === 1 &&
  229. ( rdescend.test( selector ) || rleadingCombinator.test( selector ) ) ) {
  230. // Expand context for sibling selectors
  231. newContext = rsibling.test( selector ) && testContext( context.parentNode ) ||
  232. context;
  233. // We can use :scope instead of the ID hack if the browser
  234. // supports it & if we're not changing the context.
  235. // Support: IE 11+, Edge 17 - 18+
  236. // IE/Edge sometimes throw a "Permission denied" error when
  237. // strict-comparing two documents; shallow comparisons work.
  238. // eslint-disable-next-line eqeqeq
  239. if ( newContext != context || !support.scope ) {
  240. // Capture the context ID, setting it first if necessary
  241. if ( ( nid = context.getAttribute( "id" ) ) ) {
  242. nid = jQuery.escapeSelector( nid );
  243. } else {
  244. context.setAttribute( "id", ( nid = expando ) );
  245. }
  246. }
  247. // Prefix every selector in the list
  248. groups = tokenize( selector );
  249. i = groups.length;
  250. while ( i-- ) {
  251. groups[ i ] = ( nid ? "#" + nid : ":scope" ) + " " +
  252. toSelector( groups[ i ] );
  253. }
  254. newSelector = groups.join( "," );
  255. }
  256. try {
  257. push.apply( results,
  258. newContext.querySelectorAll( newSelector )
  259. );
  260. return results;
  261. } catch ( qsaError ) {
  262. nonnativeSelectorCache( selector, true );
  263. } finally {
  264. if ( nid === expando ) {
  265. context.removeAttribute( "id" );
  266. }
  267. }
  268. }
  269. }
  270. }
  271. // All others
  272. return select( selector.replace( rtrimCSS, "$1" ), context, results, seed );
  273. }
  274. /**
  275. * Create key-value caches of limited size
  276. * @returns {function(string, object)} Returns the Object data after storing it on itself with
  277. * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
  278. * deleting the oldest entry
  279. */
  280. function createCache() {
  281. var keys = [];
  282. function cache( key, value ) {
  283. // Use (key + " ") to avoid collision with native prototype properties
  284. // (see https://github.com/jquery/sizzle/issues/157)
  285. if ( keys.push( key + " " ) > Expr.cacheLength ) {
  286. // Only keep the most recent entries
  287. delete cache[ keys.shift() ];
  288. }
  289. return ( cache[ key + " " ] = value );
  290. }
  291. return cache;
  292. }
  293. /**
  294. * Mark a function for special use by jQuery selector module
  295. * @param {Function} fn The function to mark
  296. */
  297. function markFunction( fn ) {
  298. fn[ expando ] = true;
  299. return fn;
  300. }
  301. /**
  302. * Support testing using an element
  303. * @param {Function} fn Passed the created element and returns a boolean result
  304. */
  305. function assert( fn ) {
  306. var el = document.createElement( "fieldset" );
  307. try {
  308. return !!fn( el );
  309. } catch ( e ) {
  310. return false;
  311. } finally {
  312. // Remove from its parent by default
  313. if ( el.parentNode ) {
  314. el.parentNode.removeChild( el );
  315. }
  316. // release memory in IE
  317. el = null;
  318. }
  319. }
  320. /**
  321. * Returns a function to use in pseudos for input types
  322. * @param {String} type
  323. */
  324. function createInputPseudo( type ) {
  325. return function( elem ) {
  326. return nodeName( elem, "input" ) && elem.type === type;
  327. };
  328. }
  329. /**
  330. * Returns a function to use in pseudos for buttons
  331. * @param {String} type
  332. */
  333. function createButtonPseudo( type ) {
  334. return function( elem ) {
  335. return ( nodeName( elem, "input" ) || nodeName( elem, "button" ) ) &&
  336. elem.type === type;
  337. };
  338. }
  339. /**
  340. * Returns a function to use in pseudos for :enabled/:disabled
  341. * @param {Boolean} disabled true for :disabled; false for :enabled
  342. */
  343. function createDisabledPseudo( disabled ) {
  344. // Known :disabled false positives: fieldset[disabled] > legend:nth-of-type(n+2) :can-disable
  345. return function( elem ) {
  346. // Only certain elements can match :enabled or :disabled
  347. // https://html.spec.whatwg.org/multipage/scripting.html#selector-enabled
  348. // https://html.spec.whatwg.org/multipage/scripting.html#selector-disabled
  349. if ( "form" in elem ) {
  350. // Check for inherited disabledness on relevant non-disabled elements:
  351. // * listed form-associated elements in a disabled fieldset
  352. // https://html.spec.whatwg.org/multipage/forms.html#category-listed
  353. // https://html.spec.whatwg.org/multipage/forms.html#concept-fe-disabled
  354. // * option elements in a disabled optgroup
  355. // https://html.spec.whatwg.org/multipage/forms.html#concept-option-disabled
  356. // All such elements have a "form" property.
  357. if ( elem.parentNode && elem.disabled === false ) {
  358. // Option elements defer to a parent optgroup if present
  359. if ( "label" in elem ) {
  360. if ( "label" in elem.parentNode ) {
  361. return elem.parentNode.disabled === disabled;
  362. } else {
  363. return elem.disabled === disabled;
  364. }
  365. }
  366. // Support: IE 6 - 11+
  367. // Use the isDisabled shortcut property to check for disabled fieldset ancestors
  368. return elem.isDisabled === disabled ||
  369. // Where there is no isDisabled, check manually
  370. elem.isDisabled !== !disabled &&
  371. inDisabledFieldset( elem ) === disabled;
  372. }
  373. return elem.disabled === disabled;
  374. // Try to winnow out elements that can't be disabled before trusting the disabled property.
  375. // Some victims get caught in our net (label, legend, menu, track), but it shouldn't
  376. // even exist on them, let alone have a boolean value.
  377. } else if ( "label" in elem ) {
  378. return elem.disabled === disabled;
  379. }
  380. // Remaining elements are neither :enabled nor :disabled
  381. return false;
  382. };
  383. }
  384. /**
  385. * Returns a function to use in pseudos for positionals
  386. * @param {Function} fn
  387. */
  388. function createPositionalPseudo( fn ) {
  389. return markFunction( function( argument ) {
  390. argument = +argument;
  391. return markFunction( function( seed, matches ) {
  392. var j,
  393. matchIndexes = fn( [], seed.length, argument ),
  394. i = matchIndexes.length;
  395. // Match elements found at the specified indexes
  396. while ( i-- ) {
  397. if ( seed[ ( j = matchIndexes[ i ] ) ] ) {
  398. seed[ j ] = !( matches[ j ] = seed[ j ] );
  399. }
  400. }
  401. } );
  402. } );
  403. }
  404. /**
  405. * Checks a node for validity as a jQuery selector context
  406. * @param {Element|Object=} context
  407. * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
  408. */
  409. function testContext( context ) {
  410. return context && typeof context.getElementsByTagName !== "undefined" && context;
  411. }
  412. /**
  413. * Sets document-related variables once based on the current document
  414. * @param {Element|Object} [node] An element or document object to use to set the document
  415. * @returns {Object} Returns the current document
  416. */
  417. function setDocument( node ) {
  418. var subWindow,
  419. doc = node ? node.ownerDocument || node : preferredDoc;
  420. // Return early if doc is invalid or already selected
  421. // Support: IE 11+, Edge 17 - 18+
  422. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  423. // two documents; shallow comparisons work.
  424. // eslint-disable-next-line eqeqeq
  425. if ( doc == document || doc.nodeType !== 9 || !doc.documentElement ) {
  426. return document;
  427. }
  428. // Update global variables
  429. document = doc;
  430. documentElement = document.documentElement;
  431. documentIsHTML = !jQuery.isXMLDoc( document );
  432. // Support: iOS 7 only, IE 9 - 11+
  433. // Older browsers didn't support unprefixed `matches`.
  434. matches = documentElement.matches ||
  435. documentElement.webkitMatchesSelector ||
  436. documentElement.msMatchesSelector;
  437. // Support: IE 9 - 11+, Edge 12 - 18+
  438. // Accessing iframe documents after unload throws "permission denied" errors (see trac-13936)
  439. // Support: IE 11+, Edge 17 - 18+
  440. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  441. // two documents; shallow comparisons work.
  442. // eslint-disable-next-line eqeqeq
  443. if ( preferredDoc != document &&
  444. ( subWindow = document.defaultView ) && subWindow.top !== subWindow ) {
  445. // Support: IE 9 - 11+, Edge 12 - 18+
  446. subWindow.addEventListener( "unload", unloadHandler );
  447. }
  448. // Support: IE <10
  449. // Check if getElementById returns elements by name
  450. // The broken getElementById methods don't pick up programmatically-set names,
  451. // so use a roundabout getElementsByName test
  452. support.getById = assert( function( el ) {
  453. documentElement.appendChild( el ).id = jQuery.expando;
  454. return !document.getElementsByName ||
  455. !document.getElementsByName( jQuery.expando ).length;
  456. } );
  457. // Support: IE 9 only
  458. // Check to see if it's possible to do matchesSelector
  459. // on a disconnected node.
  460. support.disconnectedMatch = assert( function( el ) {
  461. return matches.call( el, "*" );
  462. } );
  463. // Support: IE 9 - 11+, Edge 12 - 18+
  464. // IE/Edge don't support the :scope pseudo-class.
  465. support.scope = assert( function() {
  466. return document.querySelectorAll( ":scope" );
  467. } );
  468. // Support: Chrome 105 - 111 only, Safari 15.4 - 16.3 only
  469. // Make sure the `:has()` argument is parsed unforgivingly.
  470. // We include `*` in the test to detect buggy implementations that are
  471. // _selectively_ forgiving (specifically when the list includes at least
  472. // one valid selector).
  473. // Note that we treat complete lack of support for `:has()` as if it were
  474. // spec-compliant support, which is fine because use of `:has()` in such
  475. // environments will fail in the qSA path and fall back to jQuery traversal
  476. // anyway.
  477. support.cssHas = assert( function() {
  478. try {
  479. document.querySelector( ":has(*,:jqfake)" );
  480. return false;
  481. } catch ( e ) {
  482. return true;
  483. }
  484. } );
  485. // ID filter and find
  486. if ( support.getById ) {
  487. Expr.filter.ID = function( id ) {
  488. var attrId = id.replace( runescape, funescape );
  489. return function( elem ) {
  490. return elem.getAttribute( "id" ) === attrId;
  491. };
  492. };
  493. Expr.find.ID = function( id, context ) {
  494. if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
  495. var elem = context.getElementById( id );
  496. return elem ? [ elem ] : [];
  497. }
  498. };
  499. } else {
  500. Expr.filter.ID = function( id ) {
  501. var attrId = id.replace( runescape, funescape );
  502. return function( elem ) {
  503. var node = typeof elem.getAttributeNode !== "undefined" &&
  504. elem.getAttributeNode( "id" );
  505. return node && node.value === attrId;
  506. };
  507. };
  508. // Support: IE 6 - 7 only
  509. // getElementById is not reliable as a find shortcut
  510. Expr.find.ID = function( id, context ) {
  511. if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
  512. var node, i, elems,
  513. elem = context.getElementById( id );
  514. if ( elem ) {
  515. // Verify the id attribute
  516. node = elem.getAttributeNode( "id" );
  517. if ( node && node.value === id ) {
  518. return [ elem ];
  519. }
  520. // Fall back on getElementsByName
  521. elems = context.getElementsByName( id );
  522. i = 0;
  523. while ( ( elem = elems[ i++ ] ) ) {
  524. node = elem.getAttributeNode( "id" );
  525. if ( node && node.value === id ) {
  526. return [ elem ];
  527. }
  528. }
  529. }
  530. return [];
  531. }
  532. };
  533. }
  534. // Tag
  535. Expr.find.TAG = function( tag, context ) {
  536. if ( typeof context.getElementsByTagName !== "undefined" ) {
  537. return context.getElementsByTagName( tag );
  538. // DocumentFragment nodes don't have gEBTN
  539. } else {
  540. return context.querySelectorAll( tag );
  541. }
  542. };
  543. // Class
  544. Expr.find.CLASS = function( className, context ) {
  545. if ( typeof context.getElementsByClassName !== "undefined" && documentIsHTML ) {
  546. return context.getElementsByClassName( className );
  547. }
  548. };
  549. /* QSA/matchesSelector
  550. ---------------------------------------------------------------------- */
  551. // QSA and matchesSelector support
  552. rbuggyQSA = [];
  553. // Build QSA regex
  554. // Regex strategy adopted from Diego Perini
  555. assert( function( el ) {
  556. var input;
  557. documentElement.appendChild( el ).innerHTML =
  558. "<a id='" + expando + "' href='' disabled='disabled'></a>" +
  559. "<select id='" + expando + "-\r\\' disabled='disabled'>" +
  560. "<option selected=''></option></select>";
  561. // Support: iOS <=7 - 8 only
  562. // Boolean attributes and "value" are not treated correctly in some XML documents
  563. if ( !el.querySelectorAll( "[selected]" ).length ) {
  564. rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
  565. }
  566. // Support: iOS <=7 - 8 only
  567. if ( !el.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
  568. rbuggyQSA.push( "~=" );
  569. }
  570. // Support: iOS 8 only
  571. // https://bugs.webkit.org/show_bug.cgi?id=136851
  572. // In-page `selector#id sibling-combinator selector` fails
  573. if ( !el.querySelectorAll( "a#" + expando + "+*" ).length ) {
  574. rbuggyQSA.push( ".#.+[+~]" );
  575. }
  576. // Support: Chrome <=105+, Firefox <=104+, Safari <=15.4+
  577. // In some of the document kinds, these selectors wouldn't work natively.
  578. // This is probably OK but for backwards compatibility we want to maintain
  579. // handling them through jQuery traversal in jQuery 3.x.
  580. if ( !el.querySelectorAll( ":checked" ).length ) {
  581. rbuggyQSA.push( ":checked" );
  582. }
  583. // Support: Windows 8 Native Apps
  584. // The type and name attributes are restricted during .innerHTML assignment
  585. input = document.createElement( "input" );
  586. input.setAttribute( "type", "hidden" );
  587. el.appendChild( input ).setAttribute( "name", "D" );
  588. // Support: IE 9 - 11+
  589. // IE's :disabled selector does not pick up the children of disabled fieldsets
  590. // Support: Chrome <=105+, Firefox <=104+, Safari <=15.4+
  591. // In some of the document kinds, these selectors wouldn't work natively.
  592. // This is probably OK but for backwards compatibility we want to maintain
  593. // handling them through jQuery traversal in jQuery 3.x.
  594. documentElement.appendChild( el ).disabled = true;
  595. if ( el.querySelectorAll( ":disabled" ).length !== 2 ) {
  596. rbuggyQSA.push( ":enabled", ":disabled" );
  597. }
  598. // Support: IE 11+, Edge 15 - 18+
  599. // IE 11/Edge don't find elements on a `[name='']` query in some cases.
  600. // Adding a temporary attribute to the document before the selection works
  601. // around the issue.
  602. // Interestingly, IE 10 & older don't seem to have the issue.
  603. input = document.createElement( "input" );
  604. input.setAttribute( "name", "" );
  605. el.appendChild( input );
  606. if ( !el.querySelectorAll( "[name='']" ).length ) {
  607. rbuggyQSA.push( "\\[" + whitespace + "*name" + whitespace + "*=" +
  608. whitespace + "*(?:''|\"\")" );
  609. }
  610. } );
  611. if ( !support.cssHas ) {
  612. // Support: Chrome 105 - 110+, Safari 15.4 - 16.3+
  613. // Our regular `try-catch` mechanism fails to detect natively-unsupported
  614. // pseudo-classes inside `:has()` (such as `:has(:contains("Foo"))`)
  615. // in browsers that parse the `:has()` argument as a forgiving selector list.
  616. // https://drafts.csswg.org/selectors/#relational now requires the argument
  617. // to be parsed unforgivingly, but browsers have not yet fully adjusted.
  618. rbuggyQSA.push( ":has" );
  619. }
  620. rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join( "|" ) );
  621. /* Sorting
  622. ---------------------------------------------------------------------- */
  623. // Document order sorting
  624. sortOrder = function( a, b ) {
  625. // Flag for duplicate removal
  626. if ( a === b ) {
  627. hasDuplicate = true;
  628. return 0;
  629. }
  630. // Sort on method existence if only one input has compareDocumentPosition
  631. var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
  632. if ( compare ) {
  633. return compare;
  634. }
  635. // Calculate position if both inputs belong to the same document
  636. // Support: IE 11+, Edge 17 - 18+
  637. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  638. // two documents; shallow comparisons work.
  639. // eslint-disable-next-line eqeqeq
  640. compare = ( a.ownerDocument || a ) == ( b.ownerDocument || b ) ?
  641. a.compareDocumentPosition( b ) :
  642. // Otherwise we know they are disconnected
  643. 1;
  644. // Disconnected nodes
  645. if ( compare & 1 ||
  646. ( !support.sortDetached && b.compareDocumentPosition( a ) === compare ) ) {
  647. // Choose the first element that is related to our preferred document
  648. // Support: IE 11+, Edge 17 - 18+
  649. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  650. // two documents; shallow comparisons work.
  651. // eslint-disable-next-line eqeqeq
  652. if ( a === document || a.ownerDocument == preferredDoc &&
  653. find.contains( preferredDoc, a ) ) {
  654. return -1;
  655. }
  656. // Support: IE 11+, Edge 17 - 18+
  657. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  658. // two documents; shallow comparisons work.
  659. // eslint-disable-next-line eqeqeq
  660. if ( b === document || b.ownerDocument == preferredDoc &&
  661. find.contains( preferredDoc, b ) ) {
  662. return 1;
  663. }
  664. // Maintain original order
  665. return sortInput ?
  666. ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
  667. 0;
  668. }
  669. return compare & 4 ? -1 : 1;
  670. };
  671. return document;
  672. }
  673. find.matches = function( expr, elements ) {
  674. return find( expr, null, null, elements );
  675. };
  676. find.matchesSelector = function( elem, expr ) {
  677. setDocument( elem );
  678. if ( documentIsHTML &&
  679. !nonnativeSelectorCache[ expr + " " ] &&
  680. ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
  681. try {
  682. var ret = matches.call( elem, expr );
  683. // IE 9's matchesSelector returns false on disconnected nodes
  684. if ( ret || support.disconnectedMatch ||
  685. // As well, disconnected nodes are said to be in a document
  686. // fragment in IE 9
  687. elem.document && elem.document.nodeType !== 11 ) {
  688. return ret;
  689. }
  690. } catch ( e ) {
  691. nonnativeSelectorCache( expr, true );
  692. }
  693. }
  694. return find( expr, document, null, [ elem ] ).length > 0;
  695. };
  696. find.contains = function( context, elem ) {
  697. // Set document vars if needed
  698. // Support: IE 11+, Edge 17 - 18+
  699. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  700. // two documents; shallow comparisons work.
  701. // eslint-disable-next-line eqeqeq
  702. if ( ( context.ownerDocument || context ) != document ) {
  703. setDocument( context );
  704. }
  705. return jQuery.contains( context, elem );
  706. };
  707. find.attr = function( elem, name ) {
  708. // Set document vars if needed
  709. // Support: IE 11+, Edge 17 - 18+
  710. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  711. // two documents; shallow comparisons work.
  712. // eslint-disable-next-line eqeqeq
  713. if ( ( elem.ownerDocument || elem ) != document ) {
  714. setDocument( elem );
  715. }
  716. var fn = Expr.attrHandle[ name.toLowerCase() ],
  717. // Don't get fooled by Object.prototype properties (see trac-13807)
  718. val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
  719. fn( elem, name, !documentIsHTML ) :
  720. undefined;
  721. if ( val !== undefined ) {
  722. return val;
  723. }
  724. return elem.getAttribute( name );
  725. };
  726. find.error = function( msg ) {
  727. throw new Error( "Syntax error, unrecognized expression: " + msg );
  728. };
  729. /**
  730. * Document sorting and removing duplicates
  731. * @param {ArrayLike} results
  732. */
  733. jQuery.uniqueSort = function( results ) {
  734. var elem,
  735. duplicates = [],
  736. j = 0,
  737. i = 0;
  738. // Unless we *know* we can detect duplicates, assume their presence
  739. //
  740. // Support: Android <=4.0+
  741. // Testing for detecting duplicates is unpredictable so instead assume we can't
  742. // depend on duplicate detection in all browsers without a stable sort.
  743. hasDuplicate = !support.sortStable;
  744. sortInput = !support.sortStable && slice.call( results, 0 );
  745. sort.call( results, sortOrder );
  746. if ( hasDuplicate ) {
  747. while ( ( elem = results[ i++ ] ) ) {
  748. if ( elem === results[ i ] ) {
  749. j = duplicates.push( i );
  750. }
  751. }
  752. while ( j-- ) {
  753. splice.call( results, duplicates[ j ], 1 );
  754. }
  755. }
  756. // Clear input after sorting to release objects
  757. // See https://github.com/jquery/sizzle/pull/225
  758. sortInput = null;
  759. return results;
  760. };
  761. jQuery.fn.uniqueSort = function() {
  762. return this.pushStack( jQuery.uniqueSort( slice.apply( this ) ) );
  763. };
  764. Expr = jQuery.expr = {
  765. // Can be adjusted by the user
  766. cacheLength: 50,
  767. createPseudo: markFunction,
  768. match: matchExpr,
  769. attrHandle: {},
  770. find: {},
  771. relative: {
  772. ">": { dir: "parentNode", first: true },
  773. " ": { dir: "parentNode" },
  774. "+": { dir: "previousSibling", first: true },
  775. "~": { dir: "previousSibling" }
  776. },
  777. preFilter: {
  778. ATTR: function( match ) {
  779. match[ 1 ] = match[ 1 ].replace( runescape, funescape );
  780. // Move the given value to match[3] whether quoted or unquoted
  781. match[ 3 ] = ( match[ 3 ] || match[ 4 ] || match[ 5 ] || "" )
  782. .replace( runescape, funescape );
  783. if ( match[ 2 ] === "~=" ) {
  784. match[ 3 ] = " " + match[ 3 ] + " ";
  785. }
  786. return match.slice( 0, 4 );
  787. },
  788. CHILD: function( match ) {
  789. /* matches from matchExpr["CHILD"]
  790. 1 type (only|nth|...)
  791. 2 what (child|of-type)
  792. 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
  793. 4 xn-component of xn+y argument ([+-]?\d*n|)
  794. 5 sign of xn-component
  795. 6 x of xn-component
  796. 7 sign of y-component
  797. 8 y of y-component
  798. */
  799. match[ 1 ] = match[ 1 ].toLowerCase();
  800. if ( match[ 1 ].slice( 0, 3 ) === "nth" ) {
  801. // nth-* requires argument
  802. if ( !match[ 3 ] ) {
  803. find.error( match[ 0 ] );
  804. }
  805. // numeric x and y parameters for Expr.filter.CHILD
  806. // remember that false/true cast respectively to 0/1
  807. match[ 4 ] = +( match[ 4 ] ?
  808. match[ 5 ] + ( match[ 6 ] || 1 ) :
  809. 2 * ( match[ 3 ] === "even" || match[ 3 ] === "odd" )
  810. );
  811. match[ 5 ] = +( ( match[ 7 ] + match[ 8 ] ) || match[ 3 ] === "odd" );
  812. // other types prohibit arguments
  813. } else if ( match[ 3 ] ) {
  814. find.error( match[ 0 ] );
  815. }
  816. return match;
  817. },
  818. PSEUDO: function( match ) {
  819. var excess,
  820. unquoted = !match[ 6 ] && match[ 2 ];
  821. if ( matchExpr.CHILD.test( match[ 0 ] ) ) {
  822. return null;
  823. }
  824. // Accept quoted arguments as-is
  825. if ( match[ 3 ] ) {
  826. match[ 2 ] = match[ 4 ] || match[ 5 ] || "";
  827. // Strip excess characters from unquoted arguments
  828. } else if ( unquoted && rpseudo.test( unquoted ) &&
  829. // Get excess from tokenize (recursively)
  830. ( excess = tokenize( unquoted, true ) ) &&
  831. // advance to the next closing parenthesis
  832. ( excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length ) ) {
  833. // excess is a negative index
  834. match[ 0 ] = match[ 0 ].slice( 0, excess );
  835. match[ 2 ] = unquoted.slice( 0, excess );
  836. }
  837. // Return only captures needed by the pseudo filter method (type and argument)
  838. return match.slice( 0, 3 );
  839. }
  840. },
  841. filter: {
  842. TAG: function( nodeNameSelector ) {
  843. var expectedNodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
  844. return nodeNameSelector === "*" ?
  845. function() {
  846. return true;
  847. } :
  848. function( elem ) {
  849. return nodeName( elem, expectedNodeName );
  850. };
  851. },
  852. CLASS: function( className ) {
  853. var pattern = classCache[ className + " " ];
  854. return pattern ||
  855. ( pattern = new RegExp( "(^|" + whitespace + ")" + className +
  856. "(" + whitespace + "|$)" ) ) &&
  857. classCache( className, function( elem ) {
  858. return pattern.test(
  859. typeof elem.className === "string" && elem.className ||
  860. typeof elem.getAttribute !== "undefined" &&
  861. elem.getAttribute( "class" ) ||
  862. ""
  863. );
  864. } );
  865. },
  866. ATTR: function( name, operator, check ) {
  867. return function( elem ) {
  868. var result = find.attr( elem, name );
  869. if ( result == null ) {
  870. return operator === "!=";
  871. }
  872. if ( !operator ) {
  873. return true;
  874. }
  875. result += "";
  876. if ( operator === "=" ) {
  877. return result === check;
  878. }
  879. if ( operator === "!=" ) {
  880. return result !== check;
  881. }
  882. if ( operator === "^=" ) {
  883. return check && result.indexOf( check ) === 0;
  884. }
  885. if ( operator === "*=" ) {
  886. return check && result.indexOf( check ) > -1;
  887. }
  888. if ( operator === "$=" ) {
  889. return check && result.slice( -check.length ) === check;
  890. }
  891. if ( operator === "~=" ) {
  892. return ( " " + result.replace( rwhitespace, " " ) + " " )
  893. .indexOf( check ) > -1;
  894. }
  895. if ( operator === "|=" ) {
  896. return result === check || result.slice( 0, check.length + 1 ) === check + "-";
  897. }
  898. return false;
  899. };
  900. },
  901. CHILD: function( type, what, _argument, first, last ) {
  902. var simple = type.slice( 0, 3 ) !== "nth",
  903. forward = type.slice( -4 ) !== "last",
  904. ofType = what === "of-type";
  905. return first === 1 && last === 0 ?
  906. // Shortcut for :nth-*(n)
  907. function( elem ) {
  908. return !!elem.parentNode;
  909. } :
  910. function( elem, _context, xml ) {
  911. var cache, outerCache, node, nodeIndex, start,
  912. dir = simple !== forward ? "nextSibling" : "previousSibling",
  913. parent = elem.parentNode,
  914. name = ofType && elem.nodeName.toLowerCase(),
  915. useCache = !xml && !ofType,
  916. diff = false;
  917. if ( parent ) {
  918. // :(first|last|only)-(child|of-type)
  919. if ( simple ) {
  920. while ( dir ) {
  921. node = elem;
  922. while ( ( node = node[ dir ] ) ) {
  923. if ( ofType ?
  924. nodeName( node, name ) :
  925. node.nodeType === 1 ) {
  926. return false;
  927. }
  928. }
  929. // Reverse direction for :only-* (if we haven't yet done so)
  930. start = dir = type === "only" && !start && "nextSibling";
  931. }
  932. return true;
  933. }
  934. start = [ forward ? parent.firstChild : parent.lastChild ];
  935. // non-xml :nth-child(...) stores cache data on `parent`
  936. if ( forward && useCache ) {
  937. // Seek `elem` from a previously-cached index
  938. outerCache = parent[ expando ] || ( parent[ expando ] = {} );
  939. cache = outerCache[ type ] || [];
  940. nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];
  941. diff = nodeIndex && cache[ 2 ];
  942. node = nodeIndex && parent.childNodes[ nodeIndex ];
  943. while ( ( node = ++nodeIndex && node && node[ dir ] ||
  944. // Fallback to seeking `elem` from the start
  945. ( diff = nodeIndex = 0 ) || start.pop() ) ) {
  946. // When found, cache indexes on `parent` and break
  947. if ( node.nodeType === 1 && ++diff && node === elem ) {
  948. outerCache[ type ] = [ dirruns, nodeIndex, diff ];
  949. break;
  950. }
  951. }
  952. } else {
  953. // Use previously-cached element index if available
  954. if ( useCache ) {
  955. outerCache = elem[ expando ] || ( elem[ expando ] = {} );
  956. cache = outerCache[ type ] || [];
  957. nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];
  958. diff = nodeIndex;
  959. }
  960. // xml :nth-child(...)
  961. // or :nth-last-child(...) or :nth(-last)?-of-type(...)
  962. if ( diff === false ) {
  963. // Use the same loop as above to seek `elem` from the start
  964. while ( ( node = ++nodeIndex && node && node[ dir ] ||
  965. ( diff = nodeIndex = 0 ) || start.pop() ) ) {
  966. if ( ( ofType ?
  967. nodeName( node, name ) :
  968. node.nodeType === 1 ) &&
  969. ++diff ) {
  970. // Cache the index of each encountered element
  971. if ( useCache ) {
  972. outerCache = node[ expando ] ||
  973. ( node[ expando ] = {} );
  974. outerCache[ type ] = [ dirruns, diff ];
  975. }
  976. if ( node === elem ) {
  977. break;
  978. }
  979. }
  980. }
  981. }
  982. }
  983. // Incorporate the offset, then check against cycle size
  984. diff -= last;
  985. return diff === first || ( diff % first === 0 && diff / first >= 0 );
  986. }
  987. };
  988. },
  989. PSEUDO: function( pseudo, argument ) {
  990. // pseudo-class names are case-insensitive
  991. // https://www.w3.org/TR/selectors/#pseudo-classes
  992. // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
  993. // Remember that setFilters inherits from pseudos
  994. var args,
  995. fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
  996. find.error( "unsupported pseudo: " + pseudo );
  997. // The user may use createPseudo to indicate that
  998. // arguments are needed to create the filter function
  999. // just as jQuery does
  1000. if ( fn[ expando ] ) {
  1001. return fn( argument );
  1002. }
  1003. // But maintain support for old signatures
  1004. if ( fn.length > 1 ) {
  1005. args = [ pseudo, pseudo, "", argument ];
  1006. return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
  1007. markFunction( function( seed, matches ) {
  1008. var idx,
  1009. matched = fn( seed, argument ),
  1010. i = matched.length;
  1011. while ( i-- ) {
  1012. idx = indexOf.call( seed, matched[ i ] );
  1013. seed[ idx ] = !( matches[ idx ] = matched[ i ] );
  1014. }
  1015. } ) :
  1016. function( elem ) {
  1017. return fn( elem, 0, args );
  1018. };
  1019. }
  1020. return fn;
  1021. }
  1022. },
  1023. pseudos: {
  1024. // Potentially complex pseudos
  1025. not: markFunction( function( selector ) {
  1026. // Trim the selector passed to compile
  1027. // to avoid treating leading and trailing
  1028. // spaces as combinators
  1029. var input = [],
  1030. results = [],
  1031. matcher = compile( selector.replace( rtrimCSS, "$1" ) );
  1032. return matcher[ expando ] ?
  1033. markFunction( function( seed, matches, _context, xml ) {
  1034. var elem,
  1035. unmatched = matcher( seed, null, xml, [] ),
  1036. i = seed.length;
  1037. // Match elements unmatched by `matcher`
  1038. while ( i-- ) {
  1039. if ( ( elem = unmatched[ i ] ) ) {
  1040. seed[ i ] = !( matches[ i ] = elem );
  1041. }
  1042. }
  1043. } ) :
  1044. function( elem, _context, xml ) {
  1045. input[ 0 ] = elem;
  1046. matcher( input, null, xml, results );
  1047. // Don't keep the element
  1048. // (see https://github.com/jquery/sizzle/issues/299)
  1049. input[ 0 ] = null;
  1050. return !results.pop();
  1051. };
  1052. } ),
  1053. has: markFunction( function( selector ) {
  1054. return function( elem ) {
  1055. return find( selector, elem ).length > 0;
  1056. };
  1057. } ),
  1058. contains: markFunction( function( text ) {
  1059. text = text.replace( runescape, funescape );
  1060. return function( elem ) {
  1061. return ( elem.textContent || jQuery.text( elem ) ).indexOf( text ) > -1;
  1062. };
  1063. } ),
  1064. // "Whether an element is represented by a :lang() selector
  1065. // is based solely on the element's language value
  1066. // being equal to the identifier C,
  1067. // or beginning with the identifier C immediately followed by "-".
  1068. // The matching of C against the element's language value is performed case-insensitively.
  1069. // The identifier C does not have to be a valid language name."
  1070. // https://www.w3.org/TR/selectors/#lang-pseudo
  1071. lang: markFunction( function( lang ) {
  1072. // lang value must be a valid identifier
  1073. if ( !ridentifier.test( lang || "" ) ) {
  1074. find.error( "unsupported lang: " + lang );
  1075. }
  1076. lang = lang.replace( runescape, funescape ).toLowerCase();
  1077. return function( elem ) {
  1078. var elemLang;
  1079. do {
  1080. if ( ( elemLang = documentIsHTML ?
  1081. elem.lang :
  1082. elem.getAttribute( "xml:lang" ) || elem.getAttribute( "lang" ) ) ) {
  1083. elemLang = elemLang.toLowerCase();
  1084. return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
  1085. }
  1086. } while ( ( elem = elem.parentNode ) && elem.nodeType === 1 );
  1087. return false;
  1088. };
  1089. } ),
  1090. // Miscellaneous
  1091. target: function( elem ) {
  1092. var hash = window.location && window.location.hash;
  1093. return hash && hash.slice( 1 ) === elem.id;
  1094. },
  1095. root: function( elem ) {
  1096. return elem === documentElement;
  1097. },
  1098. focus: function( elem ) {
  1099. return elem === safeActiveElement() &&
  1100. document.hasFocus() &&
  1101. !!( elem.type || elem.href || ~elem.tabIndex );
  1102. },
  1103. // Boolean properties
  1104. enabled: createDisabledPseudo( false ),
  1105. disabled: createDisabledPseudo( true ),
  1106. checked: function( elem ) {
  1107. // In CSS3, :checked should return both checked and selected elements
  1108. // https://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
  1109. return ( nodeName( elem, "input" ) && !!elem.checked ) ||
  1110. ( nodeName( elem, "option" ) && !!elem.selected );
  1111. },
  1112. selected: function( elem ) {
  1113. // Support: IE <=11+
  1114. // Accessing the selectedIndex property
  1115. // forces the browser to treat the default option as
  1116. // selected when in an optgroup.
  1117. if ( elem.parentNode ) {
  1118. // eslint-disable-next-line no-unused-expressions
  1119. elem.parentNode.selectedIndex;
  1120. }
  1121. return elem.selected === true;
  1122. },
  1123. // Contents
  1124. empty: function( elem ) {
  1125. // https://www.w3.org/TR/selectors/#empty-pseudo
  1126. // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
  1127. // but not by others (comment: 8; processing instruction: 7; etc.)
  1128. // nodeType < 6 works because attributes (2) do not appear as children
  1129. for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
  1130. if ( elem.nodeType < 6 ) {
  1131. return false;
  1132. }
  1133. }
  1134. return true;
  1135. },
  1136. parent: function( elem ) {
  1137. return !Expr.pseudos.empty( elem );
  1138. },
  1139. // Element/input types
  1140. header: function( elem ) {
  1141. return rheader.test( elem.nodeName );
  1142. },
  1143. input: function( elem ) {
  1144. return rinputs.test( elem.nodeName );
  1145. },
  1146. button: function( elem ) {
  1147. return nodeName( elem, "input" ) && elem.type === "button" ||
  1148. nodeName( elem, "button" );
  1149. },
  1150. text: function( elem ) {
  1151. var attr;
  1152. return nodeName( elem, "input" ) && elem.type === "text" &&
  1153. // Support: IE <10 only
  1154. // New HTML5 attribute values (e.g., "search") appear
  1155. // with elem.type === "text"
  1156. ( ( attr = elem.getAttribute( "type" ) ) == null ||
  1157. attr.toLowerCase() === "text" );
  1158. },
  1159. // Position-in-collection
  1160. first: createPositionalPseudo( function() {
  1161. return [ 0 ];
  1162. } ),
  1163. last: createPositionalPseudo( function( _matchIndexes, length ) {
  1164. return [ length - 1 ];
  1165. } ),
  1166. eq: createPositionalPseudo( function( _matchIndexes, length, argument ) {
  1167. return [ argument < 0 ? argument + length : argument ];
  1168. } ),
  1169. even: createPositionalPseudo( function( matchIndexes, length ) {
  1170. var i = 0;
  1171. for ( ; i < length; i += 2 ) {
  1172. matchIndexes.push( i );
  1173. }
  1174. return matchIndexes;
  1175. } ),
  1176. odd: createPositionalPseudo( function( matchIndexes, length ) {
  1177. var i = 1;
  1178. for ( ; i < length; i += 2 ) {
  1179. matchIndexes.push( i );
  1180. }
  1181. return matchIndexes;
  1182. } ),
  1183. lt: createPositionalPseudo( function( matchIndexes, length, argument ) {
  1184. var i;
  1185. if ( argument < 0 ) {
  1186. i = argument + length;
  1187. } else if ( argument > length ) {
  1188. i = length;
  1189. } else {
  1190. i = argument;
  1191. }
  1192. for ( ; --i >= 0; ) {
  1193. matchIndexes.push( i );
  1194. }
  1195. return matchIndexes;
  1196. } ),
  1197. gt: createPositionalPseudo( function( matchIndexes, length, argument ) {
  1198. var i = argument < 0 ? argument + length : argument;
  1199. for ( ; ++i < length; ) {
  1200. matchIndexes.push( i );
  1201. }
  1202. return matchIndexes;
  1203. } )
  1204. }
  1205. };
  1206. Expr.pseudos.nth = Expr.pseudos.eq;
  1207. // Add button/input type pseudos
  1208. for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
  1209. Expr.pseudos[ i ] = createInputPseudo( i );
  1210. }
  1211. for ( i in { submit: true, reset: true } ) {
  1212. Expr.pseudos[ i ] = createButtonPseudo( i );
  1213. }
  1214. // Easy API for creating new setFilters
  1215. function setFilters() {}
  1216. setFilters.prototype = Expr.filters = Expr.pseudos;
  1217. Expr.setFilters = new setFilters();
  1218. function tokenize( selector, parseOnly ) {
  1219. var matched, match, tokens, type,
  1220. soFar, groups, preFilters,
  1221. cached = tokenCache[ selector + " " ];
  1222. if ( cached ) {
  1223. return parseOnly ? 0 : cached.slice( 0 );
  1224. }
  1225. soFar = selector;
  1226. groups = [];
  1227. preFilters = Expr.preFilter;
  1228. while ( soFar ) {
  1229. // Comma and first run
  1230. if ( !matched || ( match = rcomma.exec( soFar ) ) ) {
  1231. if ( match ) {
  1232. // Don't consume trailing commas as valid
  1233. soFar = soFar.slice( match[ 0 ].length ) || soFar;
  1234. }
  1235. groups.push( ( tokens = [] ) );
  1236. }
  1237. matched = false;
  1238. // Combinators
  1239. if ( ( match = rleadingCombinator.exec( soFar ) ) ) {
  1240. matched = match.shift();
  1241. tokens.push( {
  1242. value: matched,
  1243. // Cast descendant combinators to space
  1244. type: match[ 0 ].replace( rtrimCSS, " " )
  1245. } );
  1246. soFar = soFar.slice( matched.length );
  1247. }
  1248. // Filters
  1249. for ( type in Expr.filter ) {
  1250. if ( ( match = matchExpr[ type ].exec( soFar ) ) && ( !preFilters[ type ] ||
  1251. ( match = preFilters[ type ]( match ) ) ) ) {
  1252. matched = match.shift();
  1253. tokens.push( {
  1254. value: matched,
  1255. type: type,
  1256. matches: match
  1257. } );
  1258. soFar = soFar.slice( matched.length );
  1259. }
  1260. }
  1261. if ( !matched ) {
  1262. break;
  1263. }
  1264. }
  1265. // Return the length of the invalid excess
  1266. // if we're just parsing
  1267. // Otherwise, throw an error or return tokens
  1268. if ( parseOnly ) {
  1269. return soFar.length;
  1270. }
  1271. return soFar ?
  1272. find.error( selector ) :
  1273. // Cache the tokens
  1274. tokenCache( selector, groups ).slice( 0 );
  1275. }
  1276. function toSelector( tokens ) {
  1277. var i = 0,
  1278. len = tokens.length,
  1279. selector = "";
  1280. for ( ; i < len; i++ ) {
  1281. selector += tokens[ i ].value;
  1282. }
  1283. return selector;
  1284. }
  1285. function addCombinator( matcher, combinator, base ) {
  1286. var dir = combinator.dir,
  1287. skip = combinator.next,
  1288. key = skip || dir,
  1289. checkNonElements = base && key === "parentNode",
  1290. doneName = done++;
  1291. return combinator.first ?
  1292. // Check against closest ancestor/preceding element
  1293. function( elem, context, xml ) {
  1294. while ( ( elem = elem[ dir ] ) ) {
  1295. if ( elem.nodeType === 1 || checkNonElements ) {
  1296. return matcher( elem, context, xml );
  1297. }
  1298. }
  1299. return false;
  1300. } :
  1301. // Check against all ancestor/preceding elements
  1302. function( elem, context, xml ) {
  1303. var oldCache, outerCache,
  1304. newCache = [ dirruns, doneName ];
  1305. // We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching
  1306. if ( xml ) {
  1307. while ( ( elem = elem[ dir ] ) ) {
  1308. if ( elem.nodeType === 1 || checkNonElements ) {
  1309. if ( matcher( elem, context, xml ) ) {
  1310. return true;
  1311. }
  1312. }
  1313. }
  1314. } else {
  1315. while ( ( elem = elem[ dir ] ) ) {
  1316. if ( elem.nodeType === 1 || checkNonElements ) {
  1317. outerCache = elem[ expando ] || ( elem[ expando ] = {} );
  1318. if ( skip && nodeName( elem, skip ) ) {
  1319. elem = elem[ dir ] || elem;
  1320. } else if ( ( oldCache = outerCache[ key ] ) &&
  1321. oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
  1322. // Assign to newCache so results back-propagate to previous elements
  1323. return ( newCache[ 2 ] = oldCache[ 2 ] );
  1324. } else {
  1325. // Reuse newcache so results back-propagate to previous elements
  1326. outerCache[ key ] = newCache;
  1327. // A match means we're done; a fail means we have to keep checking
  1328. if ( ( newCache[ 2 ] = matcher( elem, context, xml ) ) ) {
  1329. return true;
  1330. }
  1331. }
  1332. }
  1333. }
  1334. }
  1335. return false;
  1336. };
  1337. }
  1338. function elementMatcher( matchers ) {
  1339. return matchers.length > 1 ?
  1340. function( elem, context, xml ) {
  1341. var i = matchers.length;
  1342. while ( i-- ) {
  1343. if ( !matchers[ i ]( elem, context, xml ) ) {
  1344. return false;
  1345. }
  1346. }
  1347. return true;
  1348. } :
  1349. matchers[ 0 ];
  1350. }
  1351. function multipleContexts( selector, contexts, results ) {
  1352. var i = 0,
  1353. len = contexts.length;
  1354. for ( ; i < len; i++ ) {
  1355. find( selector, contexts[ i ], results );
  1356. }
  1357. return results;
  1358. }
  1359. function condense( unmatched, map, filter, context, xml ) {
  1360. var elem,
  1361. newUnmatched = [],
  1362. i = 0,
  1363. len = unmatched.length,
  1364. mapped = map != null;
  1365. for ( ; i < len; i++ ) {
  1366. if ( ( elem = unmatched[ i ] ) ) {
  1367. if ( !filter || filter( elem, context, xml ) ) {
  1368. newUnmatched.push( elem );
  1369. if ( mapped ) {
  1370. map.push( i );
  1371. }
  1372. }
  1373. }
  1374. }
  1375. return newUnmatched;
  1376. }
  1377. function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
  1378. if ( postFilter && !postFilter[ expando ] ) {
  1379. postFilter = setMatcher( postFilter );
  1380. }
  1381. if ( postFinder && !postFinder[ expando ] ) {
  1382. postFinder = setMatcher( postFinder, postSelector );
  1383. }
  1384. return markFunction( function( seed, results, context, xml ) {
  1385. var temp, i, elem, matcherOut,
  1386. preMap = [],
  1387. postMap = [],
  1388. preexisting = results.length,
  1389. // Get initial elements from seed or context
  1390. elems = seed ||
  1391. multipleContexts( selector || "*",
  1392. context.nodeType ? [ context ] : context, [] ),
  1393. // Prefilter to get matcher input, preserving a map for seed-results synchronization
  1394. matcherIn = preFilter && ( seed || !selector ) ?
  1395. condense( elems, preMap, preFilter, context, xml ) :
  1396. elems;
  1397. if ( matcher ) {
  1398. // If we have a postFinder, or filtered seed, or non-seed postFilter
  1399. // or preexisting results,
  1400. matcherOut = postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
  1401. // ...intermediate processing is necessary
  1402. [] :
  1403. // ...otherwise use results directly
  1404. results;
  1405. // Find primary matches
  1406. matcher( matcherIn, matcherOut, context, xml );
  1407. } else {
  1408. matcherOut = matcherIn;
  1409. }
  1410. // Apply postFilter
  1411. if ( postFilter ) {
  1412. temp = condense( matcherOut, postMap );
  1413. postFilter( temp, [], context, xml );
  1414. // Un-match failing elements by moving them back to matcherIn
  1415. i = temp.length;
  1416. while ( i-- ) {
  1417. if ( ( elem = temp[ i ] ) ) {
  1418. matcherOut[ postMap[ i ] ] = !( matcherIn[ postMap[ i ] ] = elem );
  1419. }
  1420. }
  1421. }
  1422. if ( seed ) {
  1423. if ( postFinder || preFilter ) {
  1424. if ( postFinder ) {
  1425. // Get the final matcherOut by condensing this intermediate into postFinder contexts
  1426. temp = [];
  1427. i = matcherOut.length;
  1428. while ( i-- ) {
  1429. if ( ( elem = matcherOut[ i ] ) ) {
  1430. // Restore matcherIn since elem is not yet a final match
  1431. temp.push( ( matcherIn[ i ] = elem ) );
  1432. }
  1433. }
  1434. postFinder( null, ( matcherOut = [] ), temp, xml );
  1435. }
  1436. // Move matched elements from seed to results to keep them synchronized
  1437. i = matcherOut.length;
  1438. while ( i-- ) {
  1439. if ( ( elem = matcherOut[ i ] ) &&
  1440. ( temp = postFinder ? indexOf.call( seed, elem ) : preMap[ i ] ) > -1 ) {
  1441. seed[ temp ] = !( results[ temp ] = elem );
  1442. }
  1443. }
  1444. }
  1445. // Add elements to results, through postFinder if defined
  1446. } else {
  1447. matcherOut = condense(
  1448. matcherOut === results ?
  1449. matcherOut.splice( preexisting, matcherOut.length ) :
  1450. matcherOut
  1451. );
  1452. if ( postFinder ) {
  1453. postFinder( null, results, matcherOut, xml );
  1454. } else {
  1455. push.apply( results, matcherOut );
  1456. }
  1457. }
  1458. } );
  1459. }
  1460. function matcherFromTokens( tokens ) {
  1461. var checkContext, matcher, j,
  1462. len = tokens.length,
  1463. leadingRelative = Expr.relative[ tokens[ 0 ].type ],
  1464. implicitRelative = leadingRelative || Expr.relative[ " " ],
  1465. i = leadingRelative ? 1 : 0,
  1466. // The foundational matcher ensures that elements are reachable from top-level context(s)
  1467. matchContext = addCombinator( function( elem ) {
  1468. return elem === checkContext;
  1469. }, implicitRelative, true ),
  1470. matchAnyContext = addCombinator( function( elem ) {
  1471. return indexOf.call( checkContext, elem ) > -1;
  1472. }, implicitRelative, true ),
  1473. matchers = [ function( elem, context, xml ) {
  1474. // Support: IE 11+, Edge 17 - 18+
  1475. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  1476. // two documents; shallow comparisons work.
  1477. // eslint-disable-next-line eqeqeq
  1478. var ret = ( !leadingRelative && ( xml || context != outermostContext ) ) || (
  1479. ( checkContext = context ).nodeType ?
  1480. matchContext( elem, context, xml ) :
  1481. matchAnyContext( elem, context, xml ) );
  1482. // Avoid hanging onto element
  1483. // (see https://github.com/jquery/sizzle/issues/299)
  1484. checkContext = null;
  1485. return ret;
  1486. } ];
  1487. for ( ; i < len; i++ ) {
  1488. if ( ( matcher = Expr.relative[ tokens[ i ].type ] ) ) {
  1489. matchers = [ addCombinator( elementMatcher( matchers ), matcher ) ];
  1490. } else {
  1491. matcher = Expr.filter[ tokens[ i ].type ].apply( null, tokens[ i ].matches );
  1492. // Return special upon seeing a positional matcher
  1493. if ( matcher[ expando ] ) {
  1494. // Find the next relative operator (if any) for proper handling
  1495. j = ++i;
  1496. for ( ; j < len; j++ ) {
  1497. if ( Expr.relative[ tokens[ j ].type ] ) {
  1498. break;
  1499. }
  1500. }
  1501. return setMatcher(
  1502. i > 1 && elementMatcher( matchers ),
  1503. i > 1 && toSelector(
  1504. // If the preceding token was a descendant combinator, insert an implicit any-element `*`
  1505. tokens.slice( 0, i - 1 )
  1506. .concat( { value: tokens[ i - 2 ].type === " " ? "*" : "" } )
  1507. ).replace( rtrimCSS, "$1" ),
  1508. matcher,
  1509. i < j && matcherFromTokens( tokens.slice( i, j ) ),
  1510. j < len && matcherFromTokens( ( tokens = tokens.slice( j ) ) ),
  1511. j < len && toSelector( tokens )
  1512. );
  1513. }
  1514. matchers.push( matcher );
  1515. }
  1516. }
  1517. return elementMatcher( matchers );
  1518. }
  1519. function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
  1520. var bySet = setMatchers.length > 0,
  1521. byElement = elementMatchers.length > 0,
  1522. superMatcher = function( seed, context, xml, results, outermost ) {
  1523. var elem, j, matcher,
  1524. matchedCount = 0,
  1525. i = "0",
  1526. unmatched = seed && [],
  1527. setMatched = [],
  1528. contextBackup = outermostContext,
  1529. // We must always have either seed elements or outermost context
  1530. elems = seed || byElement && Expr.find.TAG( "*", outermost ),
  1531. // Use integer dirruns iff this is the outermost matcher
  1532. dirrunsUnique = ( dirruns += contextBackup == null ? 1 : Math.random() || 0.1 ),
  1533. len = elems.length;
  1534. if ( outermost ) {
  1535. // Support: IE 11+, Edge 17 - 18+
  1536. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  1537. // two documents; shallow comparisons work.
  1538. // eslint-disable-next-line eqeqeq
  1539. outermostContext = context == document || context || outermost;
  1540. }
  1541. // Add elements passing elementMatchers directly to results
  1542. // Support: iOS <=7 - 9 only
  1543. // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching
  1544. // elements by id. (see trac-14142)
  1545. for ( ; i !== len && ( elem = elems[ i ] ) != null; i++ ) {
  1546. if ( byElement && elem ) {
  1547. j = 0;
  1548. // Support: IE 11+, Edge 17 - 18+
  1549. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  1550. // two documents; shallow comparisons work.
  1551. // eslint-disable-next-line eqeqeq
  1552. if ( !context && elem.ownerDocument != document ) {
  1553. setDocument( elem );
  1554. xml = !documentIsHTML;
  1555. }
  1556. while ( ( matcher = elementMatchers[ j++ ] ) ) {
  1557. if ( matcher( elem, context || document, xml ) ) {
  1558. push.call( results, elem );
  1559. break;
  1560. }
  1561. }
  1562. if ( outermost ) {
  1563. dirruns = dirrunsUnique;
  1564. }
  1565. }
  1566. // Track unmatched elements for set filters
  1567. if ( bySet ) {
  1568. // They will have gone through all possible matchers
  1569. if ( ( elem = !matcher && elem ) ) {
  1570. matchedCount--;
  1571. }
  1572. // Lengthen the array for every element, matched or not
  1573. if ( seed ) {
  1574. unmatched.push( elem );
  1575. }
  1576. }
  1577. }
  1578. // `i` is now the count of elements visited above, and adding it to `matchedCount`
  1579. // makes the latter nonnegative.
  1580. matchedCount += i;
  1581. // Apply set filters to unmatched elements
  1582. // NOTE: This can be skipped if there are no unmatched elements (i.e., `matchedCount`
  1583. // equals `i`), unless we didn't visit _any_ elements in the above loop because we have
  1584. // no element matchers and no seed.
  1585. // Incrementing an initially-string "0" `i` allows `i` to remain a string only in that
  1586. // case, which will result in a "00" `matchedCount` that differs from `i` but is also
  1587. // numerically zero.
  1588. if ( bySet && i !== matchedCount ) {
  1589. j = 0;
  1590. while ( ( matcher = setMatchers[ j++ ] ) ) {
  1591. matcher( unmatched, setMatched, context, xml );
  1592. }
  1593. if ( seed ) {
  1594. // Reintegrate element matches to eliminate the need for sorting
  1595. if ( matchedCount > 0 ) {
  1596. while ( i-- ) {
  1597. if ( !( unmatched[ i ] || setMatched[ i ] ) ) {
  1598. setMatched[ i ] = pop.call( results );
  1599. }
  1600. }
  1601. }
  1602. // Discard index placeholder values to get only actual matches
  1603. setMatched = condense( setMatched );
  1604. }
  1605. // Add matches to results
  1606. push.apply( results, setMatched );
  1607. // Seedless set matches succeeding multiple successful matchers stipulate sorting
  1608. if ( outermost && !seed && setMatched.length > 0 &&
  1609. ( matchedCount + setMatchers.length ) > 1 ) {
  1610. jQuery.uniqueSort( results );
  1611. }
  1612. }
  1613. // Override manipulation of globals by nested matchers
  1614. if ( outermost ) {
  1615. dirruns = dirrunsUnique;
  1616. outermostContext = contextBackup;
  1617. }
  1618. return unmatched;
  1619. };
  1620. return bySet ?
  1621. markFunction( superMatcher ) :
  1622. superMatcher;
  1623. }
  1624. function compile( selector, match /* Internal Use Only */ ) {
  1625. var i,
  1626. setMatchers = [],
  1627. elementMatchers = [],
  1628. cached = compilerCache[ selector + " " ];
  1629. if ( !cached ) {
  1630. // Generate a function of recursive functions that can be used to check each element
  1631. if ( !match ) {
  1632. match = tokenize( selector );
  1633. }
  1634. i = match.length;
  1635. while ( i-- ) {
  1636. cached = matcherFromTokens( match[ i ] );
  1637. if ( cached[ expando ] ) {
  1638. setMatchers.push( cached );
  1639. } else {
  1640. elementMatchers.push( cached );
  1641. }
  1642. }
  1643. // Cache the compiled function
  1644. cached = compilerCache( selector,
  1645. matcherFromGroupMatchers( elementMatchers, setMatchers ) );
  1646. // Save selector and tokenization
  1647. cached.selector = selector;
  1648. }
  1649. return cached;
  1650. }
  1651. /**
  1652. * A low-level selection function that works with jQuery's compiled
  1653. * selector functions
  1654. * @param {String|Function} selector A selector or a pre-compiled
  1655. * selector function built with jQuery selector compile
  1656. * @param {Element} context
  1657. * @param {Array} [results]
  1658. * @param {Array} [seed] A set of elements to match against
  1659. */
  1660. function select( selector, context, results, seed ) {
  1661. var i, tokens, token, type, find,
  1662. compiled = typeof selector === "function" && selector,
  1663. match = !seed && tokenize( ( selector = compiled.selector || selector ) );
  1664. results = results || [];
  1665. // Try to minimize operations if there is only one selector in the list and no seed
  1666. // (the latter of which guarantees us context)
  1667. if ( match.length === 1 ) {
  1668. // Reduce context if the leading compound selector is an ID
  1669. tokens = match[ 0 ] = match[ 0 ].slice( 0 );
  1670. if ( tokens.length > 2 && ( token = tokens[ 0 ] ).type === "ID" &&
  1671. context.nodeType === 9 && documentIsHTML && Expr.relative[ tokens[ 1 ].type ] ) {
  1672. context = ( Expr.find.ID(
  1673. token.matches[ 0 ].replace( runescape, funescape ),
  1674. context
  1675. ) || [] )[ 0 ];
  1676. if ( !context ) {
  1677. return results;
  1678. // Precompiled matchers will still verify ancestry, so step up a level
  1679. } else if ( compiled ) {
  1680. context = context.parentNode;
  1681. }
  1682. selector = selector.slice( tokens.shift().value.length );
  1683. }
  1684. // Fetch a seed set for right-to-left matching
  1685. i = matchExpr.needsContext.test( selector ) ? 0 : tokens.length;
  1686. while ( i-- ) {
  1687. token = tokens[ i ];
  1688. // Abort if we hit a combinator
  1689. if ( Expr.relative[ ( type = token.type ) ] ) {
  1690. break;
  1691. }
  1692. if ( ( find = Expr.find[ type ] ) ) {
  1693. // Search, expanding context for leading sibling combinators
  1694. if ( ( seed = find(
  1695. token.matches[ 0 ].replace( runescape, funescape ),
  1696. rsibling.test( tokens[ 0 ].type ) &&
  1697. testContext( context.parentNode ) || context
  1698. ) ) ) {
  1699. // If seed is empty or no tokens remain, we can return early
  1700. tokens.splice( i, 1 );
  1701. selector = seed.length && toSelector( tokens );
  1702. if ( !selector ) {
  1703. push.apply( results, seed );
  1704. return results;
  1705. }
  1706. break;
  1707. }
  1708. }
  1709. }
  1710. }
  1711. // Compile and execute a filtering function if one is not provided
  1712. // Provide `match` to avoid retokenization if we modified the selector above
  1713. ( compiled || compile( selector, match ) )(
  1714. seed,
  1715. context,
  1716. !documentIsHTML,
  1717. results,
  1718. !context || rsibling.test( selector ) && testContext( context.parentNode ) || context
  1719. );
  1720. return results;
  1721. }
  1722. // One-time assignments
  1723. // Support: Android <=4.0 - 4.1+
  1724. // Sort stability
  1725. support.sortStable = expando.split( "" ).sort( sortOrder ).join( "" ) === expando;
  1726. // Initialize against the default document
  1727. setDocument();
  1728. // Support: Android <=4.0 - 4.1+
  1729. // Detached nodes confoundingly follow *each other*
  1730. support.sortDetached = assert( function( el ) {
  1731. // Should return 1, but returns 4 (following)
  1732. return el.compareDocumentPosition( document.createElement( "fieldset" ) ) & 1;
  1733. } );
  1734. jQuery.find = find;
  1735. // Deprecated
  1736. jQuery.expr[ ":" ] = jQuery.expr.pseudos;
  1737. jQuery.unique = jQuery.uniqueSort;
  1738. // These have always been private, but they used to be documented
  1739. // as part of Sizzle so let's maintain them in the 3.x line
  1740. // for backwards compatibility purposes.
  1741. find.compile = compile;
  1742. find.select = select;
  1743. find.setDocument = setDocument;
  1744. find.escape = jQuery.escapeSelector;
  1745. find.getText = jQuery.text;
  1746. find.isXML = jQuery.isXMLDoc;
  1747. find.selectors = jQuery.expr;
  1748. find.support = jQuery.support;
  1749. find.uniqueSort = jQuery.uniqueSort;
  1750. /* eslint-enable */
  1751. } )();
  1752. } );