<commit_before>behaviors.js
============

A library for implementing Behaviors Stylesheets (BSS) for attaching behaviors to pages with unobtrusive JavaScript. This library is based on the work of <NAME> in the Cruiser.Behaviors library, which was inspired by <NAME>'s own Behaviours library.

**Note:** The following was adapted from [this wiki page](https://code.google.com/p/cruiser/wiki/Behaviors)

Introduction
============

Our Behaviors library was originally inspired by <NAME>’s Behaviours library. Basically, the idea is to use CSS selectors to “decorate” DOM elements with Javascript handlers and the like.

We took the idea a step farther and pulled them out into a separate file, called a behaviors stylesheet (BSS). This is a stylesheet, using the same syntax as CSS, that includes a variety of attributes to support DOM decoration.

For example, you can add a mouseover handler to show a preview window for all links marked with the preview class like this:

```javascript
a.preview { mouseover: preview; }
```

The benefit of using BSS is two-fold:

* Your Javascript can now focus more or less on the interfaces you want your DOM elements to support. You don’t need to clutter up your Javascript with the mappings between elements and methods / functions. 
* You can push out design-centric Javascript to the designer. In the ‘preview’ example above, you can let the CSS designer decide which links should provide a preview, rather than embedding that in your Javascript. 

Usage
=====

behaviors.js uses [prototype.js](http://prototypejs.org/) 1.6+. Include it in the head of your page, along with [parser-generator.js](https://github.com/sjohnr/parser-generator.js) as follows:

```html
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
<script src="https://raw.github.com/sjohnr/parser-generator.js/master/parsing.js"></script>
<script src="https://raw.github.com/sjohnr/behaviors.js/master/behaviors.js"></script>
```

You can load a BSS file pretty much the same way you load a CSS file: with a `<link>` tag. For example:

```html
<link rel="behaviors" href="my-behaviors.bss" />
```

Attributes
==========

Binding Attribute
-----------------

Binds the element to another element via a binding function. Event handling will be delegated to the bound element.

```javascript
// create a submit button
a.save { binding: up(form); click: submit; }

// tabbed dialog
div.tabs { binding: new( TabControl ) }
a.tab { binding: up( div.tabs ); click: select }
```

**Binding functions:**

* `new( class )` 
  * Binds to the result of instantiating a new instance of the given class.
  * Constructor is passed the original element.
* `object( object )`
  * Binds to the given object.
* `up( selector )`
  * Binds to the first ancestor element matching the given selector.
* `down( selector )`
  * Binds to the first descendant element matching the given selector.
* `next( selector )`
  * Binds to the first sibling after the element that matches the given selector.

Load Attribute
--------------

Calls a function when the element is loaded (actually at the point the attribute is processed). Passes the bound element to the function.

```javascript
a.menu-item { binding: object( MainMenu ); load: addMenuItem; }
```

**Note:** With binding and load, order does matter, since both attributes are processed as they are parsed. So if you are depending on the binding for your load method, make sure you put the binding attribute first.
<commit_msg>Added two missing binding functions to README<commit_after>behaviors.js
============

A library for implementing Behaviors Stylesheets (BSS) for attaching behaviors to pages with unobtrusive JavaScript. This library is based on the work of <NAME> in the Cruiser.Behaviors library, which was inspired by <NAME>'s own Behaviours library.

**Note:** The following was adapted from [this wiki page](https://code.google.com/p/cruiser/wiki/Behaviors)

Introduction
============

Our Behaviors library was originally inspired by <NAME>’s Behaviours library. Basically, the idea is to use CSS selectors to “decorate” DOM elements with Javascript handlers and the like.

We took the idea a step farther and pulled them out into a separate file, called a behaviors stylesheet (BSS). This is a stylesheet, using the same syntax as CSS, that includes a variety of attributes to support DOM decoration.

For example, you can add a mouseover handler to show a preview window for all links marked with the preview class like this:

```javascript
a.preview { mouseover: preview; }
```

The benefit of using BSS is two-fold:

* Your Javascript can now focus more or less on the interfaces you want your DOM elements to support. You don’t need to clutter up your Javascript with the mappings between elements and methods / functions. 
* You can push out design-centric Javascript to the designer. In the ‘preview’ example above, you can let the CSS designer decide which links should provide a preview, rather than embedding that in your Javascript. 

Usage
=====

behaviors.js uses [prototype.js](http://prototypejs.org/) 1.6+. Include it in the head of your page, along with [parser-generator.js](https://github.com/sjohnr/parser-generator.js) as follows:

```html
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script>
<script src="https://raw.github.com/sjohnr/parser-generator.js/master/parsing.js"></script>
<script src="https://raw.github.com/sjohnr/behaviors.js/master/behaviors.js"></script>
```

You can load a BSS file pretty much the same way you load a CSS file: with a `<link>` tag. For example:

```html
<link rel="behaviors" href="my-behaviors.bss" />
```

Attributes
==========

Binding Attribute
-----------------

Binds the element to another element via a binding function. Event handling will be delegated to the bound element.

```javascript
// create a submit button
a.save { binding: up(form); click: submit; }

// tabbed dialog
div.tabs { binding: new( TabControl ) }
a.tab { binding: up( div.tabs ); click: select }
```

**Binding functions:**

* `new( class )` 
  * Binds to the result of instantiating a new instance of the given class.
  * Constructor is passed the original element.
* `object( object )`
  * Binds to the given object.
* `select( object )`
  * Binds to the first element matching the given selector.
* `up( selector )`
  * Binds to the first ancestor element matching the given selector.
* `down( selector )`
  * Binds to the first descendant element matching the given selector.
* `previous( selector )`
  * Binds to the first sibling prior to the element that matches the given selector.
* `next( selector )`
  * Binds to the first sibling after the element that matches the given selector.

Load Attribute
--------------

Calls a function when the element is loaded (actually at the point the attribute is processed). Passes the bound element to the function.

```javascript
a.menu-item { binding: object( MainMenu ); load: addMenuItem; }
```

**Note:** With binding and load, order does matter, since both attributes are processed as they are parsed. So if you are depending on the binding for your load method, make sure you put the binding attribute first.

{'fraction_non_alphanumeric': 0.10559778852798894, 'fraction_numerical': 0.00165860400829302, 'mean_word_length': 4.213256484149856, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1388389', 'n_tokens_mistral': 2030, 'n_tokens_neox': 1936, 'n_words': 933}