New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

clicked

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clicked

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

  • 4.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
60
decreased by-15.49%
Maintainers
1
Weekly downloads
 
Created
Source

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

nametypedefaultdescription
elementHTMLElement or stringelement or querySelector entry (e.g., #id-name or .class-name)
callbackClickedCallbackcallback called after clicked
[options]objectoptional options
[options].clickedbooleantruedispatch event for clicked
[options].thresholdnumber10threshold of movement to cancel all events
[options.mouse]boolean or 'left' or 'right' 'middle' or 'left-right' or 'left-middle' or 'right-middle'truewhether to listen for mouse events; can also be used to set which mouse buttons are active
[options.touch]boolean or number1whether to listen for touch events; can also be used to set the number of touch points to accept
[options.doubleClick]booleanfalsedispatch events for double click
[options.doubleClickTime]]number500wait time in millseconds for double click
[options.longClick]]booleanfalseenable watcher for long click
[options.longClickTime]]boolean500wait time for long click
[options.clickDown]booleandispatch event for click down (ie, after touchstart or mousedown callback will be called with type 'click-down')
[options.capture]booleanfalseevents 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

nametypedescription
eventMouseEvent or TouchEventmouse 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

Keywords

FAQs

Package last updated on 16 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc