Coder Social home page Coder Social logo

micro-selector's Introduction

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.

micro-selector's People

Contributors

fabiomcosta avatar urodoz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

micro-selector's Issues

Error in IE when select by id using context element.

Hi.
There is an error in IE in the following situation:

<html>
<head><script src="uSelector.js" type="text/javascript"></script></head>
<body>
    <div id="context">
        <div id="id1">DIV with identificator id1</div>
    </div>
    <script type="text/javascript">
        var context = document.getElementById('context');
        var result = $u('#id1', context);
    </script>
</body>
</html>

The fix should be like the following (in 'find' func):

- var el = doc.getElementById(parsed.id);
+ var root = typeof doc.getElementById !== 'undefined' ? doc : $u.context;
+ var el = root.getElementById(parsed.id);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.