Files
Miroca_Server/www/static/file/home/js/home-t862-popupstepform-1.0.min.js
Victor Alexandrovich Tsyrenschikov 75be663d7f css,js,ws
2026-01-02 18:20:49 +05:00

2 lines
17 KiB
JavaScript

function t862_init(t){var e=document.getElementById("rec"+t),o;if(e&&e.querySelector(".t862")){var r=e.querySelector(".t-form");if(r){var n=e.querySelector(".t862__quiz-wrapper"),i=e.querySelectorAll(".t-input-group"),s=e.querySelector(".t862__btn_prev"),a=e.querySelector(".t862__btn_next"),c=e.querySelector(".t862__btn_result"),u=e.querySelector(".t-form__submit"),l=e.querySelector(".t-submit"),p=e.querySelector(".t-form__errorbox-middle");if(p)var d=p.querySelector(".t-form__errorbox-wrapper");var _='<div class="t862__capture-form t862__screen-wrapper t-step-form__step"></div>';p.insertAdjacentHTML("beforebegin",_),r.classList.remove("js-form-proccess");var f=e.querySelector(".t862__capture-form"),y=e.querySelector(".t862__result-title"),v=y?y.textContent:"",m=Boolean(n.getAttribute("data-auto-step-change")),g=!1,S,h=300;t862_workWithAnswerCode(e),Array.prototype.forEach.call(i,(function(t,e){t.setAttribute("data-step-number",e)})),t862_wrapCaptureForm(e);var b=Boolean(f.innerHTML||v),w=0,L=null,q=r.classList.contains("t-conditional-form"),A=!1,E;t862_createSteps(i);var C=t862_createStepsArray(e),k=C.length,x=e.querySelectorAll(".t862__screen-wrapper"),H;C[w]&&(q?t_onFuncLoad("t_form__conditionals__initStepForm",(function(){var o;L=t_form__conditionals__initStepForm({recId:t,steps:x,activeStepIndex:w,ignoredSteps:[".t862__capture-form"],ignoredInputGroups:[".t862__t-input-group_capture"],onConditionalFieldChange:function t(o){k=o.totalActiveStepsCount-1,E=M(),t862_showCounter(e,E.counterCurrentStep,E.counterAllSteps),t862_setProgress(e,E.progressCurrentStep,E.progressAllSteps),K(),O()}}),k=L.getState().totalActiveStepsCount-1,T()})):T())}}function T(){N(w),E=M(),t862_showCounter(e,E.counterCurrentStep,E.counterAllSteps),t862_disabledPrevBtn(e,w),e.setAttribute("data-animationappear","off"),e.style.opacity=1,m&&V(),s.addEventListener("click",(function(t){z(t)})),a.addEventListener("click",(function(t){P(t)})),Array.prototype.forEach.call(i,(function(t){t.addEventListener("keypress",(function(t){var e=r.querySelector(".t-step-form__step_active");"Enter"!==t.code&&13!==t.keyCode||r.classList.contains("js-form-proccess")||e.querySelector(".t-input-group_ta")||P(t)}))})),c.addEventListener("click",(function(t){P(t)})),t862_openToHook(e,x,f),e.addEventListener("click",(function(t){var o=t.target,r;!!o.closest('[type="submit"]')&&o&&t862_adjustStepToHeight(e)})),t862_adjustHeightOnResize(e)}function z(t){A||(t.preventDefault(),G(),I()||(w=L?L.getState().prevStepIndex:j()-1,L&&L.onStepChange(w),E=M(),t862_setProgress(e,E.progressCurrentStep,E.progressAllSteps),t862_showCounter(e,E.counterCurrentStep,E.counterAllSteps),t862_awayFromResultScreen(e),t862_hideError(e,w),t862_disabledPrevBtn(e,w),N(w),r.classList.contains("js-form-proccess")&&r.classList.remove("js-form-proccess")))}function P(t){if(!A){t.preventDefault(),G();var o=t862_showError(e,n,w);if(o&&d&&(d.style.display="none"),!o){var r=F();w=L?L.getState().nextStepIndex:j()+1,L&&L.onStepChange(w),E=M(),t862_setProgress(e,E.progressCurrentStep,E.progressAllSteps),t862_showCounter(e,E.counterCurrentStep,E.counterAllSteps),t862_disabledPrevBtn(e,w),r&&b?W():N(w)}}}function j(){return L?L.getState().activePossibleStepIndex:w}function M(){return{counterCurrentStep:j()+1,counterAllSteps:k,progressCurrentStep:j(),progressAllSteps:b?k:k-1}}function F(){return j()===k-1}function I(){return 0===j()}function B(){return j()===k-2}function O(){if(!b){if(B())return a.style.display="none",c.style.display="block",void(u.style.display="none");if(F())return a.style.display="none",c.style.display="none",void(u.style.display="block")}if(F())return a.style.display="none",c.style.display="block",void(u.style.display="none");a.style.display="block",c.style.display="none",u.style.display="none"}function N(t){var o=r.querySelector(".t-step-form__step_active"),n=C[t];if(o)R(o,n,{onNewStepAnimationStart:function t(){t862_checkMode(),K(),O(),J(e);var o=e.querySelector(".t-range");o&&t_triggerEvent(o,"displayChanged"),A=!1,t862_adjustStepToHeight(e)},onAnimationStart:function t(){A=!0,D(e)}});else{n&&n.classList.add("t-step-form__step_active"),t862_checkMode(),K(),O();var i=e.querySelector(".t-range");i&&t_triggerEvent(i,"displayChanged"),t862_adjustStepToHeight(e)}}function W(){r.classList.add("js-form-proccess");var t=e.querySelector(".t862__quiz-description"),o;R(r.querySelector(".t-step-form__step_active"),f,{onAnimationStart:function o(){A=!0,t&&(t.style.display="none"),y&&(y.style.display="block"),c.style.display="none",u.style.display="block",D(e)},onNewStepAnimationStart:function t(){t862_checkMode(),J(e),A=!1,t862_adjustStepToHeight(e)}})}function R(t,e,o){function r(){e.classList.remove("t-step-form__step_fadeIn"),e.removeEventListener("animationend",r),e.removeEventListener("animationcancel",n),o.onAnimationComplete&&o.onAnimationComplete()}function n(){e.classList.remove("t-step-form__step_fadeIn"),e.removeEventListener("animationend",r),e.removeEventListener("animationcancel",n)}function i(){e.addEventListener("animationend",r),e.addEventListener("animationcancel",n),e.classList.add("t-step-form__step_active"),e.classList.add("t-step-form__step_fadeIn"),o.onNewStepAnimationStart&&o.onNewStepAnimationStart()}function s(){t.classList.remove("t-step-form__step_fadeOut"),t.classList.remove("t-step-form__step_active"),t.removeEventListener("animationend",s),e&&i()}function a(){t.addEventListener("animationend",s),t.classList.add("t-step-form__step_fadeOut")}return o.onAnimationStart&&o.onAnimationStart(),t?a():i()}function D(){s&&(s.disabled=!0),a&&(a.disabled=!0),c&&(c.disabled=!0),l&&(l.disabled=!0)}function J(){I()||s&&(s.disabled=!1),a&&(a.disabled=!1),c&&(c.disabled=!1),l&&(l.disabled=!1)}function V(){var t=["ri","rd","rs","sb","cb"],e;C.filter((function(e){var o=e.querySelector(".t-input-group");return-1!==t.indexOf(o.getAttribute("data-field-type"))})).forEach((function(t){var e=Array.prototype.slice.call(t.querySelectorAll(".js-tilda-rule"));(e=e.filter((function(t){return!t.classList.contains("t-radio-ownanswer")}))).forEach((function(t){t.addEventListener("change",Y)}))}))}function Y(t){var e;F()&&!b||Q(null==(e=t.target)?void 0:e.parentNode)||g||(g=!0,S=setTimeout((function(){P(t),G()}),h))}function G(){clearTimeout(S),g=!1}function K(){!b&&F()?r.classList.add("js-form-proccess"):r.classList.remove("js-form-proccess")}function Q(t){return t&&t.querySelectorAll('input[type="checkbox"]').length>0}}function t862_workWithAnswerCode(t){for(var e=t.querySelectorAll(".t-input-group_ri input"),o=t.querySelectorAll(".t-input-group_rd input"),r=t.querySelectorAll(".t-input-group_sb option"),n=0;n<e.length;n++){var i;if(-1!==(i=e[n]).value.indexOf("value::")){t862_setAnswerCode(i);var s=i.parentNode.querySelector(".t-img-select__text");s&&(s.textContent=s.textContent.split("value::")[0].trim())}}for(var n=0;n<o.length;n++){var i;if(-1!==(i=o[n]).value.indexOf("value::")){t862_setAnswerCode(i);var a=i.parentNode;a&&(a.innerHTML=a.innerHTML.split("value::")[0].trim())}}for(var n=0;n<r.length;n++){var c=r[n];-1!==c.value.indexOf("value::")&&(t862_setAnswerCode(c),c.textContent=c.textContent.split("value::")[0].trim())}}function t862_createSteps(t){Array.prototype.forEach.call(t,(function(t){if(!t.classList.contains("t862__t-input-group_capture")){var e=document.createElement("div");e.classList.add("t862__screen-wrapper"),e.classList.add("t-step-form__step"),t.parentNode.insertBefore(e,t),e.appendChild(t)}}))}function t862_setAnswerCode(t){t.value=t.value.split("value::")[1].trim()}function t862_wrapCaptureForm(t){var e=t.querySelector(".t862__capture-form"),o=t.querySelectorAll(".t-input-group"),r=t.querySelector(".t862__quiz-form-wrapper");Array.prototype.forEach.call(o,(function(t){var n=t,i=n.classList.contains("t-input-group_em"),s=n.classList.contains("t-input-group_nm"),a=n.classList.contains("t-input-group_ph"),c=n.classList.contains("t-input-group_cb"),u,l=4;if(n.getAttribute("data-step-number")>=o.length-4){var p=!0;if(r.classList.contains("t862__quiz-form-wrapper_newcapturecondition")){var d=t862_getNextAll(n);Array.prototype.forEach.call(d,(function(t){p=t.classList.contains("t-input-group_cb")||t.classList.contains("t-input-group_em")||t.classList.contains("t-input-group_nm")||t.classList.contains("t-input-group_ph")}))}p&&(i||s||a||c)&&(n.classList.add("t862__t-input-group_capture"),e.appendChild(n))}}))}function t862_showCounter(t,e,o){var r=t.querySelector(".t862__quiz-description-counter");r&&(r.innerHTML=e+"/"+o)}function t862_setProgress(t,e,o){var r=t.querySelector(".t862__progressbar"),n=parseFloat(getComputedStyle(r).width),i=t.querySelector(".t862__progress"),s=n/o,a=100*Math.abs(e*s/n)+"%";i&&(i.style.width=a)}function t862_createStepsArray(t){var e=t.querySelectorAll(".t862__screen-wrapper"),o=[];return Array.prototype.forEach.call(e,(function(t){t.classList.contains("t862__capture-form")||o.push(t)})),o}function t862_disabledPrevBtn(t,e){var o=t.querySelector(".t862__btn_prev");0===e?o.setAttribute("disabled",""):o.removeAttribute("disabled")}function t862_openToHook(t,e,o){var r=t.querySelector(".t-popup"),n=t.querySelector(".t-popup__close"),i=t.querySelectorAll('a[href*="#"]'),s=r.getAttribute("data-tooltip-hook"),a=r.getAttribute("data-track-popup"),c=r.querySelector(".t-form__submit .t-submit"),u=t862__escClosePopup.bind(r,t);s&&(t_onFuncLoad("t_popup__addAttributesForAccessibility",(function(){t_popup__addAttributesForAccessibility(s)})),document.addEventListener("click",(function(r){var n=r.target.closest('a[href="'+s+'"]');if(n&&(r.preventDefault(),window.isMobile||n.classList.add("t-popup__triggered-btn"),t862_showPopup(t,e,o,u),setTimeout((function(){t862_adjustStepToHeight(t,{initial:!0})}),50),t862__lazyLoad(),a)){var i=s;"#popup:"==i.substring(0,7)&&(i=i.substring(7)),Tilda.sendEventToStatistics(a,i)}}))),r.addEventListener("click",(function(e){e.target===this&&t862_closePopup(t,u)})),n.addEventListener("click",(function(){t862_closePopup(t,u)}));for(var l=0;l<i.length;l++)i[l].addEventListener("click",(function(){var e=this.getAttribute("href");(!e||"#price:"!=e.substring(0,7)&&"#order:"!=e.substring(0,7))&&(t862_closePopup(t,u),e&&"#popup:"!=e.substring(0,7)||setTimeout((function(){t_triggerEvent(document.body,"popupShowed"),document.body.classList.add("t-body_popupshowed")}),300))})),i[l].addEventListener("keydown",(function(t){13===t.keyCode&&(window.isMobile||this.classList.add("t-popup__triggered-btn"))}));var p=c&&c.getAttribute("href");p&&"#order:"===p.substring(0,7)&&c.addEventListener("click",(function(){t862_closePopup(t,u)}))}function t862_checkMode(){document.getElementById("allrecords").getAttribute("data-tilda-mode")||t862__lazyLoad()}function t862__lazyLoad(){"y"!==window.lazy&&"yes"!==document.getElementById("allrecords").getAttribute("data-tilda-lazy")||t_onFuncLoad("t_lazyload_update",(function(){t_lazyload_update()}))}function t862_hideError(t,e){var o,r=t862_createStepsArray(t)[e];r&&(r.classList.remove("js-error-control-box"),r.querySelector(".t-input-error").innerHTML="")}function t862_awayFromResultScreen(t){var e=t.querySelector(".t862__quiz-description"),o=t.querySelector(".t862__result-title");o&&(o.style.display="none"),e&&(e.style.display="block")}function t862_showError(t,e,o){if(e.classList.contains("t862__quiz-published"))return t862_setError(t,o)}function t862_setError(t,e){var o,r=t862_createStepsArray(t)[e],n;if("object"!=typeof window.tildaForm)return n;var i=window.tildaForm.validate(r),s=i[0];if(s){var a=s.type[0],c=t.querySelector(".t-form .t-form__errorbox-middle .js-rule-error-"+a),u="";c&&(u=c.textContent),u||t_onFuncLoad("t_forms__getMsg",(function(){u=t_forms__getMsg(a)})),"emptyfill"===a?n=!1:(r&&r.classList.add("js-error-control-box"),n=window.tildaForm.showErrors(r,i));var l=r.querySelector(".t-input-error");l&&(l.innerHTML=u)}return n}function t862_onSuccess(t){t_forms__onSuccess(t)}function t862_lockScroll(){var t=document.body;if(!t.classList.contains("t-body_scroll-locked")){var e=void 0!==window.pageYOffset?window.pageYOffset:(document.documentElement||t.parentNode||t).scrollTop;t.classList.add("t-body_scroll-locked"),t.style.top="-"+e+"px",t.setAttribute("data-popup-scrolltop",e)}}function t862_unlockScroll(){var t=document.body;if(t.classList.contains("t-body_scroll-locked")){var e=t.getAttribute("data-popup-scrolltop");t.classList.remove("t-body_scroll-locked"),t.style.top="",t.removeAttribute("data-popup-scrolltop"),window.scrollTo(0,parseInt(e))}}function t862_showPopup(t,e,o,r){var n=window.innerWidth,i=document.body,s=t.querySelector(".t-popup"),a=s.querySelector(".t-popup__container"),c=t.querySelector(".t862__quiz"),u=t.querySelector(".t-range");s.style.display="block",u&&t_triggerEvent(u,"popupOpened"),t862__lazyLoad(),setTimeout((function(){s.classList.add("t-popup_show"),a.classList.add("t-popup__container-animated"),t_onFuncLoad("t_popup__trapFocus",(function(){t_popup__trapFocus(s)})),n>640&&c.classList.contains("t862__quiz_fixedheight")&&t862_setHeight(t,e,o),n>640&&c.classList.contains("t862__quiz_nofixedheight")&&(a.style.transition="height ease-in-out 0.3s"),n<=640&&t862_setMobileHeight(),t862__showJivo("1","1")}),50),t_triggerEvent(document.body,"popupShowed"),i.classList.add("t-body_popupshowed"),i.classList.add("t862__body_popupshowed"),/iPhone|iPad|iPod/i.test(navigator.userAgent)&&!window.MSStream&&setTimeout((function(){t862_lockScroll()}),500),document.addEventListener("keydown",r)}function t862__escClosePopup(t,e){"Escape"===arguments[1].key&&t862_closePopup(t,e)}var t862_debounceAdjustheight=t862_debounce(t862_adjustStepToHeight,200);function t862_adjustHeightOnResize(t){window.addEventListener("resize",(function(){t862_debounceAdjustheight(t)}))}function t862_debounce(t,e){var o;return function(){var r=Array.prototype.slice.call(arguments);clearTimeout(o),o=setTimeout((function(){t.apply(null,r)}),e)}}function t862_adjustStepToHeight(t,e){var o=30;e=e||{initial:!1};var r=t.querySelector(".t862__quiz_nofixedheight");if(r){var n=t.querySelector(".t862__quiz-description-wrapper"),i=t.querySelector(".t862__quiz-form-wrapper"),s=n?n.offsetHeight:0,a=i?i.offsetHeight:0;if(0!==a){var c=t.querySelector(".t862__wrapper"),u=getComputedStyle(c),l,p=s+a,d=p+(parseInt(u.paddingBottom,10)||0),_=parseInt(getComputedStyle(r).height,10),f=Math.abs(_-p);if(e.initial)return t862_resizePopup(t,d),void(r.style.height=p+"px");f<o||(p>_&&(r.style.overflow="hidden",setTimeout((function(){r.style.overflow=""}),300)),t862_resizePopup(t,d),r.style.height=p+"px")}}else t862_resizePopup(t)}function t862_setHeight(t,e){var o=t.querySelector(".t862__quiz-form-wrapper"),r=t.querySelector(".t862__result-title"),n=t.querySelector(".t862__quiz-description"),i=r?r.offsetHeight:0,s=n?n.offsetHeight:0,a=Array.prototype.slice.call(e),c=null;a.forEach((function(t){var e=t.classList.contains("t-step-form__step_active");e||t.classList.add("t-step-form__step_active"),c=Math.max(t.offsetHeight,c),e||t.classList.remove("t-step-form__step_active")})),a.forEach((function(t){t.style.minHeight=c+"px"})),o.style.minHeight=c+"px";var u=Math.max(s,i),l=o.offsetHeight,p=t.querySelector(".t862__btn-wrapper").offsetHeight;t.querySelector(".t862__wrapper").style.minHeight=u+l+p+"px"}function t862_setMobileHeight(){t862_calcVH(),window.addEventListener("resize",t862_calcVH)}function t862_calcVH(){var t=.01*window.innerHeight;document.documentElement.style.setProperty("--vh",t+"px")}function t862_closePopup(t,e){t="string"==typeof t?document.getElementById("rec"+t):t;var o=document.body,r=t.querySelector(".t-popup"),n=r.querySelector(".t-popup__container"),i;r===document.querySelector(".t-popup.t-popup_show")&&(t_triggerEvent(document.body,"popupHidden"),o.classList.remove("t-body_popupshowed"),o.classList.remove("t862__body_popupshowed")),/iPhone|iPad|iPod/i.test(navigator.userAgent)&&!window.MSStream&&t862_unlockScroll(),t_onFuncLoad("t_popup__addFocusOnTriggerButton",(function(){t_popup__addFocusOnTriggerButton()})),r.classList.remove("t-popup_show"),n.style.removeProperty("transition"),t862__showJivo("2147483647","2147483648"),setTimeout((function(){for(var t=document.querySelectorAll(".t-popup:not(.t-popup_show)"),e=0;e<t.length;e++)t[e].style.display="none"}),300),document.removeEventListener("keydown",e)}function t862_resizePopup(t,e){var o=window.innerHeight-120,r=t.querySelector(".t-popup__container"),n=getComputedStyle(r,null),i=parseInt(n.paddingTop)||0,s=parseInt(n.paddingBottom)||0,a=r.clientHeight-(i+s),c;(e||a)>o?r.classList.add("t-popup__container-static"):r.classList.remove("t-popup__container-static")}function t862__showJivo(t,e){for(var o=document.querySelectorAll("._show_1e.wrap_mW.__jivoMobileButton"),r=document.querySelectorAll(".label_39#jvlabelWrap"),n=0;n<o.length;n++)o[n].style.zIndex=t;for(var n=0;n<r.length;n++)r[n].style.zIndex=e}function t862_getNextAll(t){for(var e=[],o=t;o.nextElementSibling;)o.nextElementSibling.classList.contains("t-input-group")&&e.push(o.nextElementSibling),o=o.nextElementSibling;return e}function t_triggerEvent(t,e){var o;document.createEvent?(o=document.createEvent("HTMLEvents")).initEvent(e,!0,!1):document.createEventObject&&((o=document.createEventObject()).eventType=e),o.eventName=e,t.dispatchEvent?t.dispatchEvent(o):t.fireEvent?t.fireEvent("on"+o.eventType,o):t[e]?t[e]():t["on"+e]&&t["on"+e]()}