1chainedQuiz = {}; 2chainedQuiz.points = 0; // initialize the points as 0 3chainedQuiz.questions_answered = 0; 4 5chainedQuiz.goon = function(quizID, url) { 6 jQuery('#chainedLoading').show(); 7 // make sure there is answer selected 8 var qType = jQuery('#chained-quiz-form-' + quizID + ' input[name=question_type]').val(); 9 var chkClass = 'chained-quiz-' + qType; 10 jQuery('#chained-quiz-action-' + quizID).attr('disabled', true); 11 12 // is any checked? 13 var anyChecked = false; 14 jQuery('#chained-quiz-form-' + quizID + ' .' + chkClass).each(function(){ 15 if(this.checked) anyChecked = true; 16 }); 17 18 if(!anyChecked && (qType != 'text')) { 19 alert(chained_i18n.please_answer); 20 jQuery('#chained-quiz-action-' + quizID).removeAttr('disabled'); 21 return false; 22 } 23 24 if(qType == 'text' && jQuery('#chained-quiz-form-' + quizID + ' textarea[name=answer]').val() == '') { 25 alert(chained_i18n.please_answer); 26 jQuery('#chained-quiz-action-' + quizID).removeAttr('disabled'); 27 return false; 28 } 29 30 // email is required? 31 if(jQuery('#chainedUserEmail').length > 0 && jQuery('#chainedUserEmail').hasClass('required')) { 32 var userEmail = jQuery('#chainedUserEmail').val(); 33 if(/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(userEmail) == false) { 34 alert(chained_i18n.please_provide_email); 35 jQuery('#chainedUserEmail').focus(); 36 jQuery('#chained-quiz-action-' + quizID).removeAttr('disabled'); 37 return false; 38 } 39 } // end checking for required email address 40 41 // if text captcha is there we have to make sure it's shown 42 if(jQuery('#ChainedTextCaptcha').length && !jQuery('#ChainedTextCaptcha').is(':visible')) { 43 alert(chained_i18n.complete_text_captcha); 44 jQuery('#ChainedTextCaptcha').show(); 45 return false; 46 } 47 48 // submit the answer by ajax 49 data = jQuery('#chained-quiz-form-'+quizID).serialize(); 50 data += '&action=chainedquiz_ajax'; 51 data += '&chainedquiz_action=answer'; 52 if (data.indexOf('chainedquiz_nonce=') === -1 && typeof chained_i18n !== 'undefined' && chained_i18n.ajax_nonce) { 53 data += '&chainedquiz_nonce=' + chained_i18n.ajax_nonce; 54 } 55 this.questions_answered++; 56 data += '&total_questions=' + this.questions_answered; 57 58 // if question captcha is available, add to data 59 if(jQuery('#ChainedTextCaptcha').length > 0) { 60 data += '&chained_text_captcha_answer=' + jQuery('#chained-quiz-form-' + quizID + ' input[name=chained_text_captcha_answer]').val(); 61 data += '&chained_text_captcha_question=' + jQuery('#chained-quiz-form-' + quizID + ' input[name=chained_text_captcha_question]').val(); 62 } 63 64 // console.log(data); 65 jQuery.post(url, data, function(msg) { 66 parts = msg.split("|CHAINEDQUIZ|"); 67 points = parseFloat(parts[0]); 68 if(isNaN(points)) points = 0; 69 chainedQuiz.points += points; 70 71 if(jQuery(document).scrollTop() > 250 && chained_i18n.dont_autoscroll != 1) { 72 jQuery('html, body').animate({ 73 scrollTop: jQuery('#chained-quiz-wrap-'+quizID).offset().top -100 74 }, 500); 75 } 76 77 jQuery('#chained-quiz-action-' + quizID).removeAttr('disabled'); 78 79 if(msg.indexOf('CHAINED_CAPTCHA:::') != -1) { 80 let aparts = msg.split(':::'); 81 alert(aparts[1]); 82 return false; 83 } 84 85 // redirect? 86 if(parts[1].indexOf('[CHAINED_REDIRECT]') != -1) { 87 var sparts = parts[1].split('[CHAINED_REDIRECT]'); 88 window.location=sparts[1]; 89 } 90 else { 91 // load next question or the final screen 92 jQuery('#chained-quiz-div-'+quizID).html(parts[1]); 93 94 // hide/show "go ahead" button depending on comment in the HTML code 95 if(parts[1].indexOf('<!--hide_go_ahead-->') != -1) jQuery('#chained-quiz-action-' + quizID).hide(); 96 else jQuery('#chained-quiz-action-' + quizID).show(); 97 98 jQuery('#chained-quiz-form-' + quizID + ' input[name=points]').val(chainedQuiz.points); 99 chainedQuiz.initializeQuestion(quizID); 100 } 101 102 jQuery('#chainedLoading').hide(); 103 }); 104} 105 106chainedQuiz.initializeQuestion = function(quizID) { 107 jQuery(".chained-quiz-frontend").click(function() {
108 if(this.type == 'radio' || this.type == 'checkbox') { 109 // enable button 110 jQuery('#chained-quiz-action-' + quizID).removeAttr('disabled'); 111 } 112 }); 113 114 jQuery(".chained-quiz-frontend").keyup(function() { 115 if(this.type == 'textarea') { 116 jQuery('#chained-quiz-action-' + quizID).removeAttr('disabled'); 117 } 118 }); 119 120 jQuery("#chainedTextCaptchaAnswer" + quizID).keyup(function() { 121 jQuery('#chained-quiz-action-' + quizID).removeAttr('disabled'); 122 }); 123}
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.