sizzle.js 62 KB

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