JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 215
  • Score
    100M100P100Q71702F
  • License MIT

Javascript: create click event for both mouse and touch

Package Exports

  • clicked

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (clicked) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

clicked

Create click event for both mouse and touch

rationale

To create a simple way to handle mouse and touch click events without any external dependencies.

example

var clicked = require('clicked')

function handleClick()
{
    console.log('I was clicked.');
}

var div = document.getElementById('clickme');
clicked(div, handleClick, {thresshold: 15});

API

/**
 * Javascript: create click event for both mouse and touch
 * @example
 *
 * const clicked = require('clicked')
 *
 * function handleClick()
 * {
 *    console.log('I was clicked.')
 * }
 *
 * const div = document.getElementById('clickme')
 * const c = clicked(div, handleClick, {thresshold: 15})
 *
 * // change callback
 * c.callback = () => console.log('different clicker')
 *
 */

/**
 * @param {HTMLElement} element
 * @param {function} callback called after click: callback(event, options.args)
 * @param {object} [options]
 * @param {number} [options.thresshold=10] if touch moves threshhold-pixels then the touch-click is cancelled
 * @param {*} [options.args] arguments for callback function
 * @returns {Clicked}
 */
function clicked(element, callback, options)

/**
 * removes event listeners added by Clicked
 */
Clicked.destroy()

license

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