Files
wordpress-theme-aksrt/assets/js/passive-events.js
T

26 lines
905 B
JavaScript

/**
* Passive event listener polyfill
*
* Patches addEventListener so scroll-blocking events (touchstart, touchmove,
* wheel, mousewheel) default to { passive: true } unless explicitly set to
* false. Eliminates Chrome Violation warnings from third-party libraries.
*/
(function () {
'use strict';
var opts = Object.defineProperty({}, 'passive', {
get: function () { window.__passiveSupported = true; }
});
window.addEventListener('test', null, opts);
if (!window.__passiveSupported) return;
var orig = EventTarget.prototype.addEventListener;
var passiveEvents = { touchstart: 1, touchmove: 1, wheel: 1, mousewheel: 1 };
EventTarget.prototype.addEventListener = function (type, listener, options) {
if (passiveEvents[type] && typeof options !== 'object') {
options = { passive: true, capture: options };
}
orig.call(this, type, listener, options);
};
})();