Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/firstandthird/data-attrs

jQuery Plugin for data attributes
https://github.com/firstandthird/data-attrs

Last synced: 3 days ago
JSON representation

jQuery Plugin for data attributes

Awesome Lists containing this project

README

        

# Data Attrs

A set of utility plugins to deal with data attributes. Data attributes are great when you want to separate your javascript completely from IDs and classes.

## Install

`bower install data-attrs --save`

## Utilities

### $.named

`$.named('element')` will search for `

`

### $.action

`$.action('delete', handler)` will get called when `Delete` is clicked.

If it will also pass back values, so if you had `Approve` you could have something like this:

```
$.action('approve', function(e, values) {
//this is the a tag that was clicked
//e is the click event
//values is an object that looks like { id: '123' }
});
```

#### Scoped Actions

`$.action('delete', el, handler)` will get called when `Delete` is clicked inside `el`.

### $.module

`$.module('name', function(el, values, els) {});` callback will only get called if the `data-module="name"` exists.

It will also pass back any values and named elements. For example:

```html


Title

Content



```

The callback will be called with:

`callback(el, { value: '123' }, { title: titleEl });`

### Declaritive Plugins

Declaritive Plugins will automatically bind elements to jQuery plugins.

With something like this:

```


```

It will automatically call this behind the scenes:

```
$(el).slider({ pages: 3 });
```