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

clicked

v4.0.3

Published

Configurable vanilla handler for clicks, double-clicks, and/or long-clicks that works with both mouse and touch

Downloads

869

Readme

clicked

Configurable vanilla handler for clicks, double-clicks, and/or long-clicks that works for both mouse and touch

changes in version 4

  • ported code to typescript
  • added options.mouse to select which mouse buttons are active (if any)
  • added options.touch to select whether touch is active and how many touch points are allowed
  • removed rollup and compiled using tsc
  • improved demo

usage

import { clicked } from 'clicked'

or

const clicked = require('clicked').clicked

demo

https://davidfig.github.io/clicked/

rationale

I wanted to create a vanilla javascript way to handle mouse and touch clicks, double-clicks, and long-clicks.

example

import { clicked } from 'clicked'

function handleClick()
{
   console.log('I was clicked.')
}
const div = document.getElementById('clickme')
const c = clicked(div, handleClick, { threshold: 15 })

// change callback
c.callback = () => console.log('different clicker')

// destroy
c.destroy()

// using built-in querySelector
clicked('#clickme', handleClick2)

// support for all types of clicks
function handleAllClicks(e) {
    switch (e.type)
    {
        case 'clicked': ...
        case 'double-clicked': ...
        case 'long-clicked': ...
    }
    // view UIEvent that caused callback
    console.log(e.event)
}
clicked('#clickme', handleAllClicks, { doubleClick: true, longClick: true })

API

clicked(element, callback, options) : Clicked

creates Clicked object for element

|name|type|default|description |---|---|---|---| |element|HTMLElement or string||element or querySelector entry (e.g., #id-name or .class-name)| |callback|ClickedCallback||callback called after clicked |[options]|object||optional options| |[options].clicked|boolean|true|dispatch event for clicked |[options].threshold|number|10|threshold of movement to cancel all events |[options.mouse]|boolean or 'left' or 'right' 'middle' or 'left-right' or 'left-middle' or 'right-middle'|true|whether to listen for mouse events; can also be used to set which mouse buttons are active |[options.touch]|boolean or number|1|whether to listen for touch events; can also be used to set the number of touch points to accept |[options.doubleClick]|boolean|false|dispatch events for double click |[options.doubleClickTime]]|number|500|wait time in millseconds for double click |[options.longClick]]|boolean|false|enable watcher for long click |[options.longClickTime]]|boolean|500|wait time for long click |[options.clickDown]|boolean|dispatch event for click down (ie, after touchstart or mousedown callback will be called with type 'click-down') |[options.capture]|boolean|false|events will be dispatched to this registered listener before being dispatched to any EventTarget beneath it in the DOM tree

Clicked

returned by clicked(...)

Clicked.destroy()

removes event listeners on element

Clicked.callback (function): ClickedCallback

|name|type|description |---|---|---| |event|MouseEvent or TouchEvent|mouse or touch event that triggered callback| |type|'clicked' or 'double-clicked' or 'long-clicked' or 'click-down'|type of click|

Clicked.cancel()

cancel any outstanding events

demo

yarn demo

Open browser to https://localhost:1234/

license

MIT License
(c) 2020 YOPEY YOPEY LLC by David Figatner