Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

942 lines
34 KiB

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