intercept-link-clicks

1.1.0 • Public • Published

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
});

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i intercept-link-clicks

    Weekly Downloads

    25

    Version

    1.1.0

    License

    ISC

    Unpacked Size

    9.71 kB

    Total Files

    5

    Last publish

    Collaborators

    • wesleytodd