From 2bc8dc531ef31e9ae08daebdd428a98a493c0f9e Mon Sep 17 00:00:00 2001 From: Dragos Dascalita Haut Date: Wed, 17 Jan 2024 09:41:07 -1000 Subject: [PATCH 1/2] feat(sourceselector): highlight clicks on buttons and CTAs --- src/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.js b/src/index.js index e6716f8..a5d9277 100644 --- a/src/index.js +++ b/src/index.js @@ -53,6 +53,11 @@ const sourceselector = (element) => { if (element.getAttribute('data-block-name')) { return `.${element.getAttribute('data-block-name')}`; } + + if (Array.from(element.classList).some((className) => className.match(/button|cta/))) { + return blockName ? `.${blockName} .button` : '.button'; + } + return sourceselector(element.parentElement); }; From 21eaf26050ebec7390d66b62e61a3d8cdd6dc3d1 Mon Sep 17 00:00:00 2001 From: Dragos Dascalita Haut Date: Thu, 18 Jan 2024 10:52:02 -1000 Subject: [PATCH 2/2] fixed the undefined blockName var --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index a5d9277..68b563e 100644 --- a/src/index.js +++ b/src/index.js @@ -44,8 +44,8 @@ const sourceselector = (element) => { formElementSelector = element.tagName === 'INPUT' ? `form input[type='${element.getAttribute('type')}']` : `form ${element.tagName.toLowerCase()}`; } + const blockName = element.closest('.block') ? element.closest('.block').getAttribute('data-block-name') : ''; if (element.id || formElementSelector) { - const blockName = element.closest('.block') ? element.closest('.block').getAttribute('data-block-name') : ''; const id = element.id ? `#${element.id}` : ''; return blockName ? `.${blockName} ${formElementSelector}${id}` : `${formElementSelector}${id}`; }