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

propagating-hammerjs

v3.0.0

Published

Extend hammer.js with event propagation

Downloads

972,002

Readme

propagating-hammerjs

Extend hammer.js (v2) with event propagation.

We use the @egjs/hammerjs fork because hammer.js is not maintained anymore.

Features

  • Events emitted by hammer will propagate in order from child to parent elements.
  • Events are extended with a function event.stopPropagation() to stop propagation to parent elements.
  • Events are extended with a property event.firstTarget containing the element where a gesture started.
  • Supports changing and rearranging the HTML DOM on the fly.
  • Load via commonjs, AMD, or as a plain old JavaScript file.

Install

npm install @egjs/hammerjs propagating-hammerjs

Load

Browser

<!DOCTYPE html>
<html>
<head>
  <script src="https://unpkg.com/@egjs/hammerjs@latest/dist/hammer.js"></script>
  <script src="https://unpkg.com/propagating-hammerjs@latest/propagating.js"></script>
  <script>
    function init() {
      var hammer = propagating(new Hammer(element));
    }
  </script>
</head>
<body>
</body>
</html>

Commonjs (e.g. Node.js, Browserify)

var Hammer = require('@egjs/hammerjs');
var propagating = require('propagating-hammerjs');

function init() {
  var hammer = propagating(new Hammer(element));
}

ESM (e.g. ES6, typescript)

import Hammer from '@egjs/hammerjs';
import propagating from 'propagating-hammerjs';

function init() {
  const hammer = propagating(new Hammer(element));
}

Use

To extend individual hammer.js instances with event propagation:

var hammer = propagating(new Hammer(element));

To extend the global hammer.js constructor

Hammer = propagating(Hammer);

Examples

Here a basic usage example. More examples are available in the folder /examples.

<!DOCTYPE html>
<html>
<head>
  <script src="node_modules/@egjs/hammerjs/dist/hammer.js"></script>
  <script src="node_muludes/propagating-hammerjs/propagating.js"></script>
  <style>
    div     {border: 1px solid black;}
    #parent {width: 400px; height: 400px; background: lightgreen;}
    #child  {width: 200px; height: 200px; background: yellow; margin: 10px;}
  </style>
</head>
<body>

<div id="parent">
  parent
  <div id="child">
    child
  </div>
</div>

<script>
  var parent = document.getElementById('parent');
  var hammer1 = propagating(new Hammer(parent))
      .on('tap', function (event) {
        alert('tap on parent');
      });

  var child = document.getElementById('child');
  var hammer2 = propagating(new Hammer(child))
      .on('tap', function (event) {
        alert('tap on child');

        // stop propagation from child to parent
        event.stopPropagation();
      });
</script>
</body>
</html>

API

Construction:

propagating(hammer: Hammer.Manager, options?: {
  preventDefault?: true | 'mouse' | 'touch' | 'pen'
}): Hammer.Manager

parameters

  • hammer: Hammer.Manager An hammer instance or the global hammer constructor.

  • options: Object An optional object with options. Available options:

    • preventDefault: true | 'mouse' | 'touch' | 'pen'. Optional. Enforce preventing the default browser behavior. Cannot be set to false.

returns

Returns the same hammer instance with extended functionality.

events

The emitted hammer.js events are extended with:

  • event.stopPropagation()

    If called, the event will not further propagate the elements parents.

  • event.firstTarget

    Contains the HTML element where a gesture started (where as event.target contains the element where the pointer is right now).

Develop

To generate the UMD bundle for commonjs and browser, run:

npm run build

License

MIT