query-sizzle.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojo._base.query"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojo._base.query"] = true;
  8. /*!
  9. * Sizzle CSS Selector Engine - v0.9
  10. * Copyright 2009, John Resig
  11. * Redistributed with the Dojo Toolkit under the terms of the New BSD license.
  12. * More information: http://sizzlejs.com/
  13. *
  14. * This version from github, dated 1/23/2009, commit: e374a73bbffc12ec3b5f252e7f76e593c508dfa5
  15. * Modified for dojo loader, and to fit into dojo namespace. This was done by passing
  16. * dojo object to anonymous function, then assigning Sizzle to dojo.Sizzle instead of window.Sizzle.
  17. * Then an alias for dojo.query and dojo._filterQueryResult(). dojo.psuedos is not mapped.
  18. * Finally, dojo.provide/require added.
  19. */
  20. var startDojoMappings= function(dojo) {
  21. //Start Dojo mappings.
  22. dojo.query = function(/*String*/ query, /*String|DOMNode?*/ root, /*Function?*/listCtor){
  23. listCtor = listCtor || dojo.NodeList;
  24. if(!query){
  25. return new listCtor();
  26. }
  27. if(query.constructor == listCtor){
  28. return query;
  29. }
  30. if(!dojo.isString(query)){
  31. return new listCtor(query); // dojo.NodeList
  32. }
  33. if(dojo.isString(root)){
  34. root = dojo.byId(root);
  35. if(!root){ return new listCtor(); }
  36. }
  37. return dojo.Sizzle(query, root, new listCtor());
  38. };
  39. dojo._filterQueryResult = function(nodeList, simpleFilter){
  40. return dojo.Sizzle.filter(simpleFilter, nodeList);
  41. };
  42. };
  43. //Main Sizzle code follows...
  44. //ns argument, added for dojo, used at the end of the file.
  45. var defineSizzle= function(ns){
  46. var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|[^[\]]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g,
  47. done = 0,
  48. toString = Object.prototype.toString;
  49. var Sizzle = function(selector, context, results, seed) {
  50. results = results || [];
  51. context = context || document;
  52. if ( context.nodeType !== 1 && context.nodeType !== 9 )
  53. return [];
  54. if ( !selector || typeof selector !== "string" ) {
  55. return results;
  56. }
  57. var parts = [], m, set, checkSet, check, mode, extra, prune = true;
  58. // Reset the position of the chunker regexp (start from head)
  59. chunker.lastIndex = 0;
  60. while ( (m = chunker.exec(selector)) !== null ) {
  61. parts.push( m[1] );
  62. if ( m[2] ) {
  63. extra = RegExp.rightContext;
  64. break;
  65. }
  66. }
  67. if ( parts.length > 1 && Expr.match.POS.exec( selector ) ) {
  68. if ( parts.length === 2 && Expr.relative[ parts[0] ] ) {
  69. var later = "", match;
  70. // Position selectors must be done after the filter
  71. while ( (match = Expr.match.POS.exec( selector )) ) {
  72. later += match[0];
  73. selector = selector.replace( Expr.match.POS, "" );
  74. }
  75. set = Sizzle.filter( later, Sizzle( selector, context ) );
  76. } else {
  77. set = Expr.relative[ parts[0] ] ?
  78. [ context ] :
  79. Sizzle( parts.shift(), context );
  80. while ( parts.length ) {
  81. var tmpSet = [];
  82. selector = parts.shift();
  83. if ( Expr.relative[ selector ] )
  84. selector += parts.shift();
  85. for ( var i = 0, l = set.length; i < l; i++ ) {
  86. Sizzle( selector, set[i], tmpSet );
  87. }
  88. set = tmpSet;
  89. }
  90. }
  91. } else {
  92. var ret = seed ?
  93. { expr: parts.pop(), set: makeArray(seed) } :
  94. Sizzle.find( parts.pop(), parts.length === 1 && context.parentNode ? context.parentNode : context );
  95. set = Sizzle.filter( ret.expr, ret.set );
  96. if ( parts.length > 0 ) {
  97. checkSet = makeArray(set);
  98. } else {
  99. prune = false;
  100. }
  101. while ( parts.length ) {
  102. var cur = parts.pop(), pop = cur;
  103. if ( !Expr.relative[ cur ] ) {
  104. cur = "";
  105. } else {
  106. pop = parts.pop();
  107. }
  108. if ( pop == null ) {
  109. pop = context;
  110. }
  111. Expr.relative[ cur ]( checkSet, pop );
  112. }
  113. }
  114. if ( !checkSet ) {
  115. checkSet = set;
  116. }
  117. if ( !checkSet ) {
  118. throw "Syntax error, unrecognized expression: " + (cur || selector);
  119. }
  120. if ( toString.call(checkSet) === "[object Array]" ) {
  121. if ( !prune ) {
  122. results.push.apply( results, checkSet );
  123. } else if ( context.nodeType === 1 ) {
  124. for ( var i = 0; checkSet[i] != null; i++ ) {
  125. if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
  126. results.push( set[i] );
  127. }
  128. }
  129. } else {
  130. for ( var i = 0; checkSet[i] != null; i++ ) {
  131. if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
  132. results.push( set[i] );
  133. }
  134. }
  135. }
  136. } else {
  137. makeArray( checkSet, results );
  138. }
  139. if ( extra ) {
  140. Sizzle( extra, context, results, seed );
  141. }
  142. return results;
  143. };
  144. Sizzle.matches = function(expr, set){
  145. return Sizzle(expr, null, null, set);
  146. };
  147. Sizzle.find = function(expr, context){
  148. var set, match;
  149. if ( !expr ) {
  150. return [];
  151. }
  152. for ( var i = 0, l = Expr.order.length; i < l; i++ ) {
  153. var type = Expr.order[i], match;
  154. if ( (match = Expr.match[ type ].exec( expr )) ) {
  155. var left = RegExp.leftContext;
  156. if ( left.substr( left.length - 1 ) !== "\\" ) {
  157. match[1] = (match[1] || "").replace(/\\/g, "");
  158. set = Expr.find[ type ]( match, context );
  159. if ( set != null ) {
  160. expr = expr.replace( Expr.match[ type ], "" );
  161. break;
  162. }
  163. }
  164. }
  165. }
  166. if ( !set ) {
  167. set = context.getElementsByTagName("*");
  168. }
  169. return {set: set, expr: expr};
  170. };
  171. Sizzle.filter = function(expr, set, inplace, not){
  172. var old = expr, result = [], curLoop = set, match, anyFound;
  173. while ( expr && set.length ) {
  174. for ( var type in Expr.filter ) {
  175. if ( (match = Expr.match[ type ].exec( expr )) != null ) {
  176. var filter = Expr.filter[ type ], goodArray = null, goodPos = 0, found, item;
  177. anyFound = false;
  178. if ( curLoop == result ) {
  179. result = [];
  180. }
  181. if ( Expr.preFilter[ type ] ) {
  182. match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not );
  183. if ( !match ) {
  184. anyFound = found = true;
  185. } else if ( match[0] === true ) {
  186. goodArray = [];
  187. var last = null, elem;
  188. for ( var i = 0; (elem = curLoop[i]) !== undefined; i++ ) {
  189. if ( elem && last !== elem ) {
  190. goodArray.push( elem );
  191. last = elem;
  192. }
  193. }
  194. }
  195. }
  196. if ( match ) {
  197. for ( var i = 0; (item = curLoop[i]) !== undefined; i++ ) {
  198. if ( item ) {
  199. if ( goodArray && item != goodArray[goodPos] ) {
  200. goodPos++;
  201. }
  202. found = filter( item, match, goodPos, goodArray );
  203. var pass = not ^ !!found;
  204. if ( inplace && found != null ) {
  205. if ( pass ) {
  206. anyFound = true;
  207. } else {
  208. curLoop[i] = false;
  209. }
  210. } else if ( pass ) {
  211. result.push( item );
  212. anyFound = true;
  213. }
  214. }
  215. }
  216. }
  217. if ( found !== undefined ) {
  218. if ( !inplace ) {
  219. curLoop = result;
  220. }
  221. expr = expr.replace( Expr.match[ type ], "" );
  222. if ( !anyFound ) {
  223. return [];
  224. }
  225. break;
  226. }
  227. }
  228. }
  229. expr = expr.replace(/\s*,\s*/, "");
  230. // Improper expression
  231. if ( expr == old ) {
  232. if ( anyFound == null ) {
  233. throw "Syntax error, unrecognized expression: " + expr;
  234. } else {
  235. break;
  236. }
  237. }
  238. old = expr;
  239. }
  240. return curLoop;
  241. };
  242. var Expr = Sizzle.selectors = {
  243. order: [ "ID", "NAME", "TAG" ],
  244. match: {
  245. ID: /#((?:[\w\u0128-\uFFFF_-]|\\.)+)/,
  246. CLASS: /\.((?:[\w\u0128-\uFFFF_-]|\\.)+)/,
  247. NAME: /\[name=['"]*((?:[\w\u0128-\uFFFF_-]|\\.)+)['"]*\]/,
  248. ATTR: /\[((?:[\w\u0128-\uFFFF_-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\]/,
  249. TAG: /^((?:[\w\u0128-\uFFFF\*_-]|\\.)+)/,
  250. CHILD: /:(only|nth|last|first)-child\(?(even|odd|[\dn+-]*)\)?/,
  251. POS: /:(nth|eq|gt|lt|first|last|even|odd)\(?(\d*)\)?(?:[^-]|$)/,
  252. PSEUDO: /:((?:[\w\u0128-\uFFFF_-]|\\.)+)(?:\((['"]*)((?:\([^\)]+\)|[^\2\(\)]*)+)\2\))?/
  253. },
  254. attrMap: {
  255. "class": "className",
  256. "for": "htmlFor"
  257. },
  258. relative: {
  259. "+": function(checkSet, part){
  260. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  261. var elem = checkSet[i];
  262. if ( elem ) {
  263. var cur = elem.previousSibling;
  264. while ( cur && cur.nodeType !== 1 ) {
  265. cur = cur.previousSibling;
  266. }
  267. checkSet[i] = typeof part === "string" ?
  268. cur || false :
  269. cur === part;
  270. }
  271. }
  272. if ( typeof part === "string" ) {
  273. Sizzle.filter( part, checkSet, true );
  274. }
  275. },
  276. ">": function(checkSet, part){
  277. if ( typeof part === "string" && !/\W/.test(part) ) {
  278. part = part.toUpperCase();
  279. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  280. var elem = checkSet[i];
  281. if ( elem ) {
  282. var parent = elem.parentNode;
  283. checkSet[i] = parent.nodeName === part ? parent : false;
  284. }
  285. }
  286. } else {
  287. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  288. var elem = checkSet[i];
  289. if ( elem ) {
  290. checkSet[i] = typeof part === "string" ?
  291. elem.parentNode :
  292. elem.parentNode === part;
  293. }
  294. }
  295. if ( typeof part === "string" ) {
  296. Sizzle.filter( part, checkSet, true );
  297. }
  298. }
  299. },
  300. "": function(checkSet, part){
  301. var doneName = "done" + (done++), checkFn = dirCheck;
  302. if ( !part.match(/\W/) ) {
  303. var nodeCheck = part = part.toUpperCase();
  304. checkFn = dirNodeCheck;
  305. }
  306. checkFn("parentNode", part, doneName, checkSet, nodeCheck);
  307. },
  308. "~": function(checkSet, part){
  309. var doneName = "done" + (done++), checkFn = dirCheck;
  310. if ( typeof part === "string" && !part.match(/\W/) ) {
  311. var nodeCheck = part = part.toUpperCase();
  312. checkFn = dirNodeCheck;
  313. }
  314. checkFn("previousSibling", part, doneName, checkSet, nodeCheck);
  315. }
  316. },
  317. find: {
  318. ID: function(match, context){
  319. if ( context.getElementById ) {
  320. var m = context.getElementById(match[1]);
  321. return m ? [m] : [];
  322. }
  323. },
  324. NAME: function(match, context){
  325. return context.getElementsByName ? context.getElementsByName(match[1]) : null;
  326. },
  327. TAG: function(match, context){
  328. return context.getElementsByTagName(match[1]);
  329. }
  330. },
  331. preFilter: {
  332. CLASS: function(match, curLoop, inplace, result, not){
  333. match = " " + match[1].replace(/\\/g, "") + " ";
  334. for ( var i = 0; curLoop[i]; i++ ) {
  335. if ( not ^ (" " + curLoop[i].className + " ").indexOf(match) >= 0 ) {
  336. if ( !inplace )
  337. result.push( curLoop[i] );
  338. } else if ( inplace ) {
  339. curLoop[i] = false;
  340. }
  341. }
  342. return false;
  343. },
  344. ID: function(match){
  345. return match[1];
  346. },
  347. TAG: function(match){
  348. return match[1].toUpperCase();
  349. },
  350. CHILD: function(match){
  351. if ( match[1] == "nth" ) {
  352. // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6'
  353. var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec(
  354. match[2] == "even" && "2n" || match[2] == "odd" && "2n+1" ||
  355. !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]);
  356. // calculate the numbers (first)n+(last) including if they are negative
  357. match[2] = (test[1] + (test[2] || 1)) - 0;
  358. match[3] = test[3] - 0;
  359. }
  360. // TODO: Move to normal caching system
  361. match[0] = "done" + (done++);
  362. return match;
  363. },
  364. ATTR: function(match){
  365. var name = match[1];
  366. if ( Expr.attrMap[name] ) {
  367. match[1] = Expr.attrMap[name];
  368. }
  369. if ( match[2] === "~=" ) {
  370. match[4] = " " + match[4] + " ";
  371. }
  372. return match;
  373. },
  374. PSEUDO: function(match, curLoop, inplace, result, not){
  375. if ( match[1] === "not" ) {
  376. // If we're dealing with a complex expression, or a simple one
  377. if ( match[3].match(chunker).length > 1 ) {
  378. match[3] = Sizzle(match[3], null, null, curLoop);
  379. } else {
  380. var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);
  381. if ( !inplace ) {
  382. result.push.apply( result, ret );
  383. }
  384. return false;
  385. }
  386. }
  387. return match;
  388. },
  389. POS: function(match){
  390. match.unshift( true );
  391. return match;
  392. }
  393. },
  394. filters: {
  395. enabled: function(elem){
  396. return elem.disabled === false && elem.type !== "hidden";
  397. },
  398. disabled: function(elem){
  399. return elem.disabled === true;
  400. },
  401. checked: function(elem){
  402. return elem.checked === true;
  403. },
  404. selected: function(elem){
  405. // Accessing this property makes selected-by-default
  406. // options in Safari work properly
  407. elem.parentNode.selectedIndex;
  408. return elem.selected === true;
  409. },
  410. parent: function(elem){
  411. return !!elem.firstChild;
  412. },
  413. empty: function(elem){
  414. return !elem.firstChild;
  415. },
  416. has: function(elem, i, match){
  417. return !!Sizzle( match[3], elem ).length;
  418. },
  419. header: function(elem){
  420. return /h\d/i.test( elem.nodeName );
  421. },
  422. text: function(elem){
  423. return "text" === elem.type;
  424. },
  425. radio: function(elem){
  426. return "radio" === elem.type;
  427. },
  428. checkbox: function(elem){
  429. return "checkbox" === elem.type;
  430. },
  431. file: function(elem){
  432. return "file" === elem.type;
  433. },
  434. password: function(elem){
  435. return "password" === elem.type;
  436. },
  437. submit: function(elem){
  438. return "submit" === elem.type;
  439. },
  440. image: function(elem){
  441. return "image" === elem.type;
  442. },
  443. reset: function(elem){
  444. return "reset" === elem.type;
  445. },
  446. button: function(elem){
  447. return "button" === elem.type || elem.nodeName.toUpperCase() === "BUTTON";
  448. },
  449. input: function(elem){
  450. return /input|select|textarea|button/i.test(elem.nodeName);
  451. }
  452. },
  453. setFilters: {
  454. first: function(elem, i){
  455. return i === 0;
  456. },
  457. last: function(elem, i, match, array){
  458. return i === array.length - 1;
  459. },
  460. even: function(elem, i){
  461. return i % 2 === 0;
  462. },
  463. odd: function(elem, i){
  464. return i % 2 === 1;
  465. },
  466. lt: function(elem, i, match){
  467. return i < match[3] - 0;
  468. },
  469. gt: function(elem, i, match){
  470. return i > match[3] - 0;
  471. },
  472. nth: function(elem, i, match){
  473. return match[3] - 0 == i;
  474. },
  475. eq: function(elem, i, match){
  476. return match[3] - 0 == i;
  477. }
  478. },
  479. filter: {
  480. CHILD: function(elem, match){
  481. var type = match[1], parent = elem.parentNode;
  482. var doneName = match[0];
  483. if ( parent && !parent[ doneName ] ) {
  484. var count = 1;
  485. for ( var node = parent.firstChild; node; node = node.nextSibling ) {
  486. if ( node.nodeType == 1 ) {
  487. node.nodeIndex = count++;
  488. }
  489. }
  490. parent[ doneName ] = count - 1;
  491. }
  492. if ( type == "first" ) {
  493. return elem.nodeIndex == 1;
  494. } else if ( type == "last" ) {
  495. return elem.nodeIndex == parent[ doneName ];
  496. } else if ( type == "only" ) {
  497. return parent[ doneName ] == 1;
  498. } else if ( type == "nth" ) {
  499. var add = false, first = match[2], last = match[3];
  500. if ( first == 1 && last == 0 ) {
  501. return true;
  502. }
  503. if ( first == 0 ) {
  504. if ( elem.nodeIndex == last ) {
  505. add = true;
  506. }
  507. } else if ( (elem.nodeIndex - last) % first == 0 && (elem.nodeIndex - last) / first >= 0 ) {
  508. add = true;
  509. }
  510. return add;
  511. }
  512. },
  513. PSEUDO: function(elem, match, i, array){
  514. var name = match[1], filter = Expr.filters[ name ];
  515. if ( filter ) {
  516. return filter( elem, i, match, array );
  517. } else if ( name === "contains" ) {
  518. return (elem.textContent || elem.innerText || "").indexOf(match[3]) >= 0;
  519. } else if ( name === "not" ) {
  520. var not = match[3];
  521. for ( var i = 0, l = not.length; i < l; i++ ) {
  522. if ( not[i] === elem ) {
  523. return false;
  524. }
  525. }
  526. return true;
  527. }
  528. },
  529. ID: function(elem, match){
  530. return elem.nodeType === 1 && elem.getAttribute("id") === match;
  531. },
  532. TAG: function(elem, match){
  533. return (match === "*" && elem.nodeType === 1) || elem.nodeName === match;
  534. },
  535. CLASS: function(elem, match){
  536. return match.test( elem.className );
  537. },
  538. ATTR: function(elem, match){
  539. var result = elem[ match[1] ] || elem.getAttribute( match[1] ), value = result + "", type = match[2], check = match[4];
  540. return result == null ?
  541. false :
  542. type === "=" ?
  543. value === check :
  544. type === "*=" ?
  545. value.indexOf(check) >= 0 :
  546. type === "~=" ?
  547. (" " + value + " ").indexOf(check) >= 0 :
  548. !match[4] ?
  549. result :
  550. type === "!=" ?
  551. value != check :
  552. type === "^=" ?
  553. value.indexOf(check) === 0 :
  554. type === "$=" ?
  555. value.substr(value.length - check.length) === check :
  556. type === "|=" ?
  557. value === check || value.substr(0, check.length + 1) === check + "-" :
  558. false;
  559. },
  560. POS: function(elem, match, i, array){
  561. var name = match[2], filter = Expr.setFilters[ name ];
  562. if ( filter ) {
  563. return filter( elem, i, match, array );
  564. }
  565. }
  566. }
  567. };
  568. for ( var type in Expr.match ) {
  569. Expr.match[ type ] = RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source );
  570. }
  571. var makeArray = function(array, results) {
  572. array = Array.prototype.slice.call( array );
  573. if ( results ) {
  574. results.push.apply( results, array );
  575. return results;
  576. }
  577. return array;
  578. };
  579. // Perform a simple check to determine if the browser is capable of
  580. // converting a NodeList to an array using builtin methods.
  581. try {
  582. Array.prototype.slice.call( document.documentElement.childNodes );
  583. // Provide a fallback method if it does not work
  584. } catch(e){
  585. makeArray = function(array, results) {
  586. var ret = results || [];
  587. if ( toString.call(array) === "[object Array]" ) {
  588. Array.prototype.push.apply( ret, array );
  589. } else {
  590. if ( typeof array.length === "number" ) {
  591. for ( var i = 0, l = array.length; i < l; i++ ) {
  592. ret.push( array[i] );
  593. }
  594. } else {
  595. for ( var i = 0; array[i]; i++ ) {
  596. ret.push( array[i] );
  597. }
  598. }
  599. }
  600. return ret;
  601. };
  602. }
  603. // Check to see if the browser returns elements by name when
  604. // querying by getElementById (and provide a workaround)
  605. (function(){
  606. // We're going to inject a fake input element with a specified name
  607. var form = document.createElement("form"),
  608. id = "script" + (new Date).getTime();
  609. form.innerHTML = "<input name='" + id + "'/>";
  610. // Inject it into the root element, check its status, and remove it quickly
  611. var root = document.documentElement;
  612. root.insertBefore( form, root.firstChild );
  613. // The workaround has to do additional checks after a getElementById
  614. // Which slows things down for other browsers (hence the branching)
  615. if ( !!document.getElementById( id ) ) {
  616. Expr.find.ID = function(match, context){
  617. if ( context.getElementById ) {
  618. var m = context.getElementById(match[1]);
  619. return m ? m.id === match[1] || m.getAttributeNode && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
  620. }
  621. };
  622. Expr.filter.ID = function(elem, match){
  623. var node = elem.getAttributeNode && elem.getAttributeNode("id");
  624. return elem.nodeType === 1 && node && node.nodeValue === match;
  625. };
  626. }
  627. root.removeChild( form );
  628. })();
  629. // Check to see if the browser returns only elements
  630. // when doing getElementsByTagName("*")
  631. (function(){
  632. // Create a fake element
  633. var div = document.createElement("div");
  634. div.appendChild( document.createComment("") );
  635. // Make sure no comments are found
  636. if ( div.getElementsByTagName("*").length > 0 ) {
  637. Expr.find.TAG = function(match, context){
  638. var results = context.getElementsByTagName(match[1]);
  639. // Filter out possible comments
  640. if ( match[1] === "*" ) {
  641. var tmp = [];
  642. for ( var i = 0; results[i]; i++ ) {
  643. if ( results[i].nodeType === 1 ) {
  644. tmp.push( results[i] );
  645. }
  646. }
  647. results = tmp;
  648. }
  649. return results;
  650. };
  651. }
  652. })();
  653. if ( document.querySelectorAll ) (function(){
  654. var oldSizzle = Sizzle;
  655. Sizzle = function(query, context, extra, seed){
  656. context = context || document;
  657. if ( !seed && context.nodeType === 9 ) {
  658. try {
  659. return makeArray( context.querySelectorAll(query), extra );
  660. } catch(e){}
  661. }
  662. return oldSizzle(query, context, extra, seed);
  663. };
  664. Sizzle.find = oldSizzle.find;
  665. Sizzle.filter = oldSizzle.filter;
  666. Sizzle.selectors = oldSizzle.selectors;
  667. Sizzle.matches = oldSizzle.matches;
  668. })();
  669. if ( document.documentElement.getElementsByClassName ) {
  670. Expr.order.splice(1, 0, "CLASS");
  671. Expr.find.CLASS = function(match, context) {
  672. return context.getElementsByClassName(match[1]);
  673. };
  674. }
  675. function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck ) {
  676. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  677. var elem = checkSet[i];
  678. if ( elem ) {
  679. elem = elem[dir];
  680. var match = false;
  681. while ( elem && elem.nodeType ) {
  682. var done = elem[doneName];
  683. if ( done ) {
  684. match = checkSet[ done ];
  685. break;
  686. }
  687. if ( elem.nodeType === 1 )
  688. elem[doneName] = i;
  689. if ( elem.nodeName === cur ) {
  690. match = elem;
  691. break;
  692. }
  693. elem = elem[dir];
  694. }
  695. checkSet[i] = match;
  696. }
  697. }
  698. }
  699. function dirCheck( dir, cur, doneName, checkSet, nodeCheck ) {
  700. for ( var i = 0, l = checkSet.length; i < l; i++ ) {
  701. var elem = checkSet[i];
  702. if ( elem ) {
  703. elem = elem[dir];
  704. var match = false;
  705. while ( elem && elem.nodeType ) {
  706. if ( elem[doneName] ) {
  707. match = checkSet[ elem[doneName] ];
  708. break;
  709. }
  710. if ( elem.nodeType === 1 ) {
  711. elem[doneName] = i;
  712. if ( typeof cur !== "string" ) {
  713. if ( elem === cur ) {
  714. match = true;
  715. break;
  716. }
  717. } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) {
  718. match = elem;
  719. break;
  720. }
  721. }
  722. elem = elem[dir];
  723. }
  724. checkSet[i] = match;
  725. }
  726. }
  727. }
  728. var contains = document.compareDocumentPosition ? function(a, b){
  729. return a.compareDocumentPosition(b) & 16;
  730. } : function(a, b){
  731. return a !== b && (a.contains ? a.contains(b) : true);
  732. };
  733. // EXPOSE
  734. ns.Sizzle = Sizzle;
  735. };
  736. if (this["dojo"]) {
  737. var defined= 0;
  738. if (!defined) {
  739. // must be in a built version that stripped out the define above
  740. dojo.provide("dojo._base.query");
  741. dojo.require("dojo._base.NodeList");
  742. defineSizzle(dojo);
  743. } // else must be in a source version (or a build that likes define)
  744. } else {
  745. defineSizzle(window);
  746. }
  747. }