
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
proxyclickevent
Advanced tools
document代理点击事件的前提下阻止事件冒泡(Support to prevent bubbling in the case of html tag event proxy)
BSD 3-Clause License
npm i proxyclickevent
<div class="a" clickFn="fna">
<div class="b" clickFn="fnb">
<div class="e" clickFn="fne">点击<b>捣蛋鬼E</b>,会执行
<B>e,b,a</B>函数
</div>
<div class="c" clickFn="fnc">点击<b>捣蛋鬼C,stop</b>,执行执行<b>c</b>函数</div>
<div class="f" clickFn="fnf">点击<b>捣蛋鬼F</b>,会执行<b>f,b,a</b>函数</div>
</div>
</div>
<script src="yourPath/ProxyClickEvent.js"></script>
var funs = {
fna: function() {
console.log("点击a")
},
fnb: function() {
console.log("点击b")
},
fnc: function(e) {
//阻止事件冒泡
e.__stop = true;
console.log("点击c")
},
fnd: function() {
console.log("点击d")
},
fne: function() {
console.log("点击e")
},
fnf: function() {
console.log("点击f")
}
}
let proxyEvent = new window.ProxyClickEvent();
//如果出现父子标签关系有变化时候,必须clear后重新扫描dom,重新add
proxyEvent.clear();
let clickDoms = document.querySelectorAll("[clickFn]");
for (let i = 0; i < clickDoms.length; i++) {
let dom = clickDoms[i];
let fnStr = clickDoms[i].getAttribute("clickFn");
proxyEvent.add(dom, funs[fnStr])
}
import ProxyClickEvent from "proxyclickevent"
name | desc |
---|---|
new ProxyClickEvent | 接受一个代理点击的dom对象,如果不填写默认是document.body |
add | 接受2个参数,一个是dom,一个是对应的函数,目前不支持同一个dom被add多次,如果重复直接警告,拒绝本次add |
remove | 接受2个参数,一个是dom,一个是对应的函数 |
clear | 清空内部数组 |
destroy | 销毁document的点击事件,已经数组和检测dom是否存在的定时器,组件销毁前一定要执行它 |
__stop
并赋值为true即可FAQs
document代理点击事件的前提下阻止事件冒泡(Support to prevent bubbling in the case of html tag event proxy)
The npm package proxyclickevent receives a total of 1 weekly downloads. As such, proxyclickevent popularity was classified as not popular.
We found that proxyclickevent demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.