selector.js 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117
  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
  439. // (see trac-13936).
  440. // Limit the fix to IE & Edge Legacy; despite Edge 15+ implementing `matches`,
  441. // all IE 9+ and Edge Legacy versions implement `msMatchesSelector` as well.
  442. if ( documentElement.msMatchesSelector &&
  443. // Support: IE 11+, Edge 17 - 18+
  444. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  445. // two documents; shallow comparisons work.
  446. // eslint-disable-next-line eqeqeq
  447. preferredDoc != document &&
  448. ( subWindow = document.defaultView ) && subWindow.top !== subWindow ) {
  449. // Support: IE 9 - 11+, Edge 12 - 18+
  450. subWindow.addEventListener( "unload", unloadHandler );
  451. }
  452. // Support: IE <10
  453. // Check if getElementById returns elements by name
  454. // The broken getElementById methods don't pick up programmatically-set names,
  455. // so use a roundabout getElementsByName test
  456. support.getById = assert( function( el ) {
  457. documentElement.appendChild( el ).id = jQuery.expando;
  458. return !document.getElementsByName ||
  459. !document.getElementsByName( jQuery.expando ).length;
  460. } );
  461. // Support: IE 9 only
  462. // Check to see if it's possible to do matchesSelector
  463. // on a disconnected node.
  464. support.disconnectedMatch = assert( function( el ) {
  465. return matches.call( el, "*" );
  466. } );
  467. // Support: IE 9 - 11+, Edge 12 - 18+
  468. // IE/Edge don't support the :scope pseudo-class.
  469. support.scope = assert( function() {
  470. return document.querySelectorAll( ":scope" );
  471. } );
  472. // Support: Chrome 105 - 111 only, Safari 15.4 - 16.3 only
  473. // Make sure the `:has()` argument is parsed unforgivingly.
  474. // We include `*` in the test to detect buggy implementations that are
  475. // _selectively_ forgiving (specifically when the list includes at least
  476. // one valid selector).
  477. // Note that we treat complete lack of support for `:has()` as if it were
  478. // spec-compliant support, which is fine because use of `:has()` in such
  479. // environments will fail in the qSA path and fall back to jQuery traversal
  480. // anyway.
  481. support.cssHas = assert( function() {
  482. try {
  483. document.querySelector( ":has(*,:jqfake)" );
  484. return false;
  485. } catch ( e ) {
  486. return true;
  487. }
  488. } );
  489. // ID filter and find
  490. if ( support.getById ) {
  491. Expr.filter.ID = function( id ) {
  492. var attrId = id.replace( runescape, funescape );
  493. return function( elem ) {
  494. return elem.getAttribute( "id" ) === attrId;
  495. };
  496. };
  497. Expr.find.ID = function( id, context ) {
  498. if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
  499. var elem = context.getElementById( id );
  500. return elem ? [ elem ] : [];
  501. }
  502. };
  503. } else {
  504. Expr.filter.ID = function( id ) {
  505. var attrId = id.replace( runescape, funescape );
  506. return function( elem ) {
  507. var node = typeof elem.getAttributeNode !== "undefined" &&
  508. elem.getAttributeNode( "id" );
  509. return node && node.value === attrId;
  510. };
  511. };
  512. // Support: IE 6 - 7 only
  513. // getElementById is not reliable as a find shortcut
  514. Expr.find.ID = function( id, context ) {
  515. if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
  516. var node, i, elems,
  517. elem = context.getElementById( id );
  518. if ( elem ) {
  519. // Verify the id attribute
  520. node = elem.getAttributeNode( "id" );
  521. if ( node && node.value === id ) {
  522. return [ elem ];
  523. }
  524. // Fall back on getElementsByName
  525. elems = context.getElementsByName( id );
  526. i = 0;
  527. while ( ( elem = elems[ i++ ] ) ) {
  528. node = elem.getAttributeNode( "id" );
  529. if ( node && node.value === id ) {
  530. return [ elem ];
  531. }
  532. }
  533. }
  534. return [];
  535. }
  536. };
  537. }
  538. // Tag
  539. Expr.find.TAG = function( tag, context ) {
  540. if ( typeof context.getElementsByTagName !== "undefined" ) {
  541. return context.getElementsByTagName( tag );
  542. // DocumentFragment nodes don't have gEBTN
  543. } else {
  544. return context.querySelectorAll( tag );
  545. }
  546. };
  547. // Class
  548. Expr.find.CLASS = function( className, context ) {
  549. if ( typeof context.getElementsByClassName !== "undefined" && documentIsHTML ) {
  550. return context.getElementsByClassName( className );
  551. }
  552. };
  553. /* QSA/matchesSelector
  554. ---------------------------------------------------------------------- */
  555. // QSA and matchesSelector support
  556. rbuggyQSA = [];
  557. // Build QSA regex
  558. // Regex strategy adopted from Diego Perini
  559. assert( function( el ) {
  560. var input;
  561. documentElement.appendChild( el ).innerHTML =
  562. "<a id='" + expando + "' href='' disabled='disabled'></a>" +
  563. "<select id='" + expando + "-\r\\' disabled='disabled'>" +
  564. "<option selected=''></option></select>";
  565. // Support: iOS <=7 - 8 only
  566. // Boolean attributes and "value" are not treated correctly in some XML documents
  567. if ( !el.querySelectorAll( "[selected]" ).length ) {
  568. rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
  569. }
  570. // Support: iOS <=7 - 8 only
  571. if ( !el.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
  572. rbuggyQSA.push( "~=" );
  573. }
  574. // Support: iOS 8 only
  575. // https://bugs.webkit.org/show_bug.cgi?id=136851
  576. // In-page `selector#id sibling-combinator selector` fails
  577. if ( !el.querySelectorAll( "a#" + expando + "+*" ).length ) {
  578. rbuggyQSA.push( ".#.+[+~]" );
  579. }
  580. // Support: Chrome <=105+, Firefox <=104+, Safari <=15.4+
  581. // In some of the document kinds, these selectors wouldn't work natively.
  582. // This is probably OK but for backwards compatibility we want to maintain
  583. // handling them through jQuery traversal in jQuery 3.x.
  584. if ( !el.querySelectorAll( ":checked" ).length ) {
  585. rbuggyQSA.push( ":checked" );
  586. }
  587. // Support: Windows 8 Native Apps
  588. // The type and name attributes are restricted during .innerHTML assignment
  589. input = document.createElement( "input" );
  590. input.setAttribute( "type", "hidden" );
  591. el.appendChild( input ).setAttribute( "name", "D" );
  592. // Support: IE 9 - 11+
  593. // IE's :disabled selector does not pick up the children of disabled fieldsets
  594. // Support: Chrome <=105+, Firefox <=104+, Safari <=15.4+
  595. // In some of the document kinds, these selectors wouldn't work natively.
  596. // This is probably OK but for backwards compatibility we want to maintain
  597. // handling them through jQuery traversal in jQuery 3.x.
  598. documentElement.appendChild( el ).disabled = true;
  599. if ( el.querySelectorAll( ":disabled" ).length !== 2 ) {
  600. rbuggyQSA.push( ":enabled", ":disabled" );
  601. }
  602. // Support: IE 11+, Edge 15 - 18+
  603. // IE 11/Edge don't find elements on a `[name='']` query in some cases.
  604. // Adding a temporary attribute to the document before the selection works
  605. // around the issue.
  606. // Interestingly, IE 10 & older don't seem to have the issue.
  607. input = document.createElement( "input" );
  608. input.setAttribute( "name", "" );
  609. el.appendChild( input );
  610. if ( !el.querySelectorAll( "[name='']" ).length ) {
  611. rbuggyQSA.push( "\\[" + whitespace + "*name" + whitespace + "*=" +
  612. whitespace + "*(?:''|\"\")" );
  613. }
  614. } );
  615. if ( !support.cssHas ) {
  616. // Support: Chrome 105 - 110+, Safari 15.4 - 16.3+
  617. // Our regular `try-catch` mechanism fails to detect natively-unsupported
  618. // pseudo-classes inside `:has()` (such as `:has(:contains("Foo"))`)
  619. // in browsers that parse the `:has()` argument as a forgiving selector list.
  620. // https://drafts.csswg.org/selectors/#relational now requires the argument
  621. // to be parsed unforgivingly, but browsers have not yet fully adjusted.
  622. rbuggyQSA.push( ":has" );
  623. }
  624. rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join( "|" ) );
  625. /* Sorting
  626. ---------------------------------------------------------------------- */
  627. // Document order sorting
  628. sortOrder = function( a, b ) {
  629. // Flag for duplicate removal
  630. if ( a === b ) {
  631. hasDuplicate = true;
  632. return 0;
  633. }
  634. // Sort on method existence if only one input has compareDocumentPosition
  635. var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
  636. if ( compare ) {
  637. return compare;
  638. }
  639. // Calculate position if both inputs belong to the same document
  640. // Support: IE 11+, Edge 17 - 18+
  641. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  642. // two documents; shallow comparisons work.
  643. // eslint-disable-next-line eqeqeq
  644. compare = ( a.ownerDocument || a ) == ( b.ownerDocument || b ) ?
  645. a.compareDocumentPosition( b ) :
  646. // Otherwise we know they are disconnected
  647. 1;
  648. // Disconnected nodes
  649. if ( compare & 1 ||
  650. ( !support.sortDetached && b.compareDocumentPosition( a ) === compare ) ) {
  651. // Choose the first element that is related to our preferred document
  652. // Support: IE 11+, Edge 17 - 18+
  653. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  654. // two documents; shallow comparisons work.
  655. // eslint-disable-next-line eqeqeq
  656. if ( a === document || a.ownerDocument == preferredDoc &&
  657. find.contains( preferredDoc, a ) ) {
  658. return -1;
  659. }
  660. // Support: IE 11+, Edge 17 - 18+
  661. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  662. // two documents; shallow comparisons work.
  663. // eslint-disable-next-line eqeqeq
  664. if ( b === document || b.ownerDocument == preferredDoc &&
  665. find.contains( preferredDoc, b ) ) {
  666. return 1;
  667. }
  668. // Maintain original order
  669. return sortInput ?
  670. ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
  671. 0;
  672. }
  673. return compare & 4 ? -1 : 1;
  674. };
  675. return document;
  676. }
  677. find.matches = function( expr, elements ) {
  678. return find( expr, null, null, elements );
  679. };
  680. find.matchesSelector = function( elem, expr ) {
  681. setDocument( elem );
  682. if ( documentIsHTML &&
  683. !nonnativeSelectorCache[ expr + " " ] &&
  684. ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
  685. try {
  686. var ret = matches.call( elem, expr );
  687. // IE 9's matchesSelector returns false on disconnected nodes
  688. if ( ret || support.disconnectedMatch ||
  689. // As well, disconnected nodes are said to be in a document
  690. // fragment in IE 9
  691. elem.document && elem.document.nodeType !== 11 ) {
  692. return ret;
  693. }
  694. } catch ( e ) {
  695. nonnativeSelectorCache( expr, true );
  696. }
  697. }
  698. return find( expr, document, null, [ elem ] ).length > 0;
  699. };
  700. find.contains = function( context, elem ) {
  701. // Set document vars if needed
  702. // Support: IE 11+, Edge 17 - 18+
  703. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  704. // two documents; shallow comparisons work.
  705. // eslint-disable-next-line eqeqeq
  706. if ( ( context.ownerDocument || context ) != document ) {
  707. setDocument( context );
  708. }
  709. return jQuery.contains( context, elem );
  710. };
  711. find.attr = function( elem, name ) {
  712. // Set document vars if needed
  713. // Support: IE 11+, Edge 17 - 18+
  714. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  715. // two documents; shallow comparisons work.
  716. // eslint-disable-next-line eqeqeq
  717. if ( ( elem.ownerDocument || elem ) != document ) {
  718. setDocument( elem );
  719. }
  720. var fn = Expr.attrHandle[ name.toLowerCase() ],
  721. // Don't get fooled by Object.prototype properties (see trac-13807)
  722. val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
  723. fn( elem, name, !documentIsHTML ) :
  724. undefined;
  725. if ( val !== undefined ) {
  726. return val;
  727. }
  728. return elem.getAttribute( name );
  729. };
  730. find.error = function( msg ) {
  731. throw new Error( "Syntax error, unrecognized expression: " + msg );
  732. };
  733. /**
  734. * Document sorting and removing duplicates
  735. * @param {ArrayLike} results
  736. */
  737. jQuery.uniqueSort = function( results ) {
  738. var elem,
  739. duplicates = [],
  740. j = 0,
  741. i = 0;
  742. // Unless we *know* we can detect duplicates, assume their presence
  743. //
  744. // Support: Android <=4.0+
  745. // Testing for detecting duplicates is unpredictable so instead assume we can't
  746. // depend on duplicate detection in all browsers without a stable sort.
  747. hasDuplicate = !support.sortStable;
  748. sortInput = !support.sortStable && slice.call( results, 0 );
  749. sort.call( results, sortOrder );
  750. if ( hasDuplicate ) {
  751. while ( ( elem = results[ i++ ] ) ) {
  752. if ( elem === results[ i ] ) {
  753. j = duplicates.push( i );
  754. }
  755. }
  756. while ( j-- ) {
  757. splice.call( results, duplicates[ j ], 1 );
  758. }
  759. }
  760. // Clear input after sorting to release objects
  761. // See https://github.com/jquery/sizzle/pull/225
  762. sortInput = null;
  763. return results;
  764. };
  765. jQuery.fn.uniqueSort = function() {
  766. return this.pushStack( jQuery.uniqueSort( slice.apply( this ) ) );
  767. };
  768. Expr = jQuery.expr = {
  769. // Can be adjusted by the user
  770. cacheLength: 50,
  771. createPseudo: markFunction,
  772. match: matchExpr,
  773. attrHandle: {},
  774. find: {},
  775. relative: {
  776. ">": { dir: "parentNode", first: true },
  777. " ": { dir: "parentNode" },
  778. "+": { dir: "previousSibling", first: true },
  779. "~": { dir: "previousSibling" }
  780. },
  781. preFilter: {
  782. ATTR: function( match ) {
  783. match[ 1 ] = match[ 1 ].replace( runescape, funescape );
  784. // Move the given value to match[3] whether quoted or unquoted
  785. match[ 3 ] = ( match[ 3 ] || match[ 4 ] || match[ 5 ] || "" )
  786. .replace( runescape, funescape );
  787. if ( match[ 2 ] === "~=" ) {
  788. match[ 3 ] = " " + match[ 3 ] + " ";
  789. }
  790. return match.slice( 0, 4 );
  791. },
  792. CHILD: function( match ) {
  793. /* matches from matchExpr["CHILD"]
  794. 1 type (only|nth|...)
  795. 2 what (child|of-type)
  796. 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
  797. 4 xn-component of xn+y argument ([+-]?\d*n|)
  798. 5 sign of xn-component
  799. 6 x of xn-component
  800. 7 sign of y-component
  801. 8 y of y-component
  802. */
  803. match[ 1 ] = match[ 1 ].toLowerCase();
  804. if ( match[ 1 ].slice( 0, 3 ) === "nth" ) {
  805. // nth-* requires argument
  806. if ( !match[ 3 ] ) {
  807. find.error( match[ 0 ] );
  808. }
  809. // numeric x and y parameters for Expr.filter.CHILD
  810. // remember that false/true cast respectively to 0/1
  811. match[ 4 ] = +( match[ 4 ] ?
  812. match[ 5 ] + ( match[ 6 ] || 1 ) :
  813. 2 * ( match[ 3 ] === "even" || match[ 3 ] === "odd" )
  814. );
  815. match[ 5 ] = +( ( match[ 7 ] + match[ 8 ] ) || match[ 3 ] === "odd" );
  816. // other types prohibit arguments
  817. } else if ( match[ 3 ] ) {
  818. find.error( match[ 0 ] );
  819. }
  820. return match;
  821. },
  822. PSEUDO: function( match ) {
  823. var excess,
  824. unquoted = !match[ 6 ] && match[ 2 ];
  825. if ( matchExpr.CHILD.test( match[ 0 ] ) ) {
  826. return null;
  827. }
  828. // Accept quoted arguments as-is
  829. if ( match[ 3 ] ) {
  830. match[ 2 ] = match[ 4 ] || match[ 5 ] || "";
  831. // Strip excess characters from unquoted arguments
  832. } else if ( unquoted && rpseudo.test( unquoted ) &&
  833. // Get excess from tokenize (recursively)
  834. ( excess = tokenize( unquoted, true ) ) &&
  835. // advance to the next closing parenthesis
  836. ( excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length ) ) {
  837. // excess is a negative index
  838. match[ 0 ] = match[ 0 ].slice( 0, excess );
  839. match[ 2 ] = unquoted.slice( 0, excess );
  840. }
  841. // Return only captures needed by the pseudo filter method (type and argument)
  842. return match.slice( 0, 3 );
  843. }
  844. },
  845. filter: {
  846. TAG: function( nodeNameSelector ) {
  847. var expectedNodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
  848. return nodeNameSelector === "*" ?
  849. function() {
  850. return true;
  851. } :
  852. function( elem ) {
  853. return nodeName( elem, expectedNodeName );
  854. };
  855. },
  856. CLASS: function( className ) {
  857. var pattern = classCache[ className + " " ];
  858. return pattern ||
  859. ( pattern = new RegExp( "(^|" + whitespace + ")" + className +
  860. "(" + whitespace + "|$)" ) ) &&
  861. classCache( className, function( elem ) {
  862. return pattern.test(
  863. typeof elem.className === "string" && elem.className ||
  864. typeof elem.getAttribute !== "undefined" &&
  865. elem.getAttribute( "class" ) ||
  866. ""
  867. );
  868. } );
  869. },
  870. ATTR: function( name, operator, check ) {
  871. return function( elem ) {
  872. var result = find.attr( elem, name );
  873. if ( result == null ) {
  874. return operator === "!=";
  875. }
  876. if ( !operator ) {
  877. return true;
  878. }
  879. result += "";
  880. if ( operator === "=" ) {
  881. return result === check;
  882. }
  883. if ( operator === "!=" ) {
  884. return result !== check;
  885. }
  886. if ( operator === "^=" ) {
  887. return check && result.indexOf( check ) === 0;
  888. }
  889. if ( operator === "*=" ) {
  890. return check && result.indexOf( check ) > -1;
  891. }
  892. if ( operator === "$=" ) {
  893. return check && result.slice( -check.length ) === check;
  894. }
  895. if ( operator === "~=" ) {
  896. return ( " " + result.replace( rwhitespace, " " ) + " " )
  897. .indexOf( check ) > -1;
  898. }
  899. if ( operator === "|=" ) {
  900. return result === check || result.slice( 0, check.length + 1 ) === check + "-";
  901. }
  902. return false;
  903. };
  904. },
  905. CHILD: function( type, what, _argument, first, last ) {
  906. var simple = type.slice( 0, 3 ) !== "nth",
  907. forward = type.slice( -4 ) !== "last",
  908. ofType = what === "of-type";
  909. return first === 1 && last === 0 ?
  910. // Shortcut for :nth-*(n)
  911. function( elem ) {
  912. return !!elem.parentNode;
  913. } :
  914. function( elem, _context, xml ) {
  915. var cache, outerCache, node, nodeIndex, start,
  916. dir = simple !== forward ? "nextSibling" : "previousSibling",
  917. parent = elem.parentNode,
  918. name = ofType && elem.nodeName.toLowerCase(),
  919. useCache = !xml && !ofType,
  920. diff = false;
  921. if ( parent ) {
  922. // :(first|last|only)-(child|of-type)
  923. if ( simple ) {
  924. while ( dir ) {
  925. node = elem;
  926. while ( ( node = node[ dir ] ) ) {
  927. if ( ofType ?
  928. nodeName( node, name ) :
  929. node.nodeType === 1 ) {
  930. return false;
  931. }
  932. }
  933. // Reverse direction for :only-* (if we haven't yet done so)
  934. start = dir = type === "only" && !start && "nextSibling";
  935. }
  936. return true;
  937. }
  938. start = [ forward ? parent.firstChild : parent.lastChild ];
  939. // non-xml :nth-child(...) stores cache data on `parent`
  940. if ( forward && useCache ) {
  941. // Seek `elem` from a previously-cached index
  942. outerCache = parent[ expando ] || ( parent[ expando ] = {} );
  943. cache = outerCache[ type ] || [];
  944. nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];
  945. diff = nodeIndex && cache[ 2 ];
  946. node = nodeIndex && parent.childNodes[ nodeIndex ];
  947. while ( ( node = ++nodeIndex && node && node[ dir ] ||
  948. // Fallback to seeking `elem` from the start
  949. ( diff = nodeIndex = 0 ) || start.pop() ) ) {
  950. // When found, cache indexes on `parent` and break
  951. if ( node.nodeType === 1 && ++diff && node === elem ) {
  952. outerCache[ type ] = [ dirruns, nodeIndex, diff ];
  953. break;
  954. }
  955. }
  956. } else {
  957. // Use previously-cached element index if available
  958. if ( useCache ) {
  959. outerCache = elem[ expando ] || ( elem[ expando ] = {} );
  960. cache = outerCache[ type ] || [];
  961. nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];
  962. diff = nodeIndex;
  963. }
  964. // xml :nth-child(...)
  965. // or :nth-last-child(...) or :nth(-last)?-of-type(...)
  966. if ( diff === false ) {
  967. // Use the same loop as above to seek `elem` from the start
  968. while ( ( node = ++nodeIndex && node && node[ dir ] ||
  969. ( diff = nodeIndex = 0 ) || start.pop() ) ) {
  970. if ( ( ofType ?
  971. nodeName( node, name ) :
  972. node.nodeType === 1 ) &&
  973. ++diff ) {
  974. // Cache the index of each encountered element
  975. if ( useCache ) {
  976. outerCache = node[ expando ] ||
  977. ( node[ expando ] = {} );
  978. outerCache[ type ] = [ dirruns, diff ];
  979. }
  980. if ( node === elem ) {
  981. break;
  982. }
  983. }
  984. }
  985. }
  986. }
  987. // Incorporate the offset, then check against cycle size
  988. diff -= last;
  989. return diff === first || ( diff % first === 0 && diff / first >= 0 );
  990. }
  991. };
  992. },
  993. PSEUDO: function( pseudo, argument ) {
  994. // pseudo-class names are case-insensitive
  995. // https://www.w3.org/TR/selectors/#pseudo-classes
  996. // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
  997. // Remember that setFilters inherits from pseudos
  998. var args,
  999. fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
  1000. find.error( "unsupported pseudo: " + pseudo );
  1001. // The user may use createPseudo to indicate that
  1002. // arguments are needed to create the filter function
  1003. // just as jQuery does
  1004. if ( fn[ expando ] ) {
  1005. return fn( argument );
  1006. }
  1007. // But maintain support for old signatures
  1008. if ( fn.length > 1 ) {
  1009. args = [ pseudo, pseudo, "", argument ];
  1010. return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
  1011. markFunction( function( seed, matches ) {
  1012. var idx,
  1013. matched = fn( seed, argument ),
  1014. i = matched.length;
  1015. while ( i-- ) {
  1016. idx = indexOf.call( seed, matched[ i ] );
  1017. seed[ idx ] = !( matches[ idx ] = matched[ i ] );
  1018. }
  1019. } ) :
  1020. function( elem ) {
  1021. return fn( elem, 0, args );
  1022. };
  1023. }
  1024. return fn;
  1025. }
  1026. },
  1027. pseudos: {
  1028. // Potentially complex pseudos
  1029. not: markFunction( function( selector ) {
  1030. // Trim the selector passed to compile
  1031. // to avoid treating leading and trailing
  1032. // spaces as combinators
  1033. var input = [],
  1034. results = [],
  1035. matcher = compile( selector.replace( rtrimCSS, "$1" ) );
  1036. return matcher[ expando ] ?
  1037. markFunction( function( seed, matches, _context, xml ) {
  1038. var elem,
  1039. unmatched = matcher( seed, null, xml, [] ),
  1040. i = seed.length;
  1041. // Match elements unmatched by `matcher`
  1042. while ( i-- ) {
  1043. if ( ( elem = unmatched[ i ] ) ) {
  1044. seed[ i ] = !( matches[ i ] = elem );
  1045. }
  1046. }
  1047. } ) :
  1048. function( elem, _context, xml ) {
  1049. input[ 0 ] = elem;
  1050. matcher( input, null, xml, results );
  1051. // Don't keep the element
  1052. // (see https://github.com/jquery/sizzle/issues/299)
  1053. input[ 0 ] = null;
  1054. return !results.pop();
  1055. };
  1056. } ),
  1057. has: markFunction( function( selector ) {
  1058. return function( elem ) {
  1059. return find( selector, elem ).length > 0;
  1060. };
  1061. } ),
  1062. contains: markFunction( function( text ) {
  1063. text = text.replace( runescape, funescape );
  1064. return function( elem ) {
  1065. return ( elem.textContent || jQuery.text( elem ) ).indexOf( text ) > -1;
  1066. };
  1067. } ),
  1068. // "Whether an element is represented by a :lang() selector
  1069. // is based solely on the element's language value
  1070. // being equal to the identifier C,
  1071. // or beginning with the identifier C immediately followed by "-".
  1072. // The matching of C against the element's language value is performed case-insensitively.
  1073. // The identifier C does not have to be a valid language name."
  1074. // https://www.w3.org/TR/selectors/#lang-pseudo
  1075. lang: markFunction( function( lang ) {
  1076. // lang value must be a valid identifier
  1077. if ( !ridentifier.test( lang || "" ) ) {
  1078. find.error( "unsupported lang: " + lang );
  1079. }
  1080. lang = lang.replace( runescape, funescape ).toLowerCase();
  1081. return function( elem ) {
  1082. var elemLang;
  1083. do {
  1084. if ( ( elemLang = documentIsHTML ?
  1085. elem.lang :
  1086. elem.getAttribute( "xml:lang" ) || elem.getAttribute( "lang" ) ) ) {
  1087. elemLang = elemLang.toLowerCase();
  1088. return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
  1089. }
  1090. } while ( ( elem = elem.parentNode ) && elem.nodeType === 1 );
  1091. return false;
  1092. };
  1093. } ),
  1094. // Miscellaneous
  1095. target: function( elem ) {
  1096. var hash = window.location && window.location.hash;
  1097. return hash && hash.slice( 1 ) === elem.id;
  1098. },
  1099. root: function( elem ) {
  1100. return elem === documentElement;
  1101. },
  1102. focus: function( elem ) {
  1103. return elem === safeActiveElement() &&
  1104. document.hasFocus() &&
  1105. !!( elem.type || elem.href || ~elem.tabIndex );
  1106. },
  1107. // Boolean properties
  1108. enabled: createDisabledPseudo( false ),
  1109. disabled: createDisabledPseudo( true ),
  1110. checked: function( elem ) {
  1111. // In CSS3, :checked should return both checked and selected elements
  1112. // https://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
  1113. return ( nodeName( elem, "input" ) && !!elem.checked ) ||
  1114. ( nodeName( elem, "option" ) && !!elem.selected );
  1115. },
  1116. selected: function( elem ) {
  1117. // Support: IE <=11+
  1118. // Accessing the selectedIndex property
  1119. // forces the browser to treat the default option as
  1120. // selected when in an optgroup.
  1121. if ( elem.parentNode ) {
  1122. // eslint-disable-next-line no-unused-expressions
  1123. elem.parentNode.selectedIndex;
  1124. }
  1125. return elem.selected === true;
  1126. },
  1127. // Contents
  1128. empty: function( elem ) {
  1129. // https://www.w3.org/TR/selectors/#empty-pseudo
  1130. // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
  1131. // but not by others (comment: 8; processing instruction: 7; etc.)
  1132. // nodeType < 6 works because attributes (2) do not appear as children
  1133. for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
  1134. if ( elem.nodeType < 6 ) {
  1135. return false;
  1136. }
  1137. }
  1138. return true;
  1139. },
  1140. parent: function( elem ) {
  1141. return !Expr.pseudos.empty( elem );
  1142. },
  1143. // Element/input types
  1144. header: function( elem ) {
  1145. return rheader.test( elem.nodeName );
  1146. },
  1147. input: function( elem ) {
  1148. return rinputs.test( elem.nodeName );
  1149. },
  1150. button: function( elem ) {
  1151. return nodeName( elem, "input" ) && elem.type === "button" ||
  1152. nodeName( elem, "button" );
  1153. },
  1154. text: function( elem ) {
  1155. var attr;
  1156. return nodeName( elem, "input" ) && elem.type === "text" &&
  1157. // Support: IE <10 only
  1158. // New HTML5 attribute values (e.g., "search") appear
  1159. // with elem.type === "text"
  1160. ( ( attr = elem.getAttribute( "type" ) ) == null ||
  1161. attr.toLowerCase() === "text" );
  1162. },
  1163. // Position-in-collection
  1164. first: createPositionalPseudo( function() {
  1165. return [ 0 ];
  1166. } ),
  1167. last: createPositionalPseudo( function( _matchIndexes, length ) {
  1168. return [ length - 1 ];
  1169. } ),
  1170. eq: createPositionalPseudo( function( _matchIndexes, length, argument ) {
  1171. return [ argument < 0 ? argument + length : argument ];
  1172. } ),
  1173. even: createPositionalPseudo( function( matchIndexes, length ) {
  1174. var i = 0;
  1175. for ( ; i < length; i += 2 ) {
  1176. matchIndexes.push( i );
  1177. }
  1178. return matchIndexes;
  1179. } ),
  1180. odd: createPositionalPseudo( function( matchIndexes, length ) {
  1181. var i = 1;
  1182. for ( ; i < length; i += 2 ) {
  1183. matchIndexes.push( i );
  1184. }
  1185. return matchIndexes;
  1186. } ),
  1187. lt: createPositionalPseudo( function( matchIndexes, length, argument ) {
  1188. var i;
  1189. if ( argument < 0 ) {
  1190. i = argument + length;
  1191. } else if ( argument > length ) {
  1192. i = length;
  1193. } else {
  1194. i = argument;
  1195. }
  1196. for ( ; --i >= 0; ) {
  1197. matchIndexes.push( i );
  1198. }
  1199. return matchIndexes;
  1200. } ),
  1201. gt: createPositionalPseudo( function( matchIndexes, length, argument ) {
  1202. var i = argument < 0 ? argument + length : argument;
  1203. for ( ; ++i < length; ) {
  1204. matchIndexes.push( i );
  1205. }
  1206. return matchIndexes;
  1207. } )
  1208. }
  1209. };
  1210. Expr.pseudos.nth = Expr.pseudos.eq;
  1211. // Add button/input type pseudos
  1212. for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
  1213. Expr.pseudos[ i ] = createInputPseudo( i );
  1214. }
  1215. for ( i in { submit: true, reset: true } ) {
  1216. Expr.pseudos[ i ] = createButtonPseudo( i );
  1217. }
  1218. // Easy API for creating new setFilters
  1219. function setFilters() {}
  1220. setFilters.prototype = Expr.filters = Expr.pseudos;
  1221. Expr.setFilters = new setFilters();
  1222. function tokenize( selector, parseOnly ) {
  1223. var matched, match, tokens, type,
  1224. soFar, groups, preFilters,
  1225. cached = tokenCache[ selector + " " ];
  1226. if ( cached ) {
  1227. return parseOnly ? 0 : cached.slice( 0 );
  1228. }
  1229. soFar = selector;
  1230. groups = [];
  1231. preFilters = Expr.preFilter;
  1232. while ( soFar ) {
  1233. // Comma and first run
  1234. if ( !matched || ( match = rcomma.exec( soFar ) ) ) {
  1235. if ( match ) {
  1236. // Don't consume trailing commas as valid
  1237. soFar = soFar.slice( match[ 0 ].length ) || soFar;
  1238. }
  1239. groups.push( ( tokens = [] ) );
  1240. }
  1241. matched = false;
  1242. // Combinators
  1243. if ( ( match = rleadingCombinator.exec( soFar ) ) ) {
  1244. matched = match.shift();
  1245. tokens.push( {
  1246. value: matched,
  1247. // Cast descendant combinators to space
  1248. type: match[ 0 ].replace( rtrimCSS, " " )
  1249. } );
  1250. soFar = soFar.slice( matched.length );
  1251. }
  1252. // Filters
  1253. for ( type in Expr.filter ) {
  1254. if ( ( match = matchExpr[ type ].exec( soFar ) ) && ( !preFilters[ type ] ||
  1255. ( match = preFilters[ type ]( match ) ) ) ) {
  1256. matched = match.shift();
  1257. tokens.push( {
  1258. value: matched,
  1259. type: type,
  1260. matches: match
  1261. } );
  1262. soFar = soFar.slice( matched.length );
  1263. }
  1264. }
  1265. if ( !matched ) {
  1266. break;
  1267. }
  1268. }
  1269. // Return the length of the invalid excess
  1270. // if we're just parsing
  1271. // Otherwise, throw an error or return tokens
  1272. if ( parseOnly ) {
  1273. return soFar.length;
  1274. }
  1275. return soFar ?
  1276. find.error( selector ) :
  1277. // Cache the tokens
  1278. tokenCache( selector, groups ).slice( 0 );
  1279. }
  1280. function toSelector( tokens ) {
  1281. var i = 0,
  1282. len = tokens.length,
  1283. selector = "";
  1284. for ( ; i < len; i++ ) {
  1285. selector += tokens[ i ].value;
  1286. }
  1287. return selector;
  1288. }
  1289. function addCombinator( matcher, combinator, base ) {
  1290. var dir = combinator.dir,
  1291. skip = combinator.next,
  1292. key = skip || dir,
  1293. checkNonElements = base && key === "parentNode",
  1294. doneName = done++;
  1295. return combinator.first ?
  1296. // Check against closest ancestor/preceding element
  1297. function( elem, context, xml ) {
  1298. while ( ( elem = elem[ dir ] ) ) {
  1299. if ( elem.nodeType === 1 || checkNonElements ) {
  1300. return matcher( elem, context, xml );
  1301. }
  1302. }
  1303. return false;
  1304. } :
  1305. // Check against all ancestor/preceding elements
  1306. function( elem, context, xml ) {
  1307. var oldCache, outerCache,
  1308. newCache = [ dirruns, doneName ];
  1309. // We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching
  1310. if ( xml ) {
  1311. while ( ( elem = elem[ dir ] ) ) {
  1312. if ( elem.nodeType === 1 || checkNonElements ) {
  1313. if ( matcher( elem, context, xml ) ) {
  1314. return true;
  1315. }
  1316. }
  1317. }
  1318. } else {
  1319. while ( ( elem = elem[ dir ] ) ) {
  1320. if ( elem.nodeType === 1 || checkNonElements ) {
  1321. outerCache = elem[ expando ] || ( elem[ expando ] = {} );
  1322. if ( skip && nodeName( elem, skip ) ) {
  1323. elem = elem[ dir ] || elem;
  1324. } else if ( ( oldCache = outerCache[ key ] ) &&
  1325. oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
  1326. // Assign to newCache so results back-propagate to previous elements
  1327. return ( newCache[ 2 ] = oldCache[ 2 ] );
  1328. } else {
  1329. // Reuse newcache so results back-propagate to previous elements
  1330. outerCache[ key ] = newCache;
  1331. // A match means we're done; a fail means we have to keep checking
  1332. if ( ( newCache[ 2 ] = matcher( elem, context, xml ) ) ) {
  1333. return true;
  1334. }
  1335. }
  1336. }
  1337. }
  1338. }
  1339. return false;
  1340. };
  1341. }
  1342. function elementMatcher( matchers ) {
  1343. return matchers.length > 1 ?
  1344. function( elem, context, xml ) {
  1345. var i = matchers.length;
  1346. while ( i-- ) {
  1347. if ( !matchers[ i ]( elem, context, xml ) ) {
  1348. return false;
  1349. }
  1350. }
  1351. return true;
  1352. } :
  1353. matchers[ 0 ];
  1354. }
  1355. function multipleContexts( selector, contexts, results ) {
  1356. var i = 0,
  1357. len = contexts.length;
  1358. for ( ; i < len; i++ ) {
  1359. find( selector, contexts[ i ], results );
  1360. }
  1361. return results;
  1362. }
  1363. function condense( unmatched, map, filter, context, xml ) {
  1364. var elem,
  1365. newUnmatched = [],
  1366. i = 0,
  1367. len = unmatched.length,
  1368. mapped = map != null;
  1369. for ( ; i < len; i++ ) {
  1370. if ( ( elem = unmatched[ i ] ) ) {
  1371. if ( !filter || filter( elem, context, xml ) ) {
  1372. newUnmatched.push( elem );
  1373. if ( mapped ) {
  1374. map.push( i );
  1375. }
  1376. }
  1377. }
  1378. }
  1379. return newUnmatched;
  1380. }
  1381. function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
  1382. if ( postFilter && !postFilter[ expando ] ) {
  1383. postFilter = setMatcher( postFilter );
  1384. }
  1385. if ( postFinder && !postFinder[ expando ] ) {
  1386. postFinder = setMatcher( postFinder, postSelector );
  1387. }
  1388. return markFunction( function( seed, results, context, xml ) {
  1389. var temp, i, elem, matcherOut,
  1390. preMap = [],
  1391. postMap = [],
  1392. preexisting = results.length,
  1393. // Get initial elements from seed or context
  1394. elems = seed ||
  1395. multipleContexts( selector || "*",
  1396. context.nodeType ? [ context ] : context, [] ),
  1397. // Prefilter to get matcher input, preserving a map for seed-results synchronization
  1398. matcherIn = preFilter && ( seed || !selector ) ?
  1399. condense( elems, preMap, preFilter, context, xml ) :
  1400. elems;
  1401. if ( matcher ) {
  1402. // If we have a postFinder, or filtered seed, or non-seed postFilter
  1403. // or preexisting results,
  1404. matcherOut = postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
  1405. // ...intermediate processing is necessary
  1406. [] :
  1407. // ...otherwise use results directly
  1408. results;
  1409. // Find primary matches
  1410. matcher( matcherIn, matcherOut, context, xml );
  1411. } else {
  1412. matcherOut = matcherIn;
  1413. }
  1414. // Apply postFilter
  1415. if ( postFilter ) {
  1416. temp = condense( matcherOut, postMap );
  1417. postFilter( temp, [], context, xml );
  1418. // Un-match failing elements by moving them back to matcherIn
  1419. i = temp.length;
  1420. while ( i-- ) {
  1421. if ( ( elem = temp[ i ] ) ) {
  1422. matcherOut[ postMap[ i ] ] = !( matcherIn[ postMap[ i ] ] = elem );
  1423. }
  1424. }
  1425. }
  1426. if ( seed ) {
  1427. if ( postFinder || preFilter ) {
  1428. if ( postFinder ) {
  1429. // Get the final matcherOut by condensing this intermediate into postFinder contexts
  1430. temp = [];
  1431. i = matcherOut.length;
  1432. while ( i-- ) {
  1433. if ( ( elem = matcherOut[ i ] ) ) {
  1434. // Restore matcherIn since elem is not yet a final match
  1435. temp.push( ( matcherIn[ i ] = elem ) );
  1436. }
  1437. }
  1438. postFinder( null, ( matcherOut = [] ), temp, xml );
  1439. }
  1440. // Move matched elements from seed to results to keep them synchronized
  1441. i = matcherOut.length;
  1442. while ( i-- ) {
  1443. if ( ( elem = matcherOut[ i ] ) &&
  1444. ( temp = postFinder ? indexOf.call( seed, elem ) : preMap[ i ] ) > -1 ) {
  1445. seed[ temp ] = !( results[ temp ] = elem );
  1446. }
  1447. }
  1448. }
  1449. // Add elements to results, through postFinder if defined
  1450. } else {
  1451. matcherOut = condense(
  1452. matcherOut === results ?
  1453. matcherOut.splice( preexisting, matcherOut.length ) :
  1454. matcherOut
  1455. );
  1456. if ( postFinder ) {
  1457. postFinder( null, results, matcherOut, xml );
  1458. } else {
  1459. push.apply( results, matcherOut );
  1460. }
  1461. }
  1462. } );
  1463. }
  1464. function matcherFromTokens( tokens ) {
  1465. var checkContext, matcher, j,
  1466. len = tokens.length,
  1467. leadingRelative = Expr.relative[ tokens[ 0 ].type ],
  1468. implicitRelative = leadingRelative || Expr.relative[ " " ],
  1469. i = leadingRelative ? 1 : 0,
  1470. // The foundational matcher ensures that elements are reachable from top-level context(s)
  1471. matchContext = addCombinator( function( elem ) {
  1472. return elem === checkContext;
  1473. }, implicitRelative, true ),
  1474. matchAnyContext = addCombinator( function( elem ) {
  1475. return indexOf.call( checkContext, elem ) > -1;
  1476. }, implicitRelative, true ),
  1477. matchers = [ function( elem, context, xml ) {
  1478. // Support: IE 11+, Edge 17 - 18+
  1479. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  1480. // two documents; shallow comparisons work.
  1481. // eslint-disable-next-line eqeqeq
  1482. var ret = ( !leadingRelative && ( xml || context != outermostContext ) ) || (
  1483. ( checkContext = context ).nodeType ?
  1484. matchContext( elem, context, xml ) :
  1485. matchAnyContext( elem, context, xml ) );
  1486. // Avoid hanging onto element
  1487. // (see https://github.com/jquery/sizzle/issues/299)
  1488. checkContext = null;
  1489. return ret;
  1490. } ];
  1491. for ( ; i < len; i++ ) {
  1492. if ( ( matcher = Expr.relative[ tokens[ i ].type ] ) ) {
  1493. matchers = [ addCombinator( elementMatcher( matchers ), matcher ) ];
  1494. } else {
  1495. matcher = Expr.filter[ tokens[ i ].type ].apply( null, tokens[ i ].matches );
  1496. // Return special upon seeing a positional matcher
  1497. if ( matcher[ expando ] ) {
  1498. // Find the next relative operator (if any) for proper handling
  1499. j = ++i;
  1500. for ( ; j < len; j++ ) {
  1501. if ( Expr.relative[ tokens[ j ].type ] ) {
  1502. break;
  1503. }
  1504. }
  1505. return setMatcher(
  1506. i > 1 && elementMatcher( matchers ),
  1507. i > 1 && toSelector(
  1508. // If the preceding token was a descendant combinator, insert an implicit any-element `*`
  1509. tokens.slice( 0, i - 1 )
  1510. .concat( { value: tokens[ i - 2 ].type === " " ? "*" : "" } )
  1511. ).replace( rtrimCSS, "$1" ),
  1512. matcher,
  1513. i < j && matcherFromTokens( tokens.slice( i, j ) ),
  1514. j < len && matcherFromTokens( ( tokens = tokens.slice( j ) ) ),
  1515. j < len && toSelector( tokens )
  1516. );
  1517. }
  1518. matchers.push( matcher );
  1519. }
  1520. }
  1521. return elementMatcher( matchers );
  1522. }
  1523. function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
  1524. var bySet = setMatchers.length > 0,
  1525. byElement = elementMatchers.length > 0,
  1526. superMatcher = function( seed, context, xml, results, outermost ) {
  1527. var elem, j, matcher,
  1528. matchedCount = 0,
  1529. i = "0",
  1530. unmatched = seed && [],
  1531. setMatched = [],
  1532. contextBackup = outermostContext,
  1533. // We must always have either seed elements or outermost context
  1534. elems = seed || byElement && Expr.find.TAG( "*", outermost ),
  1535. // Use integer dirruns iff this is the outermost matcher
  1536. dirrunsUnique = ( dirruns += contextBackup == null ? 1 : Math.random() || 0.1 ),
  1537. len = elems.length;
  1538. if ( outermost ) {
  1539. // Support: IE 11+, Edge 17 - 18+
  1540. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  1541. // two documents; shallow comparisons work.
  1542. // eslint-disable-next-line eqeqeq
  1543. outermostContext = context == document || context || outermost;
  1544. }
  1545. // Add elements passing elementMatchers directly to results
  1546. // Support: iOS <=7 - 9 only
  1547. // Tolerate NodeList properties (IE: "length"; Safari: <number>) matching
  1548. // elements by id. (see trac-14142)
  1549. for ( ; i !== len && ( elem = elems[ i ] ) != null; i++ ) {
  1550. if ( byElement && elem ) {
  1551. j = 0;
  1552. // Support: IE 11+, Edge 17 - 18+
  1553. // IE/Edge sometimes throw a "Permission denied" error when strict-comparing
  1554. // two documents; shallow comparisons work.
  1555. // eslint-disable-next-line eqeqeq
  1556. if ( !context && elem.ownerDocument != document ) {
  1557. setDocument( elem );
  1558. xml = !documentIsHTML;
  1559. }
  1560. while ( ( matcher = elementMatchers[ j++ ] ) ) {
  1561. if ( matcher( elem, context || document, xml ) ) {
  1562. push.call( results, elem );
  1563. break;
  1564. }
  1565. }
  1566. if ( outermost ) {
  1567. dirruns = dirrunsUnique;
  1568. }
  1569. }
  1570. // Track unmatched elements for set filters
  1571. if ( bySet ) {
  1572. // They will have gone through all possible matchers
  1573. if ( ( elem = !matcher && elem ) ) {
  1574. matchedCount--;
  1575. }
  1576. // Lengthen the array for every element, matched or not
  1577. if ( seed ) {
  1578. unmatched.push( elem );
  1579. }
  1580. }
  1581. }
  1582. // `i` is now the count of elements visited above, and adding it to `matchedCount`
  1583. // makes the latter nonnegative.
  1584. matchedCount += i;
  1585. // Apply set filters to unmatched elements
  1586. // NOTE: This can be skipped if there are no unmatched elements (i.e., `matchedCount`
  1587. // equals `i`), unless we didn't visit _any_ elements in the above loop because we have
  1588. // no element matchers and no seed.
  1589. // Incrementing an initially-string "0" `i` allows `i` to remain a string only in that
  1590. // case, which will result in a "00" `matchedCount` that differs from `i` but is also
  1591. // numerically zero.
  1592. if ( bySet && i !== matchedCount ) {
  1593. j = 0;
  1594. while ( ( matcher = setMatchers[ j++ ] ) ) {
  1595. matcher( unmatched, setMatched, context, xml );
  1596. }
  1597. if ( seed ) {
  1598. // Reintegrate element matches to eliminate the need for sorting
  1599. if ( matchedCount > 0 ) {
  1600. while ( i-- ) {
  1601. if ( !( unmatched[ i ] || setMatched[ i ] ) ) {
  1602. setMatched[ i ] = pop.call( results );
  1603. }
  1604. }
  1605. }
  1606. // Discard index placeholder values to get only actual matches
  1607. setMatched = condense( setMatched );
  1608. }
  1609. // Add matches to results
  1610. push.apply( results, setMatched );
  1611. // Seedless set matches succeeding multiple successful matchers stipulate sorting
  1612. if ( outermost && !seed && setMatched.length > 0 &&
  1613. ( matchedCount + setMatchers.length ) > 1 ) {
  1614. jQuery.uniqueSort( results );
  1615. }
  1616. }
  1617. // Override manipulation of globals by nested matchers
  1618. if ( outermost ) {
  1619. dirruns = dirrunsUnique;
  1620. outermostContext = contextBackup;
  1621. }
  1622. return unmatched;
  1623. };
  1624. return bySet ?
  1625. markFunction( superMatcher ) :
  1626. superMatcher;
  1627. }
  1628. function compile( selector, match /* Internal Use Only */ ) {
  1629. var i,
  1630. setMatchers = [],
  1631. elementMatchers = [],
  1632. cached = compilerCache[ selector + " " ];
  1633. if ( !cached ) {
  1634. // Generate a function of recursive functions that can be used to check each element
  1635. if ( !match ) {
  1636. match = tokenize( selector );
  1637. }
  1638. i = match.length;
  1639. while ( i-- ) {
  1640. cached = matcherFromTokens( match[ i ] );
  1641. if ( cached[ expando ] ) {
  1642. setMatchers.push( cached );
  1643. } else {
  1644. elementMatchers.push( cached );
  1645. }
  1646. }
  1647. // Cache the compiled function
  1648. cached = compilerCache( selector,
  1649. matcherFromGroupMatchers( elementMatchers, setMatchers ) );
  1650. // Save selector and tokenization
  1651. cached.selector = selector;
  1652. }
  1653. return cached;
  1654. }
  1655. /**
  1656. * A low-level selection function that works with jQuery's compiled
  1657. * selector functions
  1658. * @param {String|Function} selector A selector or a pre-compiled
  1659. * selector function built with jQuery selector compile
  1660. * @param {Element} context
  1661. * @param {Array} [results]
  1662. * @param {Array} [seed] A set of elements to match against
  1663. */
  1664. function select( selector, context, results, seed ) {
  1665. var i, tokens, token, type, find,
  1666. compiled = typeof selector === "function" && selector,
  1667. match = !seed && tokenize( ( selector = compiled.selector || selector ) );
  1668. results = results || [];
  1669. // Try to minimize operations if there is only one selector in the list and no seed
  1670. // (the latter of which guarantees us context)
  1671. if ( match.length === 1 ) {
  1672. // Reduce context if the leading compound selector is an ID
  1673. tokens = match[ 0 ] = match[ 0 ].slice( 0 );
  1674. if ( tokens.length > 2 && ( token = tokens[ 0 ] ).type === "ID" &&
  1675. context.nodeType === 9 && documentIsHTML && Expr.relative[ tokens[ 1 ].type ] ) {
  1676. context = ( Expr.find.ID(
  1677. token.matches[ 0 ].replace( runescape, funescape ),
  1678. context
  1679. ) || [] )[ 0 ];
  1680. if ( !context ) {
  1681. return results;
  1682. // Precompiled matchers will still verify ancestry, so step up a level
  1683. } else if ( compiled ) {
  1684. context = context.parentNode;
  1685. }
  1686. selector = selector.slice( tokens.shift().value.length );
  1687. }
  1688. // Fetch a seed set for right-to-left matching
  1689. i = matchExpr.needsContext.test( selector ) ? 0 : tokens.length;
  1690. while ( i-- ) {
  1691. token = tokens[ i ];
  1692. // Abort if we hit a combinator
  1693. if ( Expr.relative[ ( type = token.type ) ] ) {
  1694. break;
  1695. }
  1696. if ( ( find = Expr.find[ type ] ) ) {
  1697. // Search, expanding context for leading sibling combinators
  1698. if ( ( seed = find(
  1699. token.matches[ 0 ].replace( runescape, funescape ),
  1700. rsibling.test( tokens[ 0 ].type ) &&
  1701. testContext( context.parentNode ) || context
  1702. ) ) ) {
  1703. // If seed is empty or no tokens remain, we can return early
  1704. tokens.splice( i, 1 );
  1705. selector = seed.length && toSelector( tokens );
  1706. if ( !selector ) {
  1707. push.apply( results, seed );
  1708. return results;
  1709. }
  1710. break;
  1711. }
  1712. }
  1713. }
  1714. }
  1715. // Compile and execute a filtering function if one is not provided
  1716. // Provide `match` to avoid retokenization if we modified the selector above
  1717. ( compiled || compile( selector, match ) )(
  1718. seed,
  1719. context,
  1720. !documentIsHTML,
  1721. results,
  1722. !context || rsibling.test( selector ) && testContext( context.parentNode ) || context
  1723. );
  1724. return results;
  1725. }
  1726. // One-time assignments
  1727. // Support: Android <=4.0 - 4.1+
  1728. // Sort stability
  1729. support.sortStable = expando.split( "" ).sort( sortOrder ).join( "" ) === expando;
  1730. // Initialize against the default document
  1731. setDocument();
  1732. // Support: Android <=4.0 - 4.1+
  1733. // Detached nodes confoundingly follow *each other*
  1734. support.sortDetached = assert( function( el ) {
  1735. // Should return 1, but returns 4 (following)
  1736. return el.compareDocumentPosition( document.createElement( "fieldset" ) ) & 1;
  1737. } );
  1738. jQuery.find = find;
  1739. // Deprecated
  1740. jQuery.expr[ ":" ] = jQuery.expr.pseudos;
  1741. jQuery.unique = jQuery.uniqueSort;
  1742. // These have always been private, but they used to be documented as part of
  1743. // Sizzle so let's maintain them for now for backwards compatibility purposes.
  1744. find.compile = compile;
  1745. find.select = select;
  1746. find.setDocument = setDocument;
  1747. find.tokenize = tokenize;
  1748. find.escape = jQuery.escapeSelector;
  1749. find.getText = jQuery.text;
  1750. find.isXML = jQuery.isXMLDoc;
  1751. find.selectors = jQuery.expr;
  1752. find.support = jQuery.support;
  1753. find.uniqueSort = jQuery.uniqueSort;
  1754. /* eslint-enable */
  1755. } )();
  1756. } );