72017202// TODO ST-2949_2: implicit any on params, vars, this, and index access (TS7006, TS7005, TS7008, TS7034, TS2683, TS7053, TS7015)7203// @ts-expect-error ST-2949_27204function tcart_ceil(num) {7205var result = num * 100;7206// TODO ST-2949_5: assignability, arguments, calls, return types (TS2345, TS2322, TS2554, TS2769, TS2740, TS2739, TS2353, TS2349, TS2355, TS2366, TS2774, TS18046)7207// @ts-expect-error ST-2949_57208result = result.toFixed(3);7209result = Math.ceil(result) / 100;7210return result;7211}
/** * Показывает всплывающее сообщение о том, что товар добавлен в корзину * Если корзина открывается сразу после нажатия "Купить", то всплывающего сообщения не будет * * @param {string} text - текст сообщения */function tcart__showBubble(text) { const MAX_BUBBLES = 4; const DELAY_MS = 3000; // Если корзина открывается по кнопке "купить", то не показываем сообщение const cart = tcart__getCartBlock(); // TODO ST-2949_3: null / undefined (TS18047, TS18048, TS2531, TS2722, TS2454, TS2538) // @ts-expect-error ST-2949_3 if (cart.getAttribute('data-opencart-onorder') === 'yes') return; // Общий контейнер всех сообщений if (!document.querySelector('.t706__bubble-container')) { const container = document.createElement('div'); container.className = 't706__bubble-container'; document.body.appendChild(container); } const container = document.querySelector('.t706__bubble-container'); // TODO ST-2949_3: null / undefined (TS18047, TS18048, TS2531, TS2722, TS2454, TS2538) // @ts-expect-error ST-2949_3 const existingBubbles = container.querySelectorAll('.t706__bubble.t706__bubble_visible'); // Удаляем самый старый bubble if (existingBubbles.length >= MAX_BUBBLES) { const oldestBubble = existingBubbles[0]; // TODO ST-2949_5: assignability, arguments, calls, return types (TS2345, TS2322, TS2554, TS2769, TS2740, TS2739, TS2353, TS2349, TS2355, TS2366, TS2774, TS18046) // @ts-expect-error ST-2949_5 tcart__closeBubble(oldestBubble); } const bubble = document.createElement('div'); bubble.className = 't706__bubble t706__bubble_visible'; bubble.innerHTML = ` <div class="t706__bubble-close">×</div> <div class="t706__bubble-text t-descr"></div> `; // TODO ST-2949_3: null / undefined (TS18047, TS18048, TS2531, TS2722, TS2454, TS2538) // @ts-expect-error ST-2949_3 bubble.querySelector('.t706__bubble-text').textContent = tcart__decodeHtml(text); // @ts-expect-error ST-2949_3 bubble.querySelector('.t706__bubble-close').addEventListener('click', () => { tcart__closeBubble(bubble); }); // TODO ST-2949_3: null / undefined (TS18047, TS18048, TS2531, TS2722, TS2454, TS2538) // @ts-expect-error ST-2949_3 container.appendChild(bubble); // Удаление после задержки 3с const timerId = setTimeout(() => { tcart__closeBubble(bubble); }, DELAY_MS); // TODO ST-2949_5: assignability, arguments, calls, return types (TS2345, TS2322, TS2554, TS2769, TS2740, TS2739, TS2353, TS2349, TS2355, TS2366, TS2774, TS18046) // @ts-expect-error ST-2949_5 bubble.dataset.id = timerId;}/** * Закрывает всплывающее сообщение * * @param {HTMLElement} bubble - элемент bubble для закрытия */function tcart__closeBubble(bubble) { // Элемент может быть закрыт вручную или по таймеру if (bubble) { const bubbleId = bubble.dataset.id; clearTimeout(bubbleId); bubble.classList.remove('t706__bubble_visible'); bubble.classList.add('t706__bubble_hidden'); bubble.addEventListener( 'animationend', () => { bubble.remove(); }, { once: true } ); }}/**