Query.html 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js">/*
  19. * This is code is also distributed under MIT license for use
  20. * with jQuery and prototype JavaScript libraries.
  21. */
  22. <span id='Ext-dom-Query'>/**
  23. </span> * @class Ext.dom.Query
  24. * @alternateClassName Ext.DomQuery
  25. * @alternateClassName Ext.core.DomQuery
  26. * @singleton
  27. *
  28. * Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes
  29. * and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).
  30. *
  31. * DomQuery supports most of the [CSS3 selectors spec][1], along with some custom selectors and basic XPath.
  32. *
  33. * All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example
  34. * `div.foo:nth-child(odd)[@foo=bar].bar:first` would be a perfectly valid selector. Node filters are processed
  35. * in the order in which they appear, which allows you to optimize your queries for your document structure.
  36. *
  37. * ## Element Selectors:
  38. *
  39. * - **`*`** any element
  40. * - **`E`** an element with the tag E
  41. * - **`E F`** All descendent elements of E that have the tag F
  42. * - **`E &gt; F`** or **E/F** all direct children elements of E that have the tag F
  43. * - **`E + F`** all elements with the tag F that are immediately preceded by an element with the tag E
  44. * - **`E ~ F`** all elements with the tag F that are preceded by a sibling element with the tag E
  45. *
  46. * ## Attribute Selectors:
  47. *
  48. * The use of `@` and quotes are optional. For example, `div[@foo='bar']` is also a valid attribute selector.
  49. *
  50. * - **`E[foo]`** has an attribute &quot;foo&quot;
  51. * - **`E[foo=bar]`** has an attribute &quot;foo&quot; that equals &quot;bar&quot;
  52. * - **`E[foo^=bar]`** has an attribute &quot;foo&quot; that starts with &quot;bar&quot;
  53. * - **`E[foo$=bar]`** has an attribute &quot;foo&quot; that ends with &quot;bar&quot;
  54. * - **`E[foo*=bar]`** has an attribute &quot;foo&quot; that contains the substring &quot;bar&quot;
  55. * - **`E[foo%=2]`** has an attribute &quot;foo&quot; that is evenly divisible by 2
  56. * - **`E[foo!=bar]`** attribute &quot;foo&quot; does not equal &quot;bar&quot;
  57. *
  58. * ## Pseudo Classes:
  59. *
  60. * - **`E:first-child`** E is the first child of its parent
  61. * - **`E:last-child`** E is the last child of its parent
  62. * - **`E:nth-child(_n_)`** E is the _n_th child of its parent (1 based as per the spec)
  63. * - **`E:nth-child(odd)`** E is an odd child of its parent
  64. * - **`E:nth-child(even)`** E is an even child of its parent
  65. * - **`E:only-child`** E is the only child of its parent
  66. * - **`E:checked`** E is an element that is has a checked attribute that is true (e.g. a radio or checkbox)
  67. * - **`E:first`** the first E in the resultset
  68. * - **`E:last`** the last E in the resultset
  69. * - **`E:nth(_n_)`** the _n_th E in the resultset (1 based)
  70. * - **`E:odd`** shortcut for :nth-child(odd)
  71. * - **`E:even`** shortcut for :nth-child(even)
  72. * - **`E:contains(foo)`** E's innerHTML contains the substring &quot;foo&quot;
  73. * - **`E:nodeValue(foo)`** E contains a textNode with a nodeValue that equals &quot;foo&quot;
  74. * - **`E:not(S)`** an E element that does not match simple selector S
  75. * - **`E:has(S)`** an E element that has a descendent that matches simple selector S
  76. * - **`E:next(S)`** an E element whose next sibling matches simple selector S
  77. * - **`E:prev(S)`** an E element whose previous sibling matches simple selector S
  78. * - **`E:any(S1|S2|S2)`** an E element which matches any of the simple selectors S1, S2 or S3
  79. *
  80. * ## CSS Value Selectors:
  81. *
  82. * - **`E{display=none}`** css value &quot;display&quot; that equals &quot;none&quot;
  83. * - **`E{display^=none}`** css value &quot;display&quot; that starts with &quot;none&quot;
  84. * - **`E{display$=none}`** css value &quot;display&quot; that ends with &quot;none&quot;
  85. * - **`E{display*=none}`** css value &quot;display&quot; that contains the substring &quot;none&quot;
  86. * - **`E{display%=2}`** css value &quot;display&quot; that is evenly divisible by 2
  87. * - **`E{display!=none}`** css value &quot;display&quot; that does not equal &quot;none&quot;
  88. *
  89. * [1]: http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors
  90. */
  91. Ext.ns('Ext.core');
  92. Ext.dom.Query = Ext.core.DomQuery = Ext.DomQuery = (function(){
  93. var cache = {},
  94. simpleCache = {},
  95. valueCache = {},
  96. nonSpace = /\S/,
  97. trimRe = /^\s+|\s+$/g,
  98. tplRe = /\{(\d+)\}/g,
  99. modeRe = /^(\s?[\/&gt;+~]\s?|\s|$)/,
  100. tagTokenRe = /^(#)?([\w\-\*\\]+)/,
  101. nthRe = /(\d*)n\+?(\d*)/,
  102. nthRe2 = /\D/,
  103. startIdRe = /^\s*\#/,
  104. // This is for IE MSXML which does not support expandos.
  105. // IE runs the same speed using setAttribute, however FF slows way down
  106. // and Safari completely fails so they need to continue to use expandos.
  107. isIE = window.ActiveXObject ? true : false,
  108. key = 30803,
  109. longHex = /\\([0-9a-fA-F]{6})/g,
  110. shortHex = /\\([0-9a-fA-F]{1,6})\s{0,1}/g,
  111. nonHex = /\\([^0-9a-fA-F]{1})/g,
  112. escapes = /\\/g,
  113. num, hasEscapes,
  114. // replaces a long hex regex match group with the appropriate ascii value
  115. // $args indicate regex match pos
  116. longHexToChar = function($0, $1) {
  117. return String.fromCharCode(parseInt($1, 16));
  118. },
  119. // converts a shortHex regex match to the long form
  120. shortToLongHex = function($0, $1) {
  121. while ($1.length &lt; 6) {
  122. $1 = '0' + $1;
  123. }
  124. return '\\' + $1;
  125. },
  126. // converts a single char escape to long escape form
  127. charToLongHex = function($0, $1) {
  128. num = $1.charCodeAt(0).toString(16);
  129. if (num.length === 1) {
  130. num = '0' + num;
  131. }
  132. return '\\0000' + num;
  133. },
  134. // Un-escapes an input selector string. Assumes all escape sequences have been
  135. // normalized to the css '\\0000##' 6-hex-digit style escape sequence :
  136. // will not handle any other escape formats
  137. unescapeCssSelector = function (selector) {
  138. return (hasEscapes)
  139. ? selector.replace(longHex, longHexToChar)
  140. : selector;
  141. },
  142. // checks if the path has escaping &amp; does any appropriate replacements
  143. setupEscapes = function(path){
  144. hasEscapes = (path.indexOf('\\') &gt; -1);
  145. if (hasEscapes) {
  146. path = path
  147. .replace(shortHex, shortToLongHex)
  148. .replace(nonHex, charToLongHex)
  149. .replace(escapes, '\\\\'); // double the '\' for js compilation
  150. }
  151. return path;
  152. };
  153. // this eval is stop the compressor from
  154. // renaming the variable to something shorter
  155. eval(&quot;var batch = 30803;&quot;);
  156. // Retrieve the child node from a particular
  157. // parent at the specified index.
  158. function child(parent, index){
  159. var i = 0,
  160. n = parent.firstChild;
  161. while(n){
  162. if(n.nodeType == 1){
  163. if(++i == index){
  164. return n;
  165. }
  166. }
  167. n = n.nextSibling;
  168. }
  169. return null;
  170. }
  171. // retrieve the next element node
  172. function next(n){
  173. while((n = n.nextSibling) &amp;&amp; n.nodeType != 1);
  174. return n;
  175. }
  176. // retrieve the previous element node
  177. function prev(n){
  178. while((n = n.previousSibling) &amp;&amp; n.nodeType != 1);
  179. return n;
  180. }
  181. // Mark each child node with a nodeIndex skipping and
  182. // removing empty text nodes.
  183. function children(parent){
  184. var n = parent.firstChild,
  185. nodeIndex = -1,
  186. nextNode;
  187. while(n){
  188. nextNode = n.nextSibling;
  189. // clean worthless empty nodes.
  190. if(n.nodeType == 3 &amp;&amp; !nonSpace.test(n.nodeValue)){
  191. parent.removeChild(n);
  192. }else{
  193. // add an expando nodeIndex
  194. n.nodeIndex = ++nodeIndex;
  195. }
  196. n = nextNode;
  197. }
  198. return this;
  199. }
  200. // nodeSet - array of nodes
  201. // cls - CSS Class
  202. function byClassName(nodeSet, cls){
  203. cls = unescapeCssSelector(cls);
  204. if(!cls){
  205. return nodeSet;
  206. }
  207. var result = [], ri = -1,
  208. i, ci;
  209. for(i = 0, ci; ci = nodeSet[i]; i++){
  210. if((' '+ci.className+' ').indexOf(cls) != -1){
  211. result[++ri] = ci;
  212. }
  213. }
  214. return result;
  215. }
  216. function attrValue(n, attr){
  217. // if its an array, use the first node.
  218. if(!n.tagName &amp;&amp; typeof n.length != &quot;undefined&quot;){
  219. n = n[0];
  220. }
  221. if(!n){
  222. return null;
  223. }
  224. if(attr == &quot;for&quot;){
  225. return n.htmlFor;
  226. }
  227. if(attr == &quot;class&quot; || attr == &quot;className&quot;){
  228. return n.className;
  229. }
  230. return n.getAttribute(attr) || n[attr];
  231. }
  232. // ns - nodes
  233. // mode - false, /, &gt;, +, ~
  234. // tagName - defaults to &quot;*&quot;
  235. function getNodes(ns, mode, tagName){
  236. var result = [], ri = -1, cs,
  237. i, ni, j, ci, cn, utag, n, cj;
  238. if(!ns){
  239. return result;
  240. }
  241. tagName = tagName || &quot;*&quot;;
  242. // convert to array
  243. if(typeof ns.getElementsByTagName != &quot;undefined&quot;){
  244. ns = [ns];
  245. }
  246. // no mode specified, grab all elements by tagName
  247. // at any depth
  248. if(!mode){
  249. for(i = 0, ni; ni = ns[i]; i++){
  250. cs = ni.getElementsByTagName(tagName);
  251. for(j = 0, ci; ci = cs[j]; j++){
  252. result[++ri] = ci;
  253. }
  254. }
  255. // Direct Child mode (/ or &gt;)
  256. // E &gt; F or E/F all direct children elements of E that have the tag
  257. } else if(mode == &quot;/&quot; || mode == &quot;&gt;&quot;){
  258. utag = tagName.toUpperCase();
  259. for(i = 0, ni, cn; ni = ns[i]; i++){
  260. cn = ni.childNodes;
  261. for(j = 0, cj; cj = cn[j]; j++){
  262. if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
  263. result[++ri] = cj;
  264. }
  265. }
  266. }
  267. // Immediately Preceding mode (+)
  268. // E + F all elements with the tag F that are immediately preceded by an element with the tag E
  269. }else if(mode == &quot;+&quot;){
  270. utag = tagName.toUpperCase();
  271. for(i = 0, n; n = ns[i]; i++){
  272. while((n = n.nextSibling) &amp;&amp; n.nodeType != 1);
  273. if(n &amp;&amp; (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
  274. result[++ri] = n;
  275. }
  276. }
  277. // Sibling mode (~)
  278. // E ~ F all elements with the tag F that are preceded by a sibling element with the tag E
  279. }else if(mode == &quot;~&quot;){
  280. utag = tagName.toUpperCase();
  281. for(i = 0, n; n = ns[i]; i++){
  282. while((n = n.nextSibling)){
  283. if (n.nodeName == utag || n.nodeName == tagName || tagName == '*'){
  284. result[++ri] = n;
  285. }
  286. }
  287. }
  288. }
  289. return result;
  290. }
  291. function concat(a, b){
  292. if(b.slice){
  293. return a.concat(b);
  294. }
  295. for(var i = 0, l = b.length; i &lt; l; i++){
  296. a[a.length] = b[i];
  297. }
  298. return a;
  299. }
  300. function byTag(cs, tagName){
  301. if(cs.tagName || cs == document){
  302. cs = [cs];
  303. }
  304. if(!tagName){
  305. return cs;
  306. }
  307. var result = [], ri = -1,
  308. i, ci;
  309. tagName = tagName.toLowerCase();
  310. for(i = 0, ci; ci = cs[i]; i++){
  311. if(ci.nodeType == 1 &amp;&amp; ci.tagName.toLowerCase() == tagName){
  312. result[++ri] = ci;
  313. }
  314. }
  315. return result;
  316. }
  317. function byId(cs, id){
  318. id = unescapeCssSelector(id);
  319. if(cs.tagName || cs == document){
  320. cs = [cs];
  321. }
  322. if(!id){
  323. return cs;
  324. }
  325. var result = [], ri = -1,
  326. i, ci;
  327. for(i = 0, ci; ci = cs[i]; i++){
  328. if(ci &amp;&amp; ci.id == id){
  329. result[++ri] = ci;
  330. return result;
  331. }
  332. }
  333. return result;
  334. }
  335. // operators are =, !=, ^=, $=, *=, %=, |= and ~=
  336. // custom can be &quot;{&quot;
  337. function byAttribute(cs, attr, value, op, custom){
  338. var result = [],
  339. ri = -1,
  340. useGetStyle = custom == &quot;{&quot;,
  341. fn = Ext.DomQuery.operators[op],
  342. a,
  343. xml,
  344. hasXml,
  345. i, ci;
  346. value = unescapeCssSelector(value);
  347. for(i = 0, ci; ci = cs[i]; i++){
  348. // skip non-element nodes.
  349. if(ci.nodeType != 1){
  350. continue;
  351. }
  352. // only need to do this for the first node
  353. if(!hasXml){
  354. xml = Ext.DomQuery.isXml(ci);
  355. hasXml = true;
  356. }
  357. // we only need to change the property names if we're dealing with html nodes, not XML
  358. if(!xml){
  359. if(useGetStyle){
  360. a = Ext.DomQuery.getStyle(ci, attr);
  361. } else if (attr == &quot;class&quot; || attr == &quot;className&quot;){
  362. a = ci.className;
  363. } else if (attr == &quot;for&quot;){
  364. a = ci.htmlFor;
  365. } else if (attr == &quot;href&quot;){
  366. // getAttribute href bug
  367. // http://www.glennjones.net/Post/809/getAttributehrefbug.htm
  368. a = ci.getAttribute(&quot;href&quot;, 2);
  369. } else{
  370. a = ci.getAttribute(attr);
  371. }
  372. }else{
  373. a = ci.getAttribute(attr);
  374. }
  375. if((fn &amp;&amp; fn(a, value)) || (!fn &amp;&amp; a)){
  376. result[++ri] = ci;
  377. }
  378. }
  379. return result;
  380. }
  381. function byPseudo(cs, name, value){
  382. value = unescapeCssSelector(value);
  383. return Ext.DomQuery.pseudos[name](cs, value);
  384. }
  385. function nodupIEXml(cs){
  386. var d = ++key,
  387. r,
  388. i, len, c;
  389. cs[0].setAttribute(&quot;_nodup&quot;, d);
  390. r = [cs[0]];
  391. for(i = 1, len = cs.length; i &lt; len; i++){
  392. c = cs[i];
  393. if(!c.getAttribute(&quot;_nodup&quot;) != d){
  394. c.setAttribute(&quot;_nodup&quot;, d);
  395. r[r.length] = c;
  396. }
  397. }
  398. for(i = 0, len = cs.length; i &lt; len; i++){
  399. cs[i].removeAttribute(&quot;_nodup&quot;);
  400. }
  401. return r;
  402. }
  403. function nodup(cs){
  404. if(!cs){
  405. return [];
  406. }
  407. var len = cs.length, c, i, r = cs, cj, ri = -1, d, j;
  408. if(!len || typeof cs.nodeType != &quot;undefined&quot; || len == 1){
  409. return cs;
  410. }
  411. if(isIE &amp;&amp; typeof cs[0].selectSingleNode != &quot;undefined&quot;){
  412. return nodupIEXml(cs);
  413. }
  414. d = ++key;
  415. cs[0]._nodup = d;
  416. for(i = 1; c = cs[i]; i++){
  417. if(c._nodup != d){
  418. c._nodup = d;
  419. }else{
  420. r = [];
  421. for(j = 0; j &lt; i; j++){
  422. r[++ri] = cs[j];
  423. }
  424. for(j = i+1; cj = cs[j]; j++){
  425. if(cj._nodup != d){
  426. cj._nodup = d;
  427. r[++ri] = cj;
  428. }
  429. }
  430. return r;
  431. }
  432. }
  433. return r;
  434. }
  435. function quickDiffIEXml(c1, c2){
  436. var d = ++key,
  437. r = [],
  438. i, len;
  439. for(i = 0, len = c1.length; i &lt; len; i++){
  440. c1[i].setAttribute(&quot;_qdiff&quot;, d);
  441. }
  442. for(i = 0, len = c2.length; i &lt; len; i++){
  443. if(c2[i].getAttribute(&quot;_qdiff&quot;) != d){
  444. r[r.length] = c2[i];
  445. }
  446. }
  447. for(i = 0, len = c1.length; i &lt; len; i++){
  448. c1[i].removeAttribute(&quot;_qdiff&quot;);
  449. }
  450. return r;
  451. }
  452. function quickDiff(c1, c2){
  453. var len1 = c1.length,
  454. d = ++key,
  455. r = [],
  456. i, len;
  457. if(!len1){
  458. return c2;
  459. }
  460. if(isIE &amp;&amp; typeof c1[0].selectSingleNode != &quot;undefined&quot;){
  461. return quickDiffIEXml(c1, c2);
  462. }
  463. for(i = 0; i &lt; len1; i++){
  464. c1[i]._qdiff = d;
  465. }
  466. for(i = 0, len = c2.length; i &lt; len; i++){
  467. if(c2[i]._qdiff != d){
  468. r[r.length] = c2[i];
  469. }
  470. }
  471. return r;
  472. }
  473. function quickId(ns, mode, root, id){
  474. if(ns == root){
  475. id = unescapeCssSelector(id);
  476. var d = root.ownerDocument || root;
  477. return d.getElementById(id);
  478. }
  479. ns = getNodes(ns, mode, &quot;*&quot;);
  480. return byId(ns, id);
  481. }
  482. return {
  483. getStyle : function(el, name){
  484. return Ext.fly(el).getStyle(name);
  485. },
  486. <span id='Ext-dom-Query-method-compile'> /**
  487. </span> * Compiles a selector/xpath query into a reusable function. The returned function
  488. * takes one parameter &quot;root&quot; (optional), which is the context node from where the query should start.
  489. * @param {String} selector The selector/xpath query
  490. * @param {String} [type=&quot;select&quot;] Either &quot;select&quot; or &quot;simple&quot; for a simple selector match
  491. * @return {Function}
  492. */
  493. compile : function(path, type){
  494. type = type || &quot;select&quot;;
  495. // setup fn preamble
  496. var fn = [&quot;var f = function(root){\n var mode; ++batch; var n = root || document;\n&quot;],
  497. mode,
  498. lastPath,
  499. matchers = Ext.DomQuery.matchers,
  500. matchersLn = matchers.length,
  501. modeMatch,
  502. // accept leading mode switch
  503. lmode = path.match(modeRe),
  504. tokenMatch, matched, j, t, m;
  505. path = setupEscapes(path);
  506. if(lmode &amp;&amp; lmode[1]){
  507. fn[fn.length] = 'mode=&quot;'+lmode[1].replace(trimRe, &quot;&quot;)+'&quot;;';
  508. path = path.replace(lmode[1], &quot;&quot;);
  509. }
  510. // strip leading slashes
  511. while(path.substr(0, 1)==&quot;/&quot;){
  512. path = path.substr(1);
  513. }
  514. while(path &amp;&amp; lastPath != path){
  515. lastPath = path;
  516. tokenMatch = path.match(tagTokenRe);
  517. if(type == &quot;select&quot;){
  518. if(tokenMatch){
  519. // ID Selector
  520. if(tokenMatch[1] == &quot;#&quot;){
  521. fn[fn.length] = 'n = quickId(n, mode, root, &quot;'+tokenMatch[2]+'&quot;);';
  522. }else{
  523. fn[fn.length] = 'n = getNodes(n, mode, &quot;'+tokenMatch[2]+'&quot;);';
  524. }
  525. path = path.replace(tokenMatch[0], &quot;&quot;);
  526. }else if(path.substr(0, 1) != '@'){
  527. fn[fn.length] = 'n = getNodes(n, mode, &quot;*&quot;);';
  528. }
  529. // type of &quot;simple&quot;
  530. }else{
  531. if(tokenMatch){
  532. if(tokenMatch[1] == &quot;#&quot;){
  533. fn[fn.length] = 'n = byId(n, &quot;'+tokenMatch[2]+'&quot;);';
  534. }else{
  535. fn[fn.length] = 'n = byTag(n, &quot;'+tokenMatch[2]+'&quot;);';
  536. }
  537. path = path.replace(tokenMatch[0], &quot;&quot;);
  538. }
  539. }
  540. while(!(modeMatch = path.match(modeRe))){
  541. matched = false;
  542. for(j = 0; j &lt; matchersLn; j++){
  543. t = matchers[j];
  544. m = path.match(t.re);
  545. if(m){
  546. fn[fn.length] = t.select.replace(tplRe, function(x, i){
  547. return m[i];
  548. });
  549. path = path.replace(m[0], &quot;&quot;);
  550. matched = true;
  551. break;
  552. }
  553. }
  554. // prevent infinite loop on bad selector
  555. if(!matched){
  556. Ext.Error.raise({
  557. sourceClass: 'Ext.DomQuery',
  558. sourceMethod: 'compile',
  559. msg: 'Error parsing selector. Parsing failed at &quot;' + path + '&quot;'
  560. });
  561. }
  562. }
  563. if(modeMatch[1]){
  564. fn[fn.length] = 'mode=&quot;'+modeMatch[1].replace(trimRe, &quot;&quot;)+'&quot;;';
  565. path = path.replace(modeMatch[1], &quot;&quot;);
  566. }
  567. }
  568. // close fn out
  569. fn[fn.length] = &quot;return nodup(n);\n}&quot;;
  570. // eval fn and return it
  571. eval(fn.join(&quot;&quot;));
  572. return f;
  573. },
  574. <span id='Ext-dom-Query-method-jsSelect'> /**
  575. </span> * Selects an array of DOM nodes using JavaScript-only implementation.
  576. *
  577. * Use {@link #select} to take advantage of browsers built-in support for CSS selectors.
  578. * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
  579. * @param {HTMLElement/String} [root=document] The start of the query.
  580. * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are
  581. * no matches, and empty Array is returned.
  582. */
  583. jsSelect: function(path, root, type){
  584. // set root to doc if not specified.
  585. root = root || document;
  586. if(typeof root == &quot;string&quot;){
  587. root = document.getElementById(root);
  588. }
  589. var paths = path.split(&quot;,&quot;),
  590. results = [],
  591. i, len, subPath, result;
  592. // loop over each selector
  593. for(i = 0, len = paths.length; i &lt; len; i++){
  594. subPath = paths[i].replace(trimRe, &quot;&quot;);
  595. // compile and place in cache
  596. if(!cache[subPath]){
  597. // When we compile, escaping is handled inside the compile method
  598. cache[subPath] = Ext.DomQuery.compile(subPath, type);
  599. if(!cache[subPath]){
  600. Ext.Error.raise({
  601. sourceClass: 'Ext.DomQuery',
  602. sourceMethod: 'jsSelect',
  603. msg: subPath + ' is not a valid selector'
  604. });
  605. }
  606. } else {
  607. // If we've already compiled, we still need to check if the
  608. // selector has escaping and setup the appropriate flags
  609. setupEscapes(subPath);
  610. }
  611. result = cache[subPath](root);
  612. if(result &amp;&amp; result != document){
  613. results = results.concat(result);
  614. }
  615. }
  616. // if there were multiple selectors, make sure dups
  617. // are eliminated
  618. if(paths.length &gt; 1){
  619. return nodup(results);
  620. }
  621. return results;
  622. },
  623. isXml: function(el) {
  624. var docEl = (el ? el.ownerDocument || el : 0).documentElement;
  625. return docEl ? docEl.nodeName !== &quot;HTML&quot; : false;
  626. },
  627. <span id='Ext-dom-Query-method-select'> /**
  628. </span> * Selects an array of DOM nodes by CSS/XPath selector.
  629. *
  630. * Uses [document.querySelectorAll][0] if browser supports that, otherwise falls back to
  631. * {@link Ext.dom.Query#jsSelect} to do the work.
  632. *
  633. * Aliased as {@link Ext#query}.
  634. *
  635. * [0]: https://developer.mozilla.org/en/DOM/document.querySelectorAll
  636. *
  637. * @param {String} path The selector/xpath query
  638. * @param {HTMLElement} [root=document] The start of the query.
  639. * @return {HTMLElement[]} An array of DOM elements (not a NodeList as returned by `querySelectorAll`).
  640. * @param {String} [type=&quot;select&quot;] Either &quot;select&quot; or &quot;simple&quot; for a simple selector match (only valid when
  641. * used when the call is deferred to the jsSelect method)
  642. * @method
  643. */
  644. select : document.querySelectorAll ? function(path, root, type) {
  645. root = root || document;
  646. if (!Ext.DomQuery.isXml(root)) {
  647. try {
  648. /*
  649. * This checking here is to &quot;fix&quot; the behaviour of querySelectorAll
  650. * for non root document queries. The way qsa works is intentional,
  651. * however it's definitely not the expected way it should work.
  652. * When descendant selectors are used, only the lowest selector must be inside the root!
  653. * More info: http://ejohn.org/blog/thoughts-on-queryselectorall/
  654. * So we create a descendant selector by prepending the root's ID, and query the parent node.
  655. * UNLESS the root has no parent in which qsa will work perfectly.
  656. *
  657. * We only modify the path for single selectors (ie, no multiples),
  658. * without a full parser it makes it difficult to do this correctly.
  659. */
  660. if (root.parentNode &amp;&amp; (root.nodeType !== 9) &amp;&amp; path.indexOf(',') === -1 &amp;&amp; !startIdRe.test(path)) {
  661. path = '#' + Ext.escapeId(Ext.id(root)) + ' ' + path;
  662. root = root.parentNode;
  663. }
  664. return Ext.Array.toArray(root.querySelectorAll(path));
  665. }
  666. catch (e) {
  667. }
  668. }
  669. return Ext.DomQuery.jsSelect.call(this, path, root, type);
  670. } : function(path, root, type) {
  671. return Ext.DomQuery.jsSelect.call(this, path, root, type);
  672. },
  673. <span id='Ext-dom-Query-method-selectNode'> /**
  674. </span> * Selects a single element.
  675. * @param {String} selector The selector/xpath query
  676. * @param {HTMLElement} [root=document] The start of the query.
  677. * @return {HTMLElement} The DOM element which matched the selector.
  678. */
  679. selectNode : function(path, root){
  680. return Ext.DomQuery.select(path, root)[0];
  681. },
  682. <span id='Ext-dom-Query-method-selectValue'> /**
  683. </span> * Selects the value of a node, optionally replacing null with the defaultValue.
  684. * @param {String} selector The selector/xpath query
  685. * @param {HTMLElement} [root=document] The start of the query.
  686. * @param {String} [defaultValue] When specified, this is return as empty value.
  687. * @return {String}
  688. */
  689. selectValue : function(path, root, defaultValue){
  690. path = path.replace(trimRe, &quot;&quot;);
  691. if (!valueCache[path]) {
  692. valueCache[path] = Ext.DomQuery.compile(path, &quot;select&quot;);
  693. } else {
  694. setupEscapes(path);
  695. }
  696. var n = valueCache[path](root),
  697. v;
  698. n = n[0] ? n[0] : n;
  699. // overcome a limitation of maximum textnode size
  700. // Rumored to potentially crash IE6 but has not been confirmed.
  701. // http://reference.sitepoint.com/javascript/Node/normalize
  702. // https://developer.mozilla.org/En/DOM/Node.normalize
  703. if (typeof n.normalize == 'function') {
  704. n.normalize();
  705. }
  706. v = (n &amp;&amp; n.firstChild ? n.firstChild.nodeValue : null);
  707. return ((v === null||v === undefined||v==='') ? defaultValue : v);
  708. },
  709. <span id='Ext-dom-Query-method-selectNumber'> /**
  710. </span> * Selects the value of a node, parsing integers and floats.
  711. * Returns the defaultValue, or 0 if none is specified.
  712. * @param {String} selector The selector/xpath query
  713. * @param {HTMLElement} [root=document] The start of the query.
  714. * @param {Number} [defaultValue] When specified, this is return as empty value.
  715. * @return {Number}
  716. */
  717. selectNumber : function(path, root, defaultValue){
  718. var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
  719. return parseFloat(v);
  720. },
  721. <span id='Ext-dom-Query-method-is'> /**
  722. </span> * Returns true if the passed element(s) match the passed simple selector
  723. * (e.g. `div.some-class` or `span:first-child`)
  724. * @param {String/HTMLElement/HTMLElement[]} el An element id, element or array of elements
  725. * @param {String} selector The simple selector to test
  726. * @return {Boolean}
  727. */
  728. is : function(el, ss){
  729. if(typeof el == &quot;string&quot;){
  730. el = document.getElementById(el);
  731. }
  732. var isArray = Ext.isArray(el),
  733. result = Ext.DomQuery.filter(isArray ? el : [el], ss);
  734. return isArray ? (result.length == el.length) : (result.length &gt; 0);
  735. },
  736. <span id='Ext-dom-Query-method-filter'> /**
  737. </span> * Filters an array of elements to only include matches of a simple selector
  738. * (e.g. `div.some-class` or `span:first-child`)
  739. * @param {HTMLElement[]} el An array of elements to filter
  740. * @param {String} selector The simple selector to test
  741. * @param {Boolean} nonMatches If true, it returns the elements that DON'T match the selector instead of the
  742. * ones that match
  743. * @return {HTMLElement[]} An Array of DOM elements which match the selector. If there are no matches, and empty
  744. * Array is returned.
  745. */
  746. filter : function(els, ss, nonMatches){
  747. ss = ss.replace(trimRe, &quot;&quot;);
  748. if (!simpleCache[ss]) {
  749. simpleCache[ss] = Ext.DomQuery.compile(ss, &quot;simple&quot;);
  750. } else {
  751. setupEscapes(ss);
  752. }
  753. var result = simpleCache[ss](els);
  754. return nonMatches ? quickDiff(result, els) : result;
  755. },
  756. <span id='Ext-dom-Query-property-matchers'> /**
  757. </span> * Collection of matching regular expressions and code snippets.
  758. * Each capture group within `()` will be replace the `{}` in the select
  759. * statement as specified by their index.
  760. */
  761. matchers : [{
  762. re: /^\.([\w\-\\]+)/,
  763. select: 'n = byClassName(n, &quot; {1} &quot;);'
  764. }, {
  765. re: /^\:([\w\-]+)(?:\(((?:[^\s&gt;\/]*|.*?))\))?/,
  766. select: 'n = byPseudo(n, &quot;{1}&quot;, &quot;{2}&quot;);'
  767. },{
  768. re: /^(?:([\[\{])(?:@)?([\w\-]+)\s?(?:(=|.=)\s?['&quot;]?(.*?)[&quot;']?)?[\]\}])/,
  769. select: 'n = byAttribute(n, &quot;{2}&quot;, &quot;{4}&quot;, &quot;{3}&quot;, &quot;{1}&quot;);'
  770. }, {
  771. re: /^#([\w\-\\]+)/,
  772. select: 'n = byId(n, &quot;{1}&quot;);'
  773. },{
  774. re: /^@([\w\-]+)/,
  775. select: 'return {firstChild:{nodeValue:attrValue(n, &quot;{1}&quot;)}};'
  776. }
  777. ],
  778. <span id='Ext-dom-Query-property-operators'> /**
  779. </span> * Collection of operator comparison functions.
  780. * The default operators are `=`, `!=`, `^=`, `$=`, `*=`, `%=`, `|=` and `~=`.
  781. * New operators can be added as long as the match the format *c*`=` where *c*
  782. * is any character other than space, `&gt;`, or `&lt;`.
  783. */
  784. operators : {
  785. &quot;=&quot; : function(a, v){
  786. return a == v;
  787. },
  788. &quot;!=&quot; : function(a, v){
  789. return a != v;
  790. },
  791. &quot;^=&quot; : function(a, v){
  792. return a &amp;&amp; a.substr(0, v.length) == v;
  793. },
  794. &quot;$=&quot; : function(a, v){
  795. return a &amp;&amp; a.substr(a.length-v.length) == v;
  796. },
  797. &quot;*=&quot; : function(a, v){
  798. return a &amp;&amp; a.indexOf(v) !== -1;
  799. },
  800. &quot;%=&quot; : function(a, v){
  801. return (a % v) == 0;
  802. },
  803. &quot;|=&quot; : function(a, v){
  804. return a &amp;&amp; (a == v || a.substr(0, v.length+1) == v+'-');
  805. },
  806. &quot;~=&quot; : function(a, v){
  807. return a &amp;&amp; (' '+a+' ').indexOf(' '+v+' ') != -1;
  808. }
  809. },
  810. <span id='Ext-dom-Query-property-pseudos'> /**
  811. </span> * Object hash of &quot;pseudo class&quot; filter functions which are used when filtering selections.
  812. * Each function is passed two parameters:
  813. *
  814. * - **c** : Array
  815. * An Array of DOM elements to filter.
  816. *
  817. * - **v** : String
  818. * The argument (if any) supplied in the selector.
  819. *
  820. * A filter function returns an Array of DOM elements which conform to the pseudo class.
  821. * In addition to the provided pseudo classes listed above such as `first-child` and `nth-child`,
  822. * developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.
  823. *
  824. * For example, to filter `a` elements to only return links to __external__ resources:
  825. *
  826. * Ext.DomQuery.pseudos.external = function(c, v){
  827. * var r = [], ri = -1;
  828. * for(var i = 0, ci; ci = c[i]; i++){
  829. * // Include in result set only if it's a link to an external resource
  830. * if(ci.hostname != location.hostname){
  831. * r[++ri] = ci;
  832. * }
  833. * }
  834. * return r;
  835. * };
  836. *
  837. * Then external links could be gathered with the following statement:
  838. *
  839. * var externalLinks = Ext.select(&quot;a:external&quot;);
  840. */
  841. pseudos : {
  842. &quot;first-child&quot; : function(c){
  843. var r = [], ri = -1, n,
  844. i, ci;
  845. for(i = 0; (ci = n = c[i]); i++){
  846. while((n = n.previousSibling) &amp;&amp; n.nodeType != 1);
  847. if(!n){
  848. r[++ri] = ci;
  849. }
  850. }
  851. return r;
  852. },
  853. &quot;last-child&quot; : function(c){
  854. var r = [], ri = -1, n,
  855. i, ci;
  856. for(i = 0; (ci = n = c[i]); i++){
  857. while((n = n.nextSibling) &amp;&amp; n.nodeType != 1);
  858. if(!n){
  859. r[++ri] = ci;
  860. }
  861. }
  862. return r;
  863. },
  864. &quot;nth-child&quot; : function(c, a) {
  865. var r = [], ri = -1,
  866. m = nthRe.exec(a == &quot;even&quot; &amp;&amp; &quot;2n&quot; || a == &quot;odd&quot; &amp;&amp; &quot;2n+1&quot; || !nthRe2.test(a) &amp;&amp; &quot;n+&quot; + a || a),
  867. f = (m[1] || 1) - 0, l = m[2] - 0,
  868. i, n, j, cn, pn;
  869. for(i = 0; n = c[i]; i++){
  870. pn = n.parentNode;
  871. if (batch != pn._batch) {
  872. j = 0;
  873. for(cn = pn.firstChild; cn; cn = cn.nextSibling){
  874. if(cn.nodeType == 1){
  875. cn.nodeIndex = ++j;
  876. }
  877. }
  878. pn._batch = batch;
  879. }
  880. if (f == 1) {
  881. if (l == 0 || n.nodeIndex == l){
  882. r[++ri] = n;
  883. }
  884. } else if ((n.nodeIndex + l) % f == 0){
  885. r[++ri] = n;
  886. }
  887. }
  888. return r;
  889. },
  890. &quot;only-child&quot; : function(c){
  891. var r = [], ri = -1,
  892. i, ci;
  893. for(i = 0; ci = c[i]; i++){
  894. if(!prev(ci) &amp;&amp; !next(ci)){
  895. r[++ri] = ci;
  896. }
  897. }
  898. return r;
  899. },
  900. &quot;empty&quot; : function(c){
  901. var r = [], ri = -1,
  902. i, ci, cns, j, cn, empty;
  903. for(i = 0, ci; ci = c[i]; i++){
  904. cns = ci.childNodes;
  905. j = 0;
  906. empty = true;
  907. while(cn = cns[j]){
  908. ++j;
  909. if(cn.nodeType == 1 || cn.nodeType == 3){
  910. empty = false;
  911. break;
  912. }
  913. }
  914. if(empty){
  915. r[++ri] = ci;
  916. }
  917. }
  918. return r;
  919. },
  920. &quot;contains&quot; : function(c, v){
  921. var r = [], ri = -1,
  922. i, ci;
  923. for(i = 0; ci = c[i]; i++){
  924. if((ci.textContent||ci.innerText||ci.text||'').indexOf(v) != -1){
  925. r[++ri] = ci;
  926. }
  927. }
  928. return r;
  929. },
  930. &quot;nodeValue&quot; : function(c, v){
  931. var r = [], ri = -1,
  932. i, ci;
  933. for(i = 0; ci = c[i]; i++){
  934. if(ci.firstChild &amp;&amp; ci.firstChild.nodeValue == v){
  935. r[++ri] = ci;
  936. }
  937. }
  938. return r;
  939. },
  940. &quot;checked&quot; : function(c){
  941. var r = [], ri = -1,
  942. i, ci;
  943. for(i = 0; ci = c[i]; i++){
  944. if(ci.checked == true){
  945. r[++ri] = ci;
  946. }
  947. }
  948. return r;
  949. },
  950. &quot;not&quot; : function(c, ss){
  951. return Ext.DomQuery.filter(c, ss, true);
  952. },
  953. &quot;any&quot; : function(c, selectors){
  954. var ss = selectors.split('|'),
  955. r = [], ri = -1, s,
  956. i, ci, j;
  957. for(i = 0; ci = c[i]; i++){
  958. for(j = 0; s = ss[j]; j++){
  959. if(Ext.DomQuery.is(ci, s)){
  960. r[++ri] = ci;
  961. break;
  962. }
  963. }
  964. }
  965. return r;
  966. },
  967. &quot;odd&quot; : function(c){
  968. return this[&quot;nth-child&quot;](c, &quot;odd&quot;);
  969. },
  970. &quot;even&quot; : function(c){
  971. return this[&quot;nth-child&quot;](c, &quot;even&quot;);
  972. },
  973. &quot;nth&quot; : function(c, a){
  974. return c[a-1] || [];
  975. },
  976. &quot;first&quot; : function(c){
  977. return c[0] || [];
  978. },
  979. &quot;last&quot; : function(c){
  980. return c[c.length-1] || [];
  981. },
  982. &quot;has&quot; : function(c, ss){
  983. var s = Ext.DomQuery.select,
  984. r = [], ri = -1,
  985. i, ci;
  986. for(i = 0; ci = c[i]; i++){
  987. if(s(ss, ci).length &gt; 0){
  988. r[++ri] = ci;
  989. }
  990. }
  991. return r;
  992. },
  993. &quot;next&quot; : function(c, ss){
  994. var is = Ext.DomQuery.is,
  995. r = [], ri = -1,
  996. i, ci, n;
  997. for(i = 0; ci = c[i]; i++){
  998. n = next(ci);
  999. if(n &amp;&amp; is(n, ss)){
  1000. r[++ri] = ci;
  1001. }
  1002. }
  1003. return r;
  1004. },
  1005. &quot;prev&quot; : function(c, ss){
  1006. var is = Ext.DomQuery.is,
  1007. r = [], ri = -1,
  1008. i, ci, n;
  1009. for(i = 0; ci = c[i]; i++){
  1010. n = prev(ci);
  1011. if(n &amp;&amp; is(n, ss)){
  1012. r[++ri] = ci;
  1013. }
  1014. }
  1015. return r;
  1016. }
  1017. }
  1018. };
  1019. }());
  1020. <span id='Ext-method-query'>/**
  1021. </span> * Shorthand of {@link Ext.dom.Query#select}
  1022. * @member Ext
  1023. * @method query
  1024. * @inheritdoc Ext.dom.Query#select
  1025. */
  1026. Ext.query = Ext.DomQuery.select;
  1027. </pre>
  1028. </body>
  1029. </html>