Skip to content

wesleytodd/intercept-link-clicks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intercept Link Clicks

NPM Version NPM Downloads js-standard-style

This module is mainly to intercept applicable link clicks for a single-page app router. The options are geared toward intercepting internal links that should change the page state in some way.

Install

$ npm install --save intercept-link-clicks

Usage

const interceptClicks = require('intercept-link-clicks')

interceptClicks((e, el) => {
  // Change the page state here
  // `e` is the event object
  // `el` is the clicked link, which might be different from `e.target`
});

A more advanced usage is to pass options and an optional element:

interceptClicks(document.querySelector('.my-el'), {
  // 
  // Leave all these as defauts:
  //
  // modifierKeys: true
  // download: true
  // target: true
  // hash: true
  // mailTo: true

  // Support events crossing a shadow dom boundry,
  // required for capturing link clicks inside web components
  // shadowDom: true 

  // Intercept all clicks, even ones that are not same origin
  sameOrigin: false
}, (e, el) => {
  // Change the page state here
});

About

Intercept link clicks and call a callback

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published