tvheadend/vendor/ext-3.4.1/docs/source/DomQuery.html
Adam Sutton bafcfff42d webui: restructure webui/extjs source files
I want to keep the 3rd-party packages away from the main source
where possible.
2013-06-03 17:11:01 +01:00

946 lines
37 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js">/*
* This is code is also distributed under MIT license for use
* with jQuery and prototype JavaScript libraries.
*/
<span id='Ext-DomQuery'>/**
</span> * @class Ext.DomQuery
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).
&lt;p&gt;
DomQuery supports most of the &lt;a href=&quot;http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors&quot;&gt;CSS3 selectors spec&lt;/a&gt;, along with some custom selectors and basic XPath.&lt;/p&gt;
&lt;p&gt;
All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example &quot;div.foo:nth-child(odd)[@foo=bar].bar:first&quot; 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.
&lt;/p&gt;
&lt;h4&gt;Element Selectors:&lt;/h4&gt;
&lt;ul class=&quot;list&quot;&gt;
&lt;li&gt; &lt;b&gt;*&lt;/b&gt; any element&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E&lt;/b&gt; an element with the tag E&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E F&lt;/b&gt; All descendent elements of E that have the tag F&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E &gt; F&lt;/b&gt; or &lt;b&gt;E/F&lt;/b&gt; all direct children elements of E that have the tag F&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E + F&lt;/b&gt; all elements with the tag F that are immediately preceded by an element with the tag E&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E ~ F&lt;/b&gt; all elements with the tag F that are preceded by a sibling element with the tag E&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Attribute Selectors:&lt;/h4&gt;
&lt;p&gt;The use of &amp;#64; and quotes are optional. For example, div[&amp;#64;foo='bar'] is also a valid attribute selector.&lt;/p&gt;
&lt;ul class=&quot;list&quot;&gt;
&lt;li&gt; &lt;b&gt;E[foo]&lt;/b&gt; has an attribute &quot;foo&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E[foo=bar]&lt;/b&gt; has an attribute &quot;foo&quot; that equals &quot;bar&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E[foo^=bar]&lt;/b&gt; has an attribute &quot;foo&quot; that starts with &quot;bar&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E[foo$=bar]&lt;/b&gt; has an attribute &quot;foo&quot; that ends with &quot;bar&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E[foo*=bar]&lt;/b&gt; has an attribute &quot;foo&quot; that contains the substring &quot;bar&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E[foo%=2]&lt;/b&gt; has an attribute &quot;foo&quot; that is evenly divisible by 2&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E[foo!=bar]&lt;/b&gt; attribute &quot;foo&quot; does not equal &quot;bar&quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;Pseudo Classes:&lt;/h4&gt;
&lt;ul class=&quot;list&quot;&gt;
&lt;li&gt; &lt;b&gt;E:first-child&lt;/b&gt; E is the first child of its parent&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:last-child&lt;/b&gt; E is the last child of its parent&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:nth-child(&lt;i&gt;n&lt;/i&gt;)&lt;/b&gt; E is the &lt;i&gt;n&lt;/i&gt;th child of its parent (1 based as per the spec)&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:nth-child(odd)&lt;/b&gt; E is an odd child of its parent&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:nth-child(even)&lt;/b&gt; E is an even child of its parent&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:only-child&lt;/b&gt; E is the only child of its parent&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:checked&lt;/b&gt; E is an element that is has a checked attribute that is true (e.g. a radio or checkbox) &lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:first&lt;/b&gt; the first E in the resultset&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:last&lt;/b&gt; the last E in the resultset&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:nth(&lt;i&gt;n&lt;/i&gt;)&lt;/b&gt; the &lt;i&gt;n&lt;/i&gt;th E in the resultset (1 based)&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:odd&lt;/b&gt; shortcut for :nth-child(odd)&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:even&lt;/b&gt; shortcut for :nth-child(even)&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:contains(foo)&lt;/b&gt; E's innerHTML contains the substring &quot;foo&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:nodeValue(foo)&lt;/b&gt; E contains a textNode with a nodeValue that equals &quot;foo&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:not(S)&lt;/b&gt; an E element that does not match simple selector S&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:has(S)&lt;/b&gt; an E element that has a descendent that matches simple selector S&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:next(S)&lt;/b&gt; an E element whose next sibling matches simple selector S&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:prev(S)&lt;/b&gt; an E element whose previous sibling matches simple selector S&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E:any(S1|S2|S2)&lt;/b&gt; an E element which matches any of the simple selectors S1, S2 or S3//\\&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;CSS Value Selectors:&lt;/h4&gt;
&lt;ul class=&quot;list&quot;&gt;
&lt;li&gt; &lt;b&gt;E{display=none}&lt;/b&gt; css value &quot;display&quot; that equals &quot;none&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E{display^=none}&lt;/b&gt; css value &quot;display&quot; that starts with &quot;none&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E{display$=none}&lt;/b&gt; css value &quot;display&quot; that ends with &quot;none&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E{display*=none}&lt;/b&gt; css value &quot;display&quot; that contains the substring &quot;none&quot;&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E{display%=2}&lt;/b&gt; css value &quot;display&quot; that is evenly divisible by 2&lt;/li&gt;
&lt;li&gt; &lt;b&gt;E{display!=none}&lt;/b&gt; css value &quot;display&quot; that does not equal &quot;none&quot;&lt;/li&gt;
&lt;/ul&gt;
* @singleton
*/
Ext.DomQuery = function(){
var cache = {},
simpleCache = {},
valueCache = {},
nonSpace = /\S/,
trimRe = /^\s+|\s+$/g,
tplRe = /\{(\d+)\}/g,
modeRe = /^(\s?[\/&gt;+~]\s?|\s|$)/,
tagTokenRe = /^(#)?([\w\-\*]+)/,
nthRe = /(\d*)n\+?(\d*)/,
nthRe2 = /\D/,
// This is for IE MSXML which does not support expandos.
// IE runs the same speed using setAttribute, however FF slows way down
// and Safari completely fails so they need to continue to use expandos.
isIE = window.ActiveXObject ? true : false,
key = 30803;
// this eval is stop the compressor from
// renaming the variable to something shorter
eval(&quot;var batch = 30803;&quot;);
// Retrieve the child node from a particular
// parent at the specified index.
function child(parent, index){
var i = 0,
n = parent.firstChild;
while(n){
if(n.nodeType == 1){
if(++i == index){
return n;
}
}
n = n.nextSibling;
}
return null;
}
// retrieve the next element node
function next(n){
while((n = n.nextSibling) &amp;&amp; n.nodeType != 1);
return n;
}
// retrieve the previous element node
function prev(n){
while((n = n.previousSibling) &amp;&amp; n.nodeType != 1);
return n;
}
// Mark each child node with a nodeIndex skipping and
// removing empty text nodes.
function children(parent){
var n = parent.firstChild,
nodeIndex = -1,
nextNode;
while(n){
nextNode = n.nextSibling;
// clean worthless empty nodes.
if(n.nodeType == 3 &amp;&amp; !nonSpace.test(n.nodeValue)){
parent.removeChild(n);
}else{
// add an expando nodeIndex
n.nodeIndex = ++nodeIndex;
}
n = nextNode;
}
return this;
}
// nodeSet - array of nodes
// cls - CSS Class
function byClassName(nodeSet, cls){
if(!cls){
return nodeSet;
}
var result = [], ri = -1;
for(var i = 0, ci; ci = nodeSet[i]; i++){
if((' '+ci.className+' ').indexOf(cls) != -1){
result[++ri] = ci;
}
}
return result;
};
function attrValue(n, attr){
// if its an array, use the first node.
if(!n.tagName &amp;&amp; typeof n.length != &quot;undefined&quot;){
n = n[0];
}
if(!n){
return null;
}
if(attr == &quot;for&quot;){
return n.htmlFor;
}
if(attr == &quot;class&quot; || attr == &quot;className&quot;){
return n.className;
}
return n.getAttribute(attr) || n[attr];
};
// ns - nodes
// mode - false, /, &gt;, +, ~
// tagName - defaults to &quot;*&quot;
function getNodes(ns, mode, tagName){
var result = [], ri = -1, cs;
if(!ns){
return result;
}
tagName = tagName || &quot;*&quot;;
// convert to array
if(typeof ns.getElementsByTagName != &quot;undefined&quot;){
ns = [ns];
}
// no mode specified, grab all elements by tagName
// at any depth
if(!mode){
for(var i = 0, ni; ni = ns[i]; i++){
cs = ni.getElementsByTagName(tagName);
for(var j = 0, ci; ci = cs[j]; j++){
result[++ri] = ci;
}
}
// Direct Child mode (/ or &gt;)
// E &gt; F or E/F all direct children elements of E that have the tag
} else if(mode == &quot;/&quot; || mode == &quot;&gt;&quot;){
var utag = tagName.toUpperCase();
for(var i = 0, ni, cn; ni = ns[i]; i++){
cn = ni.childNodes;
for(var j = 0, cj; cj = cn[j]; j++){
if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
result[++ri] = cj;
}
}
}
// Immediately Preceding mode (+)
// E + F all elements with the tag F that are immediately preceded by an element with the tag E
}else if(mode == &quot;+&quot;){
var utag = tagName.toUpperCase();
for(var i = 0, n; n = ns[i]; i++){
while((n = n.nextSibling) &amp;&amp; n.nodeType != 1);
if(n &amp;&amp; (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
result[++ri] = n;
}
}
// Sibling mode (~)
// E ~ F all elements with the tag F that are preceded by a sibling element with the tag E
}else if(mode == &quot;~&quot;){
var utag = tagName.toUpperCase();
for(var i = 0, n; n = ns[i]; i++){
while((n = n.nextSibling)){
if (n.nodeName == utag || n.nodeName == tagName || tagName == '*'){
result[++ri] = n;
}
}
}
}
return result;
}
function concat(a, b){
if(b.slice){
return a.concat(b);
}
for(var i = 0, l = b.length; i &lt; l; i++){
a[a.length] = b[i];
}
return a;
}
function byTag(cs, tagName){
if(cs.tagName || cs == document){
cs = [cs];
}
if(!tagName){
return cs;
}
var result = [], ri = -1;
tagName = tagName.toLowerCase();
for(var i = 0, ci; ci = cs[i]; i++){
if(ci.nodeType == 1 &amp;&amp; ci.tagName.toLowerCase() == tagName){
result[++ri] = ci;
}
}
return result;
}
function byId(cs, id){
if(cs.tagName || cs == document){
cs = [cs];
}
if(!id){
return cs;
}
var result = [], ri = -1;
for(var i = 0, ci; ci = cs[i]; i++){
if(ci &amp;&amp; ci.id == id){
result[++ri] = ci;
return result;
}
}
return result;
}
// operators are =, !=, ^=, $=, *=, %=, |= and ~=
// custom can be &quot;{&quot;
function byAttribute(cs, attr, value, op, custom){
var result = [],
ri = -1,
useGetStyle = custom == &quot;{&quot;,
fn = Ext.DomQuery.operators[op],
a,
xml,
hasXml;
for(var i = 0, ci; ci = cs[i]; i++){
// skip non-element nodes.
if(ci.nodeType != 1){
continue;
}
// only need to do this for the first node
if(!hasXml){
xml = Ext.DomQuery.isXml(ci);
hasXml = true;
}
// we only need to change the property names if we're dealing with html nodes, not XML
if(!xml){
if(useGetStyle){
a = Ext.DomQuery.getStyle(ci, attr);
} else if (attr == &quot;class&quot; || attr == &quot;className&quot;){
a = ci.className;
} else if (attr == &quot;for&quot;){
a = ci.htmlFor;
} else if (attr == &quot;href&quot;){
// getAttribute href bug
// http://www.glennjones.net/Post/809/getAttributehrefbug.htm
a = ci.getAttribute(&quot;href&quot;, 2);
} else{
a = ci.getAttribute(attr);
}
}else{
a = ci.getAttribute(attr);
}
if((fn &amp;&amp; fn(a, value)) || (!fn &amp;&amp; a)){
result[++ri] = ci;
}
}
return result;
}
function byPseudo(cs, name, value){
return Ext.DomQuery.pseudos[name](cs, value);
}
function nodupIEXml(cs){
var d = ++key,
r;
cs[0].setAttribute(&quot;_nodup&quot;, d);
r = [cs[0]];
for(var i = 1, len = cs.length; i &lt; len; i++){
var c = cs[i];
if(!c.getAttribute(&quot;_nodup&quot;) != d){
c.setAttribute(&quot;_nodup&quot;, d);
r[r.length] = c;
}
}
for(var i = 0, len = cs.length; i &lt; len; i++){
cs[i].removeAttribute(&quot;_nodup&quot;);
}
return r;
}
function nodup(cs){
if(!cs){
return [];
}
var len = cs.length, c, i, r = cs, cj, ri = -1;
if(!len || typeof cs.nodeType != &quot;undefined&quot; || len == 1){
return cs;
}
if(isIE &amp;&amp; typeof cs[0].selectSingleNode != &quot;undefined&quot;){
return nodupIEXml(cs);
}
var d = ++key;
cs[0]._nodup = d;
for(i = 1; c = cs[i]; i++){
if(c._nodup != d){
c._nodup = d;
}else{
r = [];
for(var j = 0; j &lt; i; j++){
r[++ri] = cs[j];
}
for(j = i+1; cj = cs[j]; j++){
if(cj._nodup != d){
cj._nodup = d;
r[++ri] = cj;
}
}
return r;
}
}
return r;
}
function quickDiffIEXml(c1, c2){
var d = ++key,
r = [];
for(var i = 0, len = c1.length; i &lt; len; i++){
c1[i].setAttribute(&quot;_qdiff&quot;, d);
}
for(var i = 0, len = c2.length; i &lt; len; i++){
if(c2[i].getAttribute(&quot;_qdiff&quot;) != d){
r[r.length] = c2[i];
}
}
for(var i = 0, len = c1.length; i &lt; len; i++){
c1[i].removeAttribute(&quot;_qdiff&quot;);
}
return r;
}
function quickDiff(c1, c2){
var len1 = c1.length,
d = ++key,
r = [];
if(!len1){
return c2;
}
if(isIE &amp;&amp; typeof c1[0].selectSingleNode != &quot;undefined&quot;){
return quickDiffIEXml(c1, c2);
}
for(var i = 0; i &lt; len1; i++){
c1[i]._qdiff = d;
}
for(var i = 0, len = c2.length; i &lt; len; i++){
if(c2[i]._qdiff != d){
r[r.length] = c2[i];
}
}
return r;
}
function quickId(ns, mode, root, id){
if(ns == root){
var d = root.ownerDocument || root;
return d.getElementById(id);
}
ns = getNodes(ns, mode, &quot;*&quot;);
return byId(ns, id);
}
return {
getStyle : function(el, name){
return Ext.fly(el).getStyle(name);
},
<span id='Ext-DomQuery-method-compile'> /**
</span> * Compiles a selector/xpath query into a reusable function. The returned function
* takes one parameter &quot;root&quot; (optional), which is the context node from where the query should start.
* @param {String} selector The selector/xpath query
* @param {String} type (optional) Either &quot;select&quot; (the default) or &quot;simple&quot; for a simple selector match
* @return {Function}
*/
compile : function(path, type){
type = type || &quot;select&quot;;
// setup fn preamble
var fn = [&quot;var f = function(root){\n var mode; ++batch; var n = root || document;\n&quot;],
mode,
lastPath,
matchers = Ext.DomQuery.matchers,
matchersLn = matchers.length,
modeMatch,
// accept leading mode switch
lmode = path.match(modeRe);
if(lmode &amp;&amp; lmode[1]){
fn[fn.length] = 'mode=&quot;'+lmode[1].replace(trimRe, &quot;&quot;)+'&quot;;';
path = path.replace(lmode[1], &quot;&quot;);
}
// strip leading slashes
while(path.substr(0, 1)==&quot;/&quot;){
path = path.substr(1);
}
while(path &amp;&amp; lastPath != path){
lastPath = path;
var tokenMatch = path.match(tagTokenRe);
if(type == &quot;select&quot;){
if(tokenMatch){
// ID Selector
if(tokenMatch[1] == &quot;#&quot;){
fn[fn.length] = 'n = quickId(n, mode, root, &quot;'+tokenMatch[2]+'&quot;);';
}else{
fn[fn.length] = 'n = getNodes(n, mode, &quot;'+tokenMatch[2]+'&quot;);';
}
path = path.replace(tokenMatch[0], &quot;&quot;);
}else if(path.substr(0, 1) != '@'){
fn[fn.length] = 'n = getNodes(n, mode, &quot;*&quot;);';
}
// type of &quot;simple&quot;
}else{
if(tokenMatch){
if(tokenMatch[1] == &quot;#&quot;){
fn[fn.length] = 'n = byId(n, &quot;'+tokenMatch[2]+'&quot;);';
}else{
fn[fn.length] = 'n = byTag(n, &quot;'+tokenMatch[2]+'&quot;);';
}
path = path.replace(tokenMatch[0], &quot;&quot;);
}
}
while(!(modeMatch = path.match(modeRe))){
var matched = false;
for(var j = 0; j &lt; matchersLn; j++){
var t = matchers[j];
var m = path.match(t.re);
if(m){
fn[fn.length] = t.select.replace(tplRe, function(x, i){
return m[i];
});
path = path.replace(m[0], &quot;&quot;);
matched = true;
break;
}
}
// prevent infinite loop on bad selector
if(!matched){
throw 'Error parsing selector, parsing failed at &quot;' + path + '&quot;';
}
}
if(modeMatch[1]){
fn[fn.length] = 'mode=&quot;'+modeMatch[1].replace(trimRe, &quot;&quot;)+'&quot;;';
path = path.replace(modeMatch[1], &quot;&quot;);
}
}
// close fn out
fn[fn.length] = &quot;return nodup(n);\n}&quot;;
// eval fn and return it
eval(fn.join(&quot;&quot;));
return f;
},
<span id='Ext-DomQuery-method-jsSelect'> /**
</span> * Selects a group of elements.
* @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
* @param {Node/String} root (optional) The start of the query (defaults to document).
* @return {Array} An Array of DOM elements which match the selector. If there are
* no matches, and empty Array is returned.
*/
jsSelect: function(path, root, type){
// set root to doc if not specified.
root = root || document;
if(typeof root == &quot;string&quot;){
root = document.getElementById(root);
}
var paths = path.split(&quot;,&quot;),
results = [];
// loop over each selector
for(var i = 0, len = paths.length; i &lt; len; i++){
var subPath = paths[i].replace(trimRe, &quot;&quot;);
// compile and place in cache
if(!cache[subPath]){
cache[subPath] = Ext.DomQuery.compile(subPath);
if(!cache[subPath]){
throw subPath + &quot; is not a valid selector&quot;;
}
}
var result = cache[subPath](root);
if(result &amp;&amp; result != document){
results = results.concat(result);
}
}
// if there were multiple selectors, make sure dups
// are eliminated
if(paths.length &gt; 1){
return nodup(results);
}
return results;
},
isXml: function(el) {
var docEl = (el ? el.ownerDocument || el : 0).documentElement;
return docEl ? docEl.nodeName !== &quot;HTML&quot; : false;
},
select : document.querySelectorAll ? function(path, root, type) {
root = root || document;
if (!Ext.DomQuery.isXml(root)) {
try {
var cs = root.querySelectorAll(path);
return Ext.toArray(cs);
}
catch (ex) {}
}
return Ext.DomQuery.jsSelect.call(this, path, root, type);
} : function(path, root, type) {
return Ext.DomQuery.jsSelect.call(this, path, root, type);
},
<span id='Ext-DomQuery-method-selectNode'> /**
</span> * Selects a single element.
* @param {String} selector The selector/xpath query
* @param {Node} root (optional) The start of the query (defaults to document).
* @return {Element} The DOM element which matched the selector.
*/
selectNode : function(path, root){
return Ext.DomQuery.select(path, root)[0];
},
<span id='Ext-DomQuery-method-selectValue'> /**
</span> * Selects the value of a node, optionally replacing null with the defaultValue.
* @param {String} selector The selector/xpath query
* @param {Node} root (optional) The start of the query (defaults to document).
* @param {String} defaultValue (optional)
* @return {String}
*/
selectValue : function(path, root, defaultValue){
path = path.replace(trimRe, &quot;&quot;);
if(!valueCache[path]){
valueCache[path] = Ext.DomQuery.compile(path, &quot;select&quot;);
}
var n = valueCache[path](root), v;
n = n[0] ? n[0] : n;
// overcome a limitation of maximum textnode size
// Rumored to potentially crash IE6 but has not been confirmed.
// http://reference.sitepoint.com/javascript/Node/normalize
// https://developer.mozilla.org/En/DOM/Node.normalize
if (typeof n.normalize == 'function') n.normalize();
v = (n &amp;&amp; n.firstChild ? n.firstChild.nodeValue : null);
return ((v === null||v === undefined||v==='') ? defaultValue : v);
},
<span id='Ext-DomQuery-method-selectNumber'> /**
</span> * Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.
* @param {String} selector The selector/xpath query
* @param {Node} root (optional) The start of the query (defaults to document).
* @param {Number} defaultValue (optional)
* @return {Number}
*/
selectNumber : function(path, root, defaultValue){
var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
return parseFloat(v);
},
<span id='Ext-DomQuery-method-is'> /**
</span> * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
* @param {String/HTMLElement/Array} el An element id, element or array of elements
* @param {String} selector The simple selector to test
* @return {Boolean}
*/
is : function(el, ss){
if(typeof el == &quot;string&quot;){
el = document.getElementById(el);
}
var isArray = Ext.isArray(el),
result = Ext.DomQuery.filter(isArray ? el : [el], ss);
return isArray ? (result.length == el.length) : (result.length &gt; 0);
},
<span id='Ext-DomQuery-method-filter'> /**
</span> * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
* @param {Array} el An array of elements to filter
* @param {String} selector The simple selector to test
* @param {Boolean} nonMatches If true, it returns the elements that DON'T match
* the selector instead of the ones that match
* @return {Array} An Array of DOM elements which match the selector. If there are
* no matches, and empty Array is returned.
*/
filter : function(els, ss, nonMatches){
ss = ss.replace(trimRe, &quot;&quot;);
if(!simpleCache[ss]){
simpleCache[ss] = Ext.DomQuery.compile(ss, &quot;simple&quot;);
}
var result = simpleCache[ss](els);
return nonMatches ? quickDiff(result, els) : result;
},
<span id='Ext-DomQuery-property-matchers'> /**
</span> * Collection of matching regular expressions and code snippets.
* Each capture group within () will be replace the {} in the select
* statement as specified by their index.
*/
matchers : [{
re: /^\.([\w\-]+)/,
select: 'n = byClassName(n, &quot; {1} &quot;);'
}, {
re: /^\:([\w\-]+)(?:\(((?:[^\s&gt;\/]*|.*?))\))?/,
select: 'n = byPseudo(n, &quot;{1}&quot;, &quot;{2}&quot;);'
},{
re: /^(?:([\[\{])(?:@)?([\w\-]+)\s?(?:(=|.=)\s?([&quot;']?)(.*?)\4)?[\]\}])/,
select: 'n = byAttribute(n, &quot;{2}&quot;, &quot;{5}&quot;, &quot;{3}&quot;, &quot;{1}&quot;);'
}, {
re: /^#([\w\-]+)/,
select: 'n = byId(n, &quot;{1}&quot;);'
},{
re: /^@([\w\-]+)/,
select: 'return {firstChild:{nodeValue:attrValue(n, &quot;{1}&quot;)}};'
}
],
<span id='Ext-DomQuery-property-operators'> /**
</span> * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
* New operators can be added as long as the match the format &lt;i&gt;c&lt;/i&gt;= where &lt;i&gt;c&lt;/i&gt; is any character other than space, &amp;gt; &amp;lt;.
*/
operators : {
&quot;=&quot; : function(a, v){
return a == v;
},
&quot;!=&quot; : function(a, v){
return a != v;
},
&quot;^=&quot; : function(a, v){
return a &amp;&amp; a.substr(0, v.length) == v;
},
&quot;$=&quot; : function(a, v){
return a &amp;&amp; a.substr(a.length-v.length) == v;
},
&quot;*=&quot; : function(a, v){
return a &amp;&amp; a.indexOf(v) !== -1;
},
&quot;%=&quot; : function(a, v){
return (a % v) == 0;
},
&quot;|=&quot; : function(a, v){
return a &amp;&amp; (a == v || a.substr(0, v.length+1) == v+'-');
},
&quot;~=&quot; : function(a, v){
return a &amp;&amp; (' '+a+' ').indexOf(' '+v+' ') != -1;
}
},
<span id='Ext-DomQuery-property-pseudos'> /**
</span> * &lt;p&gt;Object hash of &quot;pseudo class&quot; filter functions which are used when filtering selections. Each function is passed
* two parameters:&lt;/p&gt;&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
* &lt;li&gt;&lt;b&gt;c&lt;/b&gt; : Array&lt;div class=&quot;sub-desc&quot;&gt;An Array of DOM elements to filter.&lt;/div&gt;&lt;/li&gt;
* &lt;li&gt;&lt;b&gt;v&lt;/b&gt; : String&lt;div class=&quot;sub-desc&quot;&gt;The argument (if any) supplied in the selector.&lt;/div&gt;&lt;/li&gt;
* &lt;/ul&gt;&lt;/div&gt;
* &lt;p&gt;A filter function returns an Array of DOM elements which conform to the pseudo class.&lt;/p&gt;
* &lt;p&gt;In addition to the provided pseudo classes listed above such as &lt;code&gt;first-child&lt;/code&gt; and &lt;code&gt;nth-child&lt;/code&gt;,
* developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.&lt;/p&gt;
* &lt;p&gt;For example, to filter &lt;code&gt;&amp;lt;a&gt;&lt;/code&gt; elements to only return links to &lt;i&gt;external&lt;/i&gt; resources:&lt;/p&gt;
* &lt;code&gt;&lt;pre&gt;
Ext.DomQuery.pseudos.external = function(c, v){
var r = [], ri = -1;
for(var i = 0, ci; ci = c[i]; i++){
// Include in result set only if it's a link to an external resource
if(ci.hostname != location.hostname){
r[++ri] = ci;
}
}
return r;
};&lt;/pre&gt;&lt;/code&gt;
* Then external links could be gathered with the following statement:&lt;code&gt;&lt;pre&gt;
var externalLinks = Ext.select(&quot;a:external&quot;);
&lt;/code&gt;&lt;/pre&gt;
*/
pseudos : {
&quot;first-child&quot; : function(c){
var r = [], ri = -1, n;
for(var i = 0, ci; ci = n = c[i]; i++){
while((n = n.previousSibling) &amp;&amp; n.nodeType != 1);
if(!n){
r[++ri] = ci;
}
}
return r;
},
&quot;last-child&quot; : function(c){
var r = [], ri = -1, n;
for(var i = 0, ci; ci = n = c[i]; i++){
while((n = n.nextSibling) &amp;&amp; n.nodeType != 1);
if(!n){
r[++ri] = ci;
}
}
return r;
},
&quot;nth-child&quot; : function(c, a) {
var r = [], ri = -1,
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),
f = (m[1] || 1) - 0, l = m[2] - 0;
for(var i = 0, n; n = c[i]; i++){
var pn = n.parentNode;
if (batch != pn._batch) {
var j = 0;
for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
if(cn.nodeType == 1){
cn.nodeIndex = ++j;
}
}
pn._batch = batch;
}
if (f == 1) {
if (l == 0 || n.nodeIndex == l){
r[++ri] = n;
}
} else if ((n.nodeIndex + l) % f == 0){
r[++ri] = n;
}
}
return r;
},
&quot;only-child&quot; : function(c){
var r = [], ri = -1;;
for(var i = 0, ci; ci = c[i]; i++){
if(!prev(ci) &amp;&amp; !next(ci)){
r[++ri] = ci;
}
}
return r;
},
&quot;empty&quot; : function(c){
var r = [], ri = -1;
for(var i = 0, ci; ci = c[i]; i++){
var cns = ci.childNodes, j = 0, cn, empty = true;
while(cn = cns[j]){
++j;
if(cn.nodeType == 1 || cn.nodeType == 3){
empty = false;
break;
}
}
if(empty){
r[++ri] = ci;
}
}
return r;
},
&quot;contains&quot; : function(c, v){
var r = [], ri = -1;
for(var i = 0, ci; ci = c[i]; i++){
if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
r[++ri] = ci;
}
}
return r;
},
&quot;nodeValue&quot; : function(c, v){
var r = [], ri = -1;
for(var i = 0, ci; ci = c[i]; i++){
if(ci.firstChild &amp;&amp; ci.firstChild.nodeValue == v){
r[++ri] = ci;
}
}
return r;
},
&quot;checked&quot; : function(c){
var r = [], ri = -1;
for(var i = 0, ci; ci = c[i]; i++){
if(ci.checked == true){
r[++ri] = ci;
}
}
return r;
},
&quot;not&quot; : function(c, ss){
return Ext.DomQuery.filter(c, ss, true);
},
&quot;any&quot; : function(c, selectors){
var ss = selectors.split('|'),
r = [], ri = -1, s;
for(var i = 0, ci; ci = c[i]; i++){
for(var j = 0; s = ss[j]; j++){
if(Ext.DomQuery.is(ci, s)){
r[++ri] = ci;
break;
}
}
}
return r;
},
&quot;odd&quot; : function(c){
return this[&quot;nth-child&quot;](c, &quot;odd&quot;);
},
&quot;even&quot; : function(c){
return this[&quot;nth-child&quot;](c, &quot;even&quot;);
},
&quot;nth&quot; : function(c, a){
return c[a-1] || [];
},
&quot;first&quot; : function(c){
return c[0] || [];
},
&quot;last&quot; : function(c){
return c[c.length-1] || [];
},
&quot;has&quot; : function(c, ss){
var s = Ext.DomQuery.select,
r = [], ri = -1;
for(var i = 0, ci; ci = c[i]; i++){
if(s(ss, ci).length &gt; 0){
r[++ri] = ci;
}
}
return r;
},
&quot;next&quot; : function(c, ss){
var is = Ext.DomQuery.is,
r = [], ri = -1;
for(var i = 0, ci; ci = c[i]; i++){
var n = next(ci);
if(n &amp;&amp; is(n, ss)){
r[++ri] = ci;
}
}
return r;
},
&quot;prev&quot; : function(c, ss){
var is = Ext.DomQuery.is,
r = [], ri = -1;
for(var i = 0, ci; ci = c[i]; i++){
var n = prev(ci);
if(n &amp;&amp; is(n, ss)){
r[++ri] = ci;
}
}
return r;
}
}
};
}();
<span id='Ext-method-query'>/**
</span> * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Ext.DomQuery#select}
* @param {String} path The selector/xpath query
* @param {Node} root (optional) The start of the query (defaults to document).
* @return {Array}
* @member Ext
* @method query
*/
Ext.query = Ext.DomQuery.select;
</pre>
</body>
</html>