From 9a6f39af4ad18bee7774e241a56cffa7505f8c7a Mon Sep 17 00:00:00 2001 From: Nikita Karamov Date: Thu, 10 Feb 2022 22:19:03 +0100 Subject: [PATCH] Move button listener outside the loop --- src/shareon.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/shareon.js b/src/shareon.js index 668b0df..ef23e67 100644 --- a/src/shareon.js +++ b/src/shareon.js @@ -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}` : ''}`, }; +const openUrl = (buttonUrl) => () => { + window.open(buttonUrl, "_blank", "noopener,noreferrer"); +}; + const initializeShareon = () => { const shareonContainers = document.getElementsByClassName("shareon"); @@ -81,11 +85,7 @@ const initializeShareon = () => { child.setAttribute("rel", "noopener noreferrer"); child.setAttribute("target", "_blank"); } else { - const getButtonListener = (buttonUrl) => () => { - window.open(buttonUrl, "_blank", "noopener,noreferrer"); - }; - - child.addEventListener("click", getButtonListener(url)); + child.addEventListener("click", openUrl(url)); } break; // once a network is detected we don't want to check further