Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 13x 13x 13x 13x 13x 13x 4x 13x 6x 6x 4x 4x 4x 6x 4x 4x 4x 6x 6x 4x 4x 9x 3x 3x 3x 13x | /**
* Modal DOM creation utilities
*/
import type { SDKConfig } from '../types';
import { SDKError } from '../types';
export interface ModalElements {
overlayElement: HTMLDivElement;
modalElement: HTMLDivElement;
iframeElement: HTMLIFrameElement;
formElement: HTMLFormElement;
iframeName: string;
}
export interface CreateModalOptions {
config: Required<Pick<SDKConfig, 'timeout' | 'debug'>> & {
modalContainer?: string;
modalWidth?: number | 'fullscreen' | undefined;
modalHeight?: number | 'fullscreen' | undefined;
customClass?: string;
};
enableCloseBtn: boolean;
getClassName: (baseName: string) => string;
onClose: () => void;
onIframeLoad: () => void;
onIframeError: () => void;
log?: (message: string, ...args: unknown[]) => void;
}
/**
* Creates the modal HTML structure
*/
export function createModalDOM(options: CreateModalOptions): ModalElements {
const { config, enableCloseBtn } = options;
const { onClose, onIframeLoad, onIframeError, log, getClassName } = options;
// Create overlay
const overlayElement = document.createElement('div');
overlayElement.className = getClassName('tds-modal-overlay');
overlayElement.setAttribute('role', 'dialog');
overlayElement.setAttribute('aria-modal', 'true');
overlayElement.setAttribute('aria-label', '3DS Authentication');
// Close modal when clicking on overlay (but not on modal itself)
overlayElement.onclick = (e): void => {
if (e.target === overlayElement) {
// Overlay click handling disabled
}
};
// Create modal container
const modalElement = document.createElement('div');
modalElement.className = getClassName('tds-modal-container');
// Apply custom class if provided
if (config.customClass) {
modalElement.classList.add(config.customClass);
}
// Apply modal dimensions
applyModalDimensions(modalElement, config, getClassName);
// Create modal header with close button
const header = document.createElement('div');
header.className = getClassName('tds-modal-header');
const closeButton = document.createElement('button');
closeButton.className = getClassName('tds-modal-close');
closeButton.setAttribute('aria-label', 'Close authentication modal');
closeButton.setAttribute('type', 'button');
closeButton.innerHTML = '×';
closeButton.onclick = (): void => {
onClose();
};
// Add keyboard support for close button
closeButton.onkeydown = (e): void => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
onClose();
}
};
header.appendChild(closeButton);
if (enableCloseBtn) {
modalElement.appendChild(header);
}
// Create modal body with iframe
const body = document.createElement('div');
body.className = getClassName('tds-modal-body');
// Create loading indicator
const loading = document.createElement('div');
loading.className = getClassName('tds-modal-loading');
loading.innerHTML = `
<div class="${getClassName('tds-spinner')}"></div>
<p>Processing authentication...</p>
`;
body.appendChild(loading);
// Create iframe with unique name
const iframeName = `tds-auth-iframe-${Date.now()}`;
const iframeElement = document.createElement('iframe');
iframeElement.className = getClassName('tds-modal-iframe');
iframeElement.setAttribute('name', iframeName);
iframeElement.setAttribute('title', '3DS Authentication');
iframeElement.setAttribute('frameborder', '0');
iframeElement.setAttribute('allow', 'payment');
iframeElement.setAttribute('allowtransparency', 'true');
iframeElement.setAttribute('allow', 'otp-credentials; payment; clipboard-write;');
iframeElement.style.display = 'none';
// Handle iframe load
iframeElement.onload = (): void => {
log?.('Iframe loaded');
loading.style.display = 'none';
iframeElement.style.display = 'block';
onIframeLoad();
};
// Handle iframe errors
iframeElement.onerror = (): void => {
log?.('Iframe error');
onIframeError();
};
body.appendChild(iframeElement);
// Create hidden form for submission
const formElement = document.createElement('form');
formElement.setAttribute('method', 'post');
formElement.setAttribute('target', iframeName);
formElement.style.display = 'none';
body.appendChild(formElement);
// Assemble modal
modalElement.appendChild(body);
overlayElement.appendChild(modalElement);
// Append to body or custom container
const container = config.modalContainer
? document.querySelector(config.modalContainer)
: document.body;
if (!container) {
throw new SDKError('Modal container not found', 'CONTAINER_NOT_FOUND');
}
container.appendChild(overlayElement);
// Animate in with smooth entrance
requestAnimationFrame(() => {
requestAnimationFrame(() => {
overlayElement.classList.add(getClassName('tds-modal-show'));
});
});
return {
overlayElement,
modalElement,
iframeElement,
formElement,
iframeName,
};
}
/**
* Applies modal dimensions based on configuration
*/
export function applyModalDimensions(
modalElement: HTMLDivElement,
config: {
modalWidth?: number | 'fullscreen' | undefined;
modalHeight?: number | 'fullscreen' | undefined;
},
getClassName: (baseName: string) => string
): void {
const isFullscreen = config.modalWidth === 'fullscreen' || config.modalHeight === 'fullscreen';
if (isFullscreen) {
modalElement.classList.add(getClassName('tds-modal-fullscreen'));
} else if (typeof config.modalWidth === 'number' || typeof config.modalHeight === 'number') {
// Apply fixed dimensions if at least one is provided
if (typeof config.modalWidth === 'number') {
modalElement.style.width = `${config.modalWidth}px`;
modalElement.style.maxWidth = `${config.modalWidth}px`;
}
if (typeof config.modalHeight === 'number') {
modalElement.style.height = `${config.modalHeight}px`;
modalElement.style.maxHeight = `${config.modalHeight}px`;
}
// Add responsive class when dimensions are partially or fully undefined
if (config.modalWidth === undefined || config.modalHeight === undefined) {
modalElement.classList.add(getClassName('tds-modal-responsive'));
}
} else {
// No dimensions provided - make it fully responsive
modalElement.classList.add(getClassName('tds-modal-responsive'));
}
}
|