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

teeny-tap

v0.2.0

Published

Listen for both clicks and click-like touches (not scrolls or drags)

Downloads

102,899

Readme

teeny-tap

Status: Experimental, Under Active Development

Listen for both clicks and click-like touches (not scrolls or drags).

This library is very small and simple and focused, without any dependencies. It is not a touch gesture library or a complete fastclick-style solution. Plenty of similar libraries exist, but none of them seemed exactly right for my simple needs. For more about the purpose of the library, read "Why?".

This library is heavily inspired by tap.js, which is no longer maintained.

Check out the demo.

(If the demo works on your phone, would you mind tweeting me your specs, @davidtheclark? That way I can list the devices where we know it works. And of course let me know if you find any bugs!)

Installation

npm install teeny-tap

You will need to be compiling CommonJS modules (browserify or webpack).

Browser Support

IE9+ and everything help, I hope. Testing underway. (If you can help out by trying the demo on your mobile device, please do!)

Usage

var createTapListener = require('teeny-tap');

var docTapListener = createTapListener(document.documentElement, function(e) {
  console.log('A tap happened!');
});

// ...
docTapListener.remove();

That's it. Very simple. You create and remove listeners.

API

var tapListenerInstance = createTapListener(element, callback[, useCapture])

Adds a tap listener on element, using addEventListener(). When there's a tap, callback is invoked with the relevant event as its argument (either a click or touchend event).

Returns an object with a remove function, for removing the listener.

tapListenerInstance.remove()

Remove the listener that you added when you created tapListenerInstance.

Why?

For react-aria-menubutton, I need to close an open menu when the user taps/clicks outside of it.

The click event wasn't reliable: mobile Safari screws it up. So I needed to distinguish, on touch devices, between touches that are scrolling or dragging and touches that are clicking, in situations where the regular click event doesn't work. Existing solutions that I found weren't satisfactory for a few reasons:

  • jQuery or other dependencies I didn't want or need.

  • Many just threw in a touchstart or touchend listener, in addition to the click; but that alone won't distinguish between tapping and scrolling/dragging, so it's insufficient. The menu might close when you, say, scroll down in order to see more of it. Egad!

  • One solution to the detect-clicks-outside-an-element problem is to add an underlay that covers the page, beneath the element, and listen for clicks on that. However, this prevents the click from getting through and actually doing something; so if I click a link outside the open menu, that click only closes the menu, and I have to click again to go where I wanted to go. Non-optimal.

  • A number of solutions just use click events, which won't work on most browsers on most iPhones and iPads, due to mobile Safari's unique and unpleasant handling of click events.

  • Some went the other way, and had more fine-tuning than I want or need.

tap.js pretty much provided exactly what I needed, but that library is no longer maintained so I made this one to carry the torch, to fill the need.

But know that I do not like that this exists, do not want it to need to exist. If you know of a way to accomplish the same goal without this library, please let me know!