Некодим логотипНекодим
МодификацииПубликацииНекодИИмЦены
Некодим логотипНекодим

© 2020-2026 Некодим

Готовые модификации для вашего сайта. Улучшайте функциональность и дизайн без программирования.

Компания

  • Контакты
  • Публичная оферта
  • Политика конфиденциальности
  • Согласие на обработку данных
  • Лицензионное соглашение
  • Реферальная программа

Полезное

  • Модификации
  • Публикации
  • Каталог блоков Tilda
  • MCP для агентов
  • Журнал изменений
  • Доска почёта

Личный кабинет

  • Вход
  • Регистрация
  • Цены
Журнал измененийИстория GitФайлыTilda MCP
Каталог файлов

tilda-popup-1.0.js

Код файла
Версия от 18.08.2026, 07:00:16 МСК
Оригинал на CDNСнимок 56c3b845Полный текст
1/*2 tilda-popup содержит функции для работы попапов.3 Сюда вынесена часть общих функций из блоков,4 также, несколько функций, отвечающих за a11y.5*/6 7/**8 * a11y9 * Добавление ловушки фокуса внутри попапа10 * При навигации с клавиатуры фокус не выходит за пределы попапа11 * @param {node} popup - popup element12 */13
История файла и сравнение версий
  • 18.08.2026, 07:00:16 · 56c3b845
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"]'
16 );
17 var firstFocusableElement = focusableElements[0];
18 var lastFocusableElement = focusableElements[focusableElements.length - 1];
19
20 document.addEventListener('keydown', function (event) {
21 if (!document.body.classList.contains('t-body_popupshowed')) return;
22
23 var isTab = event.key === 'Tab' || event.keyCode === 9;
24 var isTabPressed = isTab || (isTab && event.shiftKey);
25 if (!isTabPressed) {
26 return;
27 }
28
29 if (event.shiftKey && document.activeElement.classList.contains('t-popup_show')) {
30 lastFocusableElement.focus();
31 }
32
33 if (event.key === 'Tab' && !event.shiftKey && document.activeElement === lastFocusableElement) {
34 event.preventDefault();
35 firstFocusableElement.focus();
36 }
37
38 // if tab+shift and we moving back
39 if (event.key === 'Tab' && event.shiftKey && document.activeElement === firstFocusableElement) {
40 event.preventDefault();
41 lastFocusableElement.focus();
42 }
43 });
44
45 // TODO: требует доработки фокусировка в первом поле при открытии попапа
46 // на стороне форм проблема с тем, что не видна подсказка в поле
47 // if (firstFocusableElement &&
48 // firstFocusableElement.closest('.t-form') &&
49 // firstFocusableElement.getAttribute('type') === 'text') {
50 // firstFocusableElement.focus();
51 // }
52}
53
54/**
55 * Добавление атрибутов для доступности к кнопке-тригеру
56 * @param {string} hook - hook for current trigger button
57 */
58
59function t_popup__addAttributesForAccessibility(hook) {
60 var allTriggerButtons = document.querySelectorAll('a[href="' + hook + '"]');
61 Array.prototype.forEach.call(allTriggerButtons, function (button) {
62 if (button) {
63 button.setAttribute('role', 'button');
64 button.setAttribute('aria-haspopup', 'dialog');
65 }
66 });
67}
68
69/**
70 * Изменение отображения попапа при ресайзе по вертикали
71 * @param {string} recId – recid of current block
72 */
73function t_popup__resizePopup(recId) {
74 var rec = document.getElementById('rec' + recId);
75 if (!rec) return;
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;
83
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;
89 }
90 if (
91 recType === '868' ||
92 recType === '331' ||
93 recType === '358' ||
94 recType === '1013' ||
95 recType === '746' ||
96 isZeroPopup
97 ) {
98 windowHeightIndent = 0;
99 }
100
Следующие 100 строк