npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eventlistener-manager

v1.0.45

Published

The EventManager is capable of handling both native and custom events seamlessly, providing a robust solution for event management in complex applications.

Downloads

26

Readme

Eventlistener Manager

NPM NPM Downloads GitHub Repo stars Static Badge

Sample page

Link

Install

npm

npm i eventlistener-manager

cdn

<script src="https://unpkg.com/eventlistener-manager@latest/dist/index.umd.js"></script>

Report errors and suggestions

Gmail

Change log

| Version | Log | |---------|----------------------------------------------------------------------------------------------------------------------| | 1.0.25 | Support CDN | | 1.0.27 | Add 'appearancechange', 'orientationchange', 'resize', 'intersectionchange' eventlistener | | 1.0.32 | Polyfill 'addEventlistener', 'removeEventlistener', 'dispatchEvent', 'requestAnimationFrame', 'cancelAnimationFrame' | | 1.0.33 | Polyfill 'WeakMap' | | 1.0.34 | Fix 'requestAnimationFrame', 'cancelAnimationFrame' polyfill error | | 1.0.37 | Polyfill 'matchMedia' | | 1.0.45 | Improve situations where Custom events are not released in special cases |

1. Add events

Add single type event

EventManager.on(eventTarget, 'click', callback);
// or
eventTarget.on('click', callback);

Add multiple type event

EventManager.on(eventTarget, ['click', 'mousedown'], callback);
// or
eventTarget.on(['click', 'mousedown'], callback);

2. Remove event

Remove single type event

EventManager.off(eventTarget, 'click', callback);
// or
eventTarget.off('click', callback);
EventManager.off(eventTarget, 'click'); // remove all click event
// or
eventTarget.off('click');
EventManager.off(eventTarget); // remove all event
// or
eventTarget.off();

Remove multiple type event

EventManager.off(eventTarget, ['click', 'mousedown']); // remove all click, mousedown event
// or
eventTarget.off(['click', 'mousedown']);

3. Add custom event

EventManager.on(eventTarget, ['mouselongpressstart'], callback);
// or
eventTarget.on(['mouselongpressstart']);

Supported custom events

Supported custom events include mouse long press, mouse pan, touch long press, touch pan, touch pinch, screen mode change, orientation change, any element resize, and any element intersection change.

interface ExtendedMouseEventMap {  
  'mouselongpressstart': MouseEvent;  
  'mouselongpressmove': MouseEvent;  
  'mouselongpressend': MouseEvent;  
  'mouselongpressleave': MouseEvent;  
  
  'mousepanstart': MouseEvent;  
  'mousepanmove': MouseEvent;  
  'mousepanleft': MouseEvent;  
  'mousepanright': MouseEvent;  
  'mousepanup': MouseEvent;  
  'mousepandown': MouseEvent;  
  'mousepanend': MouseEvent;  
  'mousepanleave': MouseEvent;  
}  
  
interface ExtendedTouchEventMap {  
  'touchlongpressstart': TouchEvent;  
  'touchlongpressmove': TouchEvent;  
  'touchlongpressend': TouchEvent;  
  'touchlongpresscancel': TouchEvent;  
  
  'touchpanstart': TouchEvent;  
  'touchpanmove': TouchEvent;  
  'touchpanleft': TouchEvent;  
  'touchpanright': TouchEvent;  
  'touchpanup': TouchEvent;  
  'touchpandown': TouchEvent;  
  'touchpanend': TouchEvent;  
  'touchpancancel': TouchEvent;  
  
  'touchpinchstart': TouchEvent;  
  'touchpinchmove': TouchEvent;  
  'touchpinchend': TouchEvent;  
  'touchpinchcancel': TouchEvent;  
}

interface ExtendedUIEventMap {
  'appearancechange': MediaQueryListEvent;
  'orientationchange': MediaQueryListEvent;
  'resize': UIEvent;
  'intersectionchange': UIEvent;
}

Options

Custom event options can be modified.

import {EventManager} from "./index";

EventManager.options.strict = true; // Use strict callback mode
EventManager.options.mouseLongpressTimeRequired = 750; // Mouse long press time required
EventManager.options.mouseLongpressBelowDistance = 15; // Mouse long press below distance
EventManager.options.touchLongpressTimeRequired = 750; // Touch long press time required
EventManager.options.touchLongpressBelowDistance = 30; // Touch long press below distance
EventManager.options.callWhenAddedUIEvent = true; // Call callback when extended ui event added

4. Support event type polyfill

EventManager.on(eventTarget, 'fullscreenchange', callback);

// This actually works on firefox with specific version as follows: eventTarget.addEventListener('mozfullscreenchange', callback);

Additional Information

  • The EventManager supports polyfills for various event types to ensure cross-browser compatibility.
  • The strict mode in options ensures that the callback is invoked in a strict manner according to the specified requirements.
  • The EventManager is capable of handling both native and custom events seamlessly, providing a robust solution for event management in complex applications.