Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # [NWMatcher](http://dperini.github.io/nwmatcher/)
  2. A fast CSS selector engine and matcher.
  3. ## Installation
  4. To include NWMatcher in a standard web page:
  5. ```html
  6. <script type="text/javascript" src="nwmatcher.js"></script>
  7. ```
  8. To use it with Node.js:
  9. ```
  10. $ npm install nwmatcher
  11. ```
  12. NWMatcher currently supports browsers (as a global, `NW.Dom`) and headless environments (as a CommonJS module).
  13. ## Supported Selectors
  14. Here is a list of all the CSS2/CSS3 [Supported selectors](https://github.com/dperini/nwmatcher/wiki/CSS-supported-selectors).
  15. ## Features and Compliance
  16. You can read more about NWMatcher [features and compliance](https://github.com/dperini/nwmatcher/wiki/Features-and-compliance) on the wiki.
  17. ## API
  18. ### DOM Selection
  19. #### `first( selector, context )`
  20. Returns a reference to the first element matching `selector`, starting at `context`.
  21. #### `match( element, selector, context )`
  22. Returns `true` if `element` matches `selector`, starting at `context`; returns `false` otherwise.
  23. #### `select( selector, context, callback )`
  24. Returns an array of all the elements matching `selector`, starting at `context`. If `callback` is provided, it is invoked for each matching element.
  25. ### DOM Helpers
  26. #### `byId( id, from )`
  27. Returns a reference to the first element with ID `id`, optionally filtered to descendants of the element `from`.
  28. #### `byTag( tag, from )`
  29. Returns an array of elements having the specified tag name `tag`, optionally filtered to descendants of the element `from`.
  30. #### `byClass( class, from )`
  31. Returns an array of elements having the specified class name `class`, optionally filtered to descendants of the element `from`.
  32. #### `byName( name, from )`
  33. Returns an array of elements having the specified value `name` for their name attribute, optionally filtered to descendants of the element `from`.
  34. #### `getAttribute( element, attribute )`
  35. Return the value read from the attribute of `element` with name `attribute`, as a string.
  36. #### `hasAttribute( element, attribute )`
  37. Returns true `element` has an attribute with name `attribute` set; returns `false` otherwise.
  38. ### Engine Configuration
  39. #### `configure( options )`
  40. The following is the list of currently available configuration options, their default values and descriptions, they are boolean flags that can be set to `true` or `false`:
  41. * `CACHING`: false - false to disable caching of result sets, true to enable
  42. * `ESCAPECHR`: true - true to allow CSS escaped identifiers, false to disallow
  43. * `NON_ASCII`: true - true to allow identifiers containing non-ASCII (utf-8) chars
  44. * `SELECTOR3`: true - switch syntax RE, true to use Level 3, false to use Level 2
  45. * `UNICODE16`: true - true to allow identifiers containing Unicode (utf-16) chars
  46. * `SHORTCUTS`: false - false to disable mangled selector strings like "+div" or "ul>"
  47. * `SIMPLENOT`: true - true to disallow complex selectors nested in ':not()' classes
  48. * `SVG_LCASE`: false - false to disable matching lowercase tag names of SVG elements
  49. * `UNIQUE_ID`: true - true to disallow multiple elements with the same id (strict)
  50. * `USE_HTML5`: true - true to use HTML5 specs for ":checked" and similar UI states
  51. * `USE_QSAPI`: true - true to use browsers native Query Selector API if available
  52. * `VERBOSITY`: true - true to throw exceptions, false to skip throwing exceptions
  53. * `LOGERRORS`: true - true to print console errors or warnings, false to mute them
  54. Example:
  55. ```js
  56. NW.Dom.configure( { USE_QSAPI: false, VERBOSITY: false } );
  57. ```
  58. #### `registerOperator( symbol, resolver )`
  59. Registers a new symbol and its matching resolver in the operators table. Example:
  60. ```js
  61. NW.Dom.registerOperator( '!=', 'n!="%m"' );
  62. ```
  63. #### `registerSelector( name, rexp, func )`
  64. Registers a new selector, with the matching regular expression and the appropriate resolver function, in the selectors table.