Diego Perini (diego.perini@gmail.com)
Samuel Lebeau (samuel.lebeau@gmail.com)
Diego Perini (diego.perini@gmail.com)
You can download this project in either zip or tar formats.
You can also clone the project with Git by running:
$ git clone git://github.com/dperini/nwmatcher
To include NWMatcher in a standard web page:
<script type="text/javascript" src="nwmatcher.js"></script>
To use it with Node.js:
$ npm install nwmatcher.js
NWMatcher currently supports browsers (as a global, NW.Dom
) and headless environments (as a CommonJS module).
Here is a list of all the CSS2/CSS3 Supported selectors.
You can read more about NWMatcher features and compliance on the wiki.
first( selector, context )
Returns a reference to the first element matching selector
, starting at context
.
match( element, selector, context )
Returns true
if element
matches selector
, starting at context
; returns false
otherwise.
select( selector, context, callback )
Returns an array of all the elements matching selector
, starting at context
. If callback
is provided, it is invoked for each matching element.
byId( id, from )
Returns a reference to the first element with ID id
, optionally filtered to descendants of the element from
.
byTag( tag, from )
Returns an array of elements having the specified tag name tag
, optionally filtered to descendants of the element from
.
byClass( class, from )
Returns an array of elements having the specified class name class
, optionally filtered to descendants of the element from
.
byName( name, from )
Returns an array of elements having the specified value name
for their name attribute, optionally filtered to descendants of the element from
.
getAttribute( element, attribute )
Return the value read from the attribute of element
with name attribute
, as a string.
hasAttribute( element, attribute )
Returns true element
has an attribute with name attribute
set; returns false
otherwise.
configure( options )
The following options exist and can be set to true
or false
:
CACHING
: enable caching of resultsSHORTCUTS
: allow accepting mangled selectorsSIMPLENOT
: disallow nested complex :not()
selectorsUNIQUE_ID
: disallow multiple elements with same IDUSE_QSAPI
: enable native querySelectorAll
if availableUSE_HTML5
: enable special HTML5 rules, related to the relationship between :checked
and :selected
VERBOSITY
: choose between throwing errors or just console warningsExample:
NW.Dom.configure( { USE_QSAPI: false, VERBOSITY: false } );
registerOperator( symbol, resolver )
Registers a new symbol and its matching resolver in the operators table. Example:
NW.Dom.registerOperator( '!=', 'n!="%m"' );
registerSelector( name, rexp, func )
Registers a new selector, with the matching regular expression and the appropriate resolver function, in the selectors table.