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

longpressbutton

v1.1.0

Published

A lightweight Long Press Button Library with static html support

Downloads

17

Readme

DeepScan grade CodeFactor

Long Press Button Module

A lightwight Long Press Button Module that let you turn everything on your Homepage into an press & hold button.

INSTALL

For the use as module you can import this module via npm.

npm install longpressbutton

DEMO

You can see this module in action on https://lucas-kirsche.de/longpressbutton/demo

USAGE

Use this module in 3 different ways.

simple

Just import the minified es5 library into you're HTML document, and every element with a parameter set to data-longpress=time-in-ms will fire a "longpress"-event after clicking it the given amount of time.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="./longpressbutton/dist/longpressbutton-min.js" defer></script>
    <title>EXAMPLE</title>
</head>
<body>
    <button data-longpress="2000">PRESS 2s</button>
</body>
</html>

Access the event by either set the onclick event directly in the html

<button data-longpress="2000" onclick="console.log('clicked!')">PRESS 2s</button>

or listen to the longpress-event in a javascript.

document.querySelector('button').addEventListener('longpress', (event) => { console.log('clicked!')});

module

If you want to pack the module with your own project, you have to import this module and call lpButton.init(). This function searches the whole document for elements with a data-longpress=time-in-ms attribute.

import {lpButton} from 'longpressbutton';

lpButton.init();

For a specific search scope, just pass the top element as argument to the init function.

lpButton.init(HTMLElement);

module with dynamic DOM-Elements

In case you have dynamic elements which are created by your script use this module class directly.

import {lpButton} from 'longpressbutton';

const customElement = document.createElement('button');

customElement.addEventListener('longpress', (event) => { cosole.log(event) });

lpButton.newButton(customElement, 1000); //returns the customElement

document.append(customElement);

Just make sure to link the longpressbutton.css.

CSS

Per default this module comes with a animation while pressing. You can specify your own stylings by overriding the classes.

Every longpress button element has a .lpb-button class and gets a child element with a .lpb-loader class. This element gets a .lpb-loading class while pressing and a .lpb-loaded class on timer expiration until a css keyframe animation ends.