1jQuery(document).ready(function($) { 2 3 // Handle user info form submission 4 $('#userInfoForm').on('submit', function(e) { 5 e.preventDefault(); 6 7 var formData = { 8 action: 'submit_user_info', 9 nonce: aptitudeTest.nonce, 10 name: $('#apt-name').val(), 11 email: $('#apt-email').val(), 12 designation: $('#apt-designation').val() 13 }; 14 15 $('#loading').show(); 16 17 $.ajax({ 18 url: aptitudeTest.ajax_url, 19 type: 'POST', 20 data: formData, 21 success: function(response) { 22 $('#loading').hide(); 23 24 if (response.success) { 25 // Hide form and show quiz 26 $('#user-info-form').hide(); 27 displayQuestions(response.data.questions); 28 $('#quiz-section').show(); 29 } else { 30 alert('Error: ' + response.data.message); 31 } 32 }, 33 error: function() { 34 $('#loading').hide(); 35 alert('An error occurred. Please try again.'); 36 } 37 }); 38 }); 39 40 // Display questions 41 function displayQuestions(questions) { 42 var html = ''; 43 44 questions.forEach(function(q, index) { 45 html += '<div class="question-block">'; 46 html += '<h3>Question ' + (index + 1) + '</h3>'; 47 html += '<p class="question-text">' + q.question + '</p>'; 48 html += '<div class="options">'; 49 50 q.options.forEach(function(option, optIndex) { 51 html += '<label class="option-label">'; 52 html += '<input type="radio" name="question_' + index + '" value="' + optIndex + '" required>'; 53 html += '<span>' + option + '</span>'; 54 html += '</label>'; 55 }); 56 57 html += '</div>'; 58 html += '</div>'; 59 }); 60 61 $('#questions-container').html(html); 62 } 63 64 // Handle quiz form submission 65 $('#quizForm').on('submit', function(e) { 66 e.preventDefault(); 67 68 var answers = []; 69 var allAnswered = true; 70 71 // Collect all answers 72 for (var i = 0; i < 5; i++) { 73 var answer = $('input[name="question_' + i + '"]:checked').val(); 74 75 if (answer === undefined) { 76 allAnswered = false; 77 break; 78 } 79 80 answers.push(parseInt(answer)); 81 } 82 83 if (!allAnswered) { 84 alert('Please answer all questions before submitting.'); 85 return; 86 } 87 88 var quizData = { 89 action: 'submit_quiz', 90 nonce: aptitudeTest.nonce, 91 answers: answers 92 }; 93 94 $('#loading').show(); 95 96 $.ajax({ 97 url: aptitudeTest.ajax_url, 98 type: 'POST', 99 data: quizData, 100 success: function(response) { 101 $('#loading').hide(); 102 103 if (response.success) { 104 // Hide quiz and show results 105 $('#quiz-section').hide(); 106 displayResults(response.data); 107 $('#result-section').show(); 108 } else { 109 alert('Error: ' + response.data.message); 110 } 111 }, 112 error: function() { 113 $('#loading').hide(); 114 alert('An error occurred. Please try again.'); 115 } 116 }); 117 }); 118 119 // Display results 120 function displayResults(data) { 121 var resultClass = ''; 122 var resultMessage = ''; 123 var resultIcon = ''; 124 125 if (data.percentage >= 80) { 126 resultClass = 'excellent'; 127 resultMessage = 'Outstanding Performance!'; 128 resultIcon = 'ð'; 129 } else if (data.percentage >= 60) { 130 resultClass = 'good'; 131 resultMessage = 'Great Job!'; 132 resultIcon = 'ð'; 133 } else if (data.percentage >= 40) { 134 resultClass = 'average'; 135 resultMessage = 'Fair Performance'; 136 resultIcon = 'ð'; 137 } else { 138 resultClass = 'poor'; 139 resultMessage = 'Keep Practicing!'; 140 resultIcon = 'ðª'; 141 } 142 143 var html = '<div class="result-card ' + resultClass + '">'; 144 html += '<div style="font-size: 64px; margin-bottom: 20px;">' + resultIcon + '</div>'; 145 html += '<h3>' + resultMessage + '</h3>'; 146 html += '<div class="score-display">'; 147 html += '<p class="percentage">' + data.percentage + '%</p>'; 148 html += '<p class="score">You answered <strong>' + data.score + ' out of ' + data.total + '</strong> questions correctly</p>'; 149 html += '</div>'; 150 html += '</div>'; 151 152 $('#result-content').html(html); 153 } 154 155 // Restart test 156 $('#restart-btn').on('click', function() { 157 $('#result-section').hide(); 158 $('#userInfoForm')[0].reset(); 159 $('#user-info-form').show(); 160 }); 161 162});
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.