New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

clickout

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clickout

Register clickout event in javascript

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

GitHub release npm

ClickOut

Register clickout event in javascript

npm install clickout --save

Demo

  • RawGit

Import

import ClickOut from 'clickout';

API

export default class ClickOut {
    // Emit a 'clickout' event each time you click outside of a specific HTMLElement
    static bindCustomEvent(element: string | HTMLElement): destroyClickOut;
    
    // Trigger a function only when you click outside of a specific HTMLElement 
    static bind(element: string | HTMLElement, onClickOut: onCLickOut): destroyClickOut;
    
    // Destroy all listeners for emit/trigger clickout event/function
    static destroy(element: string | HTMLElement): void;
}

Examples

ClickOut.bindCustomEvent(element)

CustomEvent is supported in all major browsers. If you need support for old browsers check this polyfill.

const element = document.querySelector('#myElement');

// Emit 'clickout' event when you click outside of element
ClickOut.bindCustomEvent(element);

// Listen on 'clickout' event emitted from the element
element.addEventListener('clickout', (e) => {
  console.log(`You clicked an element outside of ${e.target}`);
})

// elsewhere on your code
element.addEventListener('clickout', (e) => {
  console.log(`I'm triggered too on clickout ${e.target}!`)
})

ClickOut.bind(element, onClickOut)

const element = document.querySelector('#myElement');

// Trigger a function only when you click outside of a specific HTMLElement
ClickOut.bind(element, (e) => {
  console.log(`You clicked ${e.target} and it's out of ${element}`)
});

ClickOut.destroy(element)

Destroy bindCustomEvent

const element = document.querySelector('#myElement');

ClickOut.bindCustomEvent(element);

element.addEventListener('clickout', (e) => {
  console.log(`You clicked an element outside of ${e.target}`);
});

ClickOut.destroy(element);

/**
 *  ------------------------------
 *  Is the same as:
 */

const destroyClickOutElement = ClickOut.bindCustomEvent(element);

element.addEventListener('clickout', (e) => {
  console.log(`You clicked an element outside of ${e.target}`);
});

destroyClickOutElement();

Destroy bind function

const element = document.querySelector('#myElement');

ClickOut.bind(element, (e) => {
  console.log(`You clicked ${e.target} and it's out of ${element}`)
});

ClickOut.destroy(element);

/**
 *  ------------------------------
 *  Is the same as:
 */

const destroyClickOutElement = ClickOut.bind(element, (e) => {
  console.log(`You clicked ${e.target} and it's out of ${element}`)
});

destroyClickOutElement();

Keywords

javascript

FAQs

Package last updated on 31 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts