normify-listeners
Makes event APIs behave in the standard way
Installation
Install with npm:
npm install --save normify-listeners
Usage
However you use the normify-listeners
module, it is important that you call it before any of your other code so that its fixes are applied first.
require()
:
CommonJS ;
import
:
ES2015 ; ;
Browser globals:
Download normify-listeners.js
from the dist
directory, and include in your HTML file:
AMD:
Use normify-listeners.js
from the dist
directory:
;
Options
The normifyListeners( options )
function takes an options object with the following fields:
domOnly
: Iftrue
(default), onlywindow
,document
, andElement
are patched. Iffalse
, onlyEventTarget
is patched. SinceEventTarget
affects other prototypes likeAudioContext
and known issues only affect DOM objects, it's probably safer to usedomOnly: true
.
Known issues this lib resolves
- Chrome 56 breaks support for the
EventTarget.addEventListener
function. Chrome assumes that all touch events should be passive unless explicitly specified otherwise --- even though older apps wouldn't be aware of the options parameter toaddEventListener()
. This makes all calls toevent.preventDefault()
fail.- The
addEventListener()
function is normalised to make browsers that assume nonstandard behaviour use the correct, default options. TheaddEventListener()
function is wrapped, passing the default options explicitly (options = { capture: false, once: false, passive: false }
). This makes Chrome behave in line with standard, well-established behaviour:event.preventDefault()
works properly by default, as it always has done. - References: W3C DOM Living Standard, Chromium bug #639227, WICG/interventions#18
- The
- The addition of the
options
parameter to theaddEventListener()
function means that passing a function could be misinterpreted by older browsers asuseCapture == true
.- Browser support for the
options
parameter ofaddEventListener()
is checked in tandem with the third argument ofaddEventListener
. This means you can always use theoptions
parameter without having to worry about old browsers misinterpreting it asuseCapture == true
.
- Browser support for the