@@ -274,10 +274,10 @@ journeys_utils.addHtmlToIframe = function(iframe, html, userAgent) {
274274 bodyClass = 'branch-banner-other' ;
275275 }
276276 var iframedoc = iframe . contentDocument || iframe . contentWindow . document ;
277- iframedoc . head = iframedoc . createElement ( 'head' ) ;
278- iframedoc . body = iframedoc . createElement ( 'body' ) ;
277+ // iframedoc.head = iframedoc.createElement('head');
278+ // iframedoc.body = iframedoc.createElement('body');
279279 iframedoc . body . innerHTML = html ;
280- iframedoc . body . className = bodyClass ;
280+ // iframedoc.body.className = bodyClass;
281281 var metaTag = iframedoc . querySelector ( 'meta[name="accessibility"]' ) ;
282282 if ( metaTag && metaTag . content === 'wcag' ) {
283283 var scriptTag = iframedoc . createElement ( 'script' ) ;
@@ -287,39 +287,56 @@ journeys_utils.addHtmlToIframe = function(iframe, html, userAgent) {
287287 var modal = document.getElementById('branch-banner');
288288 var focusableContent = modal.querySelectorAll(focusableElements);
289289 var focusElementIdx = 0;
290+ console.log("yogaba");
290291
291- function handleTabKey (e) {
292+ function handleKeyboardNavigation (e) {
292293 var isTabPressed = e.key === 'Tab' || e.keyCode === 9;
293-
294- if (!isTabPressed) {
295- return;
296- }
294+ var isEnterPressed = e.key === 'Enter' || e.keyCode === 13;
297295
298- console.log('tab pressed');
299-
300- if (e.shiftKey) {
301- if (focusElementIdx <= 0) {
302- focusElementIdx = focusableContent.length - 1;
296+ // Handle Tab key for focus navigation
297+ if (isTabPressed) {
298+ console.log("tab pressed");
299+ if (e.shiftKey) {
300+ if (focusElementIdx <= 0) {
301+ focusElementIdx = focusableContent.length - 1;
302+ } else {
303+ focusElementIdx = focusElementIdx - 1;
304+ }
303305 } else {
304- focusElementIdx = focusElementIdx - 1;
306+ if (focusElementIdx >= focusableContent.length - 1) {
307+ focusElementIdx = 0;
308+ } else {
309+ focusElementIdx = focusElementIdx + 1;
310+ }
305311 }
306- } else {
307- if (focusElementIdx >= focusableContent.length - 1) {
308- focusElementIdx = 0;
309- } else {
310- focusElementIdx = focusElementIdx + 1;
312+
313+ focusableContent[focusElementIdx].focus();
314+ e.preventDefault();
315+ return;
316+ }
317+
318+ // Handle Enter key for activation
319+ if (isEnterPressed) {
320+ console.log("enter pressed");
321+ // Get the currently focused element
322+ var focusedElement = document.activeElement;
323+ if (focusedElement && (
324+ focusedElement.tagName === 'BUTTON' ||
325+ focusedElement.getAttribute('role') === 'button' ||
326+ focusedElement.tagName === 'A'
327+ )) {
328+ // Simulate a click on the element
329+ focusedElement.click();
330+ e.preventDefault();
311331 }
312332 }
313-
314- focusableContent[focusElementIdx].focus();
315- e.preventDefault();
316333 }
317334
318335 function autoFocus(delay) {
319336 setTimeout(function() { focusableContent[focusElementIdx].focus() }, delay);
320337 }
321338
322- document.addEventListener('keydown', handleTabKey );
339+ document.addEventListener('keydown', handleKeyboardNavigation );
323340 autoFocus(100);
324341
325342 ` ;
0 commit comments