Socket
Socket
Sign inDemoInstall

events-polyfill

Package Overview
Dependencies
0
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

events-polyfill


Version published
Maintainers
1
Created

Readme

Source

Polyfill different events classes and methods to match last ES7 specifications

Tested on IE 10+

Install
npm i events-polyfill --save
event-constructor-polyfill.js

Polyfill for : CustomEvent, MouseEvent and KeyboardEvent

event-listener-polyfill.js

Polyfill for :

EventTarget.prototype.addEventListener(type, listener[, options]);
EventTarget.prototype.removeEventListener(type, listener[, options]);

type : name of the event

Polyfill vendor prefixed events like 'pointerlockchange' (try 'pointerlockchange', 'mozpointerlockchange' and 'webkitpointerlockchange') and some 'experimental' events like 'wheel' (try 'wheel', 'mousewheel', 'DOMMouseScroll')

  • If option 'polyfill' set to false : disable polyfill (ex: for custom events)
  • If option 'polyfill' set to true AND can't be polyfilled : throw an error (allow you to check is event type is supported)

Polyfilled types :

[
    'wheel',
    'pointerlockchange', 'pointerlockerror',
    'fullscreenchange', 'fullscreenerror',
    'animationend', 'animationiteration', 'animationstart', 'transitionend',
    'pointercancel', 'pointerdown', 'pointerhover', 'pointermove', 'pointerout', 'pointerover', 'pointerup'
]

listener : the callback

options : last parameter which replace boolean useCapture

  • once : trigger only once this event (default: false)
  • passive : allow browser to continue animations (ex: while scrolling) by 'disabling' event.preventDefault() (default: false)
  • capture : replace useCapture (default: false)
  • polyfill : custorm property which tell if vendor properties should be auto prefixed (default: true)
Example:
document.addEventListener('pointerlockchange', function(event) {
    console.log('pointerlockchange', event);
}, { polyfill: true }); // here polyfill: true could be omited because it's the default value

document.addEventListener('click', function() {
    document.body.requestPointerLock();
}, { once: true });

FAQs

Last updated on 07 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc