com.gwtext.client.core
Class DomQuery

java.lang.Object
  extended by com.gwtext.client.core.DomQuery

public class DomQuery
extends java.lang.Object

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).

DomQuery supports most of the CSS3 selectors spec, along with some custom selectors and basic XPath.

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.

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:




Nested Class Summary
static class DomQuery.SelectorType
           
 
Field Summary
static DomQuery.SelectorType SELECT
           
static DomQuery.SelectorType SIMPLE
           
 
Constructor Summary
DomQuery()
           
 
Method Summary
static DomQueryFunction compile(java.lang.String selector)
          Compiles a selector/xpath query into a reusable function.
static DomQueryFunction compile(java.lang.String selector, DomQuery.SelectorType type)
          Compiles a selector/xpath query into a reusable function.
static com.google.gwt.user.client.Element[] filter(com.google.gwt.user.client.Element[] els, java.lang.String selector, boolean nonMatches)
          Filters an array of elements to only include matches of a simple selector (e.g.
static boolean is(com.google.gwt.user.client.Element[] els, java.lang.String selector)
          Returns true if the passed elements match the passed simple selector (e.g.
static boolean is(com.google.gwt.user.client.Element el, java.lang.String selector)
          Returns true if the passed element match the passed simple selector (e.g.
static boolean is(java.lang.String id, java.lang.String selector)
          Returns true if the passed element match the passed simple selector (e.g.
static com.google.gwt.user.client.Element[] select(java.lang.String selector)
          Selects a group of elements.
static com.google.gwt.user.client.Element[] select(java.lang.String selector, com.google.gwt.user.client.Element root)
          Selects a group of elements.
static com.google.gwt.user.client.Element selectNode(java.lang.String selector)
          Selects a single element.
static com.google.gwt.user.client.Element selectNode(java.lang.String selector, com.google.gwt.user.client.Element root)
          Selects a single element.
static float selectNumber(java.lang.String selector)
          Selects the value of a node, parsing integers and floats.
static float selectNumber(java.lang.String selector, com.google.gwt.user.client.Element root)
          Selects the value of a node, parsing integers and floats.
static java.lang.String selectValue(java.lang.String selector)
          Selects the value of a node.
static java.lang.String selectValue(java.lang.String selector, com.google.gwt.user.client.Element root)
          Selects the value of a node
static java.lang.String selectValue(java.lang.String selector, com.google.gwt.user.client.Element root, java.lang.String defaultValue)
          Selects the value of a node, optionally replacing null with the defaultValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SELECT

public static DomQuery.SelectorType SELECT

SIMPLE

public static DomQuery.SelectorType SIMPLE
Constructor Detail

DomQuery

public DomQuery()
Method Detail

compile

public static DomQueryFunction compile(java.lang.String selector)
Compiles a selector/xpath query into a reusable function. The returned function takes one parameter "root" (optional), which is the context node from where the query should start.

Parameters:
selector - the selector/xpath query
Returns:
the reusable dom query function

compile

public static DomQueryFunction compile(java.lang.String selector,
                                       DomQuery.SelectorType type)
Compiles a selector/xpath query into a reusable function. The returned function takes one parameter "root" (optional), which is the context node from where the query should start.

Parameters:
selector - the selector/xpath query
type - either SELECT (the default) or SIMPLE for a simple selector match
Returns:
the reusable dom query function

filter

public static com.google.gwt.user.client.Element[] filter(com.google.gwt.user.client.Element[] els,
                                                          java.lang.String selector,
                                                          boolean nonMatches)
Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child).

Parameters:
els - an array of elements to filter
selector - the simple selector to test
nonMatches - if true, it returns the elements that DON'T match the selector instead of the ones that match
Returns:
filtered element array

is

public static boolean is(java.lang.String id,
                         java.lang.String selector)
Returns true if the passed element match the passed simple selector (e.g. div.some-class or span:first-child).

Parameters:
id - the element id
selector - the simple selector to test
Returns:
true if matched

is

public static boolean is(com.google.gwt.user.client.Element el,
                         java.lang.String selector)
Returns true if the passed element match the passed simple selector (e.g. div.some-class or span:first-child).

Parameters:
el - the element
selector - the simple selector to test
Returns:
true if matched

is

public static boolean is(com.google.gwt.user.client.Element[] els,
                         java.lang.String selector)
Returns true if the passed elements match the passed simple selector (e.g. div.some-class or span:first-child).

Parameters:
els - the element array
selector - the simple selector to test
Returns:
true if matched

select

public static com.google.gwt.user.client.Element[] select(java.lang.String selector)
Selects a group of elements.

Parameters:
selector - the selector/xpath query (can be a comma separated list of selectors)
Returns:
array of selected elements

select

public static com.google.gwt.user.client.Element[] select(java.lang.String selector,
                                                          com.google.gwt.user.client.Element root)
Selects a group of elements.

Parameters:
selector - the selector/xpath query (can be a comma separated list of selectors)
root - the start of the query (defaults to document)
Returns:
array of selected elements

selectNode

public static com.google.gwt.user.client.Element selectNode(java.lang.String selector)
Selects a single element.

Parameters:
selector - the selector/xpath query
Returns:
the selected element

selectNode

public static com.google.gwt.user.client.Element selectNode(java.lang.String selector,
                                                            com.google.gwt.user.client.Element root)
Selects a single element.

Parameters:
selector - the selector/xpath query
root - the start of the query (defaults to document).
Returns:
the selected element

selectNumber

public static float selectNumber(java.lang.String selector)
Selects the value of a node, parsing integers and floats.

Parameters:
selector - the selector/xpath query
Returns:
the node value

selectNumber

public static float selectNumber(java.lang.String selector,
                                 com.google.gwt.user.client.Element root)
Selects the value of a node, parsing integers and floats.

Parameters:
selector - the selector/xpath query
root - the start of the query (defaults to document)
Returns:
the node value

selectValue

public static java.lang.String selectValue(java.lang.String selector)
Selects the value of a node.

Parameters:
selector - the selector/xpath query
Returns:
the node value

selectValue

public static java.lang.String selectValue(java.lang.String selector,
                                           com.google.gwt.user.client.Element root)
Selects the value of a node

Parameters:
selector - the selector/xpath query
root - the start of the query (defaults to document)
Returns:
the node value

selectValue

public static java.lang.String selectValue(java.lang.String selector,
                                           com.google.gwt.user.client.Element root,
                                           java.lang.String defaultValue)
Selects the value of a node, optionally replacing null with the defaultValue

Parameters:
selector - the selector/xpath query
root - the start of the query (defaults to document)
defaultValue - value returned if null
Returns:
the node value