201if (initOptions.checkIfCanChangeStep) {202const canTransition = initOptions.checkIfCanChangeStep(direction, getCurrentStepInfo(), transitionInfo);203if (!canTransition) return;204}205206var nextStep = direction === 'next' ? getNextActiveStep() : getPrevActiveStep();207208activeStep = nextStep;209const info = getCurrentStepInfo();210211switchSteps(prevStep, nextStep.step, callbacks);212
return info; } function getVisibleSteps() { // Текущий шаг может быть скрыт с помощью калькулятора, но он нужен нам всегда для правильного расчета return steps.filter(step => !isStepHidden(step) || step === activeStep.step); } function isActiveStepLast() { const visibleSteps = getVisibleSteps(); const index = visibleSteps.indexOf(activeStep.step); const nextSteps = visibleSteps.splice(index + 1); const isLastStep = nextSteps.every(step => step.type !== 'step' && step.type !== 'contacts'); return isLastStep; } /** * Шаг финальный, если дальше перейти некуда. * Шаг с сообщением об успешной отправке не учитываем, он показывается только после отправки формы. */ function isActiveStepFinal() { const nextStep = getNextActiveStep().step; return !nextStep || nextStep.element === initOptions.successStepElement; } function isActiveStepFirst() { const visibleSteps = getVisibleSteps(); const index = visibleSteps.indexOf(activeStep.step); const prevSteps = visibleSteps.splice(0, index); return prevSteps.length === 0; } function getCurrentStepInfo() { /** @type {CurrentStepInfo} */ const info = { type: activeStep.step?.type, index: activeStep.index, isFirst: isActiveStepFirst(), isLast: isActiveStepLast(), isFinal: isActiveStepFinal(), step: activeStep.step, }; return info; } function initAutoStepChange() { var typesWithSkip = ['ri', 'rd', 'rs', 'sb', 'cb']; var stepsWithAutoSkip = steps.filter(function (step) { var stepElement = step.element; var inputsWrapper = stepElement.querySelector('.t-quiz__inputs-wrapper'); if (inputsWrapper) return; var inputGroup = stepElement.querySelector('.t-input-group'); if (!inputGroup) return; var supportsAutoChange = typesWithSkip.includes(inputGroup.getAttribute('data-field-type')); var isCheckboxesVariants = inputGroup.getAttribute('data-field-radcb') === 'cb'; return supportsAutoChange && !isCheckboxesVariants; }); stepsWithAutoSkip.forEach(function (step) { var inputGroups = Array.from(step.element.querySelectorAll('.t-input-group')); inputGroups.forEach(function (inputGroup) { inputGroup.addEventListener('change', event => { const isOwnVariant = event.target.classList.contains('t-radio-ownanswer') || event.target.classList.contains('t-input-ownanswer'); if (isOwnVariant) return; handleAutoStepChange(); }); }); }); } function handleAutoStepChange() { if (autoStepChangeInProgress) return; autoStepChangeInProgress = true; autoStepChangeTimer = setTimeout(function () { go('next', {}, { isAutoTransition: true }); }, autoStepChangeDuration); }