delegate
delegate copied to clipboard
to ensure element eventListener bound once
to ensure element eventListener bound once
When a clipboard button is in loop, click eventListener will be bound mutiple times and onsuccess event be triggered multiple times.
This doesn't work for two reasons:
addEventListeneractually already only attaches alisteneronly once, automatically avoiding identicaltype/listeners/optionsbeing repeatedly attachedlistenerFnis generated on the fly so it's always different from the previouslyadded one, so you can'tremoveit
You can test the first reason by running this code in your browser and then clicking anywhere: the log only shows once because the listener (console.log) is only added once.
document.addEventListener('click', console.log);
document.addEventListener('click', console.log);
I took care of this in delegate-it. I forked delegate because old PRs weren't merged and took the opportunity to modernize it.