xonecas.io
142
St

startsInvasion / files

startsInvasion / libs / node_modules / bonzo / README.md

3.9 KB
1Bonzo
2-----
3a simple, to the point, hassle-free, small (2.8k), library agnostic, extensible DOM utility. Nothing else.
4Bonzo is designed to live in any host library, or simply as a stand-alone tool for the majority of your DOM-related tasks.
5
6<h3>It looks like this</h3>
7
8``` js
9bonzo(elements)
10  .hide()
11  .addClass('foo')
12  .append('<p>the happs</p>')
13  .css({
14    color: 'red',
15    'background-color': 'white'
16  })
17  .show()
18```
19
20Paired with a Selector Engine
21-----------------------------
22A great way to use Bonzo is with a selector engine (like [Qwery](https://github.com/ded/qwery) for example). You could wrap bonzo up and augment your wrapper to inherit the same methods. That looks like this:
23
24``` js
25function $(selector) {
26  return bonzo(qwery(selector));
27}
28```
29
30This now allows you to write the following code:
31
32``` js
33$('#content a[rel~="bookmark"]').after('√').css('text-decoration', 'none');
34```
35
36Bonzo Extension API
37-------------------
38One of the greatest parts about Bonzo is its simplicity to hook into the internal chain to create custom methods. For example you can create a method called **color** like this:
39
40``` js
41bonzo.aug({
42  color: function (c) {
43    return this.css('color', c);
44  }
45});
46
47// you can now do the following
48$('p').color('aqua');
49```
50
51All other API methods
52---------------------
53
54  * each
55    - function (element, index)
56  * map
57    - function (element, index)
58    - reject
59  * html
60    - html() get
61    - html(str) set
62  * text
63    - text() get
64    - text(str) set
65  * addClass
66  * removeClass
67  * hasClass
68  * show
69  * hide
70  * first
71  * last
72  * next
73  * previous
74  * append
75  * appendTo(target)
76  * prepend
77  * prependTo(target)
78  * before
79  * insertBefore(target)
80  * after
81  * insertAfter(target)
82  * css
83    - css(prop) get
84    - css(prop, val) set
85    - css({properties}) set
86  * offset()
87    - offset(x, y) set
88    - offset() get
89      - top
90      - left
91      - width
92      - height
93  * attr
94    - attr(k) get
95    - attr(k, v) set
96    - attr(obj) set
97  * val
98    - val() get
99    - val(s) set
100  * remove
101  * empty
102  * detach
103  * scrollLeft
104  * scrollTop
105  * bonzo.aug({ properties })
106  * bonzo.doc()
107    - width
108    - height
109  * bonzo.viewport()
110    - width
111    - height
112  * bonzo.isAncestor(container, child)
113  * bonzo.noConflict
114
115Added in the Ender bridge
116
117  * parents(selector)
118  * closest(selector)
119  * siblings()
120  * children()
121
122Setting a query engine host
123------------------
124For the insertion methods you can set a query selector host (like [qwery](https://github.com/ded/qwery)).
125
126``` js
127bonzo.setQueryEngine(qwery);
128bonzo(bonzo.create('div')).insertAfter('.boosh a');
129```
130
131The name Bonzo
132--------------
133Bonzo Madrid was a malicious battle school commander of whom eventually is killed by [Ender Wiggin](http://en.wikipedia.org/wiki/Ender_Wiggin). Bonzo represents the DOM, of whom we'd all love to slay.
134
135Building
136--------
137Aside from simply downloading the source, if you would like to contribute, building Bonzo requires GNU 'make' and Node >= 0.4, and of course, git. The rest is easy:
138
139    $ git clone git://github.com/ded/bonzo.git bonzo
140    $ cd !$
141    $ git submodule update --init
142    $ make
143
144*make* will run the [JSHint](http://jshint.com) linter as well as the [Uglify](https://github.com/mishoo/UglifyJS) compliler.
145
146Tests
147-----
148
149    $ open bonzo/tests/tests.html
150
151Ender integration
152----------
153Bonzo is a registered npm package and fits in nicely with the [Ender](http://ender.no.de) framework. If you don't have Ender, you should install now, and never look back, ever. As a side note the *query engine host* is set for you when you include it with Ender.
154
155    $ npm install ender -g
156
157To combine Bonzo to your Ender build, you can add it as such:
158
159    $ ender build bonzo[,modb, modc,...]
160
161or, add it to your existing ender package
162
163    $ ender add bonzo
164
165Contributors
166-----
167
168  * [Dustin Diaz](https://github.com/ded/bonzo/commits/master?author=ded)
169  * [Jacob Thornton](https://github.com/ded/bonzo/commits/master?author=fat)