var swiper; $(function () { swiper = new Swiper('.swiper-container', { /* direction: "vertical",*/ /* initialSlide: 1,*/ speed: 1, allowTouchMove: false, hashNavigation: { watchState: true, replaceState: true }, autoHeight: true, }); if (serverAnswerIds.length > 1) { recoverViewState(serverAnswerIds); } $(window).on('hashchange', function (e) { const newHash = document.location.hash.replace('#', ''); const activeSlideHash = swiper.slides.eq(swiper.activeIndex).attr('data-hash'); if (newHash !== activeSlideHash) { const newIndex = swiper.$wrapperEl.children(`.${swiper.params.slideClass}[data-hash="${newHash}"]`).index(); if (typeof newIndex === 'undefined') return; swiper.slideTo(newIndex); } var explainers = ["question-520d51cb-6fb4-48ac-9e4c-330dff284c16", "question-84fc0173-d4fc-46bd-9df1-4773f7472f1c", "question-959d8e92-d41e-4080-9d4e-4cb33f6f18f4", "question-dbe23558-aef0-46f4-9229-e5ca7b58f8b5", "question-99fe5e2c-dce6-469d-ba7e-f3a4e26b2392"]; if (explainers.includes(newHash)) { //console.log(); try { _paq.push(['trackEvent', 'Interaction', 'Section', newHash.substring(9)]); } catch (ex) {} } checkForRedirect(newHash); $('#btnLogin').hide(); // console.log('hashchange ' + newHash); }); var currentHash = document.location.hash.replace('#', ''); if (currentHash != '') checkForRedirect(currentHash); /* if (newHash == 'question-99fe5e2c-dce6-469d-ba7e-f3a4e26b2392') { setTimeout(() => { window.location = '/lead.php?source=autoredirect'; $('#divBtnLead').show(); }, 2500); setTimeout(() => { $('#divBtnLead').show(); }, 3000); } $('#btnLogin').hide();*/ // console.log('hashchange ' + newHash); $('.btn-submitdependants').click(function () { var dependants = new Array(); var questionid = $(this).data('questionid'); $('.dependant-container').each(function () { var id = $(this).data('id'); var dep = { DependantId: id, Name: $('#edtName-' + id).val(), DoB: $('#edtDob-' + id).val(), Handicapped: $('#cbHandicap-' + id).prop('checked'), InEducation: $('#cbEdu-' + id).prop('checked'), ReceivingChildMoney: $('#cbChildMoney-' + id).prop('checked'), }; if (dep.Name == '') { alert('Bitte geben Sie alle Namen und Geburtstage an'); return; } dependants.push(dep); }); if (dependants.length == 0) { if (confirm('Sie haben keine Kinder angegeben. Sie haben jedoch angegebeben, dass Sie Kinder haben. Möchten Sie diese Angabe korrigieren?')) { window.location.hash = '#question-0bda7a04-4abf-4e47-83a8-adf933dfd384'; } } else { $.post('/cb.php?' + $.param({ questionid: questionid, cmd: 'submitdependants', flowid: flowId }), JSON.stringify(dependants), function (data) { document.location.hash = 'question-' + (data.nextQuestionId); }, 'json').always(function () {}); } }); $('.btn-submitincome').click(function () { var questionid = $(this).data('questionid'); var type = $(this).data('type'); var relevantFields = $('.div-conditional-answer').not('.collapse').find('.edt-own-income'); var partnerField = $('.div-conditional-answer').not('.collapse').find('.edt-partner-income'); var needsPartner = false; var income = { sumOwnIncome: 0, sumPartnerIncome: 0 }; //var n = numeral(debtvalue).format('00.00'); relevantFields.each(function () { if ($(this).val().trim().length != '') income.sumOwnIncome += numeral($(this).val()).value(); }); if (partnerField.length > 0) { needsPartner = true; partnerField.each(function () { if ($(this).val().trim().length != '') income.sumPartnerIncome += numeral($(this).val()).value(); }); } if (income.sumOwnIncome < 100 || (needsPartner && income.sumPartnerIncome < 100)) { var s = "\n\n\Sollten Sie sich unsicher sein, geben Sie Schätzwerte ein. Sie können diese jederzeit später ändern."; if (needsPartner) { alert('Bitte geben Sie die monatlichen Einkünfte von Ihnen sowie von Ihrem Partner ein' + s); } else alert('Bitte geben Sie Ihre monatlichen Einkünfte ein.' + s); return; } $.post('/cb.php?' + $.param({ questionid: questionid, cmd: 'submitincome', flowid: flowId }), JSON.stringify(income), function (data) { document.location.hash = 'question-' + (data.nextQuestionId); }, 'json').always(function () {}); }); $('.btn-submitasset').click(function () { var questionid = $(this).data('questionid'); var type = $(this).data('type'); var asset = { name: "", type: type }; if ($('#edtAssetName-' + questionid).val().length < 3) { alert('Bitte geben Sie Marke, Modell und das ungefähre Baujahr Ihres Autos an'); return; } asset.name = $('#edtAssetName-' + questionid).val(); $.post('/cb.php?' + $.param({ questionid: questionid, cmd: 'submitasset', flowid: flowId }), JSON.stringify(asset), function (data) { document.location.hash = 'question-' + (data.nextQuestionId); }, 'json').always(function () {}); }); $('.btn-submitdebt').click(function () { var questionid = $(this).data('questionid'); var debt = { knownDebt: 0 }; var debtvalue = $('#edtDebt').val(); var n = numeral(debtvalue).format('00.00'); if (n < 1000) { var s = "\n\n\Sollten Sie sich unsicher sein, geben Sie Schätzwerte ein. Sie können diese jederzeit später ändern."; alert('Bitte geben Sie die ungefähre Höhe der zuletzt bekannten Schuldenhöhe ein. Werte unter 1.000€ werden nicht akzeptiert.' + s); return; } debt.knownDebt = n; $.post('/cb.php?' + $.param({ questionid: questionid, cmd: 'submitdebt', flowid: flowId }), JSON.stringify(debt), function (data) { document.location.hash = 'question-' + (data.nextQuestionId); }, 'json').always(function () {}); }); $('.btn-submitanswer').click(function () { var btn = $(this); var questionid = $(this).data('questionid'); var answers = new Array(); $('input[data-questionid="' + questionid + '"]').each(function (input) { if ($(this).prop('checked')) { answers.push($(this).data('answerid')); } }); if (answers.length == 0) { alert('Bitte wählen Sie eine Antwort aus'); return; } toggleLoading(false); $.post('/cb.php?' + $.param({ questionid: questionid, cmd: 'submitanswer', flowid: flowId }), { 'answers[]': answers, 'optin': $('#optin-' + questionid).prop('checked') ? $('#optin-' + questionid).data('optinid') : null }, function (data) { document.location.hash = 'question-' + (data.nextQuestionId); updateProgress(data); recoverViewState(data.existingAnswers); }, 'json').always(function () { toggleLoading(true); }); trackEvent('submit-answer', questionid); }); $('.btn-explainer-next').click(function () { var btn = $(this); var questionid = $(this).parents('.qf-slide-section').data('questionid'); var answers = new Array(); toggleLoading(false); $.post('/cb.php?' + $.param({ questionid: questionid, cmd: 'submitanswer', type: 'explainer', }), { }, function (data) { recoverViewState(data.existingAnswers); document.location.hash = 'question-' + (data.nextQuestionId); }, 'json').always(function () { toggleLoading(true); }); }); $('#btnAddDependant').click(function () { var html = $('#divDependantTemplate').html(); var id = uuidv4(); html = html.replaceAll('{id}', id); html = html.replaceAll('dependant-container-tpl', 'dependant-container'); $('#frmDependants').append(html); var count = $('#frmDependants').children('.dependant-input-container').length; $('#edtName-' + id).val('Kind ' + count); $('.btn-removedependant').click(function () { $('.dependant-container[data-id="' + $(this).data('id') + '"]').remove(); }); swiper.updateAutoHeight(1); }); $('.qf-answer').click(function (event) { //allow multiselect event.preventDefault(); var deselect = false; if ($(this).hasClass('qf-answer-checkbox')) { $(this).find('.qf-answer-checkbox-input').prop("checked", !$(this).find('.qf-answer-checkbox-input').prop('checked')); deselect = $(this).find('.qf-answer-checkbox-input').prop('checked'); } else { $(this).parent().find('.qf-answer-radio-input').prop("checked", false); $(this).find('.qf-answer-radio-input').prop("checked", true); deselect = $(this).find('.qf-radio-checkbox-input').prop('checked'); } }); swiper.on('slideChange', function () { // $('#swiperControls').hide(); // $('.btn-swiper-control').hide(); window.scrollTo(0, 0); /*if (swiper.activeIndex > 0) { $('#swiperControls').show(); $('#swiperBack').show(); var slide = swiper.slides.eq(swiper.activeIndex); if (slide.attr('data-nextbutton') != null) { $('#swiperNext').show(); } }*/ console.log('slideChange'); // console.log(location.hash); }); $('#swiperBack').click(function () { $('#swiper-questions')[0].swiper.slideTo(swiper.activeIndex - 1); }); $('#swiperNext').click(function () { $('#swiper-questions')[0].swiper.slideTo(swiper.activeIndex + 1); }); if (swiper.activeIndex == 0) $('#swiperControls').hide(); }); function checkForRedirect(newHash) { if (newHash == 'question-99fe5e2c-dce6-469d-ba7e-f3a4e26b2392') { console.log('will redirect'); setTimeout(() => { window.location = '/lead.php?source=autoredirect'; }, 2500); setTimeout(() => { $('#divBtnLead').show(); }, 5000); } } function updateProgress(data) { $('#divProgress').css('width', data.progress + '%'); } function recoverViewState(ids) { $('.div-conditional-answer').addClass('collapse'); ids.forEach(id => { $('.div-conditional-answer[data-answerid-condition="' + id + '"]').removeClass('collapse'); }); }