Skip to content

A micro, super fast, scope limited, javascript selector engine to be used anywhere

Notifications You must be signed in to change notification settings

fabiomcosta/micro-selector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uSelector

A micro, super fast, scope limited, javascript selector engine to be used anywhere

uSelector (micro selector), is a node selector for HTML documents that uses css expressions to select nodes. It's based on Slick, the selector used on the Mootools javascript framework.

Supported selectors

  • tag
  • id
  • class
  • custom pseudo-classes

Unsupported selectors

  • combinators (ex: "div span", "div > span")
  • multiple expressions (expressions with comma, ex: "div, span")
  • attribute (ex: "a[title='title']")

Suported with the uSelectorPseudoClasses module

  • :empty
  • :first-child
  • :last-child
  • :only-child
  • :first-of-type
  • :last-of-type
  • :only-of-type
  • :disabled
  • :checked
  • :selected

note: To build with these pseudo-selectors included do make build all=true

Browser Support

IE Chrome Firefox Opera Safari
IE 6+ ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔

How to use

$u('your-selector') -> returns an array of nodes that match the selector

Create your own pseudo-class

$u.pseudo['your-custom-pseudo'] = function(node){
	return boolean;
};

It should return true if the passed node fits the behavior of your pseudo. see the "src/uSelectorPseudoClasses.js"

Examples

<div>
	<span>text</span>
	<strong class="strong-class">strong-text</strong>
	<div id="id" class="div-class"></div>
</div>
  • $u('strong.strong-class') -> [<strong.strong-class>]
  • $u('span') -> [<span>]
  • $u('#id') -> [<div#id.div-class>]
  • $u('div#id') -> [<div#id.div-class>]
  • $u('div#id.div-class') -> [<div#id.div-class>]
  • $u('em') -> []

Run Tests

Enter the tests/ folder on your browser. You'll need PHP on your server to run them.

License

The MIT License (http://www.opensource.org/licenses/mit-license.php)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A micro, super fast, scope limited, javascript selector engine to be used anywhere

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages