All Projects → john-doherty → Long Press Event

john-doherty / Long Press Event

Licence: mit
Adds `long-press` event to the DOM in 1k of pure JavaScript

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Long Press Event

tabbis.js
Pure vanilla javascript tabs with nesting
Stars: ✭ 44 (-76.47%)
Mutual labels:  vanilla-javascript, no-dependencies
Medium Zoom
🔎🖼 A JavaScript library for zooming images like Medium
Stars: ✭ 2,799 (+1396.79%)
Mutual labels:  no-dependencies, vanilla-javascript
Nipplejs
🎮 A virtual joystick for touch capable interfaces.
Stars: ✭ 1,313 (+602.14%)
Mutual labels:  dom, vanilla-javascript
js-calendar
The lightest Javascript calendar out there, without any dependency.
Stars: ✭ 37 (-80.21%)
Mutual labels:  vanilla-javascript, no-dependencies
subjx
Drag/Resize/Rotate Javascript library
Stars: ✭ 155 (-17.11%)
Mutual labels:  vanilla-javascript, no-dependencies
Bunny
BunnyJS - Lightweight native (vanilla) JavaScript (JS) and ECMAScript 6 (ES6) browser library, package of small stand-alone components without dependencies: FormData, upload, image preview, HTML5 validation, Autocomplete, Dropdown, Calendar, Datepicker, Ajax, Datatable, Pagination, URL, Template engine, Element positioning, smooth scrolling, routing, inversion of control and more. Simple syntax and architecture. Next generation jQuery and front-end framework. Documentation and examples available.
Stars: ✭ 473 (+152.94%)
Mutual labels:  dom, vanilla-javascript
Mailtoui
A simple way to enhance your mailto links with a convenient user interface.
Stars: ✭ 162 (-13.37%)
Mutual labels:  no-dependencies, vanilla-javascript
Draggable
High performance, fully cross browser, full featured drag and drop in a tiny (2k gzipped), dependency-free package
Stars: ✭ 160 (-14.44%)
Mutual labels:  vanilla-javascript
Preact Markup
⚡️ Render HTML5 as VDOM, with Components as Custom Elements!
Stars: ✭ 167 (-10.7%)
Mutual labels:  dom
Preact Portal
📡 Render Preact components in (a) SPACE 🌌 🌠
Stars: ✭ 160 (-14.44%)
Mutual labels:  dom
Expected Lite
expected lite - Expected objects in C++11 and later in a single-file header-only library
Stars: ✭ 158 (-15.51%)
Mutual labels:  no-dependencies
Rangeslider
Simple, small and fast vanilla JavaScript polyfill for the HTML5 `<input type="range">` slider element.
Stars: ✭ 161 (-13.9%)
Mutual labels:  vanilla-javascript
Amplesdk
Ample SDK - JavaScript UI Framework
Stars: ✭ 169 (-9.63%)
Mutual labels:  dom
Datepickk
Simple, beautiful and powerful datepicker!
Stars: ✭ 160 (-14.44%)
Mutual labels:  vanilla-javascript
Jscolor
JavaScript color picker with opacity (alpha channel) and customizable palette. Single file of plain JS with no dependencies.
Stars: ✭ 182 (-2.67%)
Mutual labels:  vanilla-javascript
Object Visualizer
Vue JSON inspector with Chrome-like theme.
Stars: ✭ 159 (-14.97%)
Mutual labels:  dom
Online Privacy Test Resource List
Privacy Online Test and Resource Compendium (POTARC) 🕵🏻
Stars: ✭ 185 (-1.07%)
Mutual labels:  dom
Domxssscanner
DOMXSS Scanner is an online tool to scan source code for DOM based XSS vulnerabilities
Stars: ✭ 181 (-3.21%)
Mutual labels:  dom
Coingecko Api
A Node.js wrapper for the CoinGecko API with no dependencies.
Stars: ✭ 159 (-14.97%)
Mutual labels:  no-dependencies
Volt Bootstrap 5 Dashboard
Free and open source Bootstrap 5 Admin Dashboard Template with vanilla Javascript
Stars: ✭ 2,252 (+1104.28%)
Mutual labels:  vanilla-javascript

long-press-event

Shippable branch npm

A 1k script that adds a long-press event to the DOM using CustomEvent and pure JavaScript. Works in IE9+, Chrome, Firefox, Safari as well as popular mobile browsers including Cordova (Phone Gap) applications.

Defaults to 1.5 seconds but can be overridden by adding a data-long-press-delay attribute to an element.

Try the demo

Usage

Add the long-press-event.min.js file to your page and then listen for the event.

To listen for a long-press on any HTML element:

// the event bubbles, so you can listen at the root level
document.addEventListener('long-press', function(e) {
  console.log(e.target);
});

To listen for a long-press on a specific HTML element:

// grab the element
var el = document.getElementById('idOfElement');

// listen for the long-press event
el.addEventListener('long-press', function(e) {

  // stop the event from bubbling up
  e.preventDefault()

  console.log(e.target);
});

To set a custom delay and listen for a long-press:

<html>
    <head>
        <script src="long-press-event.js"></script>
        <script>
            document.addEventListener('long-press', function(e) {
                console.log(e.target);
            });
        </script>
    </head>
    <body>
        <div data-long-press-delay="500">Press and hold me for .5s</div>
    </body>
</html>

To set a default application wide data-long-press-delay, set attribute on a parent/topmost element:

<html data-long-press-delay="1500">
    <head>...</head>
    <body>...</body>
</html>

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request

Development

The project includes everything needed to tweak, including a node webserver. Run the following, then visit http://localhost:8080 in your browser.

You can test on a desktop using Device Mode in Google Chrome.

git clone https://github.com/john-doherty/long-press-event
cd long-press
npm install
npm start

Update .min files

To create a new version of the minified long-press-event.min.js file from source, tweak the version number in package.json and run the following:

npm run build

Star the repo

If you find this useful, please star the repo. It helps me priorities which open source projects issues I should resolve first.

History

For change-log, check releases.

License

Licensed under MIT License © John Doherty

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].