/default-passive-events

Makes {passive: true} by default when EventListenerOptions are supported

Primary LanguageHTMLMIT LicenseMIT

#default-passive-events

Makes {passive: true} by default when EventListenerOptions are supported

40 lines snippet that enables passive event listeners by default. It basically will set { active: true } automatically every time you declare a new event listener.

#Installation

Download the code with npm $ npm i default-passive-events -S or bower $ bower i default-passive-events -S and require the default-passive-events.js file.

#Usage Those are some examples and their output:

document.addEventListener('click', onClick); // {passive: true, capture: false}
document.addEventListener('click', onClick, true); // {passive: true, capture: true}
document.addEventListener('click', onClick, false); // {passive: true, capture: false}
document.addEventListener('click', onClick, {passive: false}); // {passive: false, capture: false}
document.addEventListener('click', onClick, {passive: false, capture: false}); // {passive: false, capture: false}
document.addEventListener('click', onClick, {passive: false, capture: true}); // {passive: false, capture: true}
document.addEventListener('click', onClick, {passive: true, capture: false}); // {passive: true, capture: false}
document.addEventListener('click', onClick, {passive: true, capture: true}); // {passive: true, capture: true}

Check the demo.html for a working example.

#Motivation Just if you want to take benefit in your apps without having to edit every single one event listener you already have.

#Resources

#Author

@zzarcon