cocktail-css-selector 0.1.4

css selector parsing/serializing and matching

Released 2014-07-20.

To install, run:

haxelib install cocktail-css-selector 0.1.4

See using Haxelib in Haxelib documentation for more information.

Maintaineryanhick
Websitehttps://github.com/haxecocktail/cocktail-css-selector
Current version0.1.4
StatisticsInstalled 13 times
LicenseMIT
Tags

README.md

Build Status

cocktail-css-selector

CSS selector matching, parsing and serializing. This lib is part of the larger Cocktail project.

Install

haxelib install cocktail-css-selector

Usage

Selectors parsing


//parser class
import cocktail.selector.SelectorsParser;

//Selectors data structures
import cocktail.selector.SelectorData;

class Main {
  public static function main() {
  
    //parse one or multiple selectors and return them in an array of SelectorVO 
    //(see SelectorData implementation)
    var selectors = SelectorsParser.parse('div, p');
  }
}

Selectors matching


//matcher class
import cocktail.selector.SelectorMatcher;

//Selectors data structures
import cocktail.selector.SelectorData;

//DOM lib
import cocktail.dom.*;

class Main {
  public static function main() {

    //create the DOM node to match
    var element = new Document().createElement('div');
  
    //takes a DOM node and a
    //selector and returns whether the element matches the 
    //selector
    var isMatched = SelectorMatcher.match(element, 'div');

    //an optional object can be provided specifiying which pseudo-class
    //(hover, active, fullscreen... are currently active in the document).
    //It is only useful for interactive documents
    var matchedPseudoClasses = new MatchedPseudoClassesVO(/*bunch of flags*/);

    isMatched = SelectorMatcher.match(element, 'div', matchedPseudoClasses);
  }
}

Run Tests

make