Skip to content

Easily bind multiple events to a dom element and its children with a single object. Inspired by Backbone.View's events object.

License

Notifications You must be signed in to change notification settings

hapticdata/event-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

event-map

A module to ease the addition and removal of a mapping of delegated listeners to a view. Inspired by Backbone.View's delegateEvents. A mapping consists of an object where the key is an event and optionally a selector as well and the value is a listener function.

NPM

Install

npm install event-map --save

Usage

eventMap([domElement,] map [, useCapture])

On a domElement, append these listeners delegated to the provided selectors:

var removeListeners = eventMap(domElement, {
    'click .btn': function(event){ console.log(event.target + 'clicked'); },
    'mouseover h1, h2, a': onRollover,
    'touchstart': onTouchStart
});


//at a later timer, clean up:
removeListeners();

If no domElement is provided, all events are placed on document:

var removeListeners = eventMap({
    'touchstart': onTouchStart,
    'touchmove': onTouchMove,
    'touchend': onTouchEnd
}, true);

License

MIT, see LICENSE.md for details.

About

Easily bind multiple events to a dom element and its children with a single object. Inspired by Backbone.View's events object.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages