142
St
startsInvasion / files
startsInvasion / libs / node_modules / qwery / README.md
3.9 KB
1Qwery - The Tiny Selector Engine 2----- 3Qwery is a small *blazing fast* query selector engine allowing you to select elements with CSS1|2|3 queries 4 5Acceptable selectors 6--------------- 7 8``` css 9basic 10#foo {} id 11.bar {} class 12a#foo.bar {} element attribute combinations 13 14attributes 15#foo a[href] {} simple 16#foo a[href=bar] {} attribute values 17#foo a[lang|=en] {} subcodes 18#foo a[title~=hello] {} attribute contains 19#foo a[href^="http://"] {} attribute starts with 20#foo a[href$=com] {} attribute ends with 21#foo a[href*=twitter] {} attribute wildcards 22 23descendants 24#foo a {} all descendants 25ul#list > li {} direct children 26 27siblings 28span ~ strong {} all adjacent 29p + p {} immediate adjacent 30 31combos 32div,p {} 33 34variations 35#foo.bar.baz {} 36div#baz.thunk a[-data-info*="hello world"] span + strong {} 37#thunk[title$='huzza'] {} 38``` 39 40Contexts 41------- 42Each query can optionally pass in a context 43 44``` js 45qwery('div', node); // existing DOM node or... 46qwery('div', '#foo'); // another query 47``` 48 49pseudo selector API 50------------------- 51 52Optionally, Qwery provides a [pseudo selector interface](https://github.com/ded/qwery/blob/master/src/pseudos.js) allowing you to extend into advanced CSS3 matchers. It looks like this: 53 54``` js 55qwery.pseudos['first-child'] = function (el, val) { 56 var p; 57 return el.parentNode && (p = el.parentNode) && (childs = p.getElementsByTagName('*')) && childs[0] == el; 58}; 59``` 60 61To create a new pseudo matcher you must set a property on `qwery.psuedos` with a boolean method that is passed back a candidate element, and a value (if any). For example: 62 63``` js 64qwery('#content p.surprise:foo(bar)') 65 66qwery.pseudos.foo = function (el, val) { 67 // val == 'bar' 68 return el.getAttribute(val) 69} 70``` 71 72Browser Support 73--------------- 74Qwery attempts to stay up to date with Yahoo's [Grade A Browser Support](http://developer.yahoo.com/yui/articles/gbs) in addition to future browser candidates. 75 76 - IE6, IE7, IE8, IE9 77 - Chrome 1 - 12 78 - Safari 3, 4, 5 79 - Firefox 2, 3, 4, 5, Aurora 80 - Opera 81 82Tests 83----- 84 85 $ open tests/index.html 86 87Note 88---- 89Qwery uses <code>querySelectorAll</code> when available. All <code>querySelectorAll</code> default behavior then applies. 90 91Ender support 92------------- 93Qwery is the recommended selector engine for [Ender](http://ender.no.de). If you don't have Ender, install it, and don't ever look back. 94 95 $ npm install ender -g 96 97To include Query in a custom build of Ender you can include it as such: 98 99 $ ender -b qwery[,mod2,mod3,...] 100 101Or add it to an existing Ender installation 102 103 $ ender add qwery 104 105Ender bridge additions 106--------- 107Assuming you already know the happs on Ender -- Qwery provides some additional niceties when included with Ender: 108 109``` js 110// the context finder - find all p elements descended from a div element 111$('div').find('p') 112 113// join one set with another 114$('div').and('p') 115 116// element creation 117$('<p>hello world</p>'); // => [HTMLParagraphElement "hello world"] 118``` 119Recommended sibling modules 120---------- 121In most cases, if you're hunting for a selector engine, you probably want to pair Qwery with a DOM module. In that case qwery pairs quite nicely with [Bonzo](https://github.com/ded/bonzo) (a DOM util) and [Bean](https://github.com/fat/bean) (an event util). Add them to your Ender installation as such: 122 123 $ ender -b qwery bonzo bean 124 125Then write code like a boss: 126 127``` js 128$('a.boosh') 129 .css({ 130 color: 'red', 131 background: 'white' 132 }) 133 .after('√') 134 .bind({ 135 'click.button': function () { 136 $(this).hide().unbind('click.button'); 137 } 138 }); 139``` 140 141Qwery Mobile! 142------------ 143If you're building a Webkit (iPhone / Android / Chrome OS) application, you may be interested in qwery-mobile! Include this (instead of qwery) in your Ender build and get a full qwery interface for just 600 bytes :) 144 145 $ ender add qwery-mobile 146 147Contributors 148------- 149 * [Dustin Diaz](https://github.com/ded/qwery/commits/master?author=ded) 150 * [Jacob Thornton](https://github.com/ded/qwery/commits/master?author=fat)