101};102const shouldClampConsultant = Boolean(consultantClampLines.desktop || consultantClampLines.mobile);103104const steps = Array.from(rec.querySelectorAll('.t-quiz__screen-wrapper:not(.t-form__hidden)'));105const successBoxResult = rec.querySelector('.t-quiz__result_ordinary');106const preparedSteps = [...steps, successBoxResult].map(function (step) {107return {108type: t_quiz__getStepType(step),109element: step,110};111});112
const analyticsEnabled = Boolean(quizWrapper.getAttribute('data-analytics-enabled')); const autoStepChangeEnabled = Boolean(quizWrapper.getAttribute('data-auto-step-change')); const isConditionalForm = !!form.querySelector('.t-conditional'); const StepsManager = t_quiz__step_manager({ recId: recid, steps: preparedSteps, successStepElement: successBoxResult, activeStepClass: 't-step-form__step_active', hiddenStepClass: 't-quiz-hidden', enableAutoStepChange: autoStepChangeEnabled, enableConditionals: isConditionalForm, onProgressChange: onProgressChange, onConditionalStateChange: onConditionalStateChange, animation: getAnimationConfig(), onInit: function () { onInitCallback && onInitCallback(); t_quiz__adjustStepToHeight({ rec }); }, checkIfCanChangeStep: canChangeStep, }); // Инициализация analyticsEnabled && initAnalytics(); initForm(); StepsManager.init(); quizWrapper.StepsManager = StepsManager; /** @type {TransitionGuard} */ function canChangeStep(direction, stepInfo, transitionInfo = {}) { // Появление первого шага, когда активного еще нет. if (!stepInfo || !stepInfo.step || !stepInfo.step.element) { return true; } // При переходе назад нет валидации, просто скрываем ошибку if (direction === 'prev') { hideStepErrors(stepInfo.step.element); return true; } // Блокируем автопереход с последнего шага if (stepInfo.isLast && transitionInfo.isAutoTransition) { return false; } // Если переход с последнего шага после отправки формы, то разрешаем if (stepInfo.isLast && transitionInfo.isOnSuccess) { return true; } if (stepInfo.isFinal && stepInfo.type === 'result') { return false; } const hasStepErrors = validateCurrentStep(); // Если на шаге есть ошибки, то переход блокируется if (hasStepErrors) { return false; } hideStepErrors(stepInfo.step.element); return true; } function onProgressChange(progress) { // Прогресс квиза может измениться без переключения шага. // Пример: изменение списка из-за условий видимости. t_quiz__setProgress(rec, progress.current, progress.total); if (progress.current) { t_quiz__showCounter(rec, progress.current, progress.total); } requestAnimationFrame(() => { t_quiz__adjustStepToHeight({ rec }); }); } function onConditionalStateChange(event) { const conditionalElement = event.target; const isHidden = event.detail && event.detail.hidden === true; const currentStep = StepsManager.getCurrentStepInfo(); // Работаем только с теми видео, которые видны на текущем шаге. const isPartOfCurrentStep = currentStep.step.element.contains(conditionalElement); if (isHidden && isPartOfCurrentStep) { t_quiz__pauseVideos(conditionalElement); }