Move button listener outside the loop

pull/45/head
Nikita Karamov 2022-02-10 22:19:03 +01:00
parent bea94e545d
commit 9a6f39af4a
No known key found for this signature in database
GPG Key ID: 3C8E688C96EEB9C9
1 changed files with 5 additions and 5 deletions

View File

@ -30,6 +30,10 @@ const urlBuilderMap = {
whatsapp: (d) => `https://wa.me/?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}`, whatsapp: (d) => `https://wa.me/?text=${d.title}%0D%0A${d.url}${d.text ? `%0D%0A%0D%0A${d.text}` : ''}`,
}; };
const openUrl = (buttonUrl) => () => {
window.open(buttonUrl, "_blank", "noopener,noreferrer");
};
const initializeShareon = () => { const initializeShareon = () => {
const shareonContainers = document.getElementsByClassName("shareon"); const shareonContainers = document.getElementsByClassName("shareon");
@ -81,11 +85,7 @@ const initializeShareon = () => {
child.setAttribute("rel", "noopener noreferrer"); child.setAttribute("rel", "noopener noreferrer");
child.setAttribute("target", "_blank"); child.setAttribute("target", "_blank");
} else { } else {
const getButtonListener = (buttonUrl) => () => { child.addEventListener("click", openUrl(url));
window.open(buttonUrl, "_blank", "noopener,noreferrer");
};
child.addEventListener("click", getButtonListener(url));
} }
break; // once a network is detected we don't want to check further break; // once a network is detected we don't want to check further