# ever

> dom events with a node-style EventEmitter api

Latest version **0.0.3** (published 2013-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install ever
pnpm add ever
yarn add ever
bun add ever
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2013-02-23 |
| First published | 2012-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | James Halliday |
| Maintainers | substack |
| Keywords | events, dom, browser, browserify, emitter |

## Links

- npm: https://www.npmjs.com/package/ever
- Repository: https://github.com/substack/ever
- npm.io page: https://npm.io/package/ever

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 0.0.3 (latest) — 2013-02-23
- 0.0.2 — 2013-02-22
- 0.0.1 — 2012-12-23
- 0.0.0 — 2012-08-28

## README

# ever

[dom events](http://www.w3.org/TR/DOM-Level-2-Events/events.html)
with a node-style
[EventEmitter](http://nodejs.org/docs/latest/api/events.html#events_class_events_eventemitter)
api

[![browser support](http://ci.testling.com/substack/ever.png)](http://ci.testling.com/substack/ever)

# example

[view the demo](http://substack.net/projects/ever-example/)

``` js
var ever = require('ever');
var box = document.querySelector('#box');

var state = false;
ever(box).on('click', function (ev) {
    ev.stopPropagation();
    state = !state;
    box.style['background-color'] = state ? 'red' : 'rgb(127,127,127)';
});

setInterval(function () {
    ever(box).emit('click');
}, 3000);
```

# methods

``` js
var ever = require('ever')
```

## var ev = ever(element)

Return a new
[EventEmitter](http://nodejs.org/docs/latest/api/events.html#events_class_events_eventemitter)
that wraps the HTML node `element`.

All the usual
[EventEmitter](http://nodejs.org/docs/latest/api/events.html#events_class_events_eventemitter)
methods should work with the caveat that adding and removing listeners are
proxied through to the underlying dom methods, which only expect a single event
object as a parameter.

## ev.emit(name, opts)

Emit an event `name` with options `opts`. This method creates a synthetic event
using `document.createEvent()` and the corresponding variant of `.initEvent()`
that works with the event `name` provided.

The options `opts` will be passed into the matching `.initEvent()` function
signature. Any additional properties will be added to the event object as
properties being calling `.dispatchEvent()`.

The signatures are documented in the file `init.json` in this distribution.
To see which event name maps to which init signature, see the `types.json` file.

## ev.on(name, cb), ev.addListener(name, cb)

Just like node's `EventEmitter.prototype.on()`, listen for events.

Internally this calls `.addEventListener()`.

## ev.removeListener(name, cb)

Just like node's `EventEmitter.prototype.removeListener()`, remove a listener.

Internally this calls `.removeEventListener()`, however there is no way to
obtain a list of all listeners from dom nodes, so only listeners registered by
the current `ever()` instance can be removed.

## ev.removeAllListeners(name)

Just like node `EventEmitter.prototype.removeAllListeners()`, remove all the
listeners with `name` or everything is `name` is falsy.

Unlike in node, this function calls `removeListener()` on each of the events to
remove them so that the underlying `.removeEventListener()` calls get fired.

# install

With [npm](http://npmjs.org) do:

```
npm install ever
```

This module is meant for use in browsers with a node-style module system.
Use [browserify](http://github.com/substack/node-browserify) or similar.

# license

MIT

---
_Source: https://npm.io/package/ever · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
