2.0.8 • Published 9 years ago

enot v2.0.8

Weekly downloads
4
License
unlicensed
Repository
github
Last release
9 years ago
<a href="https://travis-ci.org/dfcreative/enot"><img src="https://travis-ci.org/dfcreative/enot.svg?branch=master"/></a>
<a href="https://codeclimate.com/github/dfcreative/emmy"><img src="https://codeclimate.com/github/dfcreative/emmy/badges/gpa.svg"/></a>
<img src="https://david-dm.org/dfcreative/enot.svg"/>
<img src="https://img.shields.io/badge/size-4.38kb-brightgreen.svg"/>
<a href="UNLICENSE"><img src="http://upload.wikimedia.org/wikipedia/commons/6/62/PD-icon.svg" width="20"/></a>

Enot is Emitter with humanized events notation. It is like xtags events standalone with additional pseudos.

Install

To use in browser use browserify or build.

$ npm install enot

var Emitter = require('enot');

Use

Use Enot as simple emitter with optionally extended event notation:

Emitter.on('document click:pass(rightmouse)', callback);
Emitter.emit('document click');

Enot can be used with any Emmy/component-emitter use-case.

Examples

  • click - call on click
  • click:later(100) - call 100ms after click
  • click:throttle(200) - fire not more often than 200ms
  • click:one - fire once
  • window message - call on window gets message
  • document unload - call on user is going to leave
  • .bad-link click - elements matching selector click
  • :root click:delegate(.bad-link) - the same as above but in a delegate way
  • .element click, document keypress:pass(enter) - bind two callbacks

Event Notation

Basic event notation syntax is:

[<target>] <event>[<:pseudo1><:pseudo2>]...
ParameterDescription
targetRegular CSS-selector (possibly extended with relative pseudos, see query-relative), document/window keyword or target property accessible via @ prefix, e.g. @firstChild.
eventEvent name
:pseudoEvent modifier, see list of pseudos.

Pseudos

Use the following pseudos for events as click:<pseudo>.

PseudoAliasDescription
:once:onefire callback once.
:on(selector):delegate(selector)listen for bubbled event on elements mathing selector.
:not(selector)the opposite to delegate—ignore bubbled event on elements matching selector.
:pass(codes/keynames):keypass(codes/keynames)filter event by code. Useful for keyboard/mouse events. Full list of codes can be found in key-name. Use as :keypass(enter, 25, 26).
:later(100)invoke callback 100 ms after.
:throttle(20)invoke callbak not more than once per 20 ms.

Modifiers can be combined, e.g. click:once:on(.inner-tag):not(.ignore):pass(rightmouse):later(50).

API

API consists of common Emitter methods: on, off, emit, and every inherited from Emmy. Methods are chainable, so you can compose lists of calls: Enot.on(target, 'click', cb).emit(target, 'click').off(target, 'click');.

Enot.on(target(s)?, event(s)?, listener)

ParameterDescription
targetAny object, including HTMLElement, Array etc. If omitted — global event will be registered. Can be list of targets (NodeList or Array).
eventEvent declaration, in simple case — event name.
callbackAny function to invoke
eventsObject with event declarations as keys and callbacks as values.
//simple event
Enot.on(document.querySelectorAll('.buy-button'), 'click', function(){...});

//events object
Enot.on(myPlugin, {
	'window resize, document myPlugin:update': 'update',
	'update': function(){...},
	'submit, click:on(.submit-button), keypress:pass(enter)': function(){...}
});

Enot.off(target(s), event(s)?, listener?)

ParameterDescription
targetAny object, including HTMLElement, Array etc. If omitted — global event will be unbound. Can be list of targets (NodeList or Array).
eventEvent name. If omitted - all events for the target will be unbound.
callbackAny function or string previously bound. If omitted - all events for the target will be unbound.

Enot.emit(target, event, data?, bubbles?)

Fire event on the target. Optionally pass data and bubbles params. data will be accessible as event.detail in callback.

NPM

2.0.8

9 years ago

2.0.7

9 years ago

2.0.6

9 years ago

2.0.5

9 years ago

2.0.4

9 years ago

2.0.3

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.19

9 years ago

1.0.18

9 years ago

1.0.17

9 years ago

1.0.16

9 years ago

1.0.15

9 years ago

1.0.13

9 years ago

1.0.12

9 years ago

1.0.11

10 years ago

1.0.10

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.3

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.8.12

10 years ago

0.8.11

10 years ago

0.8.10

10 years ago

0.8.9

10 years ago

0.8.8

10 years ago

0.8.7

10 years ago

0.8.6

10 years ago

0.8.5

10 years ago

0.8.4

10 years ago

0.8.3

10 years ago

0.8.2

10 years ago

0.8.1

10 years ago

0.8.0

10 years ago

0.7.5

10 years ago

0.7.4

10 years ago

0.7.3

10 years ago

0.7.2

10 years ago

0.7.1

10 years ago

0.7.0

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.0

10 years ago

0.2.2

10 years ago

0.2.0

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.12

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.1

10 years ago