domy-events

0.3.2 • Public • Published

domy-events

Map DOM events to DOM elements. For use with Browserify.

Part of the Domy module collection.

browser support

Install

npm install domy-events --save

Usage

var events = require('domy-events');
 
var handlers = {
  method1: function (e) {
    e.preventDefault();
    console.log('in this method');    
  },
  
  method2: function (e) {
  
  },
  
  formHandler: function (e) {
    e.preventDefault();
  }
};
 
var eventsOptions = {
  bind: handlers, // optional
  parent: '.parent', // optional (can use a DOM object as well)
  delegate: true // optional
};
 
// Now, handle events
events({
  'click .some-css-selector': handlers.method1
  'click. #someId': 'method2',
  'submit form': handlers.formHandler
}, eventsOptions);

Note: domy-events uses querySelectorAll under the hood.

Options

  • bind - the context in which to bind the event handler method to
  • parent - the parent DOM element for all css selections. Defaults to document.
  • delegate - delegate all events to the parent

Run Tests

Requires Phantomjs is installed

npm install
npm test

Readme

Keywords

none

Package Sidebar

Install

npm i domy-events

Weekly Downloads

2

Version

0.3.2

License

MIT

Last publish

Collaborators

  • scottcorgan