@pirxpilot/events

Simple dom event management.


Keywords
browser, event, dom
License
MIT
Install
npm install @pirxpilot/events@2.0.0

Documentation

NPM version Build Status Dependency Status

events

Bare-bones dom event management. Heavily inspired by component/events. Use when multiple event listeners are naturally part of the same object.

Install

$ npm install --save @pirxpilot/events

Usage

var events = require('@pirxpilot/events');
var el = document.querySelector('button.ok');
var handlers = {
  click: function() {
    // do something on click
  },
  onblur: function() {
    // do something on blur
  }
};

var e = events(el, obj);
e.bind('click');

// add handlers
e.bind('mouseenter');
e.bind('blur', 'onblur');

e.unbind();

API

events(el, obj)

create events for dom element el and handlers object obj

bind(event, [method])

add event listener and bind it to obj - if method is not specified use method that has the same name as event ie. use mouseup method for mouseup event

Events.unbind([event])

remove event listener for specific event, if event is not specified remove all registered listeners

License

MIT © Damian Krzeminski