/events

Listen for events like click, touch, etc in a template using attributes.

Primary LanguageJavaScript

events

Build Status

Listen for events like click, touch, etc in a template using attributes.

Installation

Install with component(1):

$ component install ripplejs/events

API

A template can use on-* to emit events on the view.

<button on-click="{{ this.save }}">Save</button>

This can be any type of event, eg: on-dblclick, on-touch, on-keydown. The node just needs to emit the event after the on- portion of the attribute.

var events = require('events');
var ripple = require('ripple');

// Compile the view
var View = ripple(template);

// Use the plugin
View.use(events);

// Listen for the events
View.prototype.save = function(){
  // Do things
};

You can also pass data to the directive and it will update automatically:

<button on-click="{{ this.save.bind(this, foobar) }}">Save</button>

or pass it through filters:

<button on-click="{{ this.save | preventDefault }}">Save</button>

License

MIT