Coder Social home page Coder Social logo

ivent's Introduction

ivent

ivent.min.js

Helper functions for browser event listener

Table of Contents

Import ivent

Use one of the following examples to import script.

ESM

We provide a version of ivent built as ESM (ivent.esm.js and ivent.esm.min.js) which allows you to use ivent as a module in your browser, if your targeted browsers support it.

<script type="module">
  import { on, off } from "ivent.esm.min.js";
</script>

ESM CDN

<script type="module">
  import { on, off } from "https://cdn.jsdelivr.net/npm/[email protected]/+esm";
</script>

UMD

ivent may be also used in a traditional way by including script in HTML and using library by accessing window.ivent.

<script src="ivent.min.js"></script>

UMD CDN

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ivent.min.js"></script>

CJS (Bundlers like Webpack)

Install ivent as a Node.js module using npm

npm install ivent

Import ivent by adding this line to your app's entry point (usually index.js or app.js):

import { on, off } from 'ivent';

Methods

on

one

DOM event listener:

import { on } from 'ivent';

on(document, 'click', (e) => {
  console.log('clicked', e);
});

Event listener with delegated target:

import { on } from 'ivent';

on(document, 'click', '.custom-element-selector', (e) => {
  console.log('clicked', e);
});

Custom event listener with namespace:

import { on } from 'ivent';

on(document, 'the-custom-event.with-namespace', (e) => {
  console.log('clicked', e);
});

off

Remove DOM event listener:

import { on } from 'ivent';

on(document, 'click', (e) => {
  console.log('clicked', e);
});

off(document, 'click');

Remove DOM event listener by namespace:

import { on } from 'ivent';

on(document, 'click.my-namespace', (e) => {
  console.log('clicked', e);
});

off(document, '.my-namespace');

trigger

Trigger event:

import { trigger } from 'ivent';

trigger(document, 'click');

Custom Events

ready

Create ready event which work in the same way as DOMContentLoaded with additional check for dom loaded. For example, if dom is already loaded, the ready event callback will be fired immediately.

Example:

import { on } from 'ivent';

on(document, 'ready', (e) => {
  console.log('dom ready', e);
});

mouseenter

mouseleave

pointerenter

pointerleave

Create mouseenter / mouseleave events using mouseover / mouseout so that event delegation works properly. Do the same for pointerenter / pointerleave and pointerover / pointerout.

Example:

import { on } from 'ivent';

on(document, 'mouseenter', 'button', (e) => {
  console.log('button mouseenter event created using mouseover', e);
});

For Developers

Installation

  • Run npm install in the command line. Or if you need to update some dependencies, run npm update

Building

  • npm run build to run build

Linting

  • npm run js-lint to show eslint errors
  • npm run js-lint-fix to automatically fix some of the eslint errors

ivent's People

Contributors

nk-o avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.