capture-anchor-click

0.0.7 • Public • Published

capture-anchor-click

window click trigger for HTMLAnchorElement

You can use the capture trigger to dynamically reload the web-page, or individual web-page elements

CaptureAnchorClick object

Name Description
isBlur boolean call .blur() after prevent, default = true
blurDurationTimeout int Timeout for blur, default = 1
onTest set function(link) The function is called before dispatch all events
add function(callback) Add click event function
remove function(callback) Remove click event function
removeAll function(callback) Remove all click event functions

Example

import CaptureAnchorClick from "capture-anchor-click";
 
CaptureAnchorClick.add(evn => {
    
    let target = evn.target;
    let href = evn.detail.link;
    
    // <a href="#open-window" data-name="login">...</a>
    if( href === "#open-window" ) {
        let myWin = target.getAttribute("data-name"); // or target.dataset.name
        // todo your action 
    }
    
    // <a href="/page/name.html">...</a>
    else if( /^\/page\/(.*?)\.html/.test(href) ) {
        let page = RegExp.$1;
        // todo your action for dynamic reload page
    }
    
    // use default event click
    else {
        return void 0
    }
    
    // trigger will be prevented
    evn.preventDefault();
})

Package Sidebar

Install

npm i capture-anchor-click

Weekly Downloads

1

Version

0.0.7

License

MIT

Last publish

Collaborators

  • rozaverta