https://github.com/pirxpilot/events
Simple dom event management
https://github.com/pirxpilot/events
Last synced: 20 days ago
JSON representation
Simple dom event management
- Host: GitHub
- URL: https://github.com/pirxpilot/events
- Owner: pirxpilot
- Created: 2017-12-12T16:46:59.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2025-04-27T13:43:28.000Z (about 1 year ago)
- Last Synced: 2025-10-30T04:18:46.312Z (9 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]
# events
Bare-bones dom event management. Heavily inspired by [component/events].
Use when multiple event listeners are naturally part of the same object.
## Install
```sh
$ npm install --save @pirxpilot/events
```
## Usage
```js
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](https://pirxpilot.me)
[npm-image]: https://img.shields.io/npm/v/@pirxpilot/events
[npm-url]: https://npmjs.org/package/@pirxpilot/events
[build-url]: https://github.com/pirxpilot/events/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/events/check.yaml?branch=main
[deps-image]: https://img.shields.io/librariesio/release/npm/@pirxpilot/events
[deps-url]: https://libraries.io/npm/@pirxpilot%2Fevents
[component/events]: https://github.com/component/events