sizzle.js 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  1. /*!
  2. * Sizzle CSS Selector Engine
  3. * Copyright 2011, The Dojo Foundation
  4. * Released under the MIT, BSD, and GPL Licenses.
  5. * More information: http://sizzlejs.com/
  6. */
  7. (function(){
  8. var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
  9. expando = "sizcache" + (Math.random() + '').replace('.', ''),
  10. done = 0,
  11. toString = Object.prototype.toString,
  12. hasDuplicate = false,
  13. baseHasDuplicate = true,
  14. rBackslash = /\\/g,
  15. rReturn = /\r\n/g,
  16. rNonWord = /\W/;
  17. // Here we check if the JavaScript engine is using some sort of
  18. // optimization where it does not always call our comparision
  19. // function. If that is the case, discard the hasDuplicate value.
  20. // Thus far that includes Google Chrome.
  21. [0, 0].sort(function() {
  22. baseHasDuplicate = false;
  23. return 0;
  24. });
  25. var Sizzle = function( selector, context, results, seed ) {
  26. results = results || [];
  27. context = context || document;
  28. var origContext = context;
  29. if ( context.nodeType !== 1 && context.nodeType !== 9 ) {
  30. return [];
  31. }
  32. if ( !selector || typeof selector !== "string" ) {
  33. return results;
  34. }
  35. var m, set, checkSet, extra, ret, cur, pop, i,
  36. prune = true,
  37. contextXML = Sizzle.isXML( context ),
  38. parts = [],
  39. soFar = selector;
  40. // Reset the position of the chunker regexp (start from head)
  41. do {
  42. chunker.exec( "" );
  43. m = chunker.exec( soFar );
  44. if ( m ) {
  45. soFar = m[3];
  46. parts.push( m[1] );
  47. if ( m[2] ) {
  48. extra = m[3];
  49. break;
  50. }
  51. }
  52. } while ( m );
  53. if ( parts.length > 1 && origPOS.exec( selector ) ) {
  54. if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
  55. set = posProcess( parts[0] + parts[1], context, seed );
  56. } else {
  57. set = Expr.relative[ parts[0] ] ?
  58. [ context ] :
  59. Sizzle( parts.shift(), context );
  60. while ( parts.length ) {
  61. selector = parts.shift();
  62. if ( Expr.relative[ selector ] ) {
  63. selector += parts.shift();
  64. }
  65. set = posProcess( selector, set, seed );
  66. }
  67. }
  68. } else {
  69. // Take a shortcut and set the context if the root selector is an ID
  70. // (but not if it'll be faster if the inner selector is an ID)
  71. if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML &&
  72. Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) {
  73. ret = Sizzle.find( parts.shift(), context, contextXML );
  74. context = ret.expr ?
  75. Sizzle.filter( ret.expr, ret.set )[0] :
  76. ret.set[0];
  77. }
  78. if ( context ) {
  79. ret = seed ?
  80. { expr: parts.pop(), set: makeArray(seed) } :
  81. Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML );
  82. set = ret.expr ?
  83. Sizzle.filter( ret.expr, ret.set ) :
  84. ret.set;
  85. if ( parts.length > 0 ) {
  86. checkSet = makeArray( set );
  87. } else {
  88. prune = false;
  89. }
  90. while ( parts.length ) {
  91. cur = parts.pop();
  92. pop = cur;
  93. if ( !Expr.relative[ cur ] ) {
  94. cur = "";
  95. } else {
  96. pop = parts.pop();
  97. }
  98. if ( pop == null ) {
  99. pop = context;
  100. }
  101. Expr.relative[ cur ]( checkSet, pop, contextXML );
  102. }
  103. } else {
  104. checkSet = parts = [];
  105. }
  106. }
  107. if ( !checkSet ) {
  108. checkSet = set;
  109. }
  110. if ( !checkSet ) {
  111. Sizzle.error( cur || selector );
  112. }
  113. if ( toString.call(checkSet) === "[object Array]" ) {
  114. if ( !prune ) {
  115. results.push.apply( results, checkSet );
  116. } else if ( context && context.nodeType === 1 ) {
  117. for ( i = 0; checkSet[i] != null; i++ ) {
  118. if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) {
  119. results.push( set[i] );
  120. }
  121. }
  122. } else {
  123. for ( i = 0; checkSet[i] != null; i++ ) {
  124. if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
  125. results.push( set[i] );
  126. }
  127. }
  128. }
  129. } else {
  130. makeArray( checkSet, results );
  131. }
  132. if ( extra ) {
  133. Sizzle( extra, origContext, results, seed );
  134. Sizzle.uniqueSort( results );
  135. }
  136. return results;
  137. };
  138. Sizzle.uniqueSort = function( results ) {
  139. if ( sortOrder ) {
  140. hasDuplicate = baseHasDuplicate;
  141. results.sort( sortOrder );
  142. if ( hasDuplicate ) {
  143. for ( var i = 1; i < results.length; i++ ) {
  144. if ( results[i] === results[ i - 1 ] ) {
  145. results.splice( i--, 1 );
  146. }
  147. }
  148. }
  149. }
  150. return results;
  151. };
  152. Sizzle.matches = function( expr, set ) {
  153. return Sizzle( expr, null, null, set );
  154. };
  155. Sizzle.matchesSelector = function( node, expr ) {
  156. return Sizzle( expr, null, null, [node] ).length > 0;
  157. };
  158. Sizzle.find = function( expr, context, isXML ) {
  159. var set, i, len, match, type, left;
  160. if ( !expr ) {
  161. return [];
  162. }
  163. for ( i = 0, len = Expr.order.length; i < len; i++ ) {
  164. type = Expr.order[i];
  165. if ( (match = Expr.leftMatch[ type ].exec( expr )) ) {
  166. left = match[1];
  167. match.splice( 1, 1 );
  168. if ( left.substr( left.length - 1 ) !== "\\" ) {
  169. match[1] = (match[1] || "").replace( rBackslash, "" );
  170. set = Expr.find[ type ]( match, context, isXML );
  171. if ( set != null ) {
  172. expr = expr.replace( Expr.match[ type ], "" );
  173. break;
  174. }
  175. }
  176. }
  177. }
  178. if ( !set ) {
  179. set = typeof context.getElementsByTagName !== "undefined" ?
  180. context.getElementsByTagName( "*" ) :
  181. [];
  182. }
  183. return { set: set, expr: expr };
  184. };
  185. Sizzle.filter = function( expr, set, inplace, not ) {
  186. var match, anyFound,
  187. type, found, item, filter, left,
  188. i, pass,
  189. old = expr,
  190. result = [],
  191. curLoop = set,
  192. isXMLFilter = set && set[0] && Sizzle.isXML( set[0] );
  193. while ( expr && set.length ) {
  194. for ( type in Expr.filter ) {
  195. if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) {
  196. filter = Expr.filter[ type ];
  197. left = match[1];
  198. anyFound = false;
  199. match.splice(1,1);
  200. if ( left.substr( left.length - 1 ) === "\\" ) {
  201. continue;
  202. }
  203. if ( curLoop === result ) {
  204. result = [];
  205. }
  206. if ( Expr.preFilter[ type ] ) {
  207. match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter );
  208. if ( !match ) {
  209. anyFound = found = true;
  210. } else if ( match === true ) {
  211. continue;
  212. }
  213. }
  214. if ( match ) {
  215. for ( i = 0; (item = curLoop[i]) != null; i++ ) {
  216. if ( item ) {
  217. found = filter( item, match, i, curLoop );
  218. pass = not ^ found;
  219. if ( inplace && found != null ) {
  220. if ( pass ) {
  221. anyFound = true;
  222. } else {
  223. curLoop[i] = false;
  224. }
  225. } else if ( pass ) {
  226. result.push( item );
  227. anyFound = true;
  228. }
  229. }
  230. }
  231. }
  232. if ( found !== undefined ) {
  233. if ( !inplace ) {
  234. curLoop = result;
  235. }
  236. expr = expr.replace( Expr.match[ type ], "" );
  237. if ( !anyFound ) {
  238. return [];
  239. }
  240. break;
  241. }
  242. }
  243. }
  244. // Improper expression
  245. if ( expr === old ) {
  246. if ( anyFound == null ) {
  247. Sizzle.error( expr );
  248. } else {
  249. break;
  250. }
  251. }
  252. old = expr;
  253. }
  254. return curLoop;
  255. };
  256. Sizzle.error = function( msg ) {
  257. throw new Error( "Syntax error, unrecognized expression: " + msg );
  258. };
  259. /**
  260. * Utility function for retreiving the text value of an array of DOM nodes
  261. * @param {Array|Element} elem
  262. */
  263. var getText = Sizzle.getText = function( elem ) {
  264. var i, node,
  265. nodeType = elem.nodeType,
  266. ret = "";
  267. if ( nodeType ) {
  268. if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
  269. // Use textContent || innerText for elements
  270. if ( typeof elem.textContent === 'string' ) {
  271. return elem.textContent;
  272. } else if ( typeof elem.innerText === 'string' ) {
  273. // Replace IE's carriage returns
  274. return elem.innerText.replace( rReturn, '' );
  275. } else {
  276. // Traverse it's children
  277. for ( elem = elem.firstChild; elem; elem = elem.nextSibling) {
  278. ret += getText( elem );
  279. }
  280. }
  281. } else if ( nodeType === 3 || nodeType === 4 ) {
  282. return elem.nodeValue;
  283. }
  284. } else {
  285. // If no nodeType, this is expected to be an array
  286. for ( i = 0; (node = elem[i]); i++ ) {
  287. // Do not traverse comment nodes
  288. if ( node.nodeType !== 8 ) {
  289. ret += getText( node );
  290. }
  291. }
  292. }
  293. return ret;
  294. };
  295. var Expr = Sizzle.selectors = {
  296. order: [ "ID", "NAME", "TAG" ],
  297. match: {
  298. ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  299. CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,
  300. NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,
  301. ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,
  302. TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,
  303. CHILD: /:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,
  304. POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,
  305. PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/
  306. },
  307. leftMatch: {},
  308. attrMap: {
  309. "class": "className",
  310. "for": "htmlFor"
  311. },
  312. attrHandle: {
  313. href: function( elem ) {
  314. return elem.getAttribute( "href" );
  315. },
  316. type: function( elem ) {
  317. return elem.getAttribute( "type" );
  318. }
  319. },
  320. relative: {
  321. "+": function(checkSet, part){
  322. var isPartStr = typeof part === "string",
  323. isTag = isPartStr && !rNonWord.test( part ),
  324. isPartStrNotTag = isPartStr && !isTag;
  325. if ( isTag ) {
  326. part = part.toLowerCase();
  327. }
  328. for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) {
  329. if ( (elem = checkSet[i]) ) {
  330. while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {}
  331. checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ?
  332. elem || false :
  333. elem === part;
  334. }
  335. }
  336. if ( isPartStrNotTag ) {
  337. Sizzle.filter( part, checkSet, true );
  338. }
  339. },
  340. ">": function( checkSet, part ) {
  341. var elem,
  342. isPartStr = typeof part === "string",
  343. i = 0,
  344. l = checkSet.length;
  345. if ( isPartStr && !rNonWord.test( part ) ) {
  346. part = part.toLowerCase();
  347. for ( ; i < l; i++ ) {
  348. elem = checkSet[i];
  349. if ( elem ) {
  350. var parent = elem.parentNode;
  351. checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false;
  352. }
  353. }
  354. } else {
  355. for ( ; i < l; i++ ) {
  356. elem = checkSet[i];
  357. if ( elem ) {
  358. checkSet[i] = isPartStr ?
  359. elem.parentNode :
  360. elem.parentNode === part;
  361. }
  362. }
  363. if ( isPartStr ) {
  364. Sizzle.filter( part, checkSet, true );
  365. }
  366. }
  367. },
  368. "": function(checkSet, part, isXML){
  369. var nodeCheck,
  370. doneName = done++,
  371. checkFn = dirCheck;
  372. if ( typeof part === "string" && !rNonWord.test( part ) ) {
  373. part = part.toLowerCase();
  374. nodeCheck = part;
  375. checkFn = dirNodeCheck;
  376. }
  377. checkFn( "parentNode", part, doneName, checkSet, nodeCheck, isXML );
  378. },
  379. "~": function( checkSet, part, isXML ) {
  380. var nodeCheck,
  381. doneName = done++,
  382. checkFn = dirCheck;
  383. if ( typeof part === "string" && !rNonWord.test( part ) ) {
  384. part = part.toLowerCase();
  385. nodeCheck = part;
  386. checkFn = dirNodeCheck;
  387. }
  388. checkFn( "previousSibling", part, doneName, checkSet, nodeCheck, isXML );
  389. }
  390. },
  391. find: {
  392. ID: function( match, context, isXML ) {
  393. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  394. var m = context.getElementById(match[1]);
  395. // Check parentNode to catch when Blackberry 4.6 returns
  396. // nodes that are no longer in the document #6963
  397. return m && m.parentNode ? [m] : [];
  398. }
  399. },
  400. NAME: function( match, context ) {
  401. if ( typeof context.getElementsByName !== "undefined" ) {
  402. var ret = [],
  403. results = context.getElementsByName( match[1] );
  404. for ( var i = 0, l = results.length; i < l; i++ ) {
  405. if ( results[i].getAttribute("name") === match[1] ) {
  406. ret.push( results[i] );
  407. }
  408. }
  409. return ret.length === 0 ? null : ret;
  410. }
  411. },
  412. TAG: function( match, context ) {
  413. if ( typeof context.getElementsByTagName !== "undefined" ) {
  414. return context.getElementsByTagName( match[1] );
  415. }
  416. }
  417. },
  418. preFilter: {
  419. CLASS: function( match, curLoop, inplace, result, not, isXML ) {
  420. match = " " + match[1].replace( rBackslash, "" ) + " ";
  421. if ( isXML ) {
  422. return match;
  423. }
  424. for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) {
  425. if ( elem ) {
  426. if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n\r]/g, " ").indexOf(match) >= 0) ) {
  427. if ( !inplace ) {
  428. result.push( elem );
  429. }
  430. } else if ( inplace ) {
  431. curLoop[i] = false;
  432. }
  433. }
  434. }
  435. return false;
  436. },
  437. ID: function( match ) {
  438. return match[1].replace( rBackslash, "" );
  439. },
  440. TAG: function( match, curLoop ) {
  441. return match[1].replace( rBackslash, "" ).toLowerCase();
  442. },
  443. CHILD: function( match ) {
  444. if ( match[1] === "nth" ) {
  445. if ( !match[2] ) {
  446. Sizzle.error( match[0] );
  447. }
  448. match[2] = match[2].replace(/^\+|\s*/g, '');
  449. // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  450. var test = /(-?)(\d*)(?:n([+\-]?\d*))?/.exec(
  451. match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" ||
  452. !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
  453. // calculate the numbers (first)n+(last) including if they are negative
  454. match[2] = (test[1] + (test[2] || 1)) - 0;
  455. match[3] = test[3] - 0;
  456. }
  457. else if ( match[2] ) {
  458. Sizzle.error( match[0] );
  459. }
  460. // TODO: Move to normal caching system
  461. match[0] = done++;
  462. return match;
  463. },
  464. ATTR: function( match, curLoop, inplace, result, not, isXML ) {
  465. var name = match[1] = match[1].replace( rBackslash, "" );
  466. if ( !isXML && Expr.attrMap[name] ) {
  467. match[1] = Expr.attrMap[name];
  468. }
  469. // Handle if an un-quoted value was used
  470. match[4] = ( match[4] || match[5] || "" ).replace( rBackslash, "" );
  471. if ( match[2] === "~=" ) {
  472. match[4] = " " + match[4] + " ";
  473. }
  474. return match;
  475. },
  476. PSEUDO: function( match, curLoop, inplace, result, not ) {
  477. if ( match[1] === "not" ) {
  478. // If we're dealing with a complex expression, or a simple one
  479. if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) {
  480. match[3] = Sizzle(match[3], null, null, curLoop);
  481. } else {
  482. var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
  483. if ( !inplace ) {
  484. result.push.apply( result, ret );
  485. }
  486. return false;
  487. }
  488. } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) {
  489. return true;
  490. }
  491. return match;
  492. },
  493. POS: function( match ) {
  494. match.unshift( true );
  495. return match;
  496. }
  497. },
  498. filters: {
  499. enabled: function( elem ) {
  500. return elem.disabled === false && elem.type !== "hidden";
  501. },
  502. disabled: function( elem ) {
  503. return elem.disabled === true;
  504. },
  505. checked: function( elem ) {
  506. return elem.checked === true;
  507. },
  508. selected: function( elem ) {
  509. // Accessing this property makes selected-by-default
  510. // options in Safari work properly
  511. if ( elem.parentNode ) {
  512. elem.parentNode.selectedIndex;
  513. }
  514. return elem.selected === true;
  515. },
  516. parent: function( elem ) {
  517. return !!elem.firstChild;
  518. },
  519. empty: function( elem ) {
  520. return !elem.firstChild;
  521. },
  522. has: function( elem, i, match ) {
  523. return !!Sizzle( match[3], elem ).length;
  524. },
  525. header: function( elem ) {
  526. return (/h\d/i).test( elem.nodeName );
  527. },
  528. text: function( elem ) {
  529. var attr = elem.getAttribute( "type" ), type = elem.type;
  530. // IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
  531. // use getAttribute instead to test this case
  532. return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null );
  533. },
  534. radio: function( elem ) {
  535. return elem.nodeName.toLowerCase() === "input" && "radio" === elem.type;
  536. },
  537. checkbox: function( elem ) {
  538. return elem.nodeName.toLowerCase() === "input" && "checkbox" === elem.type;
  539. },
  540. file: function( elem ) {
  541. return elem.nodeName.toLowerCase() === "input" && "file" === elem.type;
  542. },
  543. password: function( elem ) {
  544. return elem.nodeName.toLowerCase() === "input" && "password" === elem.type;
  545. },
  546. submit: function( elem ) {
  547. var name = elem.nodeName.toLowerCase();
  548. return (name === "input" || name === "button") && "submit" === elem.type;
  549. },
  550. image: function( elem ) {
  551. return elem.nodeName.toLowerCase() === "input" && "image" === elem.type;
  552. },
  553. reset: function( elem ) {
  554. var name = elem.nodeName.toLowerCase();
  555. return (name === "input" || name === "button") && "reset" === elem.type;
  556. },
  557. button: function( elem ) {
  558. var name = elem.nodeName.toLowerCase();
  559. return name === "input" && "button" === elem.type || name === "button";
  560. },
  561. input: function( elem ) {
  562. return (/input|select|textarea|button/i).test( elem.nodeName );
  563. },
  564. focus: function( elem ) {
  565. return elem === elem.ownerDocument.activeElement;
  566. }
  567. },
  568. setFilters: {
  569. first: function( elem, i ) {
  570. return i === 0;
  571. },
  572. last: function( elem, i, match, array ) {
  573. return i === array.length - 1;
  574. },
  575. even: function( elem, i ) {
  576. return i % 2 === 0;
  577. },
  578. odd: function( elem, i ) {
  579. return i % 2 === 1;
  580. },
  581. lt: function( elem, i, match ) {
  582. return i < match[3] - 0;
  583. },
  584. gt: function( elem, i, match ) {
  585. return i > match[3] - 0;
  586. },
  587. nth: function( elem, i, match ) {
  588. return match[3] - 0 === i;
  589. },
  590. eq: function( elem, i, match ) {
  591. return match[3] - 0 === i;
  592. }
  593. },
  594. filter: {
  595. PSEUDO: function( elem, match, i, array ) {
  596. var name = match[1],
  597. filter = Expr.filters[ name ];
  598. if ( filter ) {
  599. return filter( elem, i, match, array );
  600. } else if ( name === "contains" ) {
  601. return (elem.textContent || elem.innerText || getText([ elem ]) || "").indexOf(match[3]) >= 0;
  602. } else if ( name === "not" ) {
  603. var not = match[3];
  604. for ( var j = 0, l = not.length; j < l; j++ ) {
  605. if ( not[j] === elem ) {
  606. return false;
  607. }
  608. }
  609. return true;
  610. } else {
  611. Sizzle.error( name );
  612. }
  613. },
  614. CHILD: function( elem, match ) {
  615. var first, last,
  616. doneName, parent, cache,
  617. count, diff,
  618. type = match[1],
  619. node = elem;
  620. switch ( type ) {
  621. case "only":
  622. case "first":
  623. while ( (node = node.previousSibling) ) {
  624. if ( node.nodeType === 1 ) {
  625. return false;
  626. }
  627. }
  628. if ( type === "first" ) {
  629. return true;
  630. }
  631. node = elem;
  632. /* falls through */
  633. case "last":
  634. while ( (node = node.nextSibling) ) {
  635. if ( node.nodeType === 1 ) {
  636. return false;
  637. }
  638. }
  639. return true;
  640. case "nth":
  641. first = match[2];
  642. last = match[3];
  643. if ( first === 1 && last === 0 ) {
  644. return true;
  645. }
  646. doneName = match[0];
  647. parent = elem.parentNode;
  648. if ( parent && (parent[ expando ] !== doneName || !elem.nodeIndex) ) {
  649. count = 0;
  650. for ( node = parent.firstChild; node; node = node.nextSibling ) {
  651. if ( node.nodeType === 1 ) {
  652. node.nodeIndex = ++count;
  653. }
  654. }
  655. parent[ expando ] = doneName;
  656. }
  657. diff = elem.nodeIndex - last;
  658. if ( first === 0 ) {
  659. return diff === 0;
  660. } else {
  661. return ( diff % first === 0 && diff / first >= 0 );
  662. }
  663. }
  664. },
  665. ID: function( elem, match ) {
  666. return elem.nodeType === 1 && elem.getAttribute("id") === match;
  667. },
  668. TAG: function( elem, match ) {
  669. return (match === "*" && elem.nodeType === 1) || !!elem.nodeName && elem.nodeName.toLowerCase() === match;
  670. },
  671. CLASS: function( elem, match ) {
  672. return (" " + (elem.className || elem.getAttribute("class")) + " ")
  673. .indexOf( match ) > -1;
  674. },
  675. ATTR: function( elem, match ) {
  676. var name = match[1],
  677. result = Sizzle.attr ?
  678. Sizzle.attr( elem, name ) :
  679. Expr.attrHandle[ name ] ?
  680. Expr.attrHandle[ name ]( elem ) :
  681. elem[ name ] != null ?
  682. elem[ name ] :
  683. elem.getAttribute( name ),
  684. value = result + "",
  685. type = match[2],
  686. check = match[4];
  687. return result == null ?
  688. type === "!=" :
  689. !type && Sizzle.attr ?
  690. result != null :
  691. type === "=" ?
  692. value === check :
  693. type === "*=" ?
  694. value.indexOf(check) >= 0 :
  695. type === "~=" ?
  696. (" " + value + " ").indexOf(check) >= 0 :
  697. !check ?
  698. value && result !== false :
  699. type === "!=" ?
  700. value !== check :
  701. type === "^=" ?
  702. value.indexOf(check) === 0 :
  703. type === "$=" ?
  704. value.substr(value.length - check.length) === check :
  705. type === "|=" ?
  706. value === check || value.substr(0, check.length + 1) === check + "-" :
  707. false;
  708. },
  709. POS: function( elem, match, i, array ) {
  710. var name = match[2],
  711. filter = Expr.setFilters[ name ];
  712. if ( filter ) {
  713. return filter( elem, i, match, array );
  714. }
  715. }
  716. }
  717. };
  718. var origPOS = Expr.match.POS,
  719. fescape = function(all, num){
  720. return "\\" + (num - 0 + 1);
  721. };
  722. for ( var type in Expr.match ) {
  723. Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) );
  724. Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) );
  725. }
  726. // Expose origPOS
  727. // "global" as in regardless of relation to brackets/parens
  728. Expr.match.globalPOS = origPOS;
  729. var makeArray = function( array, results ) {
  730. array = Array.prototype.slice.call( array, 0 );
  731. if ( results ) {
  732. results.push.apply( results, array );
  733. return results;
  734. }
  735. return array;
  736. };
  737. // Perform a simple check to determine if the browser is capable of
  738. // converting a NodeList to an array using builtin methods.
  739. // Also verifies that the returned array holds DOM nodes
  740. // (which is not the case in the Blackberry browser)
  741. try {
  742. Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
  743. // Provide a fallback method if it does not work
  744. } catch( e ) {
  745. makeArray = function( array, results ) {
  746. var i = 0,
  747. ret = results || [];
  748. if ( toString.call(array) === "[object Array]" ) {
  749. Array.prototype.push.apply( ret, array );
  750. } else {
  751. if ( typeof array.length === "number" ) {
  752. for ( var l = array.length; i < l; i++ ) {
  753. ret.push( array[i] );
  754. }
  755. } else {
  756. for ( ; array[i]; i++ ) {
  757. ret.push( array[i] );
  758. }
  759. }
  760. }
  761. return ret;
  762. };
  763. }
  764. var sortOrder, siblingCheck;
  765. if ( document.documentElement.compareDocumentPosition ) {
  766. sortOrder = function( a, b ) {
  767. if ( a === b ) {
  768. hasDuplicate = true;
  769. return 0;
  770. }
  771. if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) {
  772. return a.compareDocumentPosition ? -1 : 1;
  773. }
  774. return a.compareDocumentPosition(b) & 4 ? -1 : 1;
  775. };
  776. } else {
  777. sortOrder = function( a, b ) {
  778. // The nodes are identical, we can exit early
  779. if ( a === b ) {
  780. hasDuplicate = true;
  781. return 0;
  782. // Fallback to using sourceIndex (in IE) if it's available on both nodes
  783. } else if ( a.sourceIndex && b.sourceIndex ) {
  784. return a.sourceIndex - b.sourceIndex;
  785. }
  786. var al, bl,
  787. ap = [],
  788. bp = [],
  789. aup = a.parentNode,
  790. bup = b.parentNode,
  791. cur = aup;
  792. // If the nodes are siblings (or identical) we can do a quick check
  793. if ( aup === bup ) {
  794. return siblingCheck( a, b );
  795. // If no parents were found then the nodes are disconnected
  796. } else if ( !aup ) {
  797. return -1;
  798. } else if ( !bup ) {
  799. return 1;
  800. }
  801. // Otherwise they're somewhere else in the tree so we need
  802. // to build up a full list of the parentNodes for comparison
  803. while ( cur ) {
  804. ap.unshift( cur );
  805. cur = cur.parentNode;
  806. }
  807. cur = bup;
  808. while ( cur ) {
  809. bp.unshift( cur );
  810. cur = cur.parentNode;
  811. }
  812. al = ap.length;
  813. bl = bp.length;
  814. // Start walking down the tree looking for a discrepancy
  815. for ( var i = 0; i < al && i < bl; i++ ) {
  816. if ( ap[i] !== bp[i] ) {
  817. return siblingCheck( ap[i], bp[i] );
  818. }
  819. }
  820. // We ended someplace up the tree so do a sibling check
  821. return i === al ?
  822. siblingCheck( a, bp[i], -1 ) :
  823. siblingCheck( ap[i], b, 1 );
  824. };
  825. siblingCheck = function( a, b, ret ) {
  826. if ( a === b ) {
  827. return ret;
  828. }
  829. var cur = a.nextSibling;
  830. while ( cur ) {
  831. if ( cur === b ) {
  832. return -1;
  833. }
  834. cur = cur.nextSibling;
  835. }
  836. return 1;
  837. };
  838. }
  839. // Check to see if the browser returns elements by name when
  840. // querying by getElementById (and provide a workaround)
  841. (function(){
  842. // We're going to inject a fake input element with a specified name
  843. var form = document.createElement("div"),
  844. id = "script" + (new Date()).getTime(),
  845. root = document.documentElement;
  846. form.innerHTML = "<a name='" + id + "'/>";
  847. // Inject it into the root element, check its status, and remove it quickly
  848. root.insertBefore( form, root.firstChild );
  849. // The workaround has to do additional checks after a getElementById
  850. // Which slows things down for other browsers (hence the branching)
  851. if ( document.getElementById( id ) ) {
  852. Expr.find.ID = function( match, context, isXML ) {
  853. if ( typeof context.getElementById !== "undefined" && !isXML ) {
  854. var m = context.getElementById(match[1]);
  855. return m ?
  856. m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ?
  857. [m] :
  858. undefined :
  859. [];
  860. }
  861. };
  862. Expr.filter.ID = function( elem, match ) {
  863. var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
  864. return elem.nodeType === 1 && node && node.nodeValue === match;
  865. };
  866. }
  867. root.removeChild( form );
  868. // release memory in IE
  869. root = form = null;
  870. })();
  871. (function(){
  872. // Check to see if the browser returns only elements
  873. // when doing getElementsByTagName("*")
  874. // Create a fake element
  875. var div = document.createElement("div");
  876. div.appendChild( document.createComment("") );
  877. // Make sure no comments are found
  878. if ( div.getElementsByTagName("*").length > 0 ) {
  879. Expr.find.TAG = function( match, context ) {
  880. var results = context.getElementsByTagName( match[1] );
  881. // Filter out possible comments
  882. if ( match[1] === "*" ) {
  883. var tmp = [];
  884. for ( var i = 0; results[i]; i++ ) {
  885. if ( results[i].nodeType === 1 ) {
  886. tmp.push( results[i] );
  887. }
  888. }
  889. results = tmp;
  890. }
  891. return results;
  892. };
  893. }
  894. // Check to see if an attribute returns normalized href attributes
  895. div.innerHTML = "<a href='#'></a>";
  896. if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" &&
  897. div.firstChild.getAttribute("href") !== "#" ) {
  898. Expr.attrHandle.href = function( elem ) {
  899. return elem.getAttribute( "href", 2 );
  900. };
  901. }
  902. // release memory in IE
  903. div = null;
  904. })();
  905. if ( document.querySelectorAll ) {
  906. (function(){
  907. var oldSizzle = Sizzle,
  908. div = document.createElement("div"),
  909. id = "__sizzle__";
  910. div.innerHTML = "<p class='TEST'></p>";
  911. // Safari can't handle uppercase or unicode characters when
  912. // in quirks mode.
  913. if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) {
  914. return;
  915. }
  916. Sizzle = function( query, context, extra, seed ) {
  917. context = context || document;
  918. // Only use querySelectorAll on non-XML documents
  919. // (ID selectors don't work in non-HTML documents)
  920. if ( !seed && !Sizzle.isXML(context) ) {
  921. // See if we find a selector to speed up
  922. var match = /^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec( query );
  923. if ( match && (context.nodeType === 1 || context.nodeType === 9) ) {
  924. // Speed-up: Sizzle("TAG")
  925. if ( match[1] ) {
  926. return makeArray( context.getElementsByTagName( query ), extra );
  927. // Speed-up: Sizzle(".CLASS")
  928. } else if ( match[2] && Expr.find.CLASS && context.getElementsByClassName ) {
  929. return makeArray( context.getElementsByClassName( match[2] ), extra );
  930. }
  931. }
  932. if ( context.nodeType === 9 ) {
  933. // Speed-up: Sizzle("body")
  934. // The body element only exists once, optimize finding it
  935. if ( query === "body" && context.body ) {
  936. return makeArray( [ context.body ], extra );
  937. // Speed-up: Sizzle("#ID")
  938. } else if ( match && match[3] ) {
  939. var elem = context.getElementById( match[3] );
  940. // Check parentNode to catch when Blackberry 4.6 returns
  941. // nodes that are no longer in the document #6963
  942. if ( elem && elem.parentNode ) {
  943. // Handle the case where IE and Opera return items
  944. // by name instead of ID
  945. if ( elem.id === match[3] ) {
  946. return makeArray( [ elem ], extra );
  947. }
  948. } else {
  949. return makeArray( [], extra );
  950. }
  951. }
  952. try {
  953. return makeArray( context.querySelectorAll(query), extra );
  954. } catch(qsaError) {}
  955. // qSA works strangely on Element-rooted queries
  956. // We can work around this by specifying an extra ID on the root
  957. // and working up from there (Thanks to Andrew Dupont for the technique)
  958. // IE 8 doesn't work on object elements
  959. } else if ( context.nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) {
  960. var oldContext = context,
  961. old = context.getAttribute( "id" ),
  962. nid = old || id,
  963. hasParent = context.parentNode,
  964. relativeHierarchySelector = /^\s*[+~]/.test( query );
  965. if ( !old ) {
  966. context.setAttribute( "id", nid );
  967. } else {
  968. nid = nid.replace( /'/g, "\\$&" );
  969. }
  970. if ( relativeHierarchySelector && hasParent ) {
  971. context = context.parentNode;
  972. }
  973. try {
  974. if ( !relativeHierarchySelector || hasParent ) {
  975. return makeArray( context.querySelectorAll( "[id='" + nid + "'] " + query ), extra );
  976. }
  977. } catch(pseudoError) {
  978. } finally {
  979. if ( !old ) {
  980. oldContext.removeAttribute( "id" );
  981. }
  982. }
  983. }
  984. }
  985. return oldSizzle(query, context, extra, seed);
  986. };
  987. for ( var prop in oldSizzle ) {
  988. Sizzle[ prop ] = oldSizzle[ prop ];
  989. }
  990. // release memory in IE
  991. div = null;
  992. })();
  993. }
  994. (function(){
  995. var html = document.documentElement,
  996. matches = html.matchesSelector || html.mozMatchesSelector || html.webkitMatchesSelector || html.msMatchesSelector;
  997. if ( matches ) {
  998. // Check to see if it's possible to do matchesSelector
  999. // on a disconnected node (IE 9 fails this)
  1000. var disconnectedMatch = !matches.call( document.createElement( "div" ), "div" ),
  1001. pseudoWorks = false;
  1002. try {
  1003. // This should fail with an exception
  1004. // Gecko does not error, returns false instead
  1005. matches.call( document.documentElement, "[test!='']:sizzle" );
  1006. } catch( pseudoError ) {
  1007. pseudoWorks = true;
  1008. }
  1009. Sizzle.matchesSelector = function( node, expr ) {
  1010. // Make sure that attribute selectors are quoted
  1011. expr = expr.replace(/\=\s*([^'"\]]*)\s*\]/g, "='$1']");
  1012. if ( !Sizzle.isXML( node ) ) {
  1013. try {
  1014. if ( pseudoWorks || !Expr.match.PSEUDO.test( expr ) && !/!=/.test( expr ) ) {
  1015. var ret = matches.call( node, expr );
  1016. // IE 9's matchesSelector returns false on disconnected nodes
  1017. if ( ret || !disconnectedMatch ||
  1018. // As well, disconnected nodes are said to be in a document
  1019. // fragment in IE 9, so check for that
  1020. node.document && node.document.nodeType !== 11 ) {
  1021. return ret;
  1022. }
  1023. }
  1024. } catch(e) {}
  1025. }
  1026. return Sizzle(expr, null, null, [node]).length > 0;
  1027. };
  1028. }
  1029. })();
  1030. (function(){
  1031. var div = document.createElement("div");
  1032. div.innerHTML = "<div class='test e'></div><div class='test'></div>";
  1033. // Opera can't find a second classname (in 9.6)
  1034. // Also, make sure that getElementsByClassName actually exists
  1035. if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) {
  1036. return;
  1037. }
  1038. // Safari caches class attributes, doesn't catch changes (in 3.2)
  1039. div.lastChild.className = "e";
  1040. if ( div.getElementsByClassName("e").length === 1 ) {
  1041. return;
  1042. }
  1043. Expr.order.splice(1, 0, "CLASS");
  1044. Expr.find.CLASS = function( match, context, isXML ) {
  1045. if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) {
  1046. return context.getElementsByClassName(match[1]);
  1047. }
  1048. };
  1049. // release memory in IE
  1050. div = null;
  1051. })();
  1052. function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  1053. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  1054. var elem = checkSet[i];
  1055. if ( elem ) {
  1056. var match = false;
  1057. elem = elem[dir];
  1058. while ( elem ) {
  1059. if ( elem[ expando ] === doneName ) {
  1060. match = checkSet[elem.sizset];
  1061. break;
  1062. }
  1063. if ( elem.nodeType === 1 && !isXML ){
  1064. elem[ expando ] = doneName;
  1065. elem.sizset = i;
  1066. }
  1067. if ( elem.nodeName.toLowerCase() === cur ) {
  1068. match = elem;
  1069. break;
  1070. }
  1071. elem = elem[dir];
  1072. }
  1073. checkSet[i] = match;
  1074. }
  1075. }
  1076. }
  1077. function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) {
  1078. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  1079. var elem = checkSet[i];
  1080. if ( elem ) {
  1081. var match = false;
  1082. elem = elem[dir];
  1083. while ( elem ) {
  1084. if ( elem[ expando ] === doneName ) {
  1085. match = checkSet[elem.sizset];
  1086. break;
  1087. }
  1088. if ( elem.nodeType === 1 ) {
  1089. if ( !isXML ) {
  1090. elem[ expando ] = doneName;
  1091. elem.sizset = i;
  1092. }
  1093. if ( typeof cur !== "string" ) {
  1094. if ( elem === cur ) {
  1095. match = true;
  1096. break;
  1097. }
  1098. } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
  1099. match = elem;
  1100. break;
  1101. }
  1102. }
  1103. elem = elem[dir];
  1104. }
  1105. checkSet[i] = match;
  1106. }
  1107. }
  1108. }
  1109. if ( document.documentElement.contains ) {
  1110. Sizzle.contains = function( a, b ) {
  1111. return a !== b && (a.contains ? a.contains(b) : true);
  1112. };
  1113. } else if ( document.documentElement.compareDocumentPosition ) {
  1114. Sizzle.contains = function( a, b ) {
  1115. return !!(a.compareDocumentPosition(b) & 16);
  1116. };
  1117. } else {
  1118. Sizzle.contains = function() {
  1119. return false;
  1120. };
  1121. }
  1122. Sizzle.isXML = function( elem ) {
  1123. // documentElement is verified for cases where it doesn't yet exist
  1124. // (such as loading iframes in IE - #4833)
  1125. var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement;
  1126. return documentElement ? documentElement.nodeName !== "HTML" : false;
  1127. };
  1128. var posProcess = function( selector, context, seed ) {
  1129. var match,
  1130. tmpSet = [],
  1131. later = "",
  1132. root = context.nodeType ? [context] : context;
  1133. // Position selectors must be done after the filter
  1134. // And so must :not(positional) so we move all PSEUDOs to the end
  1135. while ( (match = Expr.match.PSEUDO.exec( selector )) ) {
  1136. later += match[0];
  1137. selector = selector.replace( Expr.match.PSEUDO, "" );
  1138. }
  1139. selector = Expr.relative[selector] ? selector + "*" : selector;
  1140. for ( var i = 0, l = root.length; i < l; i++ ) {
  1141. Sizzle( selector, root[i], tmpSet, seed );
  1142. }
  1143. return Sizzle.filter( later, tmpSet );
  1144. };
  1145. // EXPOSE
  1146. window.Sizzle = Sizzle;
  1147. })();