normify-listeners
v1.0.0
Published
Makes event APIs behave in the standard way
Maintainers
Readme
normify-listeners
Makes event APIs behave in the standard way
Installation
Install with npm:
npm install --save normify-listenersUsage
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.
CommonJS require():
require('normify-listeners')();ES2015 import:
import normifyListeners from 'normify-listeners';
normifyListeners();Browser globals:
Download normify-listeners.js from the dist directory, and include in your HTML file:
<script src="normify-listeners.js"></script>
<script>normifyListeners();</script>AMD:
Use normify-listeners.js from the dist directory:
require( ['normify-listeners'], function( normifyListeners ){
normifyListeners();
} );Options
The normifyListeners( options ) function takes an options object with the following fields:
domOnly: Iftrue(default), onlywindow,document, andElementare patched. Iffalse, onlyEventTargetis patched. SinceEventTargetaffects other prototypes likeAudioContextand 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.addEventListenerfunction. 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
optionsparameter to theaddEventListener()function means that passing a function could be misinterpreted by older browsers asuseCapture == true.- Browser support for the
optionsparameter ofaddEventListener()is checked in tandem with the third argument ofaddEventListener. This means you can always use theoptionsparameter without having to worry about old browsers misinterpreting it asuseCapture == true.
- Browser support for the
