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

@prince-obrymec/swipe-events-manager

v1.1.1

Published

A front-end library for managing touch screen events on mobile devices.

Downloads

183

Readme

Swipe Events Manager

Swipe Gestures Swipe Event Swipify Swiper Swipe

This Node Package Manager (NPM) is a Front-End library for managing touch screen events on mobile devices. It provides a support for JavaScript and TypeScript.

Table of contents

  1. Access links
  2. References
  3. Final result
  4. Installation
  5. Get started
  6. Sources code
    1. Clonning
    2. Dependencies installation
    3. Running

Access links

An example of use case of the package is already hosted on web and can be accessible through one of these links below :

  • https://CodiTheck.github.io/swipe_events_manager
  • https://obrymec.github.io/swipe_events_manager
  • https://obrymec.gitlab.io/swipe_events_manager

References

The package sources can be found via one these links below :

  • https://www.npmjs.com/package/@prince-obrymec/swipe-events-manager
  • https://github.com/CodiTheck/swipe_events_manager
  • https://gitlab.com/obrymec/swipe_events_manager

Final result

This is the final result of the project : First Render Second Render

Installation

We can install the module via npm, pnpm or yarn. For npm, use the command line below :

npm install @prince-obrymec/swipe-events-manager --save-dev

For pnpm, use the command line below :

pnpm install @prince-obrymec/swipe-events-manager --save-dev

For yarn, use the command line below :

yarn add @prince-obrymec/swipe-events-manager --save-dev

We can also get the CDN link there :

<script
  src = "https://obrymec.github.io/swipe_events_manager/build/swipe.min.js"
  type = "text/javascript"
></script>
<script
  src = "https://obrymec.github.io/swipe_events_manager/build/swipe.js"
  type = "text/javascript"
></script>

<!--CDN links for CJS support-->
<script
  src = "https://obrymec.github.io/swipe_events_manager/build/cjs/swipe.min.js"
  type = "text/javascript"
></script>
<script
  src = "https://obrymec.github.io/swipe_events_manager/build/cjs/swipe.js"
  type = "text/javascript"
></script>

Get Started

Before listen any swipe event, we must create an object instance of that. Of course, we must also import the module before any usage.

// Package importation.
import {SwipeEventsManager} from "@prince-obrymec/swipe-events-manager";

// We can create a swipe manager with a tag reference.
const swipeManager1 = new SwipeEventsManager(myTagRef);

// We can also create a swipe manager with a tag id, class etc...
const swipeManager2 = new SwipeEventsManager("#my-tag");

Notice that when we creating a swipe manager, we can pass two arguments to that object. The first is the tag where swipe events will be listened and the second is a callback method that is triggered when any swipe event is detected on the selected markup. The callback fetch the swipe direction for you. Only first argument is required when we creating an object instance of a swipe events manager.

Now we can rewrite the code above like this :

// Package importation.
import {SwipeEventsManager} from "@prince-obrymec/swipe-events-manager";

// We can create a swipe manager with a tag
// id, class, etc... and a callback method
// to listen upcoming swipe events on the
// selected tag.
const swipeManager = new SwipeEventsManager(
  "#my-tag", function (direction) {
    /** ... */
  }
);

We can know the swipe's direction thank the fetched direction from our callback. The direction is a constant with the following values :

  • SWIPE_UP : Returned when the swipe direction is to top.
  • SWIPE_RIGHT : Returned when the swipe direction is to right.
  • SWIPE_DOWN : Returned when the swipe direction is to bottom.
  • SWIPE_LEFT : Returned when the swipe direction is to left.

Finally the full source code will be :

// Package importation.
import {
  SwipeEventsManager,
  SwipeEventType
} from "@prince-obrymec/swipe-events-manager";

// We can create a swipe manager with a tag
// id, class, etc... and a callback method
// to listen upcoming swipe events on the
// selected tag.
const swipeManager = new SwipeEventsManager(
  "#my-tag", function (direction) {
    // The selected tag's name.
    const tagName = swipeManager.getTag().tagName;

    // Whether the direction is right.
    if (direction === SwipeEventType.SWIPE_RIGHT) {
      // Makes a warn on the browser.
      window.alert(`SWIPE RIGHT DETECTED: ${tagName}`);
    }

    // Whether the direction is bottom.
    else if (direction === SwipeEventType.SWIPE_DOWN) {
      // Makes a warn on the browser.
      window.alert(`SWIPE DOWN DETECTED: ${tagName}`);
    }

    // Whether the direction is left.
    else if (direction === SwipeEventType.SWIPE_LEFT) {
      // Makes a warn on the browser.
      window.alert(`SWIPE LEFT DETECTED: ${tagName}`);
    }

    // Whether the direction is top.
    else if (direction === SwipeEventType.SWIPE_UP) {
      // Makes a warn on the browser.
      window.alert(`SWIPE UP DETECTED: ${tagName}`);
    }
  }
);

Another way to do that is to use listen method provided by the swipe events manager directly. But use this method if and only if you don't provide a callback when you creating a swipe events manager. The code below show you a use case :

// Package importation.
import {
  SwipeEventsManager,
  SwipeEventType
} from "@prince-obrymec/swipe-events-manager";

// We can create a swipe manager with a tag reference.
const swipeManager = new SwipeEventsManager(myTagRef);

// Listens swipe directions.
swipeManager.listen(function (direction) {
  // Whether the direction is right.
  if (direction === SwipeEventType.SWIPE_RIGHT) {
    // Makes a warn on the browser.
    window.alert("SWIPE RIGHT DETECTED !");
  }

  // Whether the direction is bottom.
  else if (direction === SwipeEventType.SWIPE_DOWN) {
    // Makes a warn on the browser.
    window.alert("SWIPE DOWN DETECTED !");
  }

  // Whether the direction is left.
  else if (direction === SwipeEventType.SWIPE_LEFT) {
    // Makes a warn on the browser.
    window.alert("SWIPE LEFT DETECTED !");
  }

  // Whether the direction is top.
  else if (direction === SwipeEventType.SWIPE_UP) {
    // Makes a warn on the browser.
    window.alert("SWIPE UP DETECTED !");
  }
});

The package offers also some additional methods that are :

// Package importation.
import {SwipeEventsManager} from "@prince-obrymec/swipe-events-manager";

// The old tag reference.
const oldTag = document.querySelector("#old-tag");
// The new tag reference.
const newTag = document.querySelector("#new-tag");

// Creating a new object instance of a swipe events manager.
const swipeManager = new SwipeEventsManager(oldTag);

// Returns the current selected tag reference on the manager.
console.log(swipeManager.getTag());

// Overrides the current selected tag to another. Notice
// that old tag events are destroyed before go to the
// new tag.
swipeManager.setTag(newTag);

// We could also set the active tag by giving the id,
// class, etc... of the new tag directly.
swipeManager.setTag("#new-tag");

// We can destroy all listened swipe events on the active markup.
swipeManager.free();

Sources code

If you want to get package sources code, make sure to have NodeJs already installed in your machine. If it isn't the case, you can install NodeJs through the command lines below :

sudo apt install curl;\
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash;\
source ~/.bashrc;\
nvm --version;\
nvm install --lts;\
node --version;\
npm install yarn --global;\
yarn --version

Cloning

git clone [email protected]:obrymec/swipe_events_manager.git swipe_events_manager/

Dependencies installation

Go to the root folder of the project sources and run :

yarn install

Running

Go to the root folder of the project and run :

yarn start

Then, open your favorite browser and tap on the search bar, the following link :

http://localhost:1234

Enjoy :)