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

ngx-event-handler

v16.0.1

Published

Easy way to handle page clicks, outside or inside specific elements.

Downloads

988

Readme

ngx-event-handler

This directive can be used to handle events, by default click events, that matches given critera. For example: handle or span click, handle all clicks where element has class '.custom-button', handle all clicks where id is not 'toolbar' and also class is not .selection.

The matching occurs by checking the target element and it's parents. This makes it easy to define: don't trigger my 'clickoutside' event when clicking the div with id: 'toolbar' and also don't trigger when any of the child elements of the toolbar is clicked.

See the demo project for examples:

  • click outside
  • bind multiple event at once
  • bind events to html injected in the innerHTML

Stackblitz

Changes

Install the NPM Module

npm install ngx-event-handler --save

Usage

1. Import NgxEventHandlerModule

@NgModule({
    imports: [NgxEventHandlerModule]
  })
  export class AppModule { }

2. Add handleEvent to a htmlElement:

    <div (handleEvent)="deselect()" [exclusion]="['#buttons', '#text-control']">

API:

handleEvent:

Input:

  • exclusion: Array with classes, ids or element names. An event where the target matches one of these elements or it's children won't trigger handleEvent. Example: ['#toolbar, 'button', '.selected']. Default: []
  • inclusion: Array with classes, ids or element names. By default all elements, except the ones excluded are included. When providing a list of inclusion elements, it will only trigger Handle event if the target matches the inclusion array (or children) and doesn't match an element in the exclusion array.
  • target = 'window': the target where it listens to events.
  • event = 'click': the event listened to.
  • keepInclusionListInsideDirective = true; when providing inclusion items, if true; these will only be matched with the directive. if false, it matches all elements on the page
  • maxLevelup = 20; level of parents that are checked to match a inclusion or exclusion.
  • delay = 0; delay before handleEvent is trigged;

Output:

  • handleEvent: EventEmitter: fires when an event (by default click) occurs on a element that matches the provided inclusion/exclusion list. By default; if nothing not inputs are provided on the directive, every click will trigger this event.
  • handleOutsideEvent: EventEmitter: fires when an event (by default click) occurs, but not on a element that matches the provided inclusion/exclusion list.
outsideEvent:

Input:

See handleEvent except include list. Set the directive and event on an element for which you want to have the clickout side. With [excluded] you can add elements that should not trigger the outside click.

Output:

  • outsideEvent: EventEmitter

The function used to create an observable on page events can always be used without the directive.

    createObservableHandler(renderer: Renderer2, target = 'window', event = 'click', delayMs = 0)