UNPKG

nyg-static-jam3

Version:

Jam3 frontend static project scaffold generator based on nyg

40 lines (35 loc) 857 B
let alreadyTested = false; let passiveSupported = false; /** * Returns if passive event are supported * * @returns {Boolean} supported */ function isSupported() { if (alreadyTested) { return passiveSupported; } else { alreadyTested = true; // Test via a getter in the options object to see if the passive property is accessed try { const opts = Object.defineProperty({}, 'passive', { get: function() { passiveSupported = true; } }); window.addEventListener('test', null, opts); } catch (e) { return passiveSupported; } return passiveSupported; } } /** * Passive event polyfill * * @returns {Object|Boolean} Passive event setup if is supported */ function usePassiveEvent() { return isSupported() ? { passive: true } : false; } export default usePassiveEvent;