SlickSlick.js

JavaScript API

Slick.Finder

Slick Selector Engine

Slick.search

Search this context for any nodes that match this selector.

Expects:

  1. context: document or node or array of documents or nodes
  2. selector: String or SelectorObject
  3. (optional) append: Array or Object with a push method

Returns: append argument or Array of 0 or more nodes

Slick.search(document, "#foo > bar.baz") → [<bar>, <bar>, <bar>]
Slick.search([<ol>, <ul>], "li > a") → [<a>, <a>, <a>]
Slick.search(document, "#foo > bar.baz", { push:function(){} }) → { push:function(){}, 0:, 1:, 2: }

Slick.find

Find the first node in document that matches selector or null if none are found.

Expects:

  1. context: document or node or array of documents or nodes
  2. selector: String or SelectorObject

Returns: Element or null

Slick.find(document, "#foo > bar.baz") → <bar>
Slick.find(node, "#does-not-exist") → null

Slick.match

Does this node match this selector?

Expects:

  1. node
  2. node, String or SelectorObject

Returns: true or false

note: The HTML in the following example represent DOM nodes

Slick.match(<div class=rocks>, "div.rocks") → true
Slick.match(<div class=lame>, "div.rocks") → false
Slick.match(<div class=lame>, <div class=rocks>) → false

Slick.contains

Does this context contain this node? Is the context a parent of this node?

Expects:

  1. context: document or node
  2. node: node

Returns: true or false

Slick.contains(<ul>, <li>) → true
Slick.contains(<body>, <html>) → false

Slick.definePseudo

Defines a new custom CSS Pseudo matcher

Expects:

Slick.definePseudo('text', function(node, value){
	return node.innerHTML == value;
});

Slick.version

Defines the current version of Slick

alert(Slick.version);

Slick.Parser

Parse a CSS selector string into a JavaScript object

Usage

parse selector into object

Parse a CSS Selector String into a Selector Object.

Expects: String

Returns: SelectorObject

Slick.parse("#foo > bar.baz") → SelectorObject

SelectorObject format

#foo > bar.baz
{
    "raw":"#foo > bar.baz",
    "expressions": [[
        { "combinator":" ", "tag":"*", "id":"foo" },
        { "combinator":">", "tag":"bar", "classList": ["baz"], "classes": [{"value":"baz", "regexp":RegExp }]}
    ]]
}
h1, h2, ul > li, .things
{
    "raw": "h1, h2, ul > li, .things",
    "expressions": [
        [{ "combinator":" ", "tag": "h1" }],
        [{ "combinator":" ", "tag": "h2" }],
        [{ "combinator":" ", "tag": "ul" }, { "combinator": ">", "tag": "li" }],
        [{ "combinator":" ", "tag": "*", "classList": ["things"], "classes": [{"value": "things", "regexp":RegExp }] }]
    ]
}