710 lines
No EOL
27 KiB
HTML
710 lines
No EOL
27 KiB
HTML
<html><head><title>DomQuery.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>DomQuery.js</h1><pre class="highlighted"><code><i>/*
|
|
* This is code is also distributed under MIT license <b>for</b> use
|
|
* <b>with</b> jQuery and prototype JavaScript libraries.
|
|
*/</i>
|
|
<i>// holder</i>
|
|
<i>/***
|
|
* @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 (<b>if</b> a content node is passed <b>in</b>).
|
|
* @singleton
|
|
*/</i>
|
|
Ext.DomQuery = <b>function</b>(){
|
|
<b>var</b> cache = {}, simpleCache = {}, valueCache = {};
|
|
<b>var</b> nonSpace = /\S/;
|
|
<b>var</b> trimRe = /^\s+|\s+$/g;
|
|
<b>var</b> tplRe = /\{(\d+)\}/g;
|
|
<b>var</b> modeRe = /^(\s?[\/>]\s?|\s|$)/;
|
|
<b>var</b> tagTokenRe = /^(#)?([\w-\*]+)/;
|
|
|
|
<b>function</b> child(p, index){
|
|
<b>var</b> i = 0;
|
|
<b>var</b> n = p.firstChild;
|
|
<b>while</b>(n){
|
|
<b>if</b>(n.nodeType == 1){
|
|
<b>if</b>(++i == index){
|
|
<b>return</b> n;
|
|
}
|
|
}
|
|
n = n.nextSibling;
|
|
}
|
|
<b>return</b> null;
|
|
};
|
|
|
|
<b>function</b> next(n){
|
|
<b>while</b>((n = n.nextSibling) && n.nodeType != 1);
|
|
<b>return</b> n;
|
|
};
|
|
|
|
<b>function</b> prev(n){
|
|
<b>while</b>((n = n.previousSibling) && n.nodeType != 1);
|
|
<b>return</b> n;
|
|
};
|
|
|
|
<b>function</b> clean(d){
|
|
<b>var</b> n = d.firstChild, ni = -1;
|
|
<b>while</b>(n){
|
|
<b>var</b> nx = n.nextSibling;
|
|
<b>if</b>(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
|
|
d.removeChild(n);
|
|
}<b>else</b>{
|
|
n.nodeIndex = ++ni;
|
|
}
|
|
n = nx;
|
|
}
|
|
<b>return</b> this;
|
|
};
|
|
|
|
<b>function</b> byClassName(c, a, v, re, cn){
|
|
<b>if</b>(!v){
|
|
<b>return</b> c;
|
|
}
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
cn = ci.className;
|
|
<b>if</b>(cn && (' '+cn+' ').indexOf(v) != -1){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
};
|
|
|
|
<b>function</b> attrValue(n, attr){
|
|
<b>if</b>(!n.tagName && <b>typeof</b> n.length != "undefined"){
|
|
n = n[0];
|
|
}
|
|
<b>if</b>(!n){
|
|
<b>return</b> null;
|
|
}
|
|
<b>if</b>(attr == "<b>for</b>"){
|
|
<b>return</b> n.htmlFor;
|
|
}
|
|
<b>if</b>(attr == "class" || attr == "className"){
|
|
<b>return</b> n.className;
|
|
}
|
|
<b>return</b> n.getAttribute(attr) || n[attr];
|
|
|
|
};
|
|
|
|
<b>function</b> getNodes(ns, mode, tagName){
|
|
<b>var</b> result = [], cs;
|
|
<b>if</b>(!ns){
|
|
<b>return</b> result;
|
|
}
|
|
mode = mode ? mode.replace(trimRe, "") : "";
|
|
tagName = tagName || "*";
|
|
<b>if</b>(typeof ns.getElementsByTagName != "undefined"){
|
|
ns = [ns];
|
|
}
|
|
<b>if</b>(mode != "/" && mode != ">"){
|
|
<b>for</b>(var i = 0, ni; ni = ns[i]; i++){
|
|
cs = ni.getElementsByTagName(tagName);
|
|
<b>for</b>(var j = 0, ci; ci = cs[j]; j++){
|
|
result[result.length] = ci;
|
|
}
|
|
}
|
|
}<b>else</b>{
|
|
<b>for</b>(var i = 0, ni; ni = ns[i]; i++){
|
|
<b>var</b> cn = ni.getElementsByTagName(tagName);
|
|
<b>for</b>(var j = 0, cj; cj = cn[j]; j++){
|
|
<b>if</b>(cj.parentNode == ni){
|
|
result[result.length] = cj;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
<b>return</b> result;
|
|
};
|
|
|
|
<b>function</b> concat(a, b){
|
|
<b>if</b>(b.slice){
|
|
<b>return</b> a.concat(b);
|
|
}
|
|
<b>for</b>(var i = 0, l = b.length; i < l; i++){
|
|
a[a.length] = b[i];
|
|
}
|
|
<b>return</b> a;
|
|
}
|
|
|
|
<b>function</b> byTag(cs, tagName){
|
|
<b>if</b>(cs.tagName || cs == document){
|
|
cs = [cs];
|
|
}
|
|
<b>if</b>(!tagName){
|
|
<b>return</b> cs;
|
|
}
|
|
<b>var</b> r = []; tagName = tagName.toLowerCase();
|
|
<b>for</b>(var i = 0, ci; ci = cs[i]; i++){
|
|
<b>if</b>(ci.nodeType == 1 && ci.tagName.toLowerCase()==tagName){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
};
|
|
|
|
<b>function</b> byId(cs, attr, id){
|
|
<b>if</b>(cs.tagName || cs == document){
|
|
cs = [cs];
|
|
}
|
|
<b>if</b>(!id){
|
|
<b>return</b> cs;
|
|
}
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0,ci; ci = cs[i]; i++){
|
|
<b>if</b>(ci && ci.id == id){
|
|
r[r.length] = ci;
|
|
<b>return</b> r;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
};
|
|
|
|
<b>function</b> byAttribute(cs, attr, value, op, custom){
|
|
<b>var</b> r = [], st = custom=="{";
|
|
<b>var</b> f = Ext.DomQuery.operators[op];
|
|
<b>for</b>(var i = 0; ci = cs[i]; i++){
|
|
<b>var</b> a;
|
|
<b>if</b>(st){
|
|
a = Ext.DomQuery.getStyle(ci, attr);
|
|
}
|
|
<b>else</b> if(attr == "class" || attr == "className"){
|
|
a = ci.className;
|
|
}<b>else</b> if(attr == "<b>for</b>"){
|
|
a = ci.htmlFor;
|
|
}<b>else</b> if(attr == "href"){
|
|
a = ci.getAttribute("href", 2);
|
|
}<b>else</b>{
|
|
a = ci.getAttribute(attr);
|
|
}
|
|
<b>if</b>((f && f(a, value)) || (!f && a)){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
};
|
|
|
|
<b>function</b> byPseudo(cs, name, value){
|
|
<b>return</b> Ext.DomQuery.pseudos[name](cs, value);
|
|
};
|
|
|
|
<i>// This is <b>for</b> IE MSXML which does not support expandos.</i>
|
|
<i>// IE runs the same speed using setAttribute, however FF slows way down</i>
|
|
<i>// and Safari completely fails so they need to <b>continue</b> to use expandos.</i>
|
|
<b>var</b> isIE = window.ActiveXObject ? true : false;
|
|
|
|
<b>var</b> key = 30803;
|
|
|
|
<b>function</b> nodupIEXml(cs){
|
|
<b>var</b> d = ++key;
|
|
cs[0].setAttribute("_nodup", d);
|
|
<b>var</b> r = [cs[0]];
|
|
<b>for</b>(var i = 1, len = cs.length; i < len; i++){
|
|
<b>var</b> c = cs[i];
|
|
<b>if</b>(!c.getAttribute("_nodup") != d){
|
|
c.setAttribute("_nodup", d);
|
|
r[r.length] = c;
|
|
}
|
|
}
|
|
<b>for</b>(var i = 0, len = cs.length; i < len; i++){
|
|
cs[i].removeAttribute("_nodup");
|
|
}
|
|
<b>return</b> r;
|
|
}
|
|
|
|
<b>function</b> nodup(cs){
|
|
<b>if</b>(!cs){
|
|
<b>return</b> [];
|
|
}
|
|
<b>var</b> len = cs.length, c, i, r = cs, cj;
|
|
<b>if</b>(!len || <b>typeof</b> cs.nodeType != "undefined" || len == 1){
|
|
<b>return</b> cs;
|
|
}
|
|
<b>if</b>(isIE && <b>typeof</b> cs[0].selectSingleNode != "undefined"){
|
|
<b>return</b> nodupIEXml(cs);
|
|
}
|
|
<b>var</b> d = ++key;
|
|
cs[0]._nodup = d;
|
|
<b>for</b>(i = 1; c = cs[i]; i++){
|
|
<b>if</b>(c._nodup != d){
|
|
c._nodup = d;
|
|
}<b>else</b>{
|
|
r = [];
|
|
<b>for</b>(var j = 0; j < i; j++){
|
|
r[r.length] = cs[j];
|
|
}
|
|
<b>for</b>(j = i+1; cj = cs[j]; j++){
|
|
<b>if</b>(cj._nodup != d){
|
|
cj._nodup = d;
|
|
r[r.length] = cj;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
}
|
|
|
|
<b>function</b> quickDiffIEXml(c1, c2){
|
|
<b>var</b> d = ++key;
|
|
<b>for</b>(var i = 0, len = c1.length; i < len; i++){
|
|
c1[i].setAttribute("_qdiff", d);
|
|
}
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, len = c2.length; i < len; i++){
|
|
<b>if</b>(c2[i].getAttribute("_qdiff") != d){
|
|
r[r.length] = c2[i];
|
|
}
|
|
}
|
|
<b>for</b>(var i = 0, len = c1.length; i < len; i++){
|
|
c1[i].removeAttribute("_qdiff");
|
|
}
|
|
<b>return</b> r;
|
|
}
|
|
|
|
<b>function</b> quickDiff(c1, c2){
|
|
<b>var</b> len1 = c1.length;
|
|
<b>if</b>(!len1){
|
|
<b>return</b> c2;
|
|
}
|
|
<b>if</b>(isIE && c1[0].selectSingleNode){
|
|
<b>return</b> quickDiffIEXml(c1, c2);
|
|
}
|
|
<b>var</b> d = ++key;
|
|
<b>for</b>(var i = 0; i < len1; i++){
|
|
c1[i]._qdiff = d;
|
|
}
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, len = c2.length; i < len; i++){
|
|
<b>if</b>(c2[i]._qdiff != d){
|
|
r[r.length] = c2[i];
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
}
|
|
|
|
<b>function</b> quickId(ns, mode, root, id){
|
|
<b>if</b>(ns == root){
|
|
<b>var</b> d = root.ownerDocument || root;
|
|
<b>return</b> d.getElementById(id);
|
|
}
|
|
ns = getNodes(ns, mode, "*");
|
|
<b>return</b> byId(ns, null, id);
|
|
}
|
|
|
|
<b>return</b> {
|
|
getStyle : <b>function</b>(el, name){
|
|
<b>return</b> Ext.fly(el).getStyle(name);
|
|
},
|
|
<i>/**
|
|
* Compiles a selector/xpath query into a reusable <b>function</b>. The returned <b>function</b>
|
|
* takes one parameter "root" (optional), which is the context node from where the query should start.
|
|
* @param {String} selector The selector/xpath query
|
|
* @param {String} type (optional) Either "select" (the <b>default</b>) or "simple" <b>for</b> a simple selector match
|
|
* @<b>return</b> {Function}
|
|
*/</i>
|
|
compile : <b>function</b>(path, type){
|
|
<i>// strip leading slashes</i>
|
|
<b>while</b>(path.substr(0, 1)=="/"){
|
|
path = path.substr(1);
|
|
}
|
|
type = type || "select";
|
|
|
|
<b>var</b> fn = ["<b>var</b> f = <b>function</b>(root){\n <b>var</b> mode; <b>var</b> n = root || document;\n"];
|
|
<b>var</b> q = path, mode, lq;
|
|
<b>var</b> tk = Ext.DomQuery.matchers;
|
|
<b>var</b> tklen = tk.length;
|
|
<b>var</b> mm;
|
|
<b>while</b>(q && lq != q){
|
|
lq = q;
|
|
<b>var</b> tm = q.match(tagTokenRe);
|
|
<b>if</b>(type == "select"){
|
|
<b>if</b>(tm){
|
|
<b>if</b>(tm[1] == "#"){
|
|
fn[fn.length] = 'n = quickId(n, mode, root, "'+tm[2]+'");';
|
|
}<b>else</b>{
|
|
fn[fn.length] = 'n = getNodes(n, mode, "'+tm[2]+'");';
|
|
}
|
|
q = q.replace(tm[0], "");
|
|
}<b>else</b> if(q.substr(0, 1) != '@'){
|
|
fn[fn.length] = 'n = getNodes(n, mode, "*");';
|
|
}
|
|
}<b>else</b>{
|
|
<b>if</b>(tm){
|
|
<b>if</b>(tm[1] == "#"){
|
|
fn[fn.length] = 'n = byId(n, null, "'+tm[2]+'");';
|
|
}<b>else</b>{
|
|
fn[fn.length] = 'n = byTag(n, "'+tm[2]+'");';
|
|
}
|
|
q = q.replace(tm[0], "");
|
|
}
|
|
}
|
|
<b>while</b>(!(mm = q.match(modeRe))){
|
|
<b>var</b> matched = false;
|
|
<b>for</b>(var j = 0; j < tklen; j++){
|
|
<b>var</b> t = tk[j];
|
|
<b>var</b> m = q.match(t.re);
|
|
<b>if</b>(m){
|
|
fn[fn.length] = t.select.replace(tplRe, <b>function</b>(x, i){
|
|
<b>return</b> m[i];
|
|
});
|
|
q = q.replace(m[0], "");
|
|
matched = true;
|
|
<b>break</b>;
|
|
}
|
|
}
|
|
<i>// prevent infinite loop on bad selector</i>
|
|
<b>if</b>(!matched){
|
|
throw 'Error parsing selector, parsing failed at "' + q + '"';
|
|
}
|
|
}
|
|
<b>if</b>(mm[1]){
|
|
fn[fn.length] = 'mode="'+mm[1]+'";';
|
|
q = q.replace(mm[1], "");
|
|
}
|
|
}
|
|
fn[fn.length] = "<b>return</b> nodup(n);\n}";
|
|
eval(fn.join(""));
|
|
<b>return</b> f;
|
|
},
|
|
|
|
<i>/**
|
|
* Selects a group of elements.
|
|
* @param {String} selector The selector/xpath query
|
|
* @param {Node} root (optional) The start of the query (defaults to document).
|
|
* @<b>return</b> {Array}
|
|
*/</i>
|
|
select : <b>function</b>(path, root, type){
|
|
<b>if</b>(!root || root == document){
|
|
root = document;
|
|
}
|
|
<b>if</b>(typeof root == "string"){
|
|
root = document.getElementById(root);
|
|
}
|
|
<b>var</b> paths = path.split(",");
|
|
<b>var</b> results = [];
|
|
<b>for</b>(var i = 0, len = paths.length; i < len; i++){
|
|
<b>var</b> p = paths[i].replace(trimRe, "");
|
|
<b>if</b>(!cache[p]){
|
|
cache[p] = Ext.DomQuery.compile(p);
|
|
<b>if</b>(!cache[p]){
|
|
throw p + " is not a valid selector";
|
|
}
|
|
}
|
|
<b>var</b> result = cache[p](root);
|
|
<b>if</b>(result && result != document){
|
|
results = results.concat(result);
|
|
}
|
|
}
|
|
<b>return</b> results;
|
|
},
|
|
|
|
<i>/**
|
|
* Selects a single element.
|
|
* @param {String} selector The selector/xpath query
|
|
* @param {Node} root (optional) The start of the query (defaults to document).
|
|
* @<b>return</b> {Element}
|
|
*/</i>
|
|
selectNode : <b>function</b>(path, root){
|
|
<b>return</b> Ext.DomQuery.select(path, root)[0];
|
|
},
|
|
|
|
<i>/**
|
|
* Selects the value of a node, optionally replacing null <b>with</b> the defaultValue.
|
|
* @param {String} selector The selector/xpath query
|
|
* @param {Node} root (optional) The start of the query (defaults to document).
|
|
* @param {String} defaultValue
|
|
*/</i>
|
|
selectValue : <b>function</b>(path, root, defaultValue){
|
|
path = path.replace(trimRe, "");
|
|
<b>if</b>(!valueCache[path]){
|
|
valueCache[path] = Ext.DomQuery.compile(path, "select");
|
|
}
|
|
<b>var</b> n = valueCache[path](root);
|
|
n = n[0] ? n[0] : n;
|
|
<b>var</b> v = (n && n.firstChild ? n.firstChild.nodeValue : null);
|
|
<b>return</b> (v === null ? defaultValue : v);
|
|
},
|
|
|
|
<i>/**
|
|
* Selects the value of a node, parsing integers and floats.
|
|
* @param {String} selector The selector/xpath query
|
|
* @param {Node} root (optional) The start of the query (defaults to document).
|
|
* @param {Number} defaultValue
|
|
* @<b>return</b> {Number}
|
|
*/</i>
|
|
selectNumber : <b>function</b>(path, root, defaultValue){
|
|
<b>var</b> v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
|
|
<b>return</b> parseFloat(v);
|
|
},
|
|
|
|
<i>/**
|
|
* Returns true <b>if</b> 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
|
|
* @<b>return</b> {Boolean}
|
|
*/</i>
|
|
is : <b>function</b>(el, ss){
|
|
<b>if</b>(typeof el == "string"){
|
|
el = document.getElementById(el);
|
|
}
|
|
<b>var</b> isArray = (el instanceof Array);
|
|
<b>var</b> result = Ext.DomQuery.filter(isArray ? el : [el], ss);
|
|
<b>return</b> isArray ? (result.length == el.length) : (result.length > 0);
|
|
},
|
|
|
|
<i>/**
|
|
* 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
|
|
* @<b>return</b> {Array}
|
|
*/</i>
|
|
filter : <b>function</b>(els, ss, nonMatches){
|
|
ss = ss.replace(trimRe, "");
|
|
<b>if</b>(!simpleCache[ss]){
|
|
simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");
|
|
}
|
|
<b>var</b> result = simpleCache[ss](els);
|
|
<b>return</b> nonMatches ? quickDiff(result, els) : result;
|
|
},
|
|
|
|
<i>/**
|
|
* Collection of matching regular expressions and code snippets.
|
|
*/</i>
|
|
matchers : [{
|
|
re: /^\.([\w-]+)/,
|
|
select: 'n = byClassName(n, null, " {1} ");'
|
|
}, {
|
|
re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
|
|
select: 'n = byPseudo(n, "{1}", "{2}");'
|
|
},{
|
|
re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
|
|
select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
|
|
}, {
|
|
re: /^#([\w-]+)/,
|
|
select: 'n = byId(n, null, "{1}");'
|
|
},{
|
|
re: /^@([\w-]+)/,
|
|
select: '<b>return</b> {firstChild:{nodeValue:attrValue(n, "{1}")}};'
|
|
}
|
|
],
|
|
|
|
<i>/**
|
|
* Collection of operator comparison functions. The <b>default</b> operators are =, !=, ^=, $=, *= and %=.
|
|
* 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;.
|
|
*/</i>
|
|
operators : {
|
|
"=" : <b>function</b>(a, v){
|
|
<b>return</b> a == v;
|
|
},
|
|
"!=" : <b>function</b>(a, v){
|
|
<b>return</b> a != v;
|
|
},
|
|
"^=" : <b>function</b>(a, v){
|
|
<b>return</b> a && a.substr(0, v.length) == v;
|
|
},
|
|
"$=" : <b>function</b>(a, v){
|
|
<b>return</b> a && a.substr(a.length-v.length) == v;
|
|
},
|
|
"*=" : <b>function</b>(a, v){
|
|
<b>return</b> a && a.indexOf(v) !== -1;
|
|
},
|
|
"%=" : <b>function</b>(a, v){
|
|
<b>return</b> (a % v) == 0;
|
|
}
|
|
},
|
|
|
|
<i>/**
|
|
* Collection of "pseudo class" processors. Each processor is passed the current nodeset (array)
|
|
* and the argument (<b>if</b> any) supplied <b>in</b> the selector.
|
|
*/</i>
|
|
pseudos : {
|
|
"first-child" : <b>function</b>(c){
|
|
<b>var</b> r = [], n;
|
|
<b>for</b>(var i = 0, ci; ci = n = c[i]; i++){
|
|
<b>while</b>((n = n.previousSibling) && n.nodeType != 1);
|
|
<b>if</b>(!n){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
},
|
|
|
|
"last-child" : <b>function</b>(c){
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, ci; ci = n = c[i]; i++){
|
|
<b>while</b>((n = n.nextSibling) && n.nodeType != 1);
|
|
<b>if</b>(!n){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
},
|
|
|
|
"nth-child" : <b>function</b>(c, a){
|
|
<b>var</b> r = [];
|
|
<b>if</b>(a != "odd" && a != "even"){
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
<b>var</b> m = child(ci.parentNode, a);
|
|
<b>if</b>(m == ci){
|
|
r[r.length] = m;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
}
|
|
<b>var</b> p;
|
|
<i>// first let's clean up the parent nodes</i>
|
|
<b>for</b>(var i = 0, l = c.length; i < l; i++){
|
|
<b>var</b> cp = c[i].parentNode;
|
|
<b>if</b>(cp != p){
|
|
clean(cp);
|
|
p = cp;
|
|
}
|
|
}
|
|
<i>// then lets see <b>if</b> we match</i>
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
<b>var</b> m = false;
|
|
<b>if</b>(a == "odd"){
|
|
m = ((ci.nodeIndex+1) % 2 == 1);
|
|
}<b>else</b> if(a == "even"){
|
|
m = ((ci.nodeIndex+1) % 2 == 0);
|
|
}
|
|
<b>if</b>(m){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
},
|
|
|
|
"only-child" : <b>function</b>(c){
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
<b>if</b>(!prev(ci) && !next(ci)){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
},
|
|
|
|
"empty" : <b>function</b>(c){
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
<b>var</b> cns = ci.childNodes, j = 0, cn, empty = true;
|
|
<b>while</b>(cn = cns[j]){
|
|
++j;
|
|
<b>if</b>(cn.nodeType == 1 || cn.nodeType == 3){
|
|
empty = false;
|
|
<b>break</b>;
|
|
}
|
|
}
|
|
<b>if</b>(empty){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
},
|
|
|
|
"contains" : <b>function</b>(c, v){
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
<b>if</b>(ci.innerHTML.indexOf(v) !== -1){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
},
|
|
|
|
"nodeValue" : <b>function</b>(c, v){
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
<b>if</b>(ci.firstChild && ci.firstChild.nodeValue == v){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
},
|
|
|
|
"checked" : <b>function</b>(c){
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
<b>if</b>(ci.checked == true){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
},
|
|
|
|
"not" : <b>function</b>(c, ss){
|
|
<b>return</b> Ext.DomQuery.filter(c, ss, true);
|
|
},
|
|
|
|
"odd" : <b>function</b>(c){
|
|
<b>return</b> this["nth-child"](c, "odd");
|
|
},
|
|
|
|
"even" : <b>function</b>(c){
|
|
<b>return</b> this["nth-child"](c, "even");
|
|
},
|
|
|
|
"nth" : <b>function</b>(c, a){
|
|
<b>return</b> c[a-1] || [];
|
|
},
|
|
|
|
"first" : <b>function</b>(c){
|
|
<b>return</b> c[0] || [];
|
|
},
|
|
|
|
"last" : <b>function</b>(c){
|
|
<b>return</b> c[c.length-1] || [];
|
|
},
|
|
|
|
"has" : <b>function</b>(c, ss){
|
|
<b>var</b> s = Ext.DomQuery.select;
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
<b>if</b>(s(ss, ci).length > 0){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
},
|
|
|
|
"next" : <b>function</b>(c, ss){
|
|
<b>var</b> is = Ext.DomQuery.is;
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
<b>var</b> n = next(ci);
|
|
<b>if</b>(n && is(n, ss)){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
},
|
|
|
|
"prev" : <b>function</b>(c, ss){
|
|
<b>var</b> is = Ext.DomQuery.is;
|
|
<b>var</b> r = [];
|
|
<b>for</b>(var i = 0, ci; ci = c[i]; i++){
|
|
<b>var</b> n = prev(ci);
|
|
<b>if</b>(n && is(n, ss)){
|
|
r[r.length] = ci;
|
|
}
|
|
}
|
|
<b>return</b> r;
|
|
}
|
|
}
|
|
};
|
|
}();
|
|
|
|
<i>/**
|
|
* 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).
|
|
* @<b>return</b> {Array}
|
|
* @member Ext
|
|
* @method query
|
|
*/</i>
|
|
Ext.query = Ext.DomQuery.select;
|
|
</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright © 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
|
|
</body></html> |