Некодим© 2020-2026 Некодим
Готовые модификации для вашего сайта. Улучшайте функциональность и дизайн без программирования.
Журнал изменений История Git Файлы Tilda MCP Каталог файловtilda-popup-1.0.js Следить за файлом 1 /*2 tilda-popup содержит функции для работы попапов.3 Сюда вынесена часть общих функций из блоков,4 также, несколько функций, отвечающих за a11y.5 */6 7 /**8 * a11y9 * Добавление ловушки фокуса внутри попапа10 * При навигации с клавиатуры фокус не выходит за пределы попапа11 * @param {node} popup - popup element12 */13 История файла и сравнение версий function t_popup__trapFocus(popup) {
14 var focusableElements = popup.querySelectorAll(15 'a, button, input:not([type="hidden"]):not(.js-form-spec-comments), select, textarea, embed, video, iframe, [tabindex="0"]'17 var firstFocusableElement = focusableElements[0];18 var lastFocusableElement = focusableElements[focusableElements.length - 1];20 document.addEventListener('keydown', function (event) {21 if (!document.body.classList.contains('t-body_popupshowed')) return;23 var isTab = event.key === 'Tab' || event.keyCode === 9;24 var isTabPressed = isTab || (isTab && event.shiftKey);29 if (event.shiftKey && document.activeElement.classList.contains('t-popup_show')) {30 lastFocusableElement.focus();33 if (event.key === 'Tab' && !event.shiftKey && document.activeElement === lastFocusableElement) {34 event.preventDefault();35 firstFocusableElement.focus();38 // if tab+shift and we moving back39 if (event.key === 'Tab' && event.shiftKey && document.activeElement === firstFocusableElement) {40 event.preventDefault();41 lastFocusableElement.focus();45 // TODO: требует доработки фокусировка в первом поле при открытии попапа46 // на стороне форм проблема с тем, что не видна подсказка в поле47 // if (firstFocusableElement &&48 // firstFocusableElement.closest('.t-form') &&49 // firstFocusableElement.getAttribute('type') === 'text') {50 // firstFocusableElement.focus();55 * Добавление атрибутов для доступности к кнопке-тригеру56 * @param {string} hook - hook for current trigger button59 function t_popup__addAttributesForAccessibility(hook) {60 var allTriggerButtons = document.querySelectorAll('a[href="' + hook + '"]');61 Array.prototype.forEach.call(allTriggerButtons, function (button) {63 button.setAttribute('role', 'button');64 button.setAttribute('aria-haspopup', 'dialog');70 * Изменение отображения попапа при ресайзе по вертикали71 * @param {string} recId – recid of current block73 function t_popup__resizePopup(recId) {74 var rec = document.getElementById('rec' + recId);76 var popupContainer = rec.querySelector('.t-popup__container');77 if (!popupContainer) return;78 var popupStyle = getComputedStyle(popupContainer, null);79 var popupPaddingTop = parseInt(popupStyle.paddingTop) || 0;80 var popupPaddingBottom = parseInt(popupStyle.paddingBottom) || 0;81 var popupHeight = popupContainer.clientHeight - (popupPaddingTop + popupPaddingBottom);82 var windowHeightIndent = 120;84 var recType = rec.getAttribute('data-parenttplid') || rec.getAttribute('data-record-type');85 var isAlias = recType === '121';86 var isZeroPopup = recType === '1093' || (isAlias && rec.querySelector('.t1093'));87 if (recType === '364' || recType === '365') {88 windowHeightIndent = 30;98 windowHeightIndent = 0;