1class Matchmaker{constructor(root){this.root=root;this.currentStep=0;this.totalSteps=5;this.selectedAnswers=[];this.cacheDom();if(!this.drawer)return;this.renderQuestion();this.bindEvents()} 2cacheDom(){this.drawer=this.root.querySelector('.matchmaker-drawer');this.startBtn=this.root.querySelector('.matchmaker-start-btn');this.closeBtn=this.root.querySelector('.matchmaker-close');this.quizStep=this.root.querySelector('.matchmaker-step');this.resultWrapper=this.root.querySelector('.matchmaker-result');this.resultSlotWrapper=this.root.querySelector('.matchmaker-result-wrapper');this.restartBtn=this.resultWrapper?.querySelector('.matchmaker-restart')||null;this.questionTitle=this.quizStep?.querySelector('.matchmaker-question-title')||null;this.answersWrapper=this.quizStep?.querySelector('.matchmaker-answers')||null;this.nextBtn=this.quizStep?.querySelector('.matchmaker-next')||null;this.progress=this.root.querySelector('.matchmaker-progress');this.overlay=this.root.querySelector('.matchmaker-overlay');if(!this.drawer)return;this.drawer.style.zIndex='10001';if(this.overlay)this.overlay.style.zIndex='10000';this.drawer.classList.remove('open');this.overlay?.classList.remove('open');requestAnimationFrame(()=>{this.drawer.classList.add('ready');this.overlay?.classList.add('ready')})} 3bindEvents(){const isMobile=()=>window.matchMedia('(max-width: 480px)').matches;const openAll=()=>{this.drawer?.classList.add('open');this.overlay?.classList.add('open');if(isMobile())document.body.classList.add('body-lock')};const closeAll=()=>{this.drawer?.classList.remove('open');this.overlay?.classList.remove('open');document.body.classList.remove('body-lock')};this.startBtn?.addEventListener('click',openAll);this.closeBtn?.addEventListener('click',closeAll);this.overlay?.addEventListener('click',closeAll);this.nextBtn?.addEventListener('click',()=>this.next());this.restartBtn?.addEventListener('click',()=>this.reset());document.addEventListener('keydown',(e)=>{if(e.key==='Escape')closeAll()});let resizeScheduled=!1;window.addEventListener('resize',()=>{if(resizeScheduled)return;resizeScheduled=!0;requestAnimationFrame(()=>{resizeScheduled=!1;const isOpen=this.drawer?.classList.contains('open');if(!isOpen)return;if(isMobile()){document.body.classList.add('body-lock')}else{document.body.classList.remove('body-lock')}})})} 4renderQuestion(){const step=this.currentStep+1;const qKey=`mm_q${step}`;const aKeys=[`mm_q${step}_a1`,`mm_q${step}_a2`,`mm_q${step}_a3`];this.questionTitle.innerHTML=MatchMakerData?.[qKey]||'';this.answersWrapper.innerHTML='';this.nextBtn.disabled=!0;this.nextBtn.innerHTML=(this.currentStep===this.totalSteps-1)?MatchMakerData?.mm_end:MatchMakerData?.mm_next;aKeys.forEach((aKey,i)=>{const text=MatchMakerData?.[aKey];if(!text)return;const btn=document.createElement('button');btn.className='matchmaker-answer';btn.innerHTML=`<span class="radio"></span><span class="answer-text">${text}</span>`;btn.addEventListener('click',()=>this.selectAnswer(i,btn));this.answersWrapper.appendChild(btn)});const progressTemplate=MatchMakerData?.mm_progress||'Question [x] of [y]';this.progress.textContent=progressTemplate.replace('[x]',this.currentStep+1).replace('[y]',this.totalSteps);this.updateProgressBar()} 5selectAnswer(index,button){this.selectedAnswers[this.currentStep]=index;this.answersWrapper.querySelectorAll('button').forEach(btn=>btn.classList.remove('selected'));button.classList.add('selected');this.nextBtn.disabled=!1} 6next(){if(typeof this.selectedAnswers[this.currentStep]==='undefined')return;this.currentStep++;if(this.currentStep<this.totalSteps){this.renderQuestion()}else{this.calculateResult()}} 7updateProgressBar(){const bar=this.root.querySelector('.matchmaker-progress-bar');bar.style.width=`${((this.currentStep + 1) / this.totalSteps) * 100}%`} 8runSlotMachineAnimation(){if(!document.getElementById('slot-machine-animations')){const animStyle=document.createElement('style');animStyle.id='slot-machine-animations';animStyle.textContent=` 9 @keyframes spin-slow { 10 0% { transform: rotate(0deg); opacity: 0.1; } 11 50% { opacity: 0.4; } 12 100% { transform: rotate(360deg); opacity: 0.1; } 13 } 14 @keyframes lever-bounce { 15 0% { transform: translateY(0); } 16 50% { transform: translateY(10px); } 17 100% { transform: translateY(0); } 18 } 19 `;document.head.appendChild(animStyle)}
19 20const icons=MatchMakerTraits.map(key=>{return `${MatchMakerPlugin.url}assets/img/${key}.png`});const container=document.createElement('div');container.className='slot-machine-animation';container.style.display='flex';container.style.flexDirection='column';container.style.alignItems='center';container.style.justifyContent='center';container.style.minHeight='300px';container.style.padding='48px 0';const title=document.createElement('h2');title.textContent=MatchMakerData?.mm_computing;title.style.fontSize='24px';title.style.fontWeight='bold';title.style.marginBottom='40px';container.appendChild(title);const frame=document.createElement('div');frame.style.position='relative';frame.style.background='#dbc8fd';frame.style.padding='24px';frame.style.borderRadius='16px';frame.style.border='4px solid #5B2ABF';frame.style.boxShadow='0 10px 20px rgba(0,0,0,0.3)';frame.style.width='256px';frame.style.height='256px';frame.style.display='flex';frame.style.alignItems='center';frame.style.justifyContent='center';frame.style.overflow='hidden';const spinner=document.createElement('div');spinner.style.position='absolute';spinner.style.inset='0';spinner.style.background='linear-gradient(to right, rgba(165, 110, 255, 1) 0%, rgba(255, 255, 255, 1) 50%, rgba(165, 110, 255, 1) 100%)';spinner.style.animation='spin-slow 3s linear infinite';frame.appendChild(spinner);const window=document.createElement('div');window.style.position='relative';window.style.width='128px';window.style.height='128px';window.style.background='#dbc8fd';window.style.borderRadius='12px';window.style.border='2px solid #5B2ABF';window.style.overflow='hidden';const strip=document.createElement('div');strip.style.position='absolute';strip.style.top='0';strip.style.left='0';strip.style.right='0';strip.style.display='flex';strip.style.flexDirection='column';strip.style.alignItems='center';strip.style.transition='transform 3s cubic-bezier(0.45, 0.05, 0.55, 0.95)';const loopCount=10;const totalImages=icons.length*loopCount;let index=0;for(let i=0;i<totalImages;i++){const el=document.createElement('div');const img=document.createElement('img');img.src=icons[index];img.alt='slot-icon';img.style.width='78px';img.style.height='78px';el.style.margin='8px 0';el.appendChild(img);strip.appendChild(el);index=(index+1)%icons.length} 21const resultEl=document.createElement('div');const img=document.createElement('img');img.id='final-slot-image';const lastKey=MatchMakerTraits[MatchMakerTraits.length-1];img.src=`${MatchMakerPlugin.url}assets/img/${lastKey}.png`;img.alt='final-result';img.style.width='78px';img.style.height='78px';resultEl.appendChild(img);resultEl.style.fontSize='48px';resultEl.style.margin='8px 0';strip.appendChild(resultEl);window.appendChild(strip);frame.appendChild(window);const leverWrap=document.createElement('div');leverWrap.style.position='absolute';leverWrap.style.right='16px';leverWrap.style.top='50%';leverWrap.style.transform='translateY(-50%)';leverWrap.style.width='32px';leverWrap.style.height='160px';const lever=document.createElement('div');lever.style.width='32px';lever.style.height='32px';lever.style.borderRadius='50%';lever.style.background='red';lever.style.position='relative';lever.style.animation='lever-bounce 0.5s ease 0.2s';const leverStick=document.createElement('div');leverStick.style.position='absolute';leverStick.style.top='100%';leverStick.style.left='50%';leverStick.style.transform='translateX(-50%)';leverStick.style.width='16px';leverStick.style.height='128px';leverStick.style.borderRadius='0 0 8px 8px';leverStick.style.background='linear-gradient(to bottom, #aaa, #ccc)';lever.appendChild(leverStick);leverWrap.appendChild(lever);frame.appendChild(leverWrap);container.appendChild(frame);const paragraph=document.createElement('p');paragraph.textContent=MatchMakerData?.mm_cogs_working;paragraph.style.marginTop='32px';paragraph.style.color='#ccc';container.appendChild(paragraph);this.resultWrapper.innerHTML='';this.resultWrapper.appendChild(container);this.resultWrapper.style.display='block';setTimeout(()=>{const slotHeight=window.clientHeight;const finalImage=strip.querySelector('#final-slot-image');if(finalImage){const imgHeight=finalImage.clientHeight;const finalTop=finalImage.offsetTop;const offset=finalTop-(slotHeight/2)+(imgHeight/2);strip.style.transform=`translateY(-${offset}px)`}},50);this.finalSlotImage=function(finalResultPath){const finalSlot=this.root.querySelector('#final-slot-image');if(finalSlot){finalSlot.src=finalResultPath}}.bind(this)} 22removeSlotMachineAnimation(){this.resultSlotWrapper.innerHTML='';this.resultSlotWrapper.style.display='none'} 23calculateResult(){const payload=new URLSearchParams();payload.append('action','calculate_matchmaker_result');payload.append('country',MatchMakerMeta?.country);payload.append('region',MatchMakerMeta?.region);
23this.selectedAnswers.forEach((val,i)=>{payload.append(`answers[${i}]`,val)});this.quizStep.style.display='none';this.progress.style.display='none';this.root.querySelector('.matchmaker-progress-wrapper').style.display='none';this.runSlotMachineAnimation();fetch('/wp-admin/admin-ajax.php',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:payload.toString()}).then(response=>response.json()).then(data=>{if(data.success&&data.data&&data.data.html&&data.data.result){const finalKey=data.data.result;const finalImagePath=`${MatchMakerPlugin.url}assets/img/${finalKey}.png`;if(typeof this.finalSlotImage==='function'){this.finalSlotImage(finalImagePath)} 24setTimeout(()=>{this.removeSlotMachineAnimation();this.resultWrapper.innerHTML=data.data.html;this.resultWrapper.style.display='block';attachImgFallbacks(this.resultWrapper);if(window.ktag&&typeof ktag.reRender==="function"){ktag.reRender(".matchmaker-bonus-card")} 25observeBonusButton(this.resultWrapper);const restartBtn=this.resultWrapper.querySelector('.matchmaker-restart');restartBtn?.addEventListener('click',()=>this.reset())},3200)}else{console.error('Error in returned data:',data)}}).catch(error=>{console.error('AJAX error:',error)})} 26reset(){this.currentStep=0;this.selectedAnswers=[];this.quizStep.style.display='block';this.progress.style.display='block';this.root.querySelector('.matchmaker-progress-wrapper').style.display='block';this.resultWrapper.style.display='none';this.nextBtn.innerHTML=MatchMakerData?.mm_next;this.renderQuestion()}} 27function attachImgFallbacks(root=document){const scope=root instanceof Element?root:document;const imgs=scope.querySelectorAll('img.js-img-fallback');imgs.forEach((img)=>{const handler=()=>{const fallbackText=img.getAttribute('data-fallback')||img.alt||'Image not available';img.style.display='none';img.insertAdjacentHTML('afterend',`<h2 class="img-fallback">${fallbackText}</h2>`)};img.addEventListener('error',handler,{once:!0});if(img.complete&&img.naturalWidth===0){handler()}})} 28function observeBonusButton(root=document){const container=root.querySelector('.matchmaker-result');if(!container)return;const observer=new MutationObserver(()=>{const btn=container.querySelector('.matchmaker-bonus-btn');if(btn){if(window.ktag&&typeof ktag.reRender==="function"){ktag.reRender(".matchmaker-bonus-card")} 29observer.disconnect();btn.addEventListener('click',()=>{if(window.ktag&&typeof ktag.track==="function"){ktag.track("cta")}})}});observer.observe(container,{childList:!0,subtree:!0})} 30function matchmakerInit(root){const scope=root||document;scope.querySelectorAll('.matchmaker-instance').forEach(instance=>{if(instance.matchmakerInitialized){return} 31instance.matchmakerInitialized=!0;new Matchmaker(instance)})} 32window.matchmakerInit=matchmakerInit;document.addEventListener('DOMContentLoaded',()=>matchmakerInit(document))
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.