1901/** @type {HTMLElement} */1902var tooltip = document.querySelector('.tlk-tooltip');1903if (!tooltip) return;19041905if (options.maxWidth) tooltip.style.maxWidth = options.maxWidth + 'px';19061907var coords = tma__getTooltipPosition(options, tooltip);19081909tooltip.style.top = coords.top;1910tooltip.style.left = coords.left;1911tooltip.style.zIndex = options.zIndex;1912
}, options.timeout); } function tma__onMouseLeaveTooltipHandler() { var tooltipEl = document.querySelector('.tlk-tooltip'); clearTimeout(timeoutId); if (tooltipEl) tooltipEl.remove(); } element.addEventListener('mouseenter', tma__onMouseEnterTooltipHandler); element.addEventListener('mouseleave', tma__onMouseLeaveTooltipHandler);}/** * Возвращает разметку tooltip * @param {string} text * @param {string} [tooltipClass] */function tma__getTooltipHtml(text, tooltipClass) { var html = ''; html += '<div class="tlk-tooltip ' + (tooltipClass || '') + '">'; html += '<div class="tlk-tooltip__text">' + text + '</div>'; html += '</div>'; return html;}/** * Возвращает позицию элемента * @param {TTooltipParams} options - настройки * @param {Element} tooltip - элемент тултипа * @returns {{[key: string]: string}} */function tma__getTooltipPosition(options, tooltip) { var elementRect = options.element.getBoundingClientRect(); var tooltipRect = tooltip.getBoundingClientRect(); var correctedTop = elementRect.y + window.pageYOffset; var correctedLeft = elementRect.x + window.pageXOffset; if (options.position === 'top') { correctedTop = correctedTop - tooltipRect.height - options.gap; correctedLeft = correctedLeft + elementRect.width / 2 - tooltipRect.width / 2; } else if (options.position === 'bottom') { correctedTop = correctedTop + elementRect.height + options.gap; correctedLeft = correctedLeft + elementRect.width / 2 - tooltipRect.width / 2; } else if (options.position === 'left') { correctedTop = correctedTop + elementRect.height / 2 - tooltipRect.height / 2; correctedLeft = elementRect.left - tooltipRect.width - options.gap; } else { correctedTop = correctedTop + elementRect.height / 2 - tooltipRect.height / 2; correctedLeft = correctedLeft + elementRect.width + options.gap; } correctedTop = Math.abs(correctedTop); correctedLeft = Math.abs(correctedLeft); return { top: correctedTop + 'px', left: correctedLeft + 'px', };}/** * Экранирование символов * * @param {string} str - строка текста * @returns - строка текста без символов */function tma__escapeHTML(str) { var entities = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''', '/': '/', }; return str.replace(/[&<>"']/g, function (match) { return entities[match]; });}/** * Деэкранирование символов * * @param {string} str