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

swiftclick

v2.1.1

Published

Eliminates the 300ms click event delay on touch devices that support orientation change

Downloads

549

Readme

SwiftClick

SwiftClick is a library created to eliminate the 300ms click event delay on touch devices that support orientation change and is designed to be super lightweight.

Teeny-tiny

~1KB minified & gzipped :-)

Usage

You can install SwiftClick using npm:

npm i swiftclick --save

You can install via Bower instead, if that's your thing:

bower install swiftclick

You can also use CDNJS: https://cdnjs.com/libraries/swiftclick

Otherwise, you can grab either the minified, or non-minified source from Github.

Include SwiftClick in your application

If using CommonJS then simply require SwiftClick as per usual:

var SwiftClick = require('swiftclick');

Otherwise, use a script tag:

<script type="application/javascript" src="path/to/swiftclick.min.js"></script>

Setup SwiftClick

Setting up SwiftClick is a very easy process, which mirrors that of FastClick in that instances must be attached to a context element. Touch events from all elements within the context element are automatically captured and converted to click events when necessary, minus the delay.

Start by creating a reference to a new instance of SwiftClick using the 'attach' helper method and attach it to a context element. Attaching to document.body is easiest if you only need a single instance of SwiftClick:

var swiftclick = SwiftClick.attach(document.body);

If necessary, multiple instances of SwiftClick can be created for specific context elements which, although not really necessary in most cases, can sometimes be useful for optimising applications with a large amount of HTML:

var navigationSwiftClick = SwiftClick.attach(someNavElement);
var uiSwiftClick = SwiftClick.attach(someOtherElement);

Default Elements

Once attached, by default SwiftClick will track events originating from the following element types:

  • <a>
  • <div>
  • <span>
  • <button>

Adding non-default element types

If necessary you can make SwiftClick track events originating from additional element types by adding an array of node names. This requires a reference to an instance of SwiftClick:

var swiftclick = SwiftClick.attach(someElement);
swiftclick.addNodeNamesToTrack(['p', 'h1', 'nav']);

Replacing all stored node names to track

var swiftclick = SwiftClick.attach(someElement);
swiftclick.replaceNodeNamesToTrack(['a', 'div', 'h1']);

Doing this will remove all default node names, as well as any that have been added, and replace them with the node names within the array that is passed in, resulting in only the new node names being tracked.

Updating the maximum drift distance

It is possible to set the maximum pixel distance that a touchmove can travel before SwiftClick no longer considers it a click:

var swiftclick = SwiftClick.attach(someElement);
swiftclick.setMaxTouchDrift(10);

The default value is 16 and the minimum value is 4. A value between 10 and 30 is recommended.

Ignoring swift clicks on specific elements

The parsing of CSS class names is disabled by default to improve performance, so in order to use this feature, it must be explicity switched on:

var swiftclick = SwiftClick.attach(document.body);
swiftclick.useCssParser(true);

Adding the swiftclick-ignore class to an element will disable swift clicks on the element and all off its children:

<div class="swiftclick-ignore">
    This element and its children will not get swift clicks.
</div>

Enabling swift clicks on specific elements within an ignored element

Turn on CSS class name parsing:

var swiftclick = SwiftClick.attach(document.body);
swiftclick.useCssParser(true);

Within any element containing the swiftclick-ignore class, swift clicks can be enabled for specific child elements by adding the swiftclick-force class:

<div class="swiftclick-ignore">
    <button>First</button>
    <button class="swiftclick-force">Second</button>
</div>

In this example, the first button will not get swift clicks, but the second button will.

Automatically disabled when not needed

SwiftClick only intercepts events for touch devices that support orientation change, otherwise it just sits there looking pretty.

About the Project

SwiftClick was developed and is currently maintained by Ivan Hayes.