/** * @class Ext.DomQuery * Provides functionality to select elements on the page based on a CSS selector. *

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.

Element Selectors:

Attribute Selectors:

The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.

Pseudo Classes:

CSS Value Selectors:

* @singleton */ Ext.DomQuery = {
/** * 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. */ select : function(q, root) { var results = [], nodes, i, j, qlen, nlen; root = root || document; if (typeof root == 'string') { root = document.getElementById(root); } q = q.split(","); for (i = 0, qlen = q.length; i < qlen; i++) { if (typeof q[i] == 'string') { nodes = root.querySelectorAll(q[i]); for (j = 0, nlen = nodes.length; j < nlen; j++) { results.push(nodes[j]); } } } return results; },
/** * Selects a single element. * @param {String} selector The selector/xpath query * @param {Node} root (optional) The start of the query (defaults to document). * @return {HtmlElement} The DOM element which matched the selector. */ selectNode : function(q, root) { return Ext.DomQuery.select(q, root)[0]; },
/** * 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, q) { if (typeof el == "string") { el = document.getElementById(el); } return Ext.DomQuery.select(q).indexOf(el) !== -1; } }; Ext.Element.selectorFunction = Ext.DomQuery.select; Ext.query = Ext.DomQuery.select;