Sizzle.js 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  1. /**
  2. * Sizzle.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. *
  10. * @ignore-file
  11. */
  12. /*jshint bitwise:false, expr:true, noempty:false, sub:true, eqnull:true, latedef:false, maxlen:255 */
  13. /*eslint dot-notation:0, no-empty:0, no-cond-assign:0, no-unused-expressions:0, new-cap:0, no-nested-ternary:0, func-style:0, no-bitwise: 0 */
  14. /*
  15. * Sizzle CSS Selector Engine
  16. * Copyright, The Dojo Foundation
  17. * Released under the MIT, BSD, and GPL Licenses.
  18. * More information: http://sizzlejs.com/
  19. */
  20. define("tinymce/dom/Sizzle", [], function() {
  21. var i,
  22. cachedruns,
  23. Expr,
  24. getText,
  25. isXML,
  26. compile,
  27. outermostContext,
  28. recompare,
  29. sortInput,
  30. // Local document vars
  31. setDocument,
  32. document,
  33. docElem,
  34. documentIsHTML,
  35. rbuggyQSA,
  36. rbuggyMatches,
  37. matches,
  38. contains,
  39. // Instance-specific data
  40. expando = "sizzle" + -(new Date()),
  41. preferredDoc = window.document,
  42. support = {},
  43. dirruns = 0,
  44. done = 0,
  45. classCache = createCache(),
  46. tokenCache = createCache(),
  47. compilerCache = createCache(),
  48. hasDuplicate = false,
  49. sortOrder = function() { return 0; },
  50. // General-purpose constants
  51. strundefined = typeof undefined,
  52. MAX_NEGATIVE = 1 << 31,
  53. // Array methods
  54. arr = [],
  55. pop = arr.pop,
  56. push_native = arr.push,
  57. push = arr.push,
  58. slice = arr.slice,
  59. // Use a stripped-down indexOf if we can't use a native one
  60. indexOf = arr.indexOf || function( elem ) {
  61. var i = 0,
  62. len = this.length;
  63. for ( ; i < len; i++ ) {
  64. if ( this[i] === elem ) {
  65. return i;
  66. }
  67. }
  68. return -1;
  69. },
  70. // Regular expressions
  71. // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace
  72. whitespace = "[\\x20\\t\\r\\n\\f]",
  73. // http://www.w3.org/TR/css3-syntax/#characters
  74. characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
  75. // Loosely modeled on CSS identifier characters
  76. // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors
  77. // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
  78. identifier = characterEncoding.replace( "w", "w#" ),
  79. // Acceptable operators http://www.w3.org/TR/selectors/#attribute-selectors
  80. operators = "([*^$|!~]?=)",
  81. attributes = "\\[" + whitespace + "*(" + characterEncoding + ")" + whitespace +
  82. "*(?:" + operators + whitespace + "*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|(" + identifier + ")|)|)" + whitespace + "*\\]",
  83. // Prefer arguments quoted,
  84. // then not containing pseudos/brackets,
  85. // then attribute selectors/non-parenthetical expressions,
  86. // then anything else
  87. // These preferences are here to reduce the number of selectors
  88. // needing tokenize in the PSEUDO preFilter
  89. pseudos = ":(" + characterEncoding + ")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|" + attributes.replace( 3, 8 ) + ")*)|.*)\\)|)",
  90. // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
  91. rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
  92. rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
  93. rcombinators = new RegExp( "^" + whitespace + "*([\\x20\\t\\r\\n\\f>+~])" + whitespace + "*" ),
  94. rpseudo = new RegExp( pseudos ),
  95. ridentifier = new RegExp( "^" + identifier + "$" ),
  96. matchExpr = {
  97. "ID": new RegExp( "^#(" + characterEncoding + ")" ),
  98. "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ),
  99. "NAME": new RegExp( "^\\[name=['\"]?(" + characterEncoding + ")['\"]?\\]" ),
  100. "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ),
  101. "ATTR": new RegExp( "^" + attributes ),
  102. "PSEUDO": new RegExp( "^" + pseudos ),
  103. "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
  104. "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
  105. "*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
  106. // For use in libraries implementing .is()
  107. // We use this for POS matching in `select`
  108. "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
  109. whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
  110. },
  111. rsibling = /[\x20\t\r\n\f]*[+~]/,
  112. rnative = /^[^{]+\{\s*\[native code/,
  113. // Easily-parseable/retrievable ID or TAG or CLASS selectors
  114. rquickExpr = /^(?:#([\w\-]+)|(\w+)|\.([\w\-]+))$/,
  115. rinputs = /^(?:input|select|textarea|button)$/i,
  116. rheader = /^h\d$/i,
  117. rescape = /'|\\/g,
  118. rattributeQuotes = /\=[\x20\t\r\n\f]*([^'"\]]*)[\x20\t\r\n\f]*\]/g,
  119. // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
  120. runescape = /\\([\da-fA-F]{1,6}[\x20\t\r\n\f]?|.)/g,
  121. funescape = function( _, escaped ) {
  122. var high = "0x" + escaped - 0x10000;
  123. // NaN means non-codepoint
  124. return high !== high ?
  125. escaped :
  126. // BMP codepoint
  127. high < 0 ?
  128. String.fromCharCode( high + 0x10000 ) :
  129. // Supplemental Plane codepoint (surrogate pair)
  130. String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
  131. };
  132. // Optimize for push.apply( _, NodeList )
  133. try {
  134. push.apply(
  135. (arr = slice.call( preferredDoc.childNodes )),
  136. preferredDoc.childNodes
  137. );
  138. // Support: Android<4.0
  139. // Detect silently failing push.apply
  140. arr[ preferredDoc.childNodes.length ].nodeType;
  141. } catch ( e ) {
  142. push = { apply: arr.length ?
  143. // Leverage slice if possible
  144. function( target, els ) {
  145. push_native.apply( target, slice.call(els) );
  146. } :
  147. // Support: IE<9
  148. // Otherwise append directly
  149. function( target, els ) {
  150. var j = target.length,
  151. i = 0;
  152. // Can't trust NodeList.length
  153. while ( (target[j++] = els[i++]) ) {}
  154. target.length = j - 1;
  155. }
  156. };
  157. }
  158. /**
  159. * For feature detection
  160. * @param {Function} fn The function to test for native support
  161. */
  162. function isNative( fn ) {
  163. return rnative.test( fn + "" );
  164. }
  165. /**
  166. * Create key-value caches of limited size
  167. * @returns {Function(string, Object)} Returns the Object data after storing it on itself with
  168. * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
  169. * deleting the oldest entry
  170. */
  171. function createCache() {
  172. var cache,
  173. keys = [];
  174. cache = function( key, value ) {
  175. // Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
  176. if ( keys.push( key += " " ) > Expr.cacheLength ) {
  177. // Only keep the most recent entries
  178. delete cache[ keys.shift() ];
  179. }
  180. cache[ key ] = value;
  181. return value;
  182. };
  183. return cache;
  184. }
  185. /**
  186. * Mark a function for special use by Sizzle
  187. * @param {Function} fn The function to mark
  188. */
  189. function markFunction( fn ) {
  190. fn[ expando ] = true;
  191. return fn;
  192. }
  193. /**
  194. * Support testing using an element
  195. * @param {Function} fn Passed the created div and expects a boolean result
  196. */
  197. function assert( fn ) {
  198. var div = document.createElement("div");
  199. try {
  200. return !!fn( div );
  201. } catch (e) {
  202. return false;
  203. } finally {
  204. // release memory in IE
  205. div = null;
  206. }
  207. }
  208. function Sizzle( selector, context, results, seed ) {
  209. var match, elem, m, nodeType,
  210. // QSA vars
  211. i, groups, old, nid, newContext, newSelector;
  212. if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
  213. setDocument( context );
  214. }
  215. context = context || document;
  216. results = results || [];
  217. if ( !selector || typeof selector !== "string" ) {
  218. return results;
  219. }
  220. if ( (nodeType = context.nodeType) !== 1 && nodeType !== 9 ) {
  221. return [];
  222. }
  223. if ( documentIsHTML && !seed ) {
  224. // Shortcuts
  225. if ( (match = rquickExpr.exec( selector )) ) {
  226. // Speed-up: Sizzle("#ID")
  227. if ( (m = match[1]) ) {
  228. if ( nodeType === 9 ) {
  229. elem = context.getElementById( m );
  230. // Check parentNode to catch when Blackberry 4.6 returns
  231. // nodes that are no longer in the document #6963
  232. if ( elem && elem.parentNode ) {
  233. // Handle the case where IE, Opera, and Webkit return items
  234. // by name instead of ID
  235. if ( elem.id === m ) {
  236. results.push( elem );
  237. return results;
  238. }
  239. } else {
  240. return results;
  241. }
  242. } else {
  243. // Context is not a document
  244. if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) &&
  245. contains( context, elem ) && elem.id === m ) {
  246. results.push( elem );
  247. return results;
  248. }
  249. }
  250. // Speed-up: Sizzle("TAG")
  251. } else if ( match[2] ) {
  252. push.apply( results, context.getElementsByTagName( selector ) );
  253. return results;
  254. // Speed-up: Sizzle(".CLASS")
  255. } else if ( (m = match[3]) && support.getElementsByClassName && context.getElementsByClassName ) {
  256. push.apply( results, context.getElementsByClassName( m ) );
  257. return results;
  258. }
  259. }
  260. // QSA path
  261. if ( support.qsa && !rbuggyQSA.test(selector) ) {
  262. old = true;
  263. nid = expando;
  264. newContext = context;
  265. newSelector = nodeType === 9 && selector;
  266. // qSA works strangely on Element-rooted queries
  267. // We can work around this by specifying an extra ID on the root
  268. // and working up from there (Thanks to Andrew Dupont for the technique)
  269. // IE 8 doesn't work on object elements
  270. if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
  271. groups = tokenize( selector );
  272. if ( (old = context.getAttribute("id")) ) {
  273. nid = old.replace( rescape, "\\$&" );
  274. } else {
  275. context.setAttribute( "id", nid );
  276. }
  277. nid = "[id='" + nid + "'] ";
  278. i = groups.length;
  279. while ( i-- ) {
  280. groups[i] = nid + toSelector( groups[i] );
  281. }
  282. newContext = rsibling.test( selector ) && context.parentNode || context;
  283. newSelector = groups.join(",");
  284. }
  285. if ( newSelector ) {
  286. try {
  287. push.apply( results,
  288. newContext.querySelectorAll( newSelector )
  289. );
  290. return results;
  291. } catch(qsaError) {
  292. } finally {
  293. if ( !old ) {
  294. context.removeAttribute("id");
  295. }
  296. }
  297. }
  298. }
  299. }
  300. // All others
  301. return select( selector.replace( rtrim, "$1" ), context, results, seed );
  302. }
  303. /**
  304. * Detect xml
  305. * @param {Element|Object} elem An element or a document
  306. */
  307. isXML = Sizzle.isXML = function( elem ) {
  308. // documentElement is verified for cases where it doesn't yet exist
  309. // (such as loading iframes in IE - #4833)
  310. var documentElement = elem && (elem.ownerDocument || elem).documentElement;
  311. return documentElement ? documentElement.nodeName !== "HTML" : false;
  312. };
  313. /**
  314. * Sets document-related variables once based on the current document
  315. * @param {Element|Object} [doc] An element or document object to use to set the document
  316. * @returns {Object} Returns the current document
  317. */
  318. setDocument = Sizzle.setDocument = function( node ) {
  319. var doc = node ? node.ownerDocument || node : preferredDoc;
  320. // If no document and documentElement is available, return
  321. if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
  322. return document;
  323. }
  324. // Set our document
  325. document = doc;
  326. docElem = doc.documentElement;
  327. // Support tests
  328. documentIsHTML = !isXML( doc );
  329. // Check if getElementsByTagName("*") returns only elements
  330. support.getElementsByTagName = assert(function( div ) {
  331. div.appendChild( doc.createComment("") );
  332. return !div.getElementsByTagName("*").length;
  333. });
  334. // Check if attributes should be retrieved by attribute nodes
  335. support.attributes = assert(function( div ) {
  336. div.innerHTML = "<select></select>";
  337. var type = typeof div.lastChild.getAttribute("multiple");
  338. // IE8 returns a string for some attributes even when not present
  339. return type !== "boolean" && type !== "string";
  340. });
  341. // Check if getElementsByClassName can be trusted
  342. support.getElementsByClassName = assert(function( div ) {
  343. // Opera can't find a second classname (in 9.6)
  344. div.innerHTML = "<div class='hidden e'></div><div class='hidden'></div>";
  345. if ( !div.getElementsByClassName || !div.getElementsByClassName("e").length ) {
  346. return false;
  347. }
  348. // Safari 3.2 caches class attributes and doesn't catch changes
  349. div.lastChild.className = "e";
  350. return div.getElementsByClassName("e").length === 2;
  351. });
  352. // Check if getElementsByName privileges form controls or returns elements by ID
  353. // If so, assume (for broader support) that getElementById returns elements by name
  354. support.getByName = assert(function( div ) {
  355. // Inject content
  356. div.id = expando + 0;
  357. // Support: Windows 8 Native Apps
  358. // Assigning innerHTML with "name" attributes throws uncatchable exceptions
  359. // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx
  360. div.appendChild( document.createElement("a") ).setAttribute( "name", expando );
  361. div.appendChild( document.createElement("i") ).setAttribute( "name", expando );
  362. docElem.appendChild( div );
  363. // Test
  364. var pass = doc.getElementsByName &&
  365. // buggy browsers will return fewer than the correct 2
  366. doc.getElementsByName( expando ).length === 2 +
  367. // buggy browsers will return more than the correct 0
  368. doc.getElementsByName( expando + 0 ).length;
  369. // Cleanup
  370. docElem.removeChild( div );
  371. return pass;
  372. });
  373. // Support: Webkit<537.32
  374. // Detached nodes confoundingly follow *each other*
  375. support.sortDetached = assert(function( div1 ) {
  376. return div1.compareDocumentPosition &&
  377. // Should return 1, but Webkit returns 4 (following)
  378. (div1.compareDocumentPosition( document.createElement("div") ) & 1);
  379. });
  380. // IE6/7 return modified attributes
  381. Expr.attrHandle = assert(function( div ) {
  382. div.innerHTML = "<a href='#'></a>";
  383. return div.firstChild && typeof div.firstChild.getAttribute !== strundefined &&
  384. div.firstChild.getAttribute("href") === "#";
  385. }) ?
  386. {} :
  387. {
  388. "href": function( elem ) {
  389. return elem.getAttribute( "href", 2 );
  390. },
  391. "type": function( elem ) {
  392. return elem.getAttribute("type");
  393. }
  394. };
  395. // ID find and filter
  396. if ( support.getByName ) {
  397. Expr.find["ID"] = function( id, context ) {
  398. if ( typeof context.getElementById !== strundefined && documentIsHTML ) {
  399. var m = context.getElementById( id );
  400. // Check parentNode to catch when Blackberry 4.6 returns
  401. // nodes that are no longer in the document #6963
  402. return m && m.parentNode ? [m] : [];
  403. }
  404. };
  405. Expr.filter["ID"] = function( id ) {
  406. var attrId = id.replace( runescape, funescape );
  407. return function( elem ) {
  408. return elem.getAttribute("id") === attrId;
  409. };
  410. };
  411. } else {
  412. Expr.find["ID"] = function( id, context ) {
  413. if ( typeof context.getElementById !== strundefined && documentIsHTML ) {
  414. var m = context.getElementById( id );
  415. return m ?
  416. m.id === id || typeof m.getAttributeNode !== strundefined && m.getAttributeNode("id").value === id ?
  417. [m] :
  418. undefined :
  419. [];
  420. }
  421. };
  422. Expr.filter["ID"] = function( id ) {
  423. var attrId = id.replace( runescape, funescape );
  424. return function( elem ) {
  425. var node = typeof elem.getAttributeNode !== strundefined && elem.getAttributeNode("id");
  426. return node && node.value === attrId;
  427. };
  428. };
  429. }
  430. // Tag
  431. Expr.find["TAG"] = support.getElementsByTagName ?
  432. function( tag, context ) {
  433. if ( typeof context.getElementsByTagName !== strundefined ) {
  434. return context.getElementsByTagName( tag );
  435. }
  436. } :
  437. function( tag, context ) {
  438. var elem,
  439. tmp = [],
  440. i = 0,
  441. results = context.getElementsByTagName( tag );
  442. // Filter out possible comments
  443. if ( tag === "*" ) {
  444. while ( (elem = results[i++]) ) {
  445. if ( elem.nodeType === 1 ) {
  446. tmp.push( elem );
  447. }
  448. }
  449. return tmp;
  450. }
  451. return results;
  452. };
  453. // Name
  454. Expr.find["NAME"] = support.getByName && function( tag, context ) {
  455. if ( typeof context.getElementsByName !== strundefined ) {
  456. return context.getElementsByName( name );
  457. }
  458. };
  459. // Class
  460. Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
  461. if ( typeof context.getElementsByClassName !== strundefined && documentIsHTML ) {
  462. return context.getElementsByClassName( className );
  463. }
  464. };
  465. // QSA and matchesSelector support
  466. // matchesSelector(:active) reports false when true (IE9/Opera 11.5)
  467. rbuggyMatches = [];
  468. // qSa(:focus) reports false when true (Chrome 21),
  469. // no need to also add to buggyMatches since matches checks buggyQSA
  470. // A support test would require too much code (would include document ready)
  471. rbuggyQSA = [ ":focus" ];
  472. if ( (support.qsa = isNative(doc.querySelectorAll)) ) {
  473. // Build QSA regex
  474. // Regex strategy adopted from Diego Perini
  475. assert(function( div ) {
  476. // Select is set to empty string on purpose
  477. // This is to test IE's treatment of not explicitly
  478. // setting a boolean content attribute,
  479. // since its presence should be enough
  480. // http://bugs.jquery.com/ticket/12359
  481. div.innerHTML = "<select><option selected=''></option></select>";
  482. // IE8 - Some boolean attributes are not treated correctly
  483. if ( !div.querySelectorAll("[selected]").length ) {
  484. rbuggyQSA.push( "\\[" + whitespace + "*(?:checked|disabled|ismap|multiple|readonly|selected|value)" );
  485. }
  486. // Webkit/Opera - :checked should return selected option elements
  487. // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
  488. // IE8 throws error here and will not see later tests
  489. if ( !div.querySelectorAll(":checked").length ) {
  490. rbuggyQSA.push(":checked");
  491. }
  492. });
  493. assert(function( div ) {
  494. // Opera 10-12/IE8 - ^= $= *= and empty values
  495. // Should not select anything
  496. div.innerHTML = "<input type='hidden' i=''/>";
  497. if ( div.querySelectorAll("[i^='']").length ) {
  498. rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:\"\"|'')" );
  499. }
  500. // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
  501. // IE8 throws error here and will not see later tests
  502. if ( !div.querySelectorAll(":enabled").length ) {
  503. rbuggyQSA.push( ":enabled", ":disabled" );
  504. }
  505. // Opera 10-11 does not throw on post-comma invalid pseudos
  506. div.querySelectorAll("*,:x");
  507. rbuggyQSA.push(",.*:");
  508. });
  509. }
  510. if ( (support.matchesSelector = isNative( (matches = docElem.matchesSelector ||
  511. docElem.mozMatchesSelector ||
  512. docElem.webkitMatchesSelector ||
  513. docElem.oMatchesSelector ||
  514. docElem.msMatchesSelector) )) ) {
  515. assert(function( div ) {
  516. // Check to see if it's possible to do matchesSelector
  517. // on a disconnected node (IE 9)
  518. support.disconnectedMatch = matches.call( div, "div" );
  519. // This should fail with an exception
  520. // Gecko does not error, returns false instead
  521. matches.call( div, "[s!='']:x" );
  522. rbuggyMatches.push( "!=", pseudos );
  523. });
  524. }
  525. rbuggyQSA = new RegExp( rbuggyQSA.join("|") );
  526. rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
  527. // Element contains another
  528. // Purposefully does not implement inclusive descendant
  529. // As in, an element does not contain itself
  530. contains = isNative(docElem.contains) || docElem.compareDocumentPosition ?
  531. function( a, b ) {
  532. var adown = a.nodeType === 9 ? a.documentElement : a,
  533. bup = b && b.parentNode;
  534. return a === bup || !!( bup && bup.nodeType === 1 && (
  535. adown.contains ?
  536. adown.contains( bup ) :
  537. a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
  538. ));
  539. } :
  540. function( a, b ) {
  541. if ( b ) {
  542. while ( (b = b.parentNode) ) {
  543. if ( b === a ) {
  544. return true;
  545. }
  546. }
  547. }
  548. return false;
  549. };
  550. // Document order sorting
  551. sortOrder = docElem.compareDocumentPosition ?
  552. function( a, b ) {
  553. // Flag for duplicate removal
  554. if ( a === b ) {
  555. hasDuplicate = true;
  556. return 0;
  557. }
  558. var compare = b.compareDocumentPosition && a.compareDocumentPosition && a.compareDocumentPosition( b );
  559. if ( compare ) {
  560. // Disconnected nodes
  561. if ( compare & 1 ||
  562. (recompare && b.compareDocumentPosition( a ) === compare) ) {
  563. // Choose the first element that is related to our preferred document
  564. if ( a === doc || contains(preferredDoc, a) ) {
  565. return -1;
  566. }
  567. if ( b === doc || contains(preferredDoc, b) ) {
  568. return 1;
  569. }
  570. // Maintain original order
  571. return sortInput ?
  572. ( indexOf.call( sortInput, a ) - indexOf.call( sortInput, b ) ) :
  573. 0;
  574. }
  575. return compare & 4 ? -1 : 1;
  576. }
  577. // Not directly comparable, sort on existence of method
  578. return a.compareDocumentPosition ? -1 : 1;
  579. } :
  580. function( a, b ) {
  581. var cur,
  582. i = 0,
  583. aup = a.parentNode,
  584. bup = b.parentNode,
  585. ap = [ a ],
  586. bp = [ b ];
  587. // Exit early if the nodes are identical
  588. if ( a === b ) {
  589. hasDuplicate = true;
  590. return 0;
  591. // Parentless nodes are either documents or disconnected
  592. } else if ( !aup || !bup ) {
  593. return a === doc ? -1 :
  594. b === doc ? 1 :
  595. aup ? -1 :
  596. bup ? 1 :
  597. 0;
  598. // If the nodes are siblings, we can do a quick check
  599. } else if ( aup === bup ) {
  600. return siblingCheck( a, b );
  601. }
  602. // Otherwise we need full lists of their ancestors for comparison
  603. cur = a;
  604. while ( (cur = cur.parentNode) ) {
  605. ap.unshift( cur );
  606. }
  607. cur = b;
  608. while ( (cur = cur.parentNode) ) {
  609. bp.unshift( cur );
  610. }
  611. // Walk down the tree looking for a discrepancy
  612. while ( ap[i] === bp[i] ) {
  613. i++;
  614. }
  615. return i ?
  616. // Do a sibling check if the nodes have a common ancestor
  617. siblingCheck( ap[i], bp[i] ) :
  618. // Otherwise nodes in our document sort first
  619. ap[i] === preferredDoc ? -1 :
  620. bp[i] === preferredDoc ? 1 :
  621. 0;
  622. };
  623. return document;
  624. };
  625. Sizzle.matches = function( expr, elements ) {
  626. return Sizzle( expr, null, null, elements );
  627. };
  628. Sizzle.matchesSelector = function( elem, expr ) {
  629. // Set document vars if needed
  630. if ( ( elem.ownerDocument || elem ) !== document ) {
  631. setDocument( elem );
  632. }
  633. // Make sure that attribute selectors are quoted
  634. expr = expr.replace( rattributeQuotes, "='$1']" );
  635. // rbuggyQSA always contains :focus, so no need for an existence check
  636. if ( support.matchesSelector && documentIsHTML && (!rbuggyMatches || !rbuggyMatches.test(expr)) && !rbuggyQSA.test(expr) ) {
  637. try {
  638. var ret = matches.call( elem, expr );
  639. // IE 9's matchesSelector returns false on disconnected nodes
  640. if ( ret || support.disconnectedMatch ||
  641. // As well, disconnected nodes are said to be in a document
  642. // fragment in IE 9
  643. elem.document && elem.document.nodeType !== 11 ) {
  644. return ret;
  645. }
  646. } catch(e) {}
  647. }
  648. return Sizzle( expr, document, null, [elem] ).length > 0;
  649. };
  650. Sizzle.contains = function( context, elem ) {
  651. // Set document vars if needed
  652. if ( ( context.ownerDocument || context ) !== document ) {
  653. setDocument( context );
  654. }
  655. return contains( context, elem );
  656. };
  657. Sizzle.attr = function( elem, name ) {
  658. var val;
  659. // Set document vars if needed
  660. if ( ( elem.ownerDocument || elem ) !== document ) {
  661. setDocument( elem );
  662. }
  663. if ( documentIsHTML ) {
  664. name = name.toLowerCase();
  665. }
  666. if ( (val = Expr.attrHandle[ name ]) ) {
  667. return val( elem );
  668. }
  669. if ( !documentIsHTML || support.attributes ) {
  670. return elem.getAttribute( name );
  671. }
  672. return ( (val = elem.getAttributeNode( name )) || elem.getAttribute( name ) ) && elem[ name ] === true ?
  673. name :
  674. val && val.specified ? val.value : null;
  675. };
  676. Sizzle.error = function( msg ) {
  677. throw new Error( "Syntax error, unrecognized expression: " + msg );
  678. };
  679. // Document sorting and removing duplicates
  680. Sizzle.uniqueSort = function( results ) {
  681. var elem,
  682. duplicates = [],
  683. j = 0,
  684. i = 0;
  685. // Unless we *know* we can detect duplicates, assume their presence
  686. hasDuplicate = !support.detectDuplicates;
  687. // Compensate for sort limitations
  688. recompare = !support.sortDetached;
  689. sortInput = !support.sortStable && results.slice( 0 );
  690. results.sort( sortOrder );
  691. if ( hasDuplicate ) {
  692. while ( (elem = results[i++]) ) {
  693. if ( elem === results[ i ] ) {
  694. j = duplicates.push( i );
  695. }
  696. }
  697. while ( j-- ) {
  698. results.splice( duplicates[ j ], 1 );
  699. }
  700. }
  701. return results;
  702. };
  703. /**
  704. * Checks document order of two siblings
  705. * @param {Element} a
  706. * @param {Element} b
  707. * @returns Returns -1 if a precedes b, 1 if a follows b
  708. */
  709. function siblingCheck( a, b ) {
  710. var cur = b && a,
  711. diff = cur && ( ~b.sourceIndex || MAX_NEGATIVE ) - ( ~a.sourceIndex || MAX_NEGATIVE );
  712. // Use IE sourceIndex if available on both nodes
  713. if ( diff ) {
  714. return diff;
  715. }
  716. // Check if b follows a
  717. if ( cur ) {
  718. while ( (cur = cur.nextSibling) ) {
  719. if ( cur === b ) {
  720. return -1;
  721. }
  722. }
  723. }
  724. return a ? 1 : -1;
  725. }
  726. // Returns a function to use in pseudos for input types
  727. function createInputPseudo( type ) {
  728. return function( elem ) {
  729. var name = elem.nodeName.toLowerCase();
  730. return name === "input" && elem.type === type;
  731. };
  732. }
  733. // Returns a function to use in pseudos for buttons
  734. function createButtonPseudo( type ) {
  735. return function( elem ) {
  736. var name = elem.nodeName.toLowerCase();
  737. return (name === "input" || name === "button") && elem.type === type;
  738. };
  739. }
  740. // Returns a function to use in pseudos for positionals
  741. function createPositionalPseudo( fn ) {
  742. return markFunction(function( argument ) {
  743. argument = +argument;
  744. return markFunction(function( seed, matches ) {
  745. var j,
  746. matchIndexes = fn( [], seed.length, argument ),
  747. i = matchIndexes.length;
  748. // Match elements found at the specified indexes
  749. while ( i-- ) {
  750. if ( seed[ (j = matchIndexes[i]) ] ) {
  751. seed[j] = !(matches[j] = seed[j]);
  752. }
  753. }
  754. });
  755. });
  756. }
  757. /**
  758. * Utility function for retrieving the text value of an array of DOM nodes
  759. * @param {Array|Element} elem
  760. */
  761. getText = Sizzle.getText = function( elem ) {
  762. var node,
  763. ret = "",
  764. i = 0,
  765. nodeType = elem.nodeType;
  766. if ( !nodeType ) {
  767. // If no nodeType, this is expected to be an array
  768. for ( ; (node = elem[i]); i++ ) {
  769. // Do not traverse comment nodes
  770. ret += getText( node );
  771. }
  772. } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
  773. // Use textContent for elements
  774. // innerText usage removed for consistency of new lines (see #11153)
  775. if ( typeof elem.textContent === "string" ) {
  776. return elem.textContent;
  777. } else {
  778. // Traverse its children
  779. for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
  780. ret += getText( elem );
  781. }
  782. }
  783. } else if ( nodeType === 3 || nodeType === 4 ) {
  784. return elem.nodeValue;
  785. }
  786. // Do not include comment or processing instruction nodes
  787. return ret;
  788. };
  789. Expr = Sizzle.selectors = {
  790. // Can be adjusted by the user
  791. cacheLength: 50,
  792. createPseudo: markFunction,
  793. match: matchExpr,
  794. find: {},
  795. relative: {
  796. ">": { dir: "parentNode", first: true },
  797. " ": { dir: "parentNode" },
  798. "+": { dir: "previousSibling", first: true },
  799. "~": { dir: "previousSibling" }
  800. },
  801. preFilter: {
  802. "ATTR": function( match ) {
  803. match[1] = match[1].replace( runescape, funescape );
  804. // Move the given value to match[3] whether quoted or unquoted
  805. match[3] = ( match[4] || match[5] || "" ).replace( runescape, funescape );
  806. if ( match[2] === "~=" ) {
  807. match[3] = " " + match[3] + " ";
  808. }
  809. return match.slice( 0, 4 );
  810. },
  811. "CHILD": function( match ) {
  812. /* matches from matchExpr["CHILD"]
  813. 1 type (only|nth|...)
  814. 2 what (child|of-type)
  815. 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
  816. 4 xn-component of xn+y argument ([+-]?\d*n|)
  817. 5 sign of xn-component
  818. 6 x of xn-component
  819. 7 sign of y-component
  820. 8 y of y-component
  821. */
  822. match[1] = match[1].toLowerCase();
  823. if ( match[1].slice( 0, 3 ) === "nth" ) {
  824. // nth-* requires argument
  825. if ( !match[3] ) {
  826. Sizzle.error( match[0] );
  827. }
  828. // numeric x and y parameters for Expr.filter.CHILD
  829. // remember that false/true cast respectively to 0/1
  830. match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
  831. match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
  832. // other types prohibit arguments
  833. } else if ( match[3] ) {
  834. Sizzle.error( match[0] );
  835. }
  836. return match;
  837. },
  838. "PSEUDO": function( match ) {
  839. var excess,
  840. unquoted = !match[5] && match[2];
  841. if ( matchExpr["CHILD"].test( match[0] ) ) {
  842. return null;
  843. }
  844. // Accept quoted arguments as-is
  845. if ( match[4] ) {
  846. match[2] = match[4];
  847. // Strip excess characters from unquoted arguments
  848. } else if ( unquoted && rpseudo.test( unquoted ) &&
  849. // Get excess from tokenize (recursively)
  850. (excess = tokenize( unquoted, true )) &&
  851. // advance to the next closing parenthesis
  852. (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
  853. // excess is a negative index
  854. match[0] = match[0].slice( 0, excess );
  855. match[2] = unquoted.slice( 0, excess );
  856. }
  857. // Return only captures needed by the pseudo filter method (type and argument)
  858. return match.slice( 0, 3 );
  859. }
  860. },
  861. filter: {
  862. "TAG": function( nodeName ) {
  863. if ( nodeName === "*" ) {
  864. return function() { return true; };
  865. }
  866. nodeName = nodeName.replace( runescape, funescape ).toLowerCase();
  867. return function( elem ) {
  868. return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
  869. };
  870. },
  871. "CLASS": function( className ) {
  872. var pattern = classCache[ className + " " ];
  873. return pattern ||
  874. (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
  875. classCache( className, function( elem ) {
  876. return pattern.test( elem.className || (typeof elem.getAttribute !== strundefined && elem.getAttribute("class")) || "" );
  877. });
  878. },
  879. "ATTR": function( name, operator, check ) {
  880. return function( elem ) {
  881. var result = Sizzle.attr( elem, name );
  882. if ( result == null ) {
  883. return operator === "!=";
  884. }
  885. if ( !operator ) {
  886. return true;
  887. }
  888. result += "";
  889. return operator === "=" ? result === check :
  890. operator === "!=" ? result !== check :
  891. operator === "^=" ? check && result.indexOf( check ) === 0 :
  892. operator === "*=" ? check && result.indexOf( check ) > -1 :
  893. operator === "$=" ? check && result.slice( -check.length ) === check :
  894. operator === "~=" ? ( " " + result + " " ).indexOf( check ) > -1 :
  895. operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
  896. false;
  897. };
  898. },
  899. "CHILD": function( type, what, argument, first, last ) {
  900. var simple = type.slice( 0, 3 ) !== "nth",
  901. forward = type.slice( -4 ) !== "last",
  902. ofType = what === "of-type";
  903. return first === 1 && last === 0 ?
  904. // Shortcut for :nth-*(n)
  905. function( elem ) {
  906. return !!elem.parentNode;
  907. } :
  908. function( elem, context, xml ) {
  909. var cache, outerCache, node, diff, nodeIndex, start,
  910. dir = simple !== forward ? "nextSibling" : "previousSibling",
  911. parent = elem.parentNode,
  912. name = ofType && elem.nodeName.toLowerCase(),
  913. useCache = !xml && !ofType;
  914. if ( parent ) {
  915. // :(first|last|only)-(child|of-type)
  916. if ( simple ) {
  917. while ( dir ) {
  918. node = elem;
  919. while ( (node = node[ dir ]) ) {
  920. if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) {
  921. return false;
  922. }
  923. }
  924. // Reverse direction for :only-* (if we haven't yet done so)
  925. start = dir = type === "only" && !start && "nextSibling";
  926. }
  927. return true;
  928. }
  929. start = [ forward ? parent.firstChild : parent.lastChild ];
  930. // non-xml :nth-child(...) stores cache data on `parent`
  931. if ( forward && useCache ) {
  932. // Seek `elem` from a previously-cached index
  933. outerCache = parent[ expando ] || (parent[ expando ] = {});
  934. cache = outerCache[ type ] || [];
  935. nodeIndex = cache[0] === dirruns && cache[1];
  936. diff = cache[0] === dirruns && cache[2];
  937. node = nodeIndex && parent.childNodes[ nodeIndex ];
  938. while ( (node = ++nodeIndex && node && node[ dir ] ||
  939. // Fallback to seeking `elem` from the start
  940. (diff = nodeIndex = 0) || start.pop()) ) {
  941. // When found, cache indexes on `parent` and break
  942. if ( node.nodeType === 1 && ++diff && node === elem ) {
  943. outerCache[ type ] = [ dirruns, nodeIndex, diff ];
  944. break;
  945. }
  946. }
  947. // Use previously-cached element index if available
  948. } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) {
  949. diff = cache[1];
  950. // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...)
  951. } else {
  952. // Use the same loop as above to seek `elem` from the start
  953. while ( (node = ++nodeIndex && node && node[ dir ] ||
  954. (diff = nodeIndex = 0) || start.pop()) ) {
  955. if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) {
  956. // Cache the index of each encountered element
  957. if ( useCache ) {
  958. (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ];
  959. }
  960. if ( node === elem ) {
  961. break;
  962. }
  963. }
  964. }
  965. }
  966. // Incorporate the offset, then check against cycle size
  967. diff -= last;
  968. return diff === first || ( diff % first === 0 && diff / first >= 0 );
  969. }
  970. };
  971. },
  972. "PSEUDO": function( pseudo, argument ) {
  973. // pseudo-class names are case-insensitive
  974. // http://www.w3.org/TR/selectors/#pseudo-classes
  975. // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
  976. // Remember that setFilters inherits from pseudos
  977. var args,
  978. fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
  979. Sizzle.error( "unsupported pseudo: " + pseudo );
  980. // The user may use createPseudo to indicate that
  981. // arguments are needed to create the filter function
  982. // just as Sizzle does
  983. if ( fn[ expando ] ) {
  984. return fn( argument );
  985. }
  986. // But maintain support for old signatures
  987. if ( fn.length > 1 ) {
  988. args = [ pseudo, pseudo, "", argument ];
  989. return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
  990. markFunction(function( seed, matches ) {
  991. var idx,
  992. matched = fn( seed, argument ),
  993. i = matched.length;
  994. while ( i-- ) {
  995. idx = indexOf.call( seed, matched[i] );
  996. seed[ idx ] = !( matches[ idx ] = matched[i] );
  997. }
  998. }) :
  999. function( elem ) {
  1000. return fn( elem, 0, args );
  1001. };
  1002. }
  1003. return fn;
  1004. }
  1005. },
  1006. pseudos: {
  1007. // Potentially complex pseudos
  1008. "not": markFunction(function( selector ) {
  1009. // Trim the selector passed to compile
  1010. // to avoid treating leading and trailing
  1011. // spaces as combinators
  1012. var input = [],
  1013. results = [],
  1014. matcher = compile( selector.replace( rtrim, "$1" ) );
  1015. return matcher[ expando ] ?
  1016. markFunction(function( seed, matches, context, xml ) {
  1017. var elem,
  1018. unmatched = matcher( seed, null, xml, [] ),
  1019. i = seed.length;
  1020. // Match elements unmatched by `matcher`
  1021. while ( i-- ) {
  1022. if ( (elem = unmatched[i]) ) {
  1023. seed[i] = !(matches[i] = elem);
  1024. }
  1025. }
  1026. }) :
  1027. function( elem, context, xml ) {
  1028. input[0] = elem;
  1029. matcher( input, null, xml, results );
  1030. return !results.pop();
  1031. };
  1032. }),
  1033. "has": markFunction(function( selector ) {
  1034. return function( elem ) {
  1035. return Sizzle( selector, elem ).length > 0;
  1036. };
  1037. }),
  1038. "contains": markFunction(function( text ) {
  1039. return function( elem ) {
  1040. return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
  1041. };
  1042. }),
  1043. // "Whether an element is represented by a :lang() selector
  1044. // is based solely on the element's language value
  1045. // being equal to the identifier C,
  1046. // or beginning with the identifier C immediately followed by "-".
  1047. // The matching of C against the element's language value is performed case-insensitively.
  1048. // The identifier C does not have to be a valid language name."
  1049. // http://www.w3.org/TR/selectors/#lang-pseudo
  1050. "lang": markFunction( function( lang ) {
  1051. // lang value must be a valid identifier
  1052. if ( !ridentifier.test(lang || "") ) {
  1053. Sizzle.error( "unsupported lang: " + lang );
  1054. }
  1055. lang = lang.replace( runescape, funescape ).toLowerCase();
  1056. return function( elem ) {
  1057. var elemLang;
  1058. do {
  1059. if ( (elemLang = documentIsHTML ?
  1060. elem.lang :
  1061. elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
  1062. elemLang = elemLang.toLowerCase();
  1063. return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
  1064. }
  1065. } while ( (elem = elem.parentNode) && elem.nodeType === 1 );
  1066. return false;
  1067. };
  1068. }),
  1069. // Miscellaneous
  1070. "target": function( elem ) {
  1071. var hash = window.location && window.location.hash;
  1072. return hash && hash.slice( 1 ) === elem.id;
  1073. },
  1074. "root": function( elem ) {
  1075. return elem === docElem;
  1076. },
  1077. "focus": function( elem ) {
  1078. return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
  1079. },
  1080. // Boolean properties
  1081. "enabled": function( elem ) {
  1082. return elem.disabled === false;
  1083. },
  1084. "disabled": function( elem ) {
  1085. return elem.disabled === true;
  1086. },
  1087. "checked": function( elem ) {
  1088. // In CSS3, :checked should return both checked and selected elements
  1089. // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
  1090. var nodeName = elem.nodeName.toLowerCase();
  1091. return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
  1092. },
  1093. "selected": function( elem ) {
  1094. // Accessing this property makes selected-by-default
  1095. // options in Safari work properly
  1096. if ( elem.parentNode ) {
  1097. elem.parentNode.selectedIndex;
  1098. }
  1099. return elem.selected === true;
  1100. },
  1101. // Contents
  1102. "empty": function( elem ) {
  1103. // http://www.w3.org/TR/selectors/#empty-pseudo
  1104. // :empty is only affected by element nodes and content nodes(including text(3), cdata(4)),
  1105. // not comment, processing instructions, or others
  1106. // Thanks to Diego Perini for the nodeName shortcut
  1107. // Greater than "@" means alpha characters (specifically not starting with "#" or "?")
  1108. for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
  1109. if ( elem.nodeName > "@" || elem.nodeType === 3 || elem.nodeType === 4 ) {
  1110. return false;
  1111. }
  1112. }
  1113. return true;
  1114. },
  1115. "parent": function( elem ) {
  1116. return !Expr.pseudos["empty"]( elem );
  1117. },
  1118. // Element/input types
  1119. "header": function( elem ) {
  1120. return rheader.test( elem.nodeName );
  1121. },
  1122. "input": function( elem ) {
  1123. return rinputs.test( elem.nodeName );
  1124. },
  1125. "button": function( elem ) {
  1126. var name = elem.nodeName.toLowerCase();
  1127. return name === "input" && elem.type === "button" || name === "button";
  1128. },
  1129. "text": function( elem ) {
  1130. var attr;
  1131. // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
  1132. // use getAttribute instead to test this case
  1133. return elem.nodeName.toLowerCase() === "input" &&
  1134. elem.type === "text" &&
  1135. ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === elem.type );
  1136. },
  1137. // Position-in-collection
  1138. "first": createPositionalPseudo(function() {
  1139. return [ 0 ];
  1140. }),
  1141. "last": createPositionalPseudo(function( matchIndexes, length ) {
  1142. return [ length - 1 ];
  1143. }),
  1144. "eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
  1145. return [ argument < 0 ? argument + length : argument ];
  1146. }),
  1147. "even": createPositionalPseudo(function( matchIndexes, length ) {
  1148. var i = 0;
  1149. for ( ; i < length; i += 2 ) {
  1150. matchIndexes.push( i );
  1151. }
  1152. return matchIndexes;
  1153. }),
  1154. "odd": createPositionalPseudo(function( matchIndexes, length ) {
  1155. var i = 1;
  1156. for ( ; i < length; i += 2 ) {
  1157. matchIndexes.push( i );
  1158. }
  1159. return matchIndexes;
  1160. }),
  1161. "lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
  1162. var i = argument < 0 ? argument + length : argument;
  1163. for ( ; --i >= 0; ) {
  1164. matchIndexes.push( i );
  1165. }
  1166. return matchIndexes;
  1167. }),
  1168. "gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
  1169. var i = argument < 0 ? argument + length : argument;
  1170. for ( ; ++i < length; ) {
  1171. matchIndexes.push( i );
  1172. }
  1173. return matchIndexes;
  1174. })
  1175. }
  1176. };
  1177. // Add button/input type pseudos
  1178. for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
  1179. Expr.pseudos[ i ] = createInputPseudo( i );
  1180. }
  1181. for ( i in { submit: true, reset: true } ) {
  1182. Expr.pseudos[ i ] = createButtonPseudo( i );
  1183. }
  1184. function tokenize( selector, parseOnly ) {
  1185. var matched, match, tokens, type,
  1186. soFar, groups, preFilters,
  1187. cached = tokenCache[ selector + " " ];
  1188. if ( cached ) {
  1189. return parseOnly ? 0 : cached.slice( 0 );
  1190. }
  1191. soFar = selector;
  1192. groups = [];
  1193. preFilters = Expr.preFilter;
  1194. while ( soFar ) {
  1195. // Comma and first run
  1196. if ( !matched || (match = rcomma.exec( soFar )) ) {
  1197. if ( match ) {
  1198. // Don't consume trailing commas as valid
  1199. soFar = soFar.slice( match[0].length ) || soFar;
  1200. }
  1201. groups.push( tokens = [] );
  1202. }
  1203. matched = false;
  1204. // Combinators
  1205. if ( (match = rcombinators.exec( soFar )) ) {
  1206. matched = match.shift();
  1207. tokens.push( {
  1208. value: matched,
  1209. // Cast descendant combinators to space
  1210. type: match[0].replace( rtrim, " " )
  1211. } );
  1212. soFar = soFar.slice( matched.length );
  1213. }
  1214. // Filters
  1215. for ( type in Expr.filter ) {
  1216. if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
  1217. (match = preFilters[ type ]( match ))) ) {
  1218. matched = match.shift();
  1219. tokens.push( {
  1220. value: matched,
  1221. type: type,
  1222. matches: match
  1223. } );
  1224. soFar = soFar.slice( matched.length );
  1225. }
  1226. }
  1227. if ( !matched ) {
  1228. break;
  1229. }
  1230. }
  1231. // Return the length of the invalid excess
  1232. // if we're just parsing
  1233. // Otherwise, throw an error or return tokens
  1234. return parseOnly ?
  1235. soFar.length :
  1236. soFar ?
  1237. Sizzle.error( selector ) :
  1238. // Cache the tokens
  1239. tokenCache( selector, groups ).slice( 0 );
  1240. }
  1241. function toSelector( tokens ) {
  1242. var i = 0,
  1243. len = tokens.length,
  1244. selector = "";
  1245. for ( ; i < len; i++ ) {
  1246. selector += tokens[i].value;
  1247. }
  1248. return selector;
  1249. }
  1250. function addCombinator( matcher, combinator, base ) {
  1251. var dir = combinator.dir,
  1252. checkNonElements = base && dir === "parentNode",
  1253. doneName = done++;
  1254. return combinator.first ?
  1255. // Check against closest ancestor/preceding element
  1256. function( elem, context, xml ) {
  1257. while ( (elem = elem[ dir ]) ) {
  1258. if ( elem.nodeType === 1 || checkNonElements ) {
  1259. return matcher( elem, context, xml );
  1260. }
  1261. }
  1262. } :
  1263. // Check against all ancestor/preceding elements
  1264. function( elem, context, xml ) {
  1265. var data, cache, outerCache,
  1266. dirkey = dirruns + " " + doneName;
  1267. // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
  1268. if ( xml ) {
  1269. while ( (elem = elem[ dir ]) ) {
  1270. if ( elem.nodeType === 1 || checkNonElements ) {
  1271. if ( matcher( elem, context, xml ) ) {
  1272. return true;
  1273. }
  1274. }
  1275. }
  1276. } else {
  1277. while ( (elem = elem[ dir ]) ) {
  1278. if ( elem.nodeType === 1 || checkNonElements ) {
  1279. outerCache = elem[ expando ] || (elem[ expando ] = {});
  1280. if ( (cache = outerCache[ dir ]) && cache[0] === dirkey ) {
  1281. if ( (data = cache[1]) === true || data === cachedruns ) {
  1282. return data === true;
  1283. }
  1284. } else {
  1285. cache = outerCache[ dir ] = [ dirkey ];
  1286. cache[1] = matcher( elem, context, xml ) || cachedruns;
  1287. if ( cache[1] === true ) {
  1288. return true;
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. };
  1295. }
  1296. function elementMatcher( matchers ) {
  1297. return matchers.length > 1 ?
  1298. function( elem, context, xml ) {
  1299. var i = matchers.length;
  1300. while ( i-- ) {
  1301. if ( !matchers[i]( elem, context, xml ) ) {
  1302. return false;
  1303. }
  1304. }
  1305. return true;
  1306. } :
  1307. matchers[0];
  1308. }
  1309. function condense( unmatched, map, filter, context, xml ) {
  1310. var elem,
  1311. newUnmatched = [],
  1312. i = 0,
  1313. len = unmatched.length,
  1314. mapped = map != null;
  1315. for ( ; i < len; i++ ) {
  1316. if ( (elem = unmatched[i]) ) {
  1317. if ( !filter || filter( elem, context, xml ) ) {
  1318. newUnmatched.push( elem );
  1319. if ( mapped ) {
  1320. map.push( i );
  1321. }
  1322. }
  1323. }
  1324. }
  1325. return newUnmatched;
  1326. }
  1327. function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
  1328. if ( postFilter && !postFilter[ expando ] ) {
  1329. postFilter = setMatcher( postFilter );
  1330. }
  1331. if ( postFinder && !postFinder[ expando ] ) {
  1332. postFinder = setMatcher( postFinder, postSelector );
  1333. }
  1334. return markFunction(function( seed, results, context, xml ) {
  1335. var temp, i, elem,
  1336. preMap = [],
  1337. postMap = [],
  1338. preexisting = results.length,
  1339. // Get initial elements from seed or context
  1340. elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
  1341. // Prefilter to get matcher input, preserving a map for seed-results synchronization
  1342. matcherIn = preFilter && ( seed || !selector ) ?
  1343. condense( elems, preMap, preFilter, context, xml ) :
  1344. elems,
  1345. matcherOut = matcher ?
  1346. // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
  1347. postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
  1348. // ...intermediate processing is necessary
  1349. [] :
  1350. // ...otherwise use results directly
  1351. results :
  1352. matcherIn;
  1353. // Find primary matches
  1354. if ( matcher ) {
  1355. matcher( matcherIn, matcherOut, context, xml );
  1356. }
  1357. // Apply postFilter
  1358. if ( postFilter ) {
  1359. temp = condense( matcherOut, postMap );
  1360. postFilter( temp, [], context, xml );
  1361. // Un-match failing elements by moving them back to matcherIn
  1362. i = temp.length;
  1363. while ( i-- ) {
  1364. if ( (elem = temp[i]) ) {
  1365. matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
  1366. }
  1367. }
  1368. }
  1369. if ( seed ) {
  1370. if ( postFinder || preFilter ) {
  1371. if ( postFinder ) {
  1372. // Get the final matcherOut by condensing this intermediate into postFinder contexts
  1373. temp = [];
  1374. i = matcherOut.length;
  1375. while ( i-- ) {
  1376. if ( (elem = matcherOut[i]) ) {
  1377. // Restore matcherIn since elem is not yet a final match
  1378. temp.push( (matcherIn[i] = elem) );
  1379. }
  1380. }
  1381. postFinder( null, (matcherOut = []), temp, xml );
  1382. }
  1383. // Move matched elements from seed to results to keep them synchronized
  1384. i = matcherOut.length;
  1385. while ( i-- ) {
  1386. if ( (elem = matcherOut[i]) &&
  1387. (temp = postFinder ? indexOf.call( seed, elem ) : preMap[i]) > -1 ) {
  1388. seed[temp] = !(results[temp] = elem);
  1389. }
  1390. }
  1391. }
  1392. // Add elements to results, through postFinder if defined
  1393. } else {
  1394. matcherOut = condense(
  1395. matcherOut === results ?
  1396. matcherOut.splice( preexisting, matcherOut.length ) :
  1397. matcherOut
  1398. );
  1399. if ( postFinder ) {
  1400. postFinder( null, results, matcherOut, xml );
  1401. } else {
  1402. push.apply( results, matcherOut );
  1403. }
  1404. }
  1405. });
  1406. }
  1407. function matcherFromTokens( tokens ) {
  1408. var checkContext, matcher, j,
  1409. len = tokens.length,
  1410. leadingRelative = Expr.relative[ tokens[0].type ],
  1411. implicitRelative = leadingRelative || Expr.relative[" "],
  1412. i = leadingRelative ? 1 : 0,
  1413. // The foundational matcher ensures that elements are reachable from top-level context(s)
  1414. matchContext = addCombinator( function( elem ) {
  1415. return elem === checkContext;
  1416. }, implicitRelative, true ),
  1417. matchAnyContext = addCombinator( function( elem ) {
  1418. return indexOf.call( checkContext, elem ) > -1;
  1419. }, implicitRelative, true ),
  1420. matchers = [ function( elem, context, xml ) {
  1421. return ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
  1422. (checkContext = context).nodeType ?
  1423. matchContext( elem, context, xml ) :
  1424. matchAnyContext( elem, context, xml ) );
  1425. } ];
  1426. for ( ; i < len; i++ ) {
  1427. if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
  1428. matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
  1429. } else {
  1430. matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
  1431. // Return special upon seeing a positional matcher
  1432. if ( matcher[ expando ] ) {
  1433. // Find the next relative operator (if any) for proper handling
  1434. j = ++i;
  1435. for ( ; j < len; j++ ) {
  1436. if ( Expr.relative[ tokens[j].type ] ) {
  1437. break;
  1438. }
  1439. }
  1440. return setMatcher(
  1441. i > 1 && elementMatcher( matchers ),
  1442. i > 1 && toSelector( tokens.slice( 0, i - 1 ) ).replace( rtrim, "$1" ),
  1443. matcher,
  1444. i < j && matcherFromTokens( tokens.slice( i, j ) ),
  1445. j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
  1446. j < len && toSelector( tokens )
  1447. );
  1448. }
  1449. matchers.push( matcher );
  1450. }
  1451. }
  1452. return elementMatcher( matchers );
  1453. }
  1454. function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
  1455. // A counter to specify which element is currently being matched
  1456. var matcherCachedRuns = 0,
  1457. bySet = setMatchers.length > 0,
  1458. byElement = elementMatchers.length > 0,
  1459. superMatcher = function( seed, context, xml, results, expandContext ) {
  1460. var elem, j, matcher,
  1461. setMatched = [],
  1462. matchedCount = 0,
  1463. i = "0",
  1464. unmatched = seed && [],
  1465. outermost = expandContext != null,
  1466. contextBackup = outermostContext,
  1467. // We must always have either seed elements or context
  1468. elems = seed || byElement && Expr.find["TAG"]( "*", expandContext && context.parentNode || context ),
  1469. // Use integer dirruns iff this is the outermost matcher
  1470. dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1);
  1471. if ( outermost ) {
  1472. outermostContext = context !== document && context;
  1473. cachedruns = matcherCachedRuns;
  1474. }
  1475. // Add elements passing elementMatchers directly to results
  1476. // Keep `i` a string if there are no elements so `matchedCount` will be "00" below
  1477. for ( ; (elem = elems[i]) != null; i++ ) {
  1478. if ( byElement && elem ) {
  1479. j = 0;
  1480. while ( (matcher = elementMatchers[j++]) ) {
  1481. if ( matcher( elem, context, xml ) ) {
  1482. results.push( elem );
  1483. break;
  1484. }
  1485. }
  1486. if ( outermost ) {
  1487. dirruns = dirrunsUnique;
  1488. cachedruns = ++matcherCachedRuns;
  1489. }
  1490. }
  1491. // Track unmatched elements for set filters
  1492. if ( bySet ) {
  1493. // They will have gone through all possible matchers
  1494. if ( (elem = !matcher && elem) ) {
  1495. matchedCount--;
  1496. }
  1497. // Lengthen the array for every element, matched or not
  1498. if ( seed ) {
  1499. unmatched.push( elem );
  1500. }
  1501. }
  1502. }
  1503. // Apply set filters to unmatched elements
  1504. matchedCount += i;
  1505. if ( bySet && i !== matchedCount ) {
  1506. j = 0;
  1507. while ( (matcher = setMatchers[j++]) ) {
  1508. matcher( unmatched, setMatched, context, xml );
  1509. }
  1510. if ( seed ) {
  1511. // Reintegrate element matches to eliminate the need for sorting
  1512. if ( matchedCount > 0 ) {
  1513. while ( i-- ) {
  1514. if ( !(unmatched[i] || setMatched[i]) ) {
  1515. setMatched[i] = pop.call( results );
  1516. }
  1517. }
  1518. }
  1519. // Discard index placeholder values to get only actual matches
  1520. setMatched = condense( setMatched );
  1521. }
  1522. // Add matches to results
  1523. push.apply( results, setMatched );
  1524. // Seedless set matches succeeding multiple successful matchers stipulate sorting
  1525. if ( outermost && !seed && setMatched.length > 0 &&
  1526. ( matchedCount + setMatchers.length ) > 1 ) {
  1527. Sizzle.uniqueSort( results );
  1528. }
  1529. }
  1530. // Override manipulation of globals by nested matchers
  1531. if ( outermost ) {
  1532. dirruns = dirrunsUnique;
  1533. outermostContext = contextBackup;
  1534. }
  1535. return unmatched;
  1536. };
  1537. return bySet ?
  1538. markFunction( superMatcher ) :
  1539. superMatcher;
  1540. }
  1541. compile = Sizzle.compile = function( selector, group /* Internal Use Only */ ) {
  1542. var i,
  1543. setMatchers = [],
  1544. elementMatchers = [],
  1545. cached = compilerCache[ selector + " " ];
  1546. if ( !cached ) {
  1547. // Generate a function of recursive functions that can be used to check each element
  1548. if ( !group ) {
  1549. group = tokenize( selector );
  1550. }
  1551. i = group.length;
  1552. while ( i-- ) {
  1553. cached = matcherFromTokens( group[i] );
  1554. if ( cached[ expando ] ) {
  1555. setMatchers.push( cached );
  1556. } else {
  1557. elementMatchers.push( cached );
  1558. }
  1559. }
  1560. // Cache the compiled function
  1561. cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
  1562. }
  1563. return cached;
  1564. };
  1565. function multipleContexts( selector, contexts, results ) {
  1566. var i = 0,
  1567. len = contexts.length;
  1568. for ( ; i < len; i++ ) {
  1569. Sizzle( selector, contexts[i], results );
  1570. }
  1571. return results;
  1572. }
  1573. function select( selector, context, results, seed ) {
  1574. var i, tokens, token, type, find,
  1575. match = tokenize( selector );
  1576. if ( !seed ) {
  1577. // Try to minimize operations if there is only one group
  1578. if ( match.length === 1 ) {
  1579. // Take a shortcut and set the context if the root selector is an ID
  1580. tokens = match[0] = match[0].slice( 0 );
  1581. if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
  1582. context.nodeType === 9 && documentIsHTML &&
  1583. Expr.relative[ tokens[1].type ] ) {
  1584. context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
  1585. if ( !context ) {
  1586. return results;
  1587. }
  1588. selector = selector.slice( tokens.shift().value.length );
  1589. }
  1590. // Fetch a seed set for right-to-left matching
  1591. i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
  1592. while ( i-- ) {
  1593. token = tokens[i];
  1594. // Abort if we hit a combinator
  1595. if ( Expr.relative[ (type = token.type) ] ) {
  1596. break;
  1597. }
  1598. if ( (find = Expr.find[ type ]) ) {
  1599. // Search, expanding context for leading sibling combinators
  1600. if ( (seed = find(
  1601. token.matches[0].replace( runescape, funescape ),
  1602. rsibling.test( tokens[0].type ) && context.parentNode || context
  1603. )) ) {
  1604. // If seed is empty or no tokens remain, we can return early
  1605. tokens.splice( i, 1 );
  1606. selector = seed.length && toSelector( tokens );
  1607. if ( !selector ) {
  1608. push.apply( results, seed );
  1609. return results;
  1610. }
  1611. break;
  1612. }
  1613. }
  1614. }
  1615. }
  1616. }
  1617. // Compile and execute a filtering function
  1618. // Provide `match` to avoid retokenization if we modified the selector above
  1619. compile( selector, match )(
  1620. seed,
  1621. context,
  1622. !documentIsHTML,
  1623. results,
  1624. rsibling.test( selector )
  1625. );
  1626. return results;
  1627. }
  1628. // Deprecated
  1629. Expr.pseudos["nth"] = Expr.pseudos["eq"];
  1630. // Easy API for creating new setFilters
  1631. function setFilters() {}
  1632. setFilters.prototype = Expr.filters = Expr.pseudos;
  1633. Expr.setFilters = new setFilters();
  1634. // Check sort stability
  1635. support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
  1636. // Initialize with the default document
  1637. setDocument();
  1638. // Always assume the presence of duplicates if sort doesn't
  1639. // pass them to our comparison function (as in Google Chrome).
  1640. [0, 0].sort( sortOrder );
  1641. support.detectDuplicates = hasDuplicate;
  1642. /*
  1643. // EXPOSE
  1644. if ( typeof define === "function" && define.amd ) {
  1645. define(function() { return Sizzle; });
  1646. } else {
  1647. window.Sizzle = Sizzle;
  1648. }
  1649. */
  1650. // EXPOSE
  1651. return Sizzle;
  1652. });