1(function ($) { 2 'use strict'; 3 $.fn.serializeFormJSON = function () { 4 var o = {}, 5 a = this.serializeArray(); 6 $.each(a, function () { 7 if (o[this.name]) { 8 if (!o[this.name].push) { 9 o[this.name] = [o[this.name]]; 10 } 11 o[this.name].push(this.value || ''); 12 } else { 13 o[this.name] = this.value || ''; 14 } 15 }); 16 return o; 17 }; 18 $(document).ready(function () { 19 var current_fs, next_fs, previous_fs; //fieldsets 20 var left, opacity, scale; //fieldset properties which we will animate 21 var animating; //flag to prevent quick multi-click glitches 22 var form, ays_quiz_container, ays_quiz_container_id; 23 24 window.aysQuizParentWindowLink = null; 25 if (window.location != window.parent.location) { 26 window.parent.postMessage("getParentUrl", "*"); 27 window.addEventListener("message", receiveMessage, false); 28 } 29 30 function receiveMessage(event) { 31 if (typeof event.data === "string") { 32 window.aysQuizParentWindowLink = event.data; 33 } 34 } 35 36 if(!$.fn.goTo){ 37 $.fn.goTo = function(myOptions) { 38 var QuizAnimationTop = (myOptions.quiz_animation_top && myOptions.quiz_animation_top != 0) ? parseInt(myOptions.quiz_animation_top) : 100; 39 40 myOptions.quiz_enable_animation_top = myOptions.quiz_enable_animation_top ? myOptions.quiz_enable_animation_top : 'on'; 41 var EnableQuizAnimationTop = ( myOptions.quiz_enable_animation_top && myOptions.quiz_enable_animation_top == 'on' ) ? true : false; 42 if( EnableQuizAnimationTop ){ 43 $('html, body').animate({ 44 scrollTop: $(this).offset().top - QuizAnimationTop + 'px' 45 }, 'slow'); 46 } 47 return this; // for chaining... 48 } 49 } 50 // for details 51 $.fn.aysModal = function(action){ 52 var $this = $(this); 53 switch(action){ 54 case 'hide': 55 $(this).find('.ays-modal-content').css('animation-name', 'zoomOut'); 56 setTimeout(function(){ 57 $(document.body).removeClass('modal-open'); 58 $(document).find('.ays-modal-backdrop').remove(); 59 $this.hide(); 60 }, 250); 61 break; 62 case 'show': 63 default: 64 $this.show(); 65 $(this).find('.ays-modal-content').css('animation-name', 'zoomIn'); 66 $(document).find('.modal-backdrop').remove(); 67 $(document.body).append('<div class="ays-modal-backdrop"></div>'); 68 $(document.body).addClass('modal-open'); 69 break; 70 } 71 } 72 73 if (!String.prototype.trim) { 74 (function() { 75 String.prototype.trim = function() { 76 return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); 77 }; 78 })(); 79 } 80 $(document).find(".ays-quiz-container .information_form").each(function(e){ 81 var $this = $(this); 82 var cont = $(document).find(".ays-quiz-container"); 83 var thisCont = $this.parents('.ays-quiz-container'); 84 var quizId = thisCont.find('input[name="ays_quiz_id"]').val(); 85 var myOptions = JSON.parse(window.atob(window.aysQuizOptions[quizId])); 86 if(myOptions.autofill_user_data && myOptions.autofill_user_data == "on"){ 87 var userData = {}; 88 userData.action = 'ays_get_user_information'; 89 $.ajax({
90 url: quiz_maker_ajax_public.ajax_url, 91 method: 'post', 92 dataType: 'json', 93 crossDomain: true, 94 data: userData, 95 success: function (response) { 96 if(response !== null){ 97 $this.find("input[name='ays_user_name']").val(response.data.display_name); 98 $this.find("input[name='ays_user_email']").val(response.data.user_email); 99 } 100 } 101 }); 102 } 103 }); 104 105 $(document).on('click', '.ays-quiz-rate-link-box .ays-quiz-rate-link', function (e) { 106 e.preventDefault(); 107 var _this = $(this); 108 var parent = _this.parents('.ays-quiz-container'); 109 var quizId = parent.find('input[name="ays_quiz_id"]').val(); 110 var form = parent.find('form'); 111 112 var action = 'ays_get_rate_last_reviews'; 113 $.ajax({
114 url: quiz_maker_ajax_public.ajax_url, 115 method: 'post', 116 dataType: 'json', 117 crossDomain: true, 118 data: { 119 quiz_id: quizId, 120 action: action 121 }, 122 success: function(response){ 123 if(response.status === true){ 124 form.find('.quiz_rate_reasons_body').html(response.quiz_rate_html); 125 form.find('.lds-spinner2').addClass('lds-spinner2-none').removeClass('lds-spinner2'); 126 form.find('.quiz_rate_reasons_container').slideDown(500); 127 128 _this.slideUp(500); 129 130 form.on('click', 'button.ays_load_more_review', function(e){ 131 form.find('.quiz_rate_load_more [data-role="loader"]').addClass(form.find('.quiz_rate_load_more .ays-loader').data('class')).removeClass('ays-loader'); 132 var startFrom = parseInt($(e.target).attr('startfrom')); 133 var zuyga = parseInt($(e.target).attr('zuyga')); 134 $.ajax({
135 url: quiz_maker_ajax_public.ajax_url, 136 method: 'post', 137 crossDomain: true, 138 data:{ 139 action: 'ays_load_more_reviews', 140 quiz_id: quizId, 141 start_from: startFrom, 142 zuyga: zuyga 143 }, 144 success: function(resp){ 145 if(zuyga == 0){ 146 zuyga = 1; 147 }else{ 148 zuyga = 0; 149 } 150 151 form.find('.quiz_rate_load_more [data-role="loader"]').addClass('ays-loader').removeClass(form.find('.quiz_rate_load_more .ays-loader').data('class')); 152 form.find('.quiz_rate_reasons_container').append(resp); 153 form.find('.quiz_rate_more_review:last-of-type').slideDown(500); 154 $(e.target).attr('startfrom', startFrom + 5 ); 155 $(e.target).attr('zuyga', zuyga); 156 if(form.find('.quiz_rate_reasons_container p.ays_no_more').length > 0){ 157 $(e.target).remove(); 158 } 159 } 160 }); 161 }); 162 } else { 163 swal.fire({ 164 type: 'info', 165 html: "<h2>"+ quizLangObj.loadResource +"</h2><br><h6>"+ quizLangObj.somethingWentWrong +"</h6>" 166 }); 167 } 168 }, 169 error: function(){ 170 swal.fire({ 171 type: 'info', 172 html: "<h2>"+ quizLangObj.loadResource +"</h2><br><h6>"+ quizLangObj.somethingWentWrong +"</h6>" 173 }); 174 } 175 }); 176 }); 177 178 $(document).find('input.ays_finish').on('click', function (e) { 179 e.preventDefault(); 180 181 var _this = $(this); 182 ays_quiz_container_id = $(this).parents(".ays-quiz-container").attr("id"); 183 ays_quiz_container = $('#'+ays_quiz_container_id); 184 185 var quizId = ays_quiz_container.find('input[name="ays_quiz_id"]').val(); 186 var myOptions = JSON.parse(window.atob(window.aysQuizOptions[quizId])); 187 var quizOptionsName = 'quizOptions_'+quizId; 188 var myQuizOptions = []; 189 190 if(typeof window[quizOptionsName] !== 'undefined'){ 191 for(var i in window[quizOptionsName]){ 192 if(window[quizOptionsName].hasOwnProperty(i)){ 193 myQuizOptions[i] = (JSON.parse(window.atob(window[quizOptionsName][i]))); 194 } 195 } 196 } 197 198 var form = ays_quiz_container.find('form'); 199 200 myOptions.enable_recaptcha = ( myOptions.enable_recaptcha ) ? myOptions.enable_recaptcha : 'off'; 201 var quizRecaptcha = myOptions.enable_recaptcha && myOptions.enable_recaptcha == "on" ? true : false; 202 203 var formCaptchaValidation = null; 204 if( quizRecaptcha ){ 205 if( form.attr('data-recaptcha-validate') ){ 206 formCaptchaValidation = form.attr('data-recaptcha-validate') == 'true' ? true : false; 207 } 208 } 209 210 if( quizRecaptcha && formCaptchaValidation === null){ 211 var cEvent = new CustomEvent('afterQuizSubmission', { 212 detail: { 213 _this: _this, 214 thisButton: $( e.target ) 215 } 216 }); 217 form.get(0).dispatchEvent(cEvent); 218 } 219 220 if( quizRecaptcha === false ){ 221 formCaptchaValidation = true; 222 } 223 224 if ( formCaptchaValidation !== true ) { 225 return; 226 } 227 228 if( myOptions.enable_timer && myOptions.enable_timer === 'on' ) { 229 if (myOptions.quiz_timer_type && myOptions.quiz_timer_type === 'question_timer') { 230 if (window.aysQuizQuestionTimers && window.aysQuizQuestionTimers[quizId]) { 231 if( myOptions.enable_navigation_bar && myOptions.enable_navigation_bar === 'on' ) { 232 if (myOptions.make_questions_required && myOptions.make_questions_required === "on") { 233 var qid = checkQuestionTimer(ays_quiz_container, quizId); 234 if (qid !== false) { 235 ays_quiz_container.find('.ays_questions_nav_question[data-id="' + qid + '"]').trigger('click'); 236 ays_quiz_is_question_required( ays_quiz_container.find('.step[data-question-id="' + qid + '"]') ); 237 return; 238 } else { 239 for ( var questionID in window.aysQuizQuestionTimers[quizId] ) { 240 stopQuestionTimer( questionID, quizId, myOptions ); 241 } 242 } 243 }else{ 244 for ( var questionID in window.aysQuizQuestionTimers[quizId] ) { 245 stopQuestionTimer( questionID, quizId, myOptions ); 246 } 247 } 248 }else{ 249 for ( var questionID in window.aysQuizQuestionTimers[quizId] ) { 250 stopQuestionTimer( questionID, quizId, myOptions ); 251 } 252 } 253 } 254 } 255 } 256 257 if( ! $(this).hasClass('ays-quiz-after-timer-end') ){ 258 var confirm = true; 259 myOptions.enable_see_result_confirm_box = ! myOptions.enable_see_result_confirm_box ? 'off' : myOptions.enable_see_result_confirm_box; 260 var enable_see_result_confirm_box = (myOptions.enable_see_result_confirm_box && myOptions.enable_see_result_confirm_box == 'on') ? true : false; 261 if (enable_see_result_confirm_box) { 262 if ( ! window.aysEarlyFinishConfirmBox[ quizId ] ) { 263 confirm = window.confirm(quizLangObj.areYouSure); 264 window.aysSeeResultConfirmBox[ quizId ] = false; 265 } 266 } 267 268 if ( ! confirm ) { 269 window.aysSeeResultConfirmBox[ quizId ] = true; 270 return false; 271 } 272 } 273 274 if($(document).scrollTop() >= $(this).parents('.ays-questions-container').offset().top){ 275 ays_quiz_container.goTo(myOptions); 276 } 277 278 if(ays_quiz_container.find('.ays_music_sound').length !== 0){ 279 ays_quiz_container.find('.ays_music_sound').fadeOut(); 280 setTimeout(function() { 281 audioVolumeOut(ays_quiz_container.find('audio.ays_quiz_music').get(0)); 282 },4000); 283 setTimeout(function() { 284 ays_quiz_container.find('audio.ays_quiz_music').get(0).pause(); 285 },6000); 286 } 287 if(ays_quiz_container.find('audio').length > 0){ 288 ays_quiz_container.find('audio').each(function(e, el){ 289 el.pause(); 290 }); 291 } 292 if(ays_quiz_container.find('video').length > 0){ 293 ays_quiz_container.find('video').each(function(e, el){ 294 el.pause(); 295 }); 296 } 297 298 var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false; 299 var enableNavigationBar = (myOptions.enable_navigation_bar && myOptions.enable_navigation_bar == "on") ? true : false; 300 var aysQuestionCountPerPage = $(this).parents('form').find('.ays_question_count_per_page'); 301 var next_sibilings_count = aysQuestionCountPerPage.length > 0 ? parseInt( aysQuestionCountPerPage.val() ) : null; 302 303 if( ! $(this).hasClass('ays-quiz-after-timer-end') && ! window.aysEarlyFinishConfirmBox[ quizId ] ){ 304 if(isRequiredQuestion === true && next_sibilings_count !== null ){ 305 ays_quiz_is_question_required( ays_quiz_container.find('.step') ); 306 if( ays_quiz_container.hasClass('ays-quiz-has-error') ){ 307 return false; 308 } 309 } else if (isRequiredQuestion === true && next_sibilings_count === null) { 310 if ( enableNavigationBar ) { 311 ays_quiz_is_question_required( ays_quiz_container.find('.step') ); 312 if( ays_quiz_container.hasClass('ays-quiz-has-error') ){ 313 return false; 314 } 315 } 316 } 317 } 318 319 ays_quiz_container.find('.ays-live-bar-wrap').addClass('bounceOut'); 320 setTimeout(function () { 321 ays_quiz_container.find('.ays-live-bar-wrap').css('display','none'); 322 },300); 323 324 var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false; 325 var aysQuestionCountPerPage = $(this).parents('form').find('.ays_question_count_per_page'); 326 var next_sibilings_count = aysQuestionCountPerPage.length > 0 ? parseInt( aysQuestionCountPerPage.val() ) : null; 327 328 if( ! $(this).hasClass('ays-quiz-after-timer-end') && ! window.aysEarlyFinishConfirmBox[ quizId ] ){ 329 if(isRequiredQuestion === true && next_sibilings_count !== null ){ 330 ays_quiz_is_question_required( ays_quiz_container.find('.step') ); 331 if( ays_quiz_container.hasClass('ays-quiz-has-error') ){ 332 return false; 333 } 334 } 335 } 336 337 var emailValivatePattern = /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.\w{2,}$/; 338 339 if (!($(this).hasClass('start_button'))) { 340 if ($(this).parents('.step').find('input[required]').length !== 0 || 341 $(this).parents('.step').find('select.ays_quiz_form_input[required]').length !== 0) { 342 var empty_inputs = 0; 343 var required_inputs = $(this).parents('.step').find('input[required]'); 344 $(this).parents('.step').find('.ays_red_border').removeClass('ays_red_border'); 345 $(this).parents('.step').find('.ays_green_border').removeClass('ays_green_border'); 346 for (var i = 0; i < required_inputs.length; i++) { 347 switch(required_inputs.eq(i).attr('type')){ 348 case "checkbox": { 349 if(required_inputs.eq(i).prop('checked') === false){ 350 required_inputs.eq(i).addClass('ays_red_border'); 351 required_inputs.eq(i).addClass('shake'); 352 empty_inputs++; 353 }else{ 354 required_inputs.eq(i).addClass('ays_green_border'); 355 } 356 break; 357 } 358 case "email": { 359 if (!(emailValivatePattern.test(required_inputs.eq(i).val()))) { 360 required_inputs.eq(i).addClass('ays_red_border'); 361 required_inputs.eq(i).addClass('shake'); 362 empty_inputs++; 363 }else{ 364 required_inputs.eq(i).addClass('ays_green_border'); 365 } 366 break; 367 } 368 case "tel": { 369 if (!validatePhoneNumber(required_inputs.eq(i).get(0))) { 370 required_inputs.eq(i).addClass('ays_red_border'); 371 required_inputs.eq(i).addClass('shake'); 372 empty_inputs++; 373 }else{ 374 required_inputs.eq(i).addClass('ays_green_border'); 375 } 376 break; 377 } 378 default:{ 379 if (required_inputs.eq(i).val() === '' && 380 required_inputs.eq(i).attr('type') !== 'hidden') { 381 required_inputs.eq(i).addClass('ays_red_border'); 382 required_inputs.eq(i).addClass('shake'); 383 empty_inputs++; 384 }else{ 385 required_inputs.eq(i).addClass('ays_green_border'); 386 } 387 if(required_inputs.eq(i).attr('name') == "ays_user_email" && !(emailValivatePattern.test(required_inputs.eq(i).val()))){ 388 empty_inputs++; 389 } 390 break; 391 } 392 } 393 } 394 var empty_inputs2 = 0; 395 var phoneInput = $(this).parents('.step').find('input[name="ays_user_phone"]'); 396 var emailInput = $(this).parents('.step').find('input[name="ays_user_email"]'); 397 var selectAttr = $(this).parents('.step').find('select.ays_quiz_form_input[required]'); 398 if(phoneInput.val() != ''){ 399 phoneInput.removeClass('ays_red_border'); 400 phoneInput.removeClass('ays_green_border'); 401 if (!validatePhoneNumber(phoneInput.get(0))) { 402 if (phoneInput.attr('type') !== 'hidden') { 403 phoneInput.addClass('ays_red_border'); 404 phoneInput.addClass('shake'); 405 empty_inputs2++; 406 } 407 }else{ 408 phoneInput.addClass('ays_green_border'); 409 } 410 } 411 if(selectAttr.val() == ''){ 412 selectAttr.removeClass('ays_red_border'); 413 selectAttr.removeClass('ays_green_border'); 414 415 selectAttr.addClass('ays_red_border'); 416 selectAttr.addClass('shake'); 417 empty_inputs++; 418 }else{ 419 selectAttr.removeClass('ays_red_border'); 420 } 421 var errorFields = $(this).parents('.step').find('.ays_red_border'); 422 if (empty_inputs2 !== 0 || empty_inputs !== 0) { 423 setTimeout(function(){ 424 errorFields.each(function(){ 425 $(this).removeClass('shake'); 426 }); 427 }, 500); 428 setTimeout(function(){ 429 required_inputs.each(function(){ 430 $(this).removeClass('shake'); 431 }); 432 }, 500); 433 return false; 434 } 435 }else{ 436
436 if($(this).parents('.step').find('.information_form').length !== 0 ){ 437 var empty_inputs = 0; 438 var phoneInput = $(this).parents('.step').find('input[name="ays_user_phone"]'); 439 var emailInput = $(this).parents('.step').find('input[name="ays_user_email"]'); 440 var emailInputs = $(this).parents('.step').find('input[type="email"]'); 441 if(phoneInput.val() != ''){ 442 phoneInput.removeClass('ays_red_border'); 443 phoneInput.removeClass('ays_green_border'); 444 if (!validatePhoneNumber(phoneInput.get(0))){ 445 if (phoneInput.attr('type') !== 'hidden') { 446 phoneInput.addClass('ays_red_border'); 447 phoneInput.addClass('shake'); 448 empty_inputs++; 449 } 450 }else{ 451 phoneInput.addClass('ays_green_border'); 452 } 453 } 454 if(emailInput.val() != ''){ 455 emailInput.removeClass('ays_red_border'); 456 emailInput.removeClass('ays_green_border'); 457 if (!(emailValivatePattern.test(emailInput.val()))) { 458 if (emailInput.attr('type') !== 'hidden') { 459 emailInput.addClass('ays_red_border'); 460 emailInput.addClass('shake'); 461 empty_inputs++; 462 } 463 }else{ 464 emailInput.addClass('ays_green_border'); 465 } 466 } 467 468 emailInputs.each(function(){ 469 var thisEmailInput = $(this); 470 if(thisEmailInput.val() != ''){ 471 thisEmailInput.removeClass('ays_red_border'); 472 thisEmailInput.removeClass('ays_green_border'); 473 if (!(emailValivatePattern.test(thisEmailInput.val()))) { 474 thisEmailInput.addClass('ays_red_border'); 475 thisEmailInput.addClass('shake'); 476 empty_inputs++; 477 }else{ 478 thisEmailInput.addClass('ays_green_border'); 479 } 480 } 481 }); 482 var errorFields = $(this).parents('.step').find('.ays_red_border'); 483 if (empty_inputs !== 0) { 484 setTimeout(function(){ 485 errorFields.each(function(){ 486 $(this).removeClass('shake'); 487 }); 488 }, 500); 489 return false; 490 } 491 } 492 } 493 } 494 495 var next_sibilings_count = $(this).parents('form').find('.ays_question_count_per_page').val(); 496 $(e.target).parents().eq(3).find('input[name^="ays_questions"]').attr('disabled', false); 497 $(e.target).parents().eq(3).find('div.ays-quiz-timer').slideUp(500); 498 if($(e.target).parents().eq(3).find('div.ays-quiz-after-timer').hasClass('empty_after_timer_text')){ 499 $(e.target).parents().eq(3).find('div.ays-quiz-timer').parent().slideUp(500); 500 } 501 502 next_fs = $(this).parents('.step').next(); 503 current_fs = $(this).parents('.step'); 504 next_fs.addClass('active-step'); 505 current_fs.removeClass('active-step'); 506 form = ays_quiz_container.find('form'); 507 508 if (!($(this).hasClass('start_button')) && ! window.aysEarlyFinishConfirmBox[ quizId ]) { 509 var minSelHasError = 0; 510 var buttonsDiv = current_fs.find('.ays_buttons_div'); 511 var enableArrows = $(this).parents(".ays-questions-container").find(".ays_qm_enable_arrows").val(); 512 var timerBox = $(this).parents(".ays-quiz-container").find(".ays-quiz-timer div.ays-quiz-after-timer"); 513 if( ays_quiz_container.find('.step[data-question-id] .enable_min_selection_number').length > 0 ){ 514 ays_quiz_container.find('.step[data-question-id] .enable_min_selection_number').each(function(){ 515 var MinSelQuestion = $(this).parents('.step[data-question-id]'); 516 var checkedMinSelCount = aysCheckMinimumCountCheckbox( MinSelQuestion, myQuizOptions ); 517 if( ays_quiz_is_question_min_count( MinSelQuestion, !checkedMinSelCount ) === true ){ 518 if( checkedMinSelCount == true ){ 519 if(enableArrows){ 520 buttonsDiv.find('i.ays_next_arrow').removeAttr('disabled'); 521 buttonsDiv.find('i.ays_next_arrow').prop('disabled', false); 522 }else{ 523 buttonsDiv.find('input.ays_next').removeAttr('disabled'); 524 buttonsDiv.find('input.ays_next').prop('disabled', false); 525 } 526 }else{ 527 if(enableArrows){ 528 buttonsDiv.find('i.ays_next_arrow').attr('disabled', 'disabled'); 529 buttonsDiv.find('i.ays_next_arrow').prop('disabled', true); 530 buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none'); 531 }else{ 532 buttonsDiv.find('input.ays_next').attr('disabled', 'disabled'); 533 buttonsDiv.find('input.ays_next').prop('disabled', true); 534 buttonsDiv.find('input.ays_next').removeClass('ays_display_none'); 535 } 536 minSelHasError++; 537 } 538 }else{ 539 if(enableArrows){ 540 buttonsDiv.find('i.ays_next_arrow').attr('disabled', 'disabled'); 541 buttonsDiv.find('i.ays_next_arrow').prop('disabled', true); 542 buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none'); 543 }else{ 544 buttonsDiv.find('input.ays_next').attr('disabled', 'disabled'); 545 buttonsDiv.find('input.ays_next').prop('disabled', true); 546 buttonsDiv.find('input.ays_next').removeClass('ays_display_none'); 547 } 548 minSelHasError++; 549 } 550 }); 551 } 552 553 var is_timerEnd = false; 554 if(timerBox.hasClass("ays_timer_end")){ 555 is_timerEnd = true; 556 } 557 558 if( minSelHasError > 0 && is_timerEnd){ 559 return false; 560 } 561 } 562 563 var textAnswers = form.find('div.ays-text-field textarea.ays-text-input'); 564 for(var i=0; i < textAnswers.length; i++){ 565 var userAnsweredText = textAnswers.eq(i).val().trim(); 566 var questionId = textAnswers.eq(i).parents('.step').data('questionId'); 567 568 var trueAnswered = false; 569 570 // Enable case sensitive text 571 var enable_case_sensitive_text = (myQuizOptions[questionId].enable_case_sensitive_text && myQuizOptions[questionId].enable_case_sensitive_text != "") ? myQuizOptions[questionId].enable_case_sensitive_text : false; 572 573 var thisQuestionCorrectAnswer = myQuizOptions[questionId].question_answer == '' ? "" : myQuizOptions[questionId].question_answer; 574 var thisQuestionAnswer = thisQuestionCorrectAnswer.toLowerCase(); 575 576 if ( enable_case_sensitive_text ) { 577 thisQuestionAnswer = thisQuestionCorrectAnswer; 578 } 579 580 thisQuestionAnswer = aysEscapeHtmlDecode( thisQuestionAnswer ).aysStripSlashes().split('%%%'); 581 for(var i_answer = 0; i_answer < thisQuestionAnswer.length; i_answer++){ 582 if ( enable_case_sensitive_text ) { 583 if(userAnsweredText == thisQuestionAnswer[i_answer].trim()){ 584 trueAnswered = true; 585 break; 586 } 587 } else { 588 if(userAnsweredText.toLowerCase() == thisQuestionAnswer[i_answer].trim()){ 589 trueAnswered = true; 590 break; 591 } 592 } 593 } 594 595 if(trueAnswered){ 596 textAnswers.eq(i).next().val(1); 597 }else{ 598 textAnswers.eq(i).next().val(0); 599 if(thisQuestionCorrectAnswer == ''){ 600 textAnswers.eq(i).attr('chishtpatasxan', '-'); 601 }else{ 602 textAnswers.eq(i).attr('chishtpatasxan', thisQuestionCorrectAnswer); 603 } 604 } 605 textAnswers.eq(i).removeAttr('disabled'); 606 } 607 608 var numberAnswers = form.find('div.ays-text-field input[type="number"].ays-text-input'); 609 for(var i=0; i < numberAnswers.length; i++){ 610 var userAnsweredText = numberAnswers.eq(i).val().trim(); 611 var questionId = numberAnswers.eq(i).parents('.step').data('questionId'); 612 if(userAnsweredText.toLowerCase().replace(/\.([^0]+)0+$/,".$1") === myQuizOptions[questionId].question_answer.toLowerCase().replace(/\.([^0]+)0+$/,".$1")){ 613 numberAnswers.eq(i).next().val(1); 614 }else{ 615 numberAnswers.eq(i).next().val(0); 616 numberAnswers.eq(i).attr('chishtpatasxan', myQuizOptions[questionId].question_answer); 617 } 618 numberAnswers.eq(i).removeAttr('disabled') 619 } 620 621 var shortTextAnswers = form.find('div.ays-text-field input[type="text"].ays-text-input'); 622 for(var i=0; i < shortTextAnswers.length; i++){ 623 var userAnsweredText = shortTextAnswers.eq(i).val().trim(); 624 var questionId = shortTextAnswers.eq(i).parents('.step').data('questionId'); 625 626 var trueAnswered = false; 627 628 // Enable case sensitive text 629 var enable_case_sensitive_text = (myQuizOptions[questionId].enable_case_sensitive_text && myQuizOptions[questionId].enable_case_sensitive_text != "") ? myQuizOptions[questionId].enable_case_sensitive_text : false; 630 631 var thisQuestionCorrectAnswer = myQuizOptions[questionId].question_answer == '' ? "" : myQuizOptions[questionId].question_answer; 632 var thisQuestionAnswer = thisQuestionCorrectAnswer.toLowerCase(); 633 634 if ( enable_case_sensitive_text ) { 635 thisQuestionAnswer = thisQuestionCorrectAnswer; 636 } 637 638 thisQuestionAnswer = aysEscapeHtmlDecode( thisQuestionAnswer ).aysStripSlashes().split('%%%'); 639 for(var i_answer = 0; i_answer < thisQuestionAnswer.length; i_answer++){ 640 if ( enable_case_sensitive_text ) { 641 if(userAnsweredText == thisQuestionAnswer[i_answer].trim()){ 642 trueAnswered = true; 643 break; 644 } 645 } else { 646 if(userAnsweredText.toLowerCase() == thisQuestionAnswer[i_answer].trim()){ 647 trueAnswered = true; 648 break; 649 } 650 } 651 } 652 653 if(trueAnswered){ 654 shortTextAnswers.eq(i).next().val(1); 655 }else{ 656 shortTextAnswers.eq(i).next().val(0); 657 if(thisQuestionCorrectAnswer == ''){ 658 shortTextAnswers.eq(i).attr('chishtpatasxan', '-'); 659 }else{ 660 shortTextAnswers.eq(i).attr('chishtpatasxan', thisQuestionCorrectAnswer); 661 } 662 } 663 664 shortTextAnswers.eq(i).removeAttr('disabled') 665 } 666 667 var dateAnswers = form.find('div.ays-text-field input[type="date"].ays-text-input'); 668 for(var i=0; i < dateAnswers.length; i++){ 669 var userAnsweredText = dateAnswers.eq(i).val(); 670 var questionId = dateAnswers.eq(i).parents('.step').data('questionId'); 671 var thisQuestionCorrectAnswer = myQuizOptions[questionId].question_answer == '' ? "" : myQuizOptions[questionId].question_answer; 672 673 var trueAnswered = false; 674 var correctDate = new Date(thisQuestionCorrectAnswer), 675 correctDateYear = correctDate.getFullYear(), 676 correctDateMonth = correctDate.getMonth(), 677 correctDateDay = correctDate.getDate(); 678 var userDate = new Date(userAnsweredText), 679 userDateYear = userDate.getFullYear(), 680 userDateMonth = userDate.getMonth(), 681 userDateDay = userDate.getDate(); 682 683 if(correctDateYear == userDateYear && correctDateMonth == userDateMonth && correctDateDay == userDateDay){ 684 trueAnswered = true; 685 } 686 687 if(trueAnswered){ 688 dateAnswers.eq(i).next().val(1); 689 }else{ 690 dateAnswers.eq(i).next().val(0); 691 if(thisQuestionCorrectAnswer == ''){ 692 dateAnswers.eq(i).attr('chishtpatasxan', '-'); 693 }else{ 694 dateAnswers.eq(i).attr('chishtpatasxan', thisQuestionCorrectAnswer); 695 } 696 } 697 698 dateAnswers.eq(i).removeAttr('disabled') 699 } 700 701 702 var data = form.serializeFormJSON(); 703 var questionsIds = data.ays_quiz_questions.split(','); 704 705 for(var i = 0; i < questionsIds.length; i++){ 706 if(! data['ays_questions[ays-question-'+questionsIds[i]+']']){ 707 data['ays_questions[ays-question-'+questionsIds[i]+']'] = ""; 708 } 709 } 710 711 var checked_inputs_arr = ays_quiz_container.find(".step .ays-field input[id*='ays-answer-']:checked"); 712 if ( checked_inputs_arr.length > 0 ) { 713 checked_inputs_arr.each(function () { 714 var checked_input = $(this); 715 var checked_input_name = checked_input.attr('name'); 716 var checked_input_value = checked_input.attr('value'); 717 718 if (checked_input_name != "" && checked_input_value != "") { 719 if ( data[checked_input_name] !== undefined && data[checked_input_name] == "") { 720 data[checked_input_name] = checked_input_value; 721 } 722 } 723 }); 724 } 725 726 $(this).parents('.ays-quiz-wrap').find('.ays-quiz-questions-nav-wrap').css("display", "none"); 727 728 data.action = 'ays_finish_quiz'; 729 data.end_date = GetFullDateTime(); 730 var ays_quiz_finish_time = ays_quiz_container.find('.ays-quiz-end-date'); 731 if ( ays_quiz_fi
731nish_time.length !== 0 && ays_quiz_finish_time.val() != "" ) { 732 data.end_date = ays_quiz_finish_time.val(); 733 } else { 734 data.end_date = GetFullDateTime(); 735 } 736 737 if ( typeof data.start_date == "undefined" || data.start_date == "" ) { 738 data.start_date = window.aysQuizStartDate; 739 } 740 741 if ( typeof data.end_date == "undefined" || data.end_date == "" ) { 742 data.end_date = GetFullDateTime(); 743 } 744 745 if (window.location != window.parent.location) { 746 if ( typeof data.ays_quiz_curent_page_link != "undefined" && data.ays_quiz_curent_page_link != "" ) { 747 if ( data.ays_quiz_curent_page_link.indexOf("action=ays_quiz_iframe_shortcode") > 0 ) { 748 if( window.aysQuizParentWindowLink && window.aysQuizParentWindowLink != ""){ 749 data.ays_quiz_curent_page_link = window.aysQuizParentWindowLink; 750 } 751 } 752 } 753 } 754 755 var aysQuizLoader = form.find('div[data-role="loader"]'); 756 aysQuizLoader.addClass(aysQuizLoader.data('class')); 757 aysQuizLoader.removeClass('ays-loader'); 758 759 var animationOptions = { 760 scale: scale, 761 left: left, 762 opacity: opacity, 763 animating: animating 764 } 765 766 setTimeout(function () { 767 sendQuizData(data, form, myOptions, animationOptions, $(e.target)); 768 },2000); 769 770 if (parseInt(next_sibilings_count) > 0 && ($(this).parents('.step').attr('data-question-id') || $(this).parents('.step').next().attr('data-question-id'))) { 771 current_fs = $(this).parents('form').find('div[data-question-id]'); 772 } 773 774 if( isRequiredQuestion ) { 775 var qid = checkQuestionTimer(ays_quiz_container, quizId); 776 if ( qid === false ){ 777 aysAnimateStep(ays_quiz_container.data('questEffect'), current_fs, next_fs); 778 } 779 } 780 }); 781 782 $(document).find('.ays_next.start_button').on('click',function(e){ 783 var $this = $(this); 784 var thisCont = $this.parents('.ays-quiz-container'); 785 var quizId = thisCont.find('input[name="ays_quiz_id"]').val(); 786 var myOptions = JSON.parse(window.atob(window.aysQuizOptions[quizId])); 787 var checkQuizGeneratedPassword = checkQuizPassword(e, myOptions, false); 788 if(checkQuizGeneratedPassword){ 789 if(myOptions.enable_password && myOptions.enable_password == 'on'){ 790 if(myOptions.generate_password && myOptions.generate_password == 'generated_password'){ 791 var userGeneratedPasswordVal = $this.parents('.ays-quiz-container').find('.ays_quiz_password').val(); 792 var userData = {}; 793 userData.action = 'ays_generated_used_passwords'; 794 userData.userGeneratedPassword = userGeneratedPasswordVal; 795 userData.quizId = quizId; 796 $.ajax({
797 url: quiz_maker_ajax_public.ajax_url, 798 method: 'post', 799 dataType: 'json', 800 crossDomain: true, 801 data: userData, 802 success: function (response) { 803 if(response.status){ 804 } 805 } 806 }); 807 } 808 } 809 810 if(myOptions.limit_users && myOptions.limit_users == 'on'){ 811 var limit_users_by = (myOptions.limit_users_by && myOptions.limit_users_by != '') ? myOptions.limit_users_by : 'ip'; 812 var isUserLoggedIn = (myOptions.is_user_logged_in && myOptions.is_user_logged_in != null) ? myOptions.is_user_logged_in : null; 813 814 myOptions.enable_restriction_pass = myOptions.enable_restriction_pass ? myOptions.enable_restriction_pass : 'off'; 815 var onlyForSelectedUserRole = (myOptions.enable_restriction_pass && myOptions.enable_restriction_pass == 'on' ) ? true : false; 816 817 myOptions.turn_on_extra_security_check = myOptions.turn_on_extra_security_check ? myOptions.turn_on_extra_security_check : 'on'; 818 var turnOnSecurityCheck = (myOptions.turn_on_extra_security_check && myOptions.turn_on_extra_security_check == 'on' ) ? true : false; 819 820 myOptions.limit_attempts_count_by_user_role = myOptions.limit_attempts_count_by_user_role ? myOptions.limit_attempts_count_by_user_role : ''; 821 var limitAttemptsCountByUserRole = (myOptions.limit_attempts_count_by_user_role !=='' ) ? parseInt( myOptions.limit_attempts_count_by_user_role ) : ''; 822 823 if( isUserLoggedIn === null ){ 824 isUserLoggedIn = false; 825 } 826 827 var checkLimit = false; 828 if( limit_users_by != 'user_id' ){ 829 checkLimit = true; 830 } 831 832 if( isUserLoggedIn ){ 833 checkLimit = true; 834 } 835 836 if( turnOnSecurityCheck === false ){ 837 checkLimit = false; 838 } 839 840 if( checkLimit ){ 841 var quiz_max_pass_count = (myOptions.quiz_max_pass_count && myOptions.quiz_max_pass_count != '') ? parseInt(myOptions.quiz_max_pass_count) : 1; 842 843 if( limitAttemptsCountByUserRole !== '' && onlyForSelectedUserRole === true ){ 844 quiz_max_pass_count = limitAttemptsCountByUserRole; 845 } 846 847 var limitation_message = (myOptions.limitation_message && myOptions.limitation_message != '') ? myOptions.limitation_message : quizLangObj.alreadyPassedQuiz; 848 var quiz_pass_score = (myOptions.quiz_pass_score && myOptions.quiz_pass_score != '') ? myOptions.quiz_pass_score : 0; 849 var text_color = (myOptions.text_color && myOptions.text_color != '') ? myOptions.text_color : "#333"; 850 851 var html = '<div style="color:'+ text_color +';min-height:200px;" class="ays_block_content">'+ limitation_message +'</div>'; 852 853 var userData = {}; 854 855 userData.action = 'ays_quiz_check_user_started'; 856 userData.quiz_id = quizId; 857 userData.quiz_max_pass_count = quiz_max_pass_count; 858 userData.quiz_pass_score = quiz_pass_score; 859 userData.start_date = GetFullDateTime(); 860 861 $.ajax({
862 url: quiz_maker_ajax_public.ajax_url, 863 method: 'post', 864 dataType: 'json', 865 crossDomain: true, 866 data: userData, 867 success: function (response) { 868 if(response.status){ 869 thisCont.find('.ays_quiz_result_row_id').val(response.result_id); 870 }else{ 871 $this.parents('.ays-quiz-wrap').find('.ays-quiz-questions-nav-wrap').hide(); 872 thisCont.find('.ays_quiz_timer_container').slideUp(500); 873 thisCont.find('form').append(html); 874 thisCont.find('div.step').remove(); 875 clearInterval(window.aysTimerInterval); 876 } 877 } 878 }); 879 } 880 } 881 else if( myOptions.store_all_not_finished_results && myOptions.store_all_not_finished_results === true ){ 882 var quiz_max_pass_count = (myOptions.quiz_max_pass_count && myOptions.quiz_max_pass_count != '') ? parseInt(myOptions.quiz_max_pass_count) : 1; 883 var limitation_message = (myOptions.limitation_message && myOptions.limitation_message != '') ? myOptions.limitation_message : quizLangObj.alreadyPassedQuiz; 884 var quiz_pass_score = (myOptions.quiz_pass_score && myOptions.quiz_pass_score != '') ? myOptions.quiz_pass_score : 0; 885 var text_color = (myOptions.text_color && myOptions.text_color != '') ? myOptions.text_color : "#333"; 886 887 var html = '<div style="color:'+ text_color +';min-height:200px;" class="ays_block_content">'+ limitation_message +'</div>'; 888 889 var userData = {}; 890 891 userData.action = 'ays_quiz_check_user_started'; 892 userData.quiz_id = quizId; 893 userData.quiz_max_pass_count = quiz_max_pass_count; 894 userData.quiz_pass_score = quiz_pass_score; 895 userData.start_date = GetFullDateTime(); 896 897 $.ajax({
898 url: quiz_maker_ajax_public.ajax_url, 899 method: 'post', 900 dataType: 'json', 901 crossDomain: true, 902 data: userData, 903 success: function (response) { 904 if(response.status){ 905 thisCont.find('.ays_quiz_result_row_id').val(response.result_id); 906 }else{ 907 clearInterval(window.aysTimerInterval); 908 } 909 } 910 }); 911 } 912 } 913 }); 914 915 }); 916 917 function sendQuizData(data, form, myOptions, options, element){ 918 if(typeof sendQuizData.counter == 'undefined'){ 919 sendQuizData.counter = 0; 920 } 921 if(window.navigator.onLine){ 922 sendQuizData.counter++; 923 $.ajax({ 924 url: window.quiz_maker_ajax_public.ajax_url, 925 method: 'post', 926 dataType: 'json', 927 crossDomain: true, 928 data: data, 929 success: function(response){ 930 if(response.status === true){ 931 doQuizResult(response, form, myOptions); 932 }else if( response.status === false && typeof response.flag !== 'undefined' && response.flag === false ){ 933 var aysQuizContainer = element.parents('.ays-quiz-container'); 934 var lastPageContent = ''; 935 936 lastPageContent += '<p>'; 937 lastPageContent += response.text; 938 lastPageContent += '</p>'; 939 940 aysQuizContainer.find('.ays_thank_you_fs').html( lastPageContent ); 941 }else{ 942 if(sendQuizData.counter >= 5){ 943 swal.fire({ 944 type: 'error', 945 html: quizLangObj.sorry + ".<br>" + quizLangObj.unableStoreData + "." 946 }); 947 goQuizFinishPage(form, options, element, myOptions); 948 }else{ 949 if(window.navigator.onLine){ 950 setTimeout(function(){ 951 sendQuizData(data, form, myOptions, options, element); 952 },3000); 953 }else{ 954 sendQuizData(data, form, myOptions, options, element); 955 } 956 } 957 } 958 }, 959 error: function(jqXHR, textStatus, errorThrown) { 960 if(sendQuizData.counter >= 5){ 961 swal.fire({ 962 type: 'error', 963 html: quizLangObj.sorry + ".<br>" + quizLangObj.unableStoreData + "." 964 }); 965 goQuizFinishPage(form, options, element, myOptions); 966 }else{ 967 setTimeout(function(){ 968 sendQuizData(data, form, myOptions, options, element); 969 },3000); 970 } 971 } 972 }); 973 }else{ 974 swal.fire({ 975 type: 'warning', 976 html: quizLangObj.connectionLost + ".<br>" + quizLangObj.checkConnection + "." 977 }); 978 sendQuizData.counter = 0; 979 goQuizFinishPage(form, options, element, myOptions); 980 var aysQuizContainer = element.parents('.ays-quiz-container'); 981 aysQuizContainer.find('.step').hide(); 982 aysQuizContainer.find('.ays_thank_you_fs').prev().removeAttr('style').css({ 983 'display':'flex', 984 'position':'static', 985 'transform':'scale(1)', 986 'opacity': 1, 987 'pointer-events': 'auto' 988 }); 989 var show_result_button = element.parents('form').find('div[data-question-id] input[name="ays_finish_quiz"]'); 990 if (show_result_button.hasClass('ays_display_none')) { 991 show_result_button.removeClass('ays_display_none'); 992 } 993 } 994 } 995 996 function goQuizFinishPage(form, options, element, myOptions){ 997 var currentFS = form.find('.step.active-step'); 998 var next_sibilings_count = form.find('.ays_question_count_per_page').val(); 999 if (parseInt(next_sibilings_count) > 0 && 1000 (element.parents('.step').attr('data-question-id') || 1001 element.parents('.step').next().attr('data-question-id'))) { 1002 currentFS = form.find('div[data-question-id]'); 1003 } 1004 currentFS.prev().css('display', 'flex'); 1005 currentFS.animate({opacity: 0}, { 1006 step: function(now, mx) { 1007 options.scale = 1 - (1 - now) * 0.2; 1008 options.left = (now * 50)+"%"; 1009 options.opacity = 1 - now; 1010 currentFS.css({ 1011 'transform': 'scale('+options.scale+')', 1012 'position': '', 1013 'pointer-events': 'none' 1014 }); 1015 currentFS.prev().css({ 1016 'left': options.left, 1017 'opacity': options.opacity, 1018 'pointer-events': 'none' 1019 }); 1020 },
1021 duration: 800, 1022 complete: function(){ 1023 currentFS.hide(); 1024 currentFS.css({ 1025 'opacity': '1', 1026 'pointer-events': 'auto', 1027 }); 1028 currentFS.prev().css({ 1029 'transform': 'scale(1)', 1030 'position': 'relative', 1031 'opacity': '1', 1032 'pointer-events': 'auto' 1033 }); 1034 options.animating = false; 1035 }, 1036 easing: 'easeInOutBack' 1037 }); 1038 if(myOptions.enable_correction == 'on'){ 1039 if(currentFS.prev().find('input:checked').length > 0){ 1040 currentFS.prev().find('.ays-field input').attr('disabled', 'disabled'); 1041 currentFS.prev().find('.ays-field input').on('click', function(){ 1042 return false; 1043 }); 1044 currentFS.prev().find('.ays-field input').on('change', function(){ 1045 return false; 1046 }); 1047 } 1048 if(currentFS.prev().find('option:checked').length > 0){ 1049 currentFS.prev().find('.ays-field select').attr('disabled', 'disabled'); 1050 currentFS.prev().find('.ays-field select').on('click', function(){ 1051 return false; 1052 }); 1053 currentFS.prev().find('.ays-field select').on('change', function(){ 1054 return false; 1055 }); 1056 } 1057 if(currentFS.prev().find('textarea').length > 0){ 1058 if(currentFS.prev().find('textarea').val() !== ''){ 1059 currentFS.prev().find('.ays-field textarea').attr('disabled', 'disabled'); 1060 currentFS.prev().find('.ays-field textarea').on('click', function(){ 1061 return false; 1062 }); 1063 currentFS.prev().find('.ays-field textarea').on('change', function(){ 1064 return false; 1065 }); 1066 } 1067 } 1068 } 1069 } 1070 1071 function doQuizResult(response, form, myOptions){ 1072 var hideQuizBGImage = form.parents('.ays-quiz-container').data('hideBgImage'); 1073 var QuizBGGragient = form.parents('.ays-quiz-container').data('bgGradient'); 1074 var quizId = form.parents('.ays-quiz-container').find('input[name="ays_quiz_id"]').val(); 1075 if(hideQuizBGImage){ 1076 form.parents('.ays-quiz-container').css('background-image', 'none'); 1077 if(typeof QuizBGGragient != 'undefined'){ 1078 form.parents('.ays-quiz-container').css('background-image', QuizBGGragient); 1079 } 1080 } 1081 1082 if(typeof response.chain_quiz_button_text != 'undefined' && response.chain_quiz_button_text === 'seeResult'){ 1083 form.find('.ays_chain_see_result_button').removeClass('ays_display_none'); 1084 }else if(typeof response.chain_quiz_button_text != 'undefined' && response.chain_quiz_button_text === 'nextQuiz'){ 1085 form.find('.ays_chain_next_quiz_button').removeClass('ays_display_none'); 1086 } 1087 1088 var conditionsData = response.conditionData; 1089 var conditionsExict = false; 1090 var conditionPageMessage = ""; 1091 var conditionEmailMessage = ""; 1092 var conditionRedirectDelay = ""; 1093 var conditionRedirectUrl = ""; 1094 var conditionRedirectCountDown = ""; 1095 var trueConditionsCount = ""; 1096 if(typeof conditionsData != "undefined"){ 1097 if(conditionsData.hasAction){ 1098 if(conditionsData.pageMessage){ 1099 conditionPageMessage = conditionsData.pageMessage; 1100 } 1101 if(conditionsData.emailMessage){ 1102 conditionEmailMessage = conditionsData.emailMessage; 1103 } 1104 if(conditionsData.redirectDelay){ 1105 conditionRedirectDelay = conditionsData.redirectDelay; 1106 } 1107 if(conditionsData.redirectUrl){ 1108 conditionRedirectUrl = conditionsData.redirectUrl; 1109 } 1110 if(conditionsData.redirectCountDown){ 1111 conditionRedirectCountDown = conditionsData.redirectCountDown; 1112 } 1113 if(conditionsData.trueConditionsCount){ 1114 trueConditionsCount = conditionsData.trueConditionsCount; 1115 } 1116 conditionsExict = true; 1117 } 1118 } 1119 1120 var ays_block_element = form.parents('.ays-quiz-container'); 1121 var redirectActionResponse = true; 1122 if(conditionsExict){ 1123 if(conditionRedirectUrl){ 1124 redirectActionResponse = redirectAction(conditionRedirectUrl, conditionRedirectDelay, ays_block_element, conditionRedirectCountDown, form, myOptions, false); 1125 }else{ 1126 if(response.showIntervalMessage && ( response.interval_redirect_url !== null && response.interval_redirect_url != '' )){ 1127 redirectActionResponse = redirectAction(response.interval_redirect_url, response.interval_redirect_delay, ays_block_element, response.interval_redirect_after, form, myOptions, false); 1128 }else{ 1129 if (myOptions.redirect_after_submit && myOptions.redirect_after_submit == 'on') { 1130 redirectActionResponse = redirectAction(myOptions.submit_redirect_url, myOptions.submit_redirect_delay, ays_block_element, myOptions.submit_redirect_after, form, myOptions, true); 1131 } 1132 } 1133 } 1134 }else{ 1135 if(response.showIntervalMessage && ( response.interval_redirect_url !== null && response.interval_redirect_url != '' )){ 1136 redirectActionResponse = redirectAction(response.interval_redirect_url, response.interval_redirect_delay, ays_block_element, response.interval_redirect_after, form, myOptions, false); 1137 }else{ 1138 if (myOptions.redirect_after_submit && myOptions.redirect_after_submit == 'on') { 1139 redirectActionResponse = redirectAction(myOptions.submit_redirect_url, myOptions.submit_redirect_delay, ays_block_element, myOptions.submit_redirect_after, form, myOptions, true); 1140 } 1141 } 1142 } 1143 1144 if( redirectActionResponse === false ){ 1145 return false; 1146 } 1147 1148 form.find('div.ays_message').css('display', 'none'); 1149 form.find('.ays_average').css({'display': 'block'});
1150 var quizScore = ''; 1151 switch(response.displayScore){ 1152 case 'by_percentage': 1153 quizScore = parseInt(response.score); 1154 break; 1155 case 'by_correctness': 1156 quizScore = response.score.split('/'); 1157 break; 1158 case 'by_points': 1159 quizScore = response.score.split('/'); 1160 break; 1161 default: 1162 quizScore = parseInt(response.score); 1163 } 1164 1165 form.find('.ays_quiz_timer_container').slideUp(500); 1166 1167 if (response.hide_result) { 1168 form.find('div.ays_message').html(response.text); 1169 } else { 1170 if(response.showIntervalMessage){ 1171 form.find('div.ays_message').html(response.intervalMessage + response.finishText); 1172 if (response.product) { 1173// var $wooBlock = $("<div class='ays-woo-block'></div>"); 1174// var $wooInBlock = $("<div class='ays-woo-product-block'></div>"); 1175// var $wooImage = $('<div class="product-image"><img src="' + response.product.image + '" alt="WooCommerce Product"></div>'); 1176// var $wooName = $('<h4 class="ays-woo-product-title"><a href="'+response.product.prodUrl+'" target="_blank">'+response.product.name+'</a></h4>'); 1177// var $wooCartLink = $(response.product.link); 1178// if(response.product.image){ 1179// $wooBlock.append($wooImage); 1180// } 1181// $wooInBlock.append($wooName); 1182// $wooInBlock.append($wooCartLink); 1183// $wooBlock.append($wooInBlock); 1184// form.find('div.ays_message').after($wooBlock); 1185// if(form.parents('.ays-quiz-container').width() < 420){ 1186// form.find('.ays-woo-block').css('flex-wrap', 'wrap'); 1187// if(response.product.image){ 1188// form.find('.ays-woo-product-block').css('padding-top', '20px'); 1189// } 1190// } 1191 var $wooBlock = ''; 1192 var $wooInBlock = ''; 1193 var $wooImage = ''; 1194 var $wooName = ''; 1195 var $wooCartLink = ''; 1196 var $wooBloks = ''; 1197 $wooBloks = $("<div class='ays-woo-block-main'></div>") 1198 for(var products in response.product){ 1199 $wooBlock = $("<div class='ays-woo-block'></div>"); 1200 $wooInBlock = $("<div class='ays-woo-product-block'></div>"); 1201 $wooImage = $('<div class="product-image"><img src="' + response.product[products].image + '" alt="WooCommerce Product"></div>'); 1202 $wooName = $('<h4 class="ays-woo-product-title"><a href="'+response.product[products].prodUrl+'" target="_blank">'+response.product[products].name+'</a></h4>'); 1203 $wooCartLink = $(response.product[products].link); 1204 if(response.product[products].image){ 1205 $wooBlock.append($wooImage); 1206 } 1207 $wooBloks.append($wooBlock); 1208 $wooInBlock.append($wooName); 1209 $wooInBlock.append($wooCartLink); 1210 $wooBlock.append($wooInBlock); 1211 form.find('div.ays_message').after($wooBloks); 1212 if(form.parents('.ays-quiz-container').width() < 420){ 1213 form.find('.ays-woo-block').css('flex-wrap', 'wrap'); 1214 if(response.product[products].image){ 1215 form.find('.ays-woo-product-block').css('padding-top', '20px'); 1216 } 1217 } 1218 } 1219 } 1220 }else{ 1221 form.find('div.ays_message').html(response.finishText); 1222 } 1223 1224 if(conditionsExict){ 1225 form.find('div.ays_message').prepend(conditionPageMessage); 1226 } 1227
1228 form.find('p.ays_score').removeClass('ays_score_display_none'); 1229 form.find('p.ays_score').html(form.find('p.ays_score').text()+'<span class="ays_score_percent animated"> ' + response.score + '</span>'); 1230 } 1231 1232 if( response.socialHeading ){ 1233 form.find(".ays-quiz-social-shares-heading").html(response.socialHeading); 1234 } 1235 1236 form.find('div.ays_message').fadeIn(500); 1237 setTimeout(function () { 1238 form.find('p.ays_score').addClass('tada'); 1239 }, 500); 1240 var numberOfPercent = 0; 1241 var percentAnimate = setInterval(function(){ 1242 if(typeof quizScore == 'number'){ 1243 form.find('.ays-progress-value').text(numberOfPercent + "%"); 1244 if(numberOfPercent == quizScore){ 1245 clearInterval(percentAnimate); 1246 } 1247 numberOfPercent++; 1248 }else{ 1249 var total = quizScore[1]; 1250 var count = quizScore[0]; 1251 total = parseFloat(total.trim()); 1252 count = parseFloat(count.trim()); 1253 form.find('.ays-progress-value').text(numberOfPercent + " / " + total); 1254 if(numberOfPercent >= count){ 1255 form.find('.ays-progress-value').text(count + " / " + total); 1256 clearInterval(percentAnimate); 1257 } 1258 numberOfPercent++; 1259 } 1260 },20); 1261 1262 var score = quizScore; 1263 if(response.displayScore == 'by_correctness' || response.displayScore == 'by_points'){ 1264 var total = parseInt(quizScore[1].trim()); 1265 var count = parseInt(quizScore[0].trim()); 1266 score = (count / total) * 100; 1267 } 1268 1269 if(response.scoreMessage){ 1270 form.find('div.ays_score_message').html(response.scoreMessage); 1271 } 1272 1273 var last_result_id = null; 1274 if(response.result_id && response.result_id != ''){ 1275 last_result_id = parseInt( response.result_id ); 1276 } 1277 1278 aysQuizSetCustomEvent(); 1279 var trackUsersEvent = new CustomEvent('getResultId', { 1280 detail: { 1281 resultId: last_result_id 1282 } 1283 }); 1284 form.get(0).dispatchEvent(trackUsersEvent); 1285 1286 // Make responses anonymous 1287 myOptions.quiz_make_responses_anonymous = ( myOptions.quiz_make_responses_anonymous ) ? myOptions.quiz_make_responses_anonymous : 'off'; 1288 var quiz_make_responses_anonymous = (myOptions.quiz_make_responses_anonymous && myOptions.quiz_make_responses_anonymous == "on") ? true : false; 1289 1290 // Enable Keyboard Navigation 1291 myOptions.quiz_enable_keyboard_navigation = ! myOptions.quiz_enable_keyboard_navigation ? 'off' : myOptions.quiz_enable_keyboard_navigation; 1292 var quiz_enable_keyboard_navigation = (myOptions.quiz_enable_keyboard_navigation && myOptions.quiz_enable_keyboard_navigation == 'on') ? true : false; 1293 1294 var class_for_keyboard = ''; 1295 var attributes_for_keyboard = ''; 1296 1297 if( quiz_enable_keyboard_navigation ){ 1298 class_for_keyboard = "ays-quiz-keyboard-active"; 1299 attributes_for_keyboard = "tabindex='0'"; 1300 } 1301 1302 if(score > 0){ 1303 form.find('.ays-progress-bar').css('padding-right', '7px'); 1304 var progressBarStyle = myOptions.progress_bar_style ? myOptions.progress_bar_style : 'first'; 1305 if(progressBarStyle == 'first' || progressBarStyle == 'second'){ 1306 form.find('.ays-progress-value').css('width', 0); 1307 form.find('.ays-progress-value').css('transition', 'width ' + score*25 + 'ms linear'); 1308 setTimeout(function(){ 1309 form.find('.ays-progress-value').css('width', score+'%'); 1310 }, 1); 1311 } 1312 form.find('.ays-progress-bar').css('transition', 'width ' + score*25 + 'ms linear'); 1313 setTimeout(function(){ 1314 form.find('.ays-progress-bar').css('width', score+'%'); 1315 }, 1); 1316 } 1317 1318 if ( score == 0 ) { 1319 // Quiz background Color 1320 var quiz_make_bg_color = (myOptions.bg_color && myOptions.bg_color != "") ? myOptions.bg_color : '#fff'; 1321 1322 form.find('.ays-progress-value').css('color', quiz_make_bg_color); 1323 } 1324 1325 form.append($("<div class='ays_quiz_results'></div>")); 1326 var formResults = form.find('.ays_quiz_results'); 1327 if (form.hasClass('enable_questions_result')) { 1328 1329 // Enable the Show/Hide toggle 1330 myOptions.quiz_enable_results_toggle = ! myOptions.quiz_enable_results_toggle ? 'off' : myOptions.quiz_enable_results_toggle; 1331 var quiz_enable_results_toggle = (myOptions.quiz_enable_results_toggle && myOptions.quiz_enable_results_toggle == 'on') ? true : false; 1332 1333 var resultToggleHTML = ""; 1334 1335 resultToggleHTML += '<div class="ays-quiz-results-toggle-block">'; 1336 resultToggleHTML += '<span class="ays-show-res-toggle ays-res-toggle-show">'+ quizLangObj.show +'</span>'; 1337 resultToggleHTML += '<input type="checkbox" class="ays_toggle ays_toggle_slide ays-quiz-res-toggle-checkbox" id="ays-quiz-show-results-toggle-'+ quizId +'" checked>'; 1338 resultToggleHTML += '<label for="ays-quiz-show-results-toggle-'+ quizId +'" class="ays_switch_toggle '+ class_for_keyboard +'" '+ attributes_for_keyboard +'>Toggle</label>'; 1339 resultToggleHTML += '<span class="ays-show-res-toggle ays-res-toggle-hide quest-toggle-failed">'+ quizLangObj.hide +'</span>'; 1340 resultToggleHTML += '</div>'; 1341 1342 if ( quiz_enable_results_toggle ) { 1343 formResults.append(resultToggleHTML); 1344 } 1345 1346 var questions = form.find('div[data-question-id]'); 1347 var showOnlyWrongAnswer = (myOptions.show_only_wrong_answer && myOptions.show_only_wrong_answer == "on") ? true : false; 1348 if(myOptions.enable_correction && myOptions.enable_correction != 'on'){ 1349 showOnlyWrongAnswer = false; 1350 } 1351 1352 var ans_right_wrong_icon = (myOptions.ans_right_wrong_icon && myOptions.ans_right_wrong_icon != "") ? myOptions.ans_right_wrong_icon : "default"; 1353 1354 var correct_img_URL = ""; 1355 var wrong_img_URL = ""; 1356 if( ans_right_wrong_icon == "default"){ 1357 correct_img_URL = quiz_maker_ajax_public.AYS_QUIZ_PUBLIC_URL + "/images/correct.png"; 1358 wrong_img_URL = quiz_maker_ajax_public.AYS_QUIZ_PUBLIC_URL + "/images/wrong.png"; 1359 } else if( ans_right_wrong_icon == "none" ){ 1360 correct_img_URL = ""; 1361 wrong_img_URL = ""; 1362 } else { 1363 correct_img_URL = quiz_maker_ajax_public.AYS_QUIZ_PUBLIC_URL + "/images/correct-"+ ans_right_wrong_icon +".png"; 1364 wrong_img_URL = quiz_maker_ajax_public.AYS_QUIZ_PUBLIC_URL + "/images/wrong-"+ ans_right_wrong_icon +".png"; 1365 } 1366 1367 var correct_img_URL_HTML = ""; 1368 var wrong_img_URL_HTML = ""; 1369 if (correct_img_URL != "") { 1370 correct_img_URL_HTML = "<img class='ays-quiz-check-button-right-wrong-icon' data-type='"+ans_right_wrong_icon+"' src='"+ correct_img_URL +"'>" 1371 } 1372 1373 if (wrong_img_URL != "") { 1374 wrong_img_URL_HTML = "<img class='ays-quiz-check-button-right-wrong-icon' data-type='"+ ans_right_wrong_icon +"' src='"+ wrong_img_URL +"'>" 1375 } 1376 1377 var answerIsRightArr = new Array(); 1378 for (var z = 0; z < questions.length; z++) { 1379 if(questions.eq(z).hasClass('not_influence_to_score')){ 1380 continue; 1381 } 1382 var question = questions.eq(z).clone(true, true); 1383 var questionId = question.attr('data-question-id'); 1384 var question_original_html = questions.eq(z).find('.ays_quiz_question'); 1385 1386 var ays_quiz_question_html = questions.eq(z).find('.ays_quiz_question'); 1387 var ays_quiz_question_img_html = questions.eq(z).find('.ays-image-question-img'); 1388 var question_explanation_html = questions.eq(z).find('.ays_questtion_explanation'); 1389 var wrong_answer_text_html = questions.eq(z).find('.wrong_answer_text'); 1390 var right_answer_text_html = questions.eq(z).find('.right_answer_text'); 1391 var note_message_box_html = questions.eq(z).find('.ays-quiz-question-note-message-box'); 1392 1393 var question_parts_arr = new Array( 1394 note_message_box_html, 1395 question_explanation_html, 1396 wrong_answer_text_html, 1397 right_answer_text_html, 1398 ); 1399 1400 question.find('.ays_quiz_question').remove(); 1401 question.find('.ays-abs-fs').prepend( questions.eq(z).find('.ays_quiz_question') ); 1402 1403 question.find('.ays_questtion_explanation').remove(); 1404 question.find('.ays-abs-fs').append( questions.eq(z).find('.ays_questtion_explanation') ); 1405 1406 question.find('.wrong_answer_text').remove(); 1407 question.find('.ays-abs-fs').append( questions.eq(z).find('.wrong_answer_text') ); 1408 1409 question.find('.right_answer_text').remove(); 1410 question.find('.ays-abs-fs').append( questions.eq(z).find('.right_answer_text') ); 1411 1412 question.find('input[type="button"]').remove(); 1413 question.find('input[type="submit"]').remove(); 1414 question.find('.ays_arrow').remove(); 1415 1416 question.find('.ays-quiz-category-description-box').addClass('ays_display_none'); 1417 1418 question.addClass('ays_question_result');
1419 var checked_inputs = question.find('input:checked'); 1420 var text_answer = question.find('textarea.ays-text-input'); 1421 var number_answer = question.find('input[type="number"].ays-text-input'); 1422 var short_text_answer = question.find('input[type="text"].ays-text-input'); 1423 var date_answer = question.find('input[type="date"].ays-text-input'); 1424 var selected_options = question.find('select'); 1425 var answerIsRight = false; 1426 1427 var fieldset_html = "<fieldset class='ays_fieldset'>" + "<legend>" + quizLangObj.notAnsweredText + "</legend>" + "</fieldset>"; 1428 var question_html = question.find('.ays-abs-fs > *:not(.ays_quiz_question)').clone(true, true); 1429 1430 if(showOnlyWrongAnswer === false){ 1431 question.find('input[name="ays_answer_correct[]"][value="1"]').parent().find('label').addClass('correct answered'); 1432 question.find('input[name="ays_answer_correct[]"][value="1"]').parents('div.ays-field').addClass('correct_div'); 1433 } 1434 1435 if(checked_inputs.length === 0){ 1436 var emptyAnswer = false; 1437 if(question.find('input[type="radio"]').length !== 0){ 1438 emptyAnswer = true; 1439 } 1440 if(question.find('input[type="checkbox"]').length !== 0){ 1441 emptyAnswer = true; 1442 } 1443 if(emptyAnswer){ 1444 1445 var q_answer_text_html = question.find('.ays-abs-fs .ays-quiz-answers'); 1446 question.find('.ays-abs-fs').html(fieldset_html); 1447 question.find('.ays-abs-fs .ays_fieldset').append(ays_quiz_question_html); 1448 question.find('.ays-abs-fs .ays_fieldset').append(ays_quiz_question_img_html); 1449 question.find('.ays-abs-fs .ays_fieldset').append(q_answer_text_html ); 1450 1451 for (var i = 0; i < question_parts_arr.length; i++) { 1452 question.find('.ays-abs-fs .ays_fieldset').append( question_parts_arr[i] ); 1453 } 1454 1455 question.find('.ays-abs-fs').css({ 1456 'padding': '7px', 1457 // 'width': '100%' 1458 }); 1459 } 1460 } 1461 1462 var aysAudio = $(document).find('.ays_question_result audio'); 1463 if(aysAudio.length > 0){ 1464 aysAudio.each(function(e, el){ 1465 el.pause(); 1466 }); 1467 } 1468 1469 selected_options.each(function(element, item){ 1470 var selectOptions = $(item).children("option[data-chisht]"); 1471 var selectedOption = $(item).children("option[data-chisht]:selected"); 1472 var answerClass, answerDivClass, attrChecked, answerClassForSelected, answerClass_tpel, answerViewClass, attrCheckedStyle = "", attrCheckedStyle2; 1473 var prefixIcon = '', attrCheckedStyle3 = '', attrCheckedStyle4; 1474 var correctAnswersDiv = '', rectAnswerBefore = ""; 1475 answerViewClass = form.parents('.ays-quiz-container').find('.answer_view_class').val(); 1476 answerViewClass = "ays_"+form.find('.answer_view_class').val()+"_view_item"; 1477 for(var j = 0; j < selectOptions.length; j++){ 1478 if($(selectOptions[j]).attr("value") == '' || $(selectOptions[j]).attr("value") == undefined || $(selectOptions[j]).attr("value") == null){ 1479 continue; 1480 } 1481 1482 if($(selectOptions[j]).attr("data-nkar") == '' || $(selectOptions[j]).attr("data-nkar") == undefined || $(selectOptions[j]).attr("data-nkar") == null){ 1483 var selectedOptionImageHTML = ""; 1484 } else { 1485 var selectedOptionImageURL = $(selectOptions[j]).attr("data-nkar"); 1486 var selectedOptionImageHTML = '<img src="'+ selectedOptionImageURL +'" alt="" class="ays-answer-image" />'; 1487 } 1488 1489 if($(selectOptions[j]).prop('selected') == true){ 1490 if(parseInt($(selectOptions[j]).data("chisht")) === 1){ 1491 answerClassForSelected = " correct answered "; 1492 answerDivClass = "correct_div checked_answer_div"; 1493 attrChecked = "checked='checked'"; 1494 answerIsRight = true; 1495 }else{ 1496 answerClassForSelected = " wrong answered "; 1497 attrChecked = "checked='checked'"; 1498 answerDivClass = "wrong_div checked_answer_div "; 1499 } 1500 }else{ 1501 if(showOnlyWrongAnswer === false){ 1502 if(parseInt($(selectOptions[j]).data("chisht")) === 1){ 1503 answerClassForSelected = " correct answered "; 1504 answerDivClass = "correct_div checked_answer_div"; 1505 attrChecked = ""; 1506 }else{ 1507 answerClassForSelected = ""; 1508 attrChecked = ""; 1509 answerDivClass = ""; 1510 } 1511 }else{ 1512 answerClassForSelected = ""; 1513 attrChecked = ""; 1514 answerDivClass = ""; 1515 } 1516 } 1517 attrCheckedStyle2 = "style='padding:0 !important;'"; 1518 if(form.parents('.ays-quiz-container').hasClass('ays_quiz_modern_dark') || 1519 form.parents('.ays-quiz-container').hasClass('ays_quiz_modern_light')){ 1520 if($(selectOptions[j]).prop('selected') == true){ 1521 if(parseInt($(selectOptions[j]).data("chisht")) === 1){ 1522 prefixIcon = '<i class="ays_fa answer-icon ays_fa_check_square_o"></i>'; 1523 attrCheckedStyle3 = ""; 1524 }else{ 1525 prefixIcon = '<i class="ays_fa answer-icon ays_fa_check_square_o"></i>'; 1526 attrCheckedStyle3 = "background-color: rgba(243,134,129,0.8);"; 1527 } 1528 }else{ 1529 if(showOnlyWrongAnswer === false){ 1530 if(parseInt($(selectOptions[j]).data("chisht")) === 1){ 1531 prefixIcon = '<i class="ays_fa answer-icon ays_fa_square_o"></i>'; 1532 attrCheckedStyle3 = ""; 1533 }else{ 1534 prefixIcon = '<i class="ays_fa answer-icon ays_fa_square_o"></i>'; 1535 attrCheckedStyle3 = ""; 1536 } 1537 }else{ 1538 prefixIcon = '<i class="ays_fa answer-icon ays_fa_square_o"></i>'; 1539 attrCheckedStyle3 = ""; 1540 } 1541 } 1542 attrCheckedStyle = "style='display:block!important;"+attrCheckedStyle3+"'"; 1543 attrCheckedStyle2 = ""; 1544 answerViewClass = ""; 1545 } 1546 if(form.parents('.ays-quiz-container').hasClass('ays_quiz_elegant_dark') || 1547 form.parents('.ays-quiz-container').hasClass('ays_quiz_elegant_light')){ 1548 if($(selectOptions[j]).prop('selected') == true){ 1549 if(parseInt($(selectOptions[j]).data("chisht")) === 1){ 1550 answerDivClass = "correct_div checked_answer_div"; 1551 attrCheckedStyle = "style='padding: 0!important;'"; 1552 }else{ 1553 answerDivClass = "wrong_div checked_answer_div"; 1554 attrCheckedStyle = "style='padding: 0!important;'"; 1555 } 1556 }else{ 1557 if(showOnlyWrongAnswer === false){ 1558 if(parseInt($(selectOptions[j]).data("chisht")) === 1){ 1559 answerDivClass = "correct_div checked_answer_div"; 1560 }else{ 1561 answerDivClass = ""; 1562 } 1563 }else{ 1564 answerDivClass = ""; 1565 } 1566 attrCheckedStyle = ""; 1567 } 1568 } 1569 if(form.parents('.ays-quiz-container').hasClass('ays_quiz_rect_dark') || 1570 form.parents('.ays-quiz-container').hasClass('ays_quiz_rect_light')){ 1571 if($(selectOptions[j]).prop('selected') == true){ 1572 if(parseInt($(selectOptions[j]).data("chisht")) === 1){ 1573 answerDivClass = "correct_div checked_answer_div"; 1574 }else{ 1575 answerDivClass = "wrong_div checked_answer_div"; 1576 } 1577 rectAnswerBefore = "rect_answer_correct_before"; 1578 }else{ 1579 if(showOnlyWrongAnswer === false){ 1580 if(parseInt($(selectOptions[j]).data("chisht")) === 1){ 1581 answerDivClass = "correct_div checked_answer_div"; 1582 }else{ 1583 answerDivClass = ""; 1584 } 1585 }else{ 1586 answerDivClass = ""; 1587 } 1588 rectAnswerBefore = "rect_answer_wrong_before"; 1589 } 1590 } 1591 1592 correctAnswersDiv += '<div class="ays-field '+answerViewClass+' '+answerDivClass+'" '+attrCheckedStyle+'>' +
1593 '<input type="radio" value="'+$(selectOptions[j]).attr("value")+'" name="'+$(item).parent().find('.ays-select-field-value').attr('name')+'" disabled="disabled" '+attrChecked+'>' + 1594 '<label class="'+answerClassForSelected+'" for="ays-answer-'+$(selectOptions[j]).attr("value")+'">'+prefixIcon+aysEscapeHtml($(selectOptions[j]).text())+'</label> ' + 1595 '<label for="ays-answer-'+$(selectOptions[j]).attr("value")+'" class="ays_answer_image ays_empty_before_content '+answerClassForSelected+'">'+ selectedOptionImageHTML +'</label>' + 1596 '</div>'; 1597 } 1598 $(item).parent().parent().find('.ays-text-right-answer').remove(); 1599 $(item).parent().parent().append(correctAnswersDiv); 1600 $(item).parent().hide(); 1601 1602 if(selectedOption.length === 0){ 1603 var _parent_item = $(item).parents('.ays-abs-fs'); 1604 1605 _parent_item.html(fieldset_html); 1606 _parent_item.find('.ays_fieldset').append(ays_quiz_question_html); 1607 _parent_item.find('.ays_fieldset').append(ays_quiz_question_img_html); 1608 _parent_item.find('.ays_fieldset').append($(item).parents('.ays-quiz-answers')); 1609 1610 for (var i = 0; i < question_parts_arr.length; i++) { 1611 _parent_item.find('.ays_fieldset').append( question_parts_arr[i] ); 1612 } 1613 1614 $(item).parents('.ays-abs-fs').css({ 1615 'padding': '7px' 1616 }); 1617 } 1618 $(item).parents('.ays-abs-fs').find('.ays_buttons_div').remove(); 1619 $(item).parent().remove(); 1620 }); 1621 1622 text_answer.next().next().remove(); 1623 text_answer.css('width', '100%'); 1624 text_answer.attr('disabled', 'disabled'); 1625 number_answer.next().next().remove(); 1626 number_answer.css('width', '100%'); 1627 number_answer.attr('disabled', 'disabled'); 1628 short_text_answer.next().next().remove(); 1629 short_text_answer.css('width', '100%'); 1630 short_text_answer.attr('disabled', 'disabled'); 1631 date_answer.next().next().remove(); 1632 date_answer.css('width', '100%'); 1633 date_answer.attr('disabled', 'disabled'); 1634 if(text_answer.val() == ''){ 1635 if(showOnlyWrongAnswer === false){ 1636 var rightAnswerText = '<div class="ays-text-right-answer">'; 1637 var thisQuestionAnswer = text_answer.attr('chishtpatasxan'); 1638 if(typeof thisQuestionAnswer != 'undefined'){ 1639 thisQuestionAnswer = aysEscapeHtmlDecode( thisQuestionAnswer ).aysStripSlashes(); 1640 thisQuestionAnswer = thisQuestionAnswer.split('%%%'); 1641 }else{ 1642 thisQuestionAnswer = ['']; 1643 } 1644 rightAnswerText += thisQuestionAnswer[0].trim(); 1645 1646 rightAnswerText += '</div>'; 1647 if(text_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').length == 0){ 1648 text_answer.parents('.ays-quiz-answers').append(rightAnswerText); 1649 } 1650 text_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').css({ 1651 'display': 'block' 1652 }); 1653 } 1654 text_answer.css('background-color', 'rgba(243,134,129,0.4)'); 1655 text_answer.parents('.ays-abs-fs').find('.ays_quiz_question_text_conteiner').addClass('ays_display_none'); 1656 1657 if (wrong_img_URL_HTML != "") { 1658 var if_img_exists = text_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1659 if ( if_img_exists.length <= 0 ) { 1660 text_answer.parent().append(wrong_img_URL_HTML); 1661 } 1662 } 1663 1664 var _text_answer_parent = text_answer.parents('.ays-abs-fs'); 1665 1666 _text_answer_parent.html(fieldset_html); 1667 _text_answer_parent.find('.ays_fieldset').append(ays_quiz_question_html); 1668 _text_answer_parent.find('.ays_fieldset').append(ays_quiz_question_img_html); 1669 _text_answer_parent.find('.ays_fieldset').append(text_answer.parents('.ays-quiz-answers')); 1670 1671 for (var i = 0; i < question_parts_arr.length; i++) { 1672 _text_answer_parent.find('.ays_fieldset').append( question_parts_arr[i] ); 1673 } 1674 1675 text_answer.parents('.ays-abs-fs').css({ 1676 'padding': '7px' 1677 }); 1678 }else{ 1679 if(parseInt(text_answer.next().val()) == 1){ 1680 text_answer.css('background-color', 'rgba(39,174,96,0.5)'); 1681 answerIsRight = true; 1682 1683 if (correct_img_URL_HTML != "") { 1684 var if_img_exists = text_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1685 if ( if_img_exists.length <= 0 ) { 1686 text_answer.parent().append(correct_img_URL_HTML); 1687 } 1688 } 1689 1690 }else{ 1691 text_answer.css('background-color', 'rgba(243,134,129,0.4)'); 1692 1693 if (wrong_img_URL_HTML != "") { 1694 var if_img_exists = text_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1695 if ( if_img_exists.length <= 0 ) { 1696 text_answer.parent().append(wrong_img_URL_HTML); 1697 } 1698 } 1699 1700 if(showOnlyWrongAnswer === false){ 1701 var rightAnswerText = '<div class="ays-text-right-answer">'; 1702 var thisQuestionAnswer = text_answer.attr('chishtpatasxan'); 1703 if(typeof thisQuestionAnswer != 'undefined'){ 1704 thisQuestionAnswer = aysEscapeHtmlDecode( thisQuestionAnswer ).aysStripSlashes(); 1705 thisQuestionAnswer = thisQuestionAnswer.split('%%%'); 1706 }else{ 1707 thisQuestionAnswer = ['']; 1708 } 1709 rightAnswerText += thisQuestionAnswer[0].trim(); 1710 1711 rightAnswerText += '</div>'; 1712 if(text_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').length == 0){ 1713 text_answer.parents('.ays-quiz-answers').append(rightAnswerText); 1714 } 1715 text_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').css({ 1716 'display': 'block' 1717 }); 1718 text_answer.parents('.ays-abs-fs').find('.ays_quiz_question_text_conteiner').addClass('ays_display_none'); 1719 } 1720 } 1721 } 1722 if(number_answer.val() == ''){ 1723 if(showOnlyWrongAnswer === false){ 1724 var rightAnswerText = '<div class="ays-text-right-answer">'+ 1725 number_answer.attr('chishtpatasxan')+ 1726 '</div>'; 1727 if(number_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').length == 0){ 1728 number_answer.parents('.ays-quiz-answers').append(rightAnswerText); 1729 } 1730 number_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').css({ 1731 'display': 'block' 1732 }); 1733 } 1734 number_answer.css('background-color', 'rgba(243,134,129,0.8)'); 1735 number_answer.parents('.ays-abs-fs').find('.ays-quiz-number-error-message').addClass('ays_display_none'); 1736 1737 if (wrong_img_URL_HTML != "") { 1738 var if_img_exists = number_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1739 if ( if_img_exists.length <= 0 ) { 1740 number_answer.parent().append(wrong_img_URL_HTML); 1741 } 1742 } 1743 1744 var _number_answer_parent = number_answer.parents('.ays-abs-fs'); 1745 1746 _number_answer_parent.html(fieldset_html); 1747 _number_answer_parent.find('.ays_fieldset').append(ays_quiz_question_html); 1748 _number_answer_parent.find('.ays_fieldset').append(ays_quiz_question_img_html); 1749 _number_answer_parent.find('.ays_fieldset').append(number_answer.parents('.ays-quiz-answers')); 1750 1751 for (var i = 0; i < question_parts_arr.length; i++) { 1752 _number_answer_parent.find('.ays_fieldset').append( question_parts_arr[i] ); 1753 } 1754 1755 number_answer.parents('.ays-abs-fs').css({ 1756 'padding': '7px' 1757 }); 1758 }else{ 1759 if(parseInt(number_answer.next().val()) == 1){ 1760 number_answer.css('background-color', 'rgba(39,174,96,0.5)'); 1761 answerIsRight = true; 1762 1763 if (correct_img_URL_HTML != "") { 1764 var if_img_exists = number_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1765 if ( if_img_exists.length <= 0 ) { 1766 number_answer.parent().append(correct_img_URL_HTML); 1767 } 1768 } 1769 1770 }else{ 1771 number_answer.css('background-color', 'rgba(243,134,129,0.4)'); 1772 1773 if (wrong_img_URL_HTML != "") { 1774 var if_img_exists = number_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1775 if ( if_img_exists.length <= 0 ) { 1776 number_answer.parent().append(wrong_img_URL_HTML); 1777 } 1778 } 1779 1780 if(showOnlyWrongAnswer === false){ 1781 var rightAnswerText = '<div class="ays-text-right-answer">'+ 1782 number_answer.attr('chishtpatasxan')+ 1783 '</div>'; 1784 if(number_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').length == 0){ 1785 number_answer.parents('.ays-quiz-answers').append(rightAnswerText); 1786 } 1787 number_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').css({ 1788 'display': 'block' 1789 }); 1790 number_answer.parents('.ays-abs-fs').find('.ays-quiz-number-error-message').addClass('ays_display_none'); 1791 } 1792 } 1793 } 1794 if(short_text_answer.val() == ''){ 1795 if(showOnlyWrongAnswer === false){ 1796 var rightAnswerText = '<div class="ays-text-right-answer">'; 1797 var thisQuestionAnswer = short_text_answer.attr('chishtpatasxan'); 1798 if(typeof thisQuestionAnswer != 'undefined'){ 1799 thisQuestionAnswer = aysEscapeHtmlDecode( thisQuestionAnswer ).aysStripSlashes(); 1800 thisQuestionAnswer = thisQuestionAnswer.split('%%%'); 1801 }else{ 1802 thisQuestionAnswer = ['']; 1803 } 1804 rightAnswerText += thisQuestionAnswer[0].trim(); 1805 1806 rightAnswerText += '</div>'; 1807 if(short_text_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').length == 0){ 1808 short_text_answer.parents('.ays-quiz-answers').append(rightAnswerText); 1809 } 1810 short_text_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').css({ 1811 'display': 'block' 1812 }); 1813 } 1814 short_text_answer.css('background-color', 'rgba(243,134,129,0.8)'); 1815 short_text_answer.parents('.ays-abs-fs').find('.ays_quiz_question_text_conteiner').addClass('ays_display_none'); 1816 1817 if (wrong_img_URL_HTML != "") { 1818 var if_img_exists = short_text_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1819 if ( if_img_exists.length <= 0 ) { 1820 short_text_answer.parent().append(wrong_img_URL_HTML); 1821 } 1822 } 1823 1824 var _short_text_parent = short_text_answer.parents('.ays-abs-fs'); 1825 1826 _short_text_parent.html(fieldset_html); 1827 _short_text_parent.find('.ays_fieldset').append(ays_quiz_question_html); 1828 _short_text_parent.find('.ays_fieldset').append(ays_quiz_question_img_html); 1829 _short_text_parent.find('.ays_fieldset').append(short_text_answer.parents('.ays-quiz-answers')); 1830 1831 for (var i = 0; i < question_parts_arr.length; i++) { 1832 _short_text_parent.find('.ays_fieldset').append( question_parts_arr[i] ); 1833 } 1834 1835 short_text_answer.parents('.ays-abs-fs').css({ 1836 'padding': '7px' 1837 }); 1838 }else{ 1839 if(parseInt(short_text_answer.next().val()) == 1){ 1840 short_text_answer.css('background-color', 'rgba(39,174,96,0.5)'); 1841 answerIsRight = true; 1842 1843 if (correct_img_URL_HTML != "") { 1844 var if_img_exists = short_text_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1845 if ( if_img_exists.length <= 0 ) { 1846 short_text_answer.parent().append(correct_img_URL_HTML); 1847 } 1848 } 1849 1850 }else{ 1851 short_text_answer.css('background-color', 'rgba(243,134,129,0.4)'); 1852 1853 if (wrong_img_URL_HTML != "") { 1854 var if_img_exists = short_text_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1855 if ( if_img_exists.length <= 0 ) { 1856 short_text_answer.parent().append(wrong_img_URL_HTML); 1857 } 1858 } 1859 1860 if(showOnlyWrongAnswer === false){ 1861 var rightAnswerText = '<div class="ays-text-right-answer">'; 1862 var thisQuestionAnswer = short_text_answer.attr('chishtpatasxan'); 1863 if(typeof thisQuestionAnswer != 'undefined'){ 1864 thisQuestionAnswer = aysEscapeHtmlDecode( thisQuestionAnswer ).aysStripSlashes(); 1865 thisQuestionAnswer = thisQuestionAnswer.split('%%%'); 1866 }else{ 1867 thisQuestionAnswer = ['']; 1868 } 1869 r
1869ightAnswerText += thisQuestionAnswer[0].trim(); 1870 1871 rightAnswerText += '</div>'; 1872 if(short_text_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').length == 0){ 1873 short_text_answer.parents('.ays-quiz-answers').append(rightAnswerText); 1874 } 1875 short_text_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').css({ 1876 'display': 'block' 1877 }); 1878 short_text_answer.parents('.ays-abs-fs').find('.ays_quiz_question_text_conteiner').addClass('ays_display_none'); 1879 } 1880 } 1881 } 1882 if(date_answer.val() == ''){ 1883 if(showOnlyWrongAnswer === false){ 1884 var rightAnswerText = '<div class="ays-text-right-answer">'; 1885 var thisQuestionAnswer = date_answer.attr('chishtpatasxan'); 1886 1887 var correctDate = new Date(thisQuestionAnswer), 1888 correctDateYear = correctDate.getUTCFullYear(), 1889 correctDateMonth = (correctDate.getUTCMonth() + 1) < 10 ? "0"+(correctDate.getUTCMonth() + 1) : (correctDate.getUTCMonth() + 1), 1890 correctDateDay = (correctDate.getUTCDate() < 10) ? "0"+correctDate.getUTCDate() : correctDate.getUTCDate(); 1891 rightAnswerText += [correctDateMonth, correctDateDay, correctDateYear].join('/'); 1892 1893 rightAnswerText += '</div>'; 1894 if(date_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').length == 0){ 1895 date_answer.parents('.ays-quiz-answers').append(rightAnswerText); 1896 } 1897 date_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').css({ 1898 'display': 'block' 1899 }); 1900 } 1901 date_answer.css('background-color', 'rgba(243,134,129,0.8)'); 1902 1903 if (wrong_img_URL_HTML != "") { 1904 var if_img_exists = date_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1905 if ( if_img_exists.length <= 0 ) { 1906 date_answer.parent().append(wrong_img_URL_HTML); 1907 } 1908 } 1909 1910 var _date_answer_parent = date_answer.parents('.ays-abs-fs'); 1911 1912 _date_answer_parent.html(fieldset_html); 1913 _date_answer_parent.find('.ays_fieldset').append(ays_quiz_question_html); 1914 _date_answer_parent.find('.ays_fieldset').append(ays_quiz_question_img_html); 1915 _date_answer_parent.find('.ays_fieldset').append(date_answer.parents('.ays-quiz-answers')); 1916 1917 for (var i = 0; i < question_parts_arr.length; i++) { 1918 _date_answer_parent.find('.ays_fieldset').append( question_parts_arr[i] ); 1919 } 1920 1921 date_answer.parents('.ays-abs-fs').css({ 1922 'padding': '7px' 1923 }); 1924 }else{ 1925 if(parseInt(date_answer.next().val()) == 1){ 1926 date_answer.css('background-color', 'rgba(39,174,96,0.5)'); 1927 answerIsRight = true; 1928 1929 if (correct_img_URL_HTML != "") { 1930 var if_img_exists = date_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1931 if ( if_img_exists.length <= 0 ) { 1932 date_answer.parent().append(correct_img_URL_HTML); 1933 } 1934 } 1935 1936 }else{ 1937 date_answer.css('background-color', 'rgba(243,134,129,0.4)'); 1938 1939 if (wrong_img_URL_HTML != "") { 1940 var if_img_exists = date_answer.parent().find(".ays-quiz-check-button-right-wrong-icon"); 1941 if ( if_img_exists.length <= 0 ) { 1942 date_answer.parent().append(wrong_img_URL_HTML); 1943 } 1944 } 1945 1946 if(showOnlyWrongAnswer === false){ 1947 var rightAnswerText = '<div class="ays-text-right-answer">'; 1948 var thisQuestionAnswer = date_answer.attr('chishtpatasxan'); 1949 var correctDate = new Date(thisQuestionAnswer), 1950 correctDateYear = correctDate.getFullYear(), 1951 correctDateMonth = (correctDate.getMonth() + 1) < 10 ? "0"+(correctDate.getMonth() + 1) : (correctDate.getMonth() + 1), 1952 correctDateDay = (correctDate.getDate() < 10) ? "0"+correctDate.getDate() : correctDate.getDate(); 1953 rightAnswerText += [correctDateMonth, correctDateDay, correctDateYear].join('/'); 1954 1955 rightAnswerText += '</div>'; 1956 if(date_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').length == 0){ 1957 date_answer.parents('.ays-quiz-answers').append(rightAnswerText); 1958 } 1959 date_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').css({ 1960 'display': 'block' 1961 }); 1962 } 1963 } 1964 } 1965 1966 if (checked_inputs.length === 1) { 1967 if(parseInt(checked_inputs.prev().val()) === 1){ 1968 checked_inputs.parent().addClass('checked_answer_div').addClass('correct_div'); 1969 checked_inputs.parent().find('label').addClass('correct answered'); 1970 answerIsRight = true; 1971 if(form.parents('.ays-quiz-container').hasClass('ays_quiz_modern_dark') || 1972 form.parents('.ays-quiz-container').hasClass('ays_quiz_modern_light')){ 1973 $(checked_inputs).next().css('background-color', "transparent"); 1974 $(checked_inputs).parent().css('background-color', ' rgba(158,208,100,0.8)'); 1975 } 1976 }else{ 1977 if($(document).find('.ays-quiz-container').hasClass('ays_quiz_modern_dark') || 1978 $(document).find('.ays-quiz-container').hasClass('ays_quiz_modern_light')){ 1979 $(checked_inputs).next().css('background-color', "transparent"); 1980 $(checked_inputs).parent().css('background-color', ' rgba(243,134,129,0.8)'); 1981 } 1982 checked_inputs.parent().addClass('checked_answer_div').addClass('wrong_div'); 1983 checked_inputs.parent().find('label').addClass('wrong wrong_div answered'); 1984 } 1985 1986 if($(document).find('.ays-quiz-container').hasClass('ays_quiz_elegant_dark') || 1987 $(document).find('.ays-quiz-container').hasClass('ays_quiz_elegant_light')){ 1988 $(this).next().css('padding', "0 10px 0 10px"); 1989 } 1990 $(checked_inputs).parents().eq(3).find('input[name^="ays_questions"]').attr('disabled', true); 1991 }else if(checked_inputs.length > 1){ 1992 var checked_right = 0; 1993 checked_inputs.map(function() { 1994 if(parseInt($(this).prev().val()) === 1){ 1995 $(this).parent().addClass('checked_answer_div').addClass('correct_div'); 1996 $(this).parent().find('label').addClass('correct answered'); 1997 if($(document).find('.ays-quiz-container').hasClass('ays_quiz_modern_dark') || 1998 $(document).find('.ays-quiz-container').hasClass('ays_quiz_modern_light')){ 1999 $(this).next().css('background-color', "transparent"); 2000 $(this).parent().css('background-color', ' rgba(158,208,100,0.8)'); 2001 } 2002 }else{ 2003 $(this).parent().addClass('checked_answer_div').addClass('wrong_div'); 2004 $(this).parent().find('label').addClass('wrong wrong_div answered'); 2005 checked_right++; 2006 if($(document).find('.ays-quiz-container').hasClass('ays_quiz_modern_dark') || 2007 $(document).find('.ays-quiz-container').hasClass('ays_quiz_modern_light')){ 2008 $(this).next().css('background-color', "transparent"); 2009 $(this).parent().css('background-color', ' rgba(243,134,129,0.8)'); 2010 } 2011 } 2012 if($(document).find('.ays-quiz-container').hasClass('ays_quiz_modern_dark') || 2013 $(document).find('.ays-quiz-container').hasClass('ays_quiz_modern_light')){ 2014 } 2015 2016 if($(document).find('.ays-quiz-container').hasClass('ays_quiz_elegant_dark') || 2017 $(document).find('.ays-quiz-container').hasClass('ays_quiz_elegant_light')){ 2018 } 2019 $(this).parents().eq(3).find('input[name^="ays_questions"]').attr('disabled', true); 2020 }); 2021 if(checked_right == 0){ 2022 answerIsRight = true; 2023 } 2024 } 2025 2026 myOptions.hide_correct_answers = (myOptions.hide_correct_answers) ? myOptions.hide_correct_answers : 'off'; 2027 var hideRightAnswers =(myOptions.hide_correct_answers && myOptions.hide_correct_answers == 'on') ? true : false; 2028 if (hideRightAnswers) { 2029 question.find('.ays-text-right-answer').addClass("ays_quiz_display_none_important"); 2030 var aysFieldsets = question.find('fieldset.ays_fieldset'); 2031 if (aysFieldsets.length > 0) { 2032 var aysFieldsetsField = aysFieldsets.find('.ays-field'); 2033 if (aysFieldsetsField.hasClass('correct_div')) { 2034 aysFieldsetsField.removeClass('correct_div'); 2035 } 2036 if (aysFieldsetsField.hasClass('checked_answer_div')) { 2037 aysFieldsetsField.removeClass('checked_answer_div'); 2038 } 2039 if (aysFieldsetsField.find('label').hasClass('correct')) { 2040 aysFieldsetsField.find('label').removeClass('correct'); 2041 } 2042 } 2043 var answers_box = question.find('.ays-quiz-answers'); 2044 if (answers_box.length > 0) { 2045 answers_box.each(function () { 2046 var userWrongAnswered = $(this).find('.ays-field'); 2047 var userWrongAnsweredLabel = userWrongAnswered.find('label'); 2048 var questionTypeCheckbox = userWrongAnswered.find('input[type="checkbox"]'); 2049 if (userWrongAnsweredLabel.hasClass('wrong') || questionTypeCheckbox.length > 0) { 2050 if (userWrongAnsweredLabel.hasClass('correct') && userWrongAnsweredLabel.hasClass('answered')) { 2051 var eachAnswers = userWrongAnswered.find('input[name^="ays_questions"]'); 2052 if (eachAnswers.length > 0) { 2053 eachAnswers.each(function () { 2054 var parentBox = $(this).parents('.ays-field'); 2055 if (! $(this).prop("checked")) { 2056 $(this).next().removeClass('correct'); 2057 if (parentBox.hasClass('correct_div')) { 2058 parentBox.removeClass('correct_div'); 2059 } 2060 if (parentBox.hasClass('checked_answer_div')) { 2061 parentBox.removeClass('checked_answer_div'); 2062 } 2063 if (! parentBox.hasClass('.checked_answer_div') ) { 2064 parentBox.find('input~label.answered.correct').addClass('ays_quiz_hide_correct_answer'); 2065 } 2066 } 2067 }); 2068 } 2069 } 2070 } 2071 }); 2072 } 2073 } 2074 2075 answerIsRightArr[ 'questionId_' + questionId ] = answerIsRight; 2076 2077 if(myOptions.answers_rw_texts && (myOptions.answers_rw_texts == 'on_results_page' || myOptions.answers_rw_texts == 'on_both')){ 2078 if(answerIsRight){ 2079 question.find('.right_answer_text').css("display", "block"); 2080 }else{ 2081 question.find('.wrong_answer_text').css("display", "block"); 2082 } 2083 }else{ 2084 question.find('.right_answer_text').css("display", "none"); 2085 question.find('.wrong_answer_text').css("display", "none"); 2086 } 2087 // question.find('.ays_questtion_explanation').css("display", "block"); 2088 var showExplanationOn = (myOptions.show_questions_explanation && myOptions.show_questions_explanation != "") ? myOptions.show_questions_explanation : "on_results_page"; 2089 if(showExplanationOn == 'on_results_page' || showExplanationOn == 'on_both'){ 2090 if(! question.hasClass('not_influence_to_score')){ 2091 question.find('.ays_questtion_explanation').css("display", "block"); 2092 } 2093 }else{ 2094 question.find('.ays_questtion_explanation').css("display", "none"); 2095 } 2096 question.find('.ays_user_explanation').css("display", "none"); 2097 question.css("pointer-events", "auto"); 2098 question.find('.ays-quiz-answers').css("pointer-events", "none"); 2099 formResults.append(question); 2100 } 2101 2102 myOptions.quiz_show_wrong_answers_first = ! myOptions.quiz_show_wrong_answers_first ? 'off' : myOptions.quiz_show_wrong_answers_first; 2103 var quiz_show_wrong_answers_first = (myOptions.quiz_show_wrong_answers_first && myOptions.quiz_show_wrong_answers_first == 'on') ? true : false; 2104 2105 myOptions.quiz_show_only_wrong_answers = ! myOptions.quiz_show_only_wrong_answers ? 'off' : myOptions.quiz_show_only_wrong_answers; 2106 var quiz_show_only_wrong_answers = (myOptions.quiz_show_only_wrong_answers && myOptions.quiz_show_only_wrong_answers == 'on') ? true : false; 2107 2108 if ( quiz_show_wrong_answers_first || quiz_show_only_wrong_answers) { 2109 var UserAnswered_true_arr = new Array(); 2110 var UserAnswered_false_arr = new Array(); 2111 for (var question_ID in answerIsRightArr) { 2112 2113 var question_ID_arr = question_ID.split("_"); 2114 var questionDataID = question_ID_arr[1]; 2115 2116 var UserAnswered_true_or_false = answerIsRightArr[question_ID]; 2117 var questionHTML = form.find('.ays_quiz_results div.ays_question_result[data-question-id="'+ question
2117DataID +'"]').clone(); 2118 2119 if ( UserAnswered_true_or_false ) { 2120 UserAnswered_true_arr.push( questionHTML ); 2121 } else { 2122 UserAnswered_false_arr.push( questionHTML ); 2123 } 2124 } 2125 2126 if ( quiz_show_only_wrong_answers ) { 2127 UserAnswered_true_arr = new Array(); 2128 } 2129 2130 var allQuestionHTML = UserAnswered_false_arr.concat( UserAnswered_true_arr ); 2131 2132 formResults.html(''); 2133 2134 if ( quiz_enable_results_toggle ) { 2135 formResults.append(resultToggleHTML); 2136 } 2137 2138 for (var ii = 0; ii < allQuestionHTML.length; ii++) { 2139 formResults.append( allQuestionHTML[ii] ); 2140 } 2141 } 2142 } 2143 2144 var showResults = true; 2145 if ( (myOptions.enable_paypal && myOptions.enable_paypal === 'on') || 2146 ( myOptions.enable_stripe && myOptions.enable_stripe === 'on' ) ) { 2147 if (myOptions.payment_type && myOptions.payment_type === 'postpay') { 2148 showResults = false; 2149 }else{ 2150 showResults = true; 2151 } 2152 } 2153 2154 if( showResults === true ){ 2155 form.find('.ays_quiz_results').slideDown(1000); 2156 } 2157 2158 form.find('.ays_quiz_rete').fadeIn(250); 2159 form.find('.for_quiz_rate').rating({ 2160 onRate: function(res){ 2161 $(this).rating('disable'); 2162 $(this).parent().find('.for_quiz_rate_reason').slideDown(500); 2163 $(this).parents('.ays_quiz_rete').attr('data-rate_score', res); 2164 } 2165 }); 2166 2167 if( quiz_enable_keyboard_navigation ){ 2168 form.find('.for_quiz_rate > i').addClass('ays-quiz-keyboard-active'); 2169 form.find('.for_quiz_rate > i').attr('tabindex', '0'); 2170 } 2171 2172 var aysQuizLoader = form.find('div[data-role="loader"]'); 2173 aysQuizLoader.addClass('ays-loader'); 2174 aysQuizLoader.removeClass(aysQuizLoader.data('class')); 2175 aysQuizLoader.find('.ays-loader-content').css('display','none'); 2176 2177 var openResultsPage = true; 2178 window.aysResultsForQuizStored = false; 2179 if ( (myOptions.enable_paypal && myOptions.enable_paypal === 'on') || 2180 (myOptions.enable_stripe && myOptions.enable_stripe === 'on') ) { 2181 if (myOptions.payment_type && myOptions.payment_type === 'prepay') { 2182 openResultsPage = true; 2183 }else{ 2184 openResultsPage = false; 2185 if( !window.aysResultsForQuizStored ) { 2186 window.aysResultsForQuiz = form.find('.ays_quiz_results_page').html(); 2187 window.aysResultsForQuizStored = true; 2188 form.find('.ays_quiz_results_page').html(''); 2189 } 2190 } 2191 } 2192 2193 if( openResultsPage === true ){ 2194 form.find('.ays_quiz_results_page').css({'display':'block'}); 2195 } 2196 2197 form.find('.ays_paypal_wrap_div, .ays_stripe_wrap_div').css({'display':'block'}); 2198 form.find('.ays_paypal_wrap_div, .ays_stripe_wrap_div').attr('data-result', response.result_id); 2199 2200 form.css({'display':'block'}); 2201 2202 aysResizeiFrame(); 2203 2204 form.on('click', '.ays_quiz_rete .for_quiz_rate_reason .action-button', function(){ 2205 2206 var _this = $(this); 2207 var _parent = _this.parents('.for_quiz_rate_reason'); 2208 2209 if(myOptions.quiz_make_review_required == 'on' && myOptions.quiz_make_review_required == 'on'){ 2210 2211 var _el = _parent.find('.quiz_rate_reason[data-required="true"]'); 2212 2213 if ( ! _this.hasClass('start_button') ) { 2214 if ( _el.length !== 0 ) { 2215 var empty_inputs = 0; 2216 2217 if (_el.val().trim() === '' && 2218 _el.attr('type') !== 'hidden') { 2219 _el.addClass('ays_red_border'); 2220 _el.addClass('ays_animated_x5ms'); 2221 _el.addClass('shake'); 2222 empty_inputs++; 2223 } 2224 2225 var errorFields = _parent.find('.ays_red_border'); 2226 if ( empty_inputs !== 0 ) { 2227 setTimeout(function(){ 2228 errorFields.each(function(){ 2229 $(this).removeClass('shake'); 2230 }); 2231 }, 500); 2232 return false; 2233 } 2234 } 2235 } 2236 } 2237 2238 $(this).parents('.for_quiz_rate_reason').find('.quiz_rate_reason').attr('disabled', 'disabled'); 2239 var data = {}; 2240 var quizId = form.parents('.ays-quiz-container').find('input[name="ays_quiz_id"]').val(); 2241 var quizCusrrentPageLink = form.parents('.ays-quiz-container').find('input[name="ays_quiz_curent_page_link"]').val(); 2242 data.action = 'ays_rate_the_quiz'; 2243 data.rate_reason = $(this).parents('.for_quiz_rate_reason').find('.quiz_rate_reason').val(); 2244 data.rate_score = $(this).parents('.ays_quiz_rete').data('rate_score'); 2245 data.rate_date = GetFullDateTime(); 2246 data.quiz_id = quizId; 2247 data.last_result_id = last_result_id; 2248 data.quiz_make_responses_anonymous = quiz_make_responses_anonymous; 2249 data.quiz_current_page_link = quizCusrrentPageLink;
2250 form.find('.for_quiz_rate_reason').slideUp(800); 2251 var showAvgRate = false; 2252 myOptions.show_rate_after_rate = (myOptions.show_rate_after_rate) ? myOptions.show_rate_after_rate : 'on'; 2253 if(myOptions.show_rate_after_rate && myOptions.show_rate_after_rate == 'on'){ 2254 showAvgRate = true; 2255 } 2256 if(showAvgRate){ 2257 $(this).parents('.ays_quiz_rete').find('.lds-spinner-none').addClass('lds-spinner').removeClass('lds-spinner-none'); 2258 } 2259 if(myOptions.enable_quiz_rate == 'on' && myOptions.enable_rate_comments == 'on'){ 2260 $(this).parents('.ays_quiz_rete').find('.lds-spinner2-none').addClass('lds-spinner2').removeClass('lds-spinner2-none'); 2261 } 2262 $.ajax({ 2263 url: quiz_maker_ajax_public.ajax_url, 2264 method: 'post', 2265 dataType: 'json', 2266 crossDomain: true, 2267 data: data, 2268 success: function(response){ 2269 if(response.status === true){ 2270 setTimeout(function(){ 2271 form.find('.ays_quiz_rete').find('.for_quiz_rate').attr('data-rating', response.score); 2272 form.find('.ays_quiz_rete').find('.for_quiz_rate').rating({ 2273 initialRating: response.score 2274 }); 2275 form.find('.ays_quiz_rete').find('.for_quiz_rate').rating('disable'); 2276 if(showAvgRate){ 2277 form.find('.lds-spinner').addClass('lds-spinner-none').removeClass('lds-spinner'); 2278 form.find('.for_quiz_rate_reason').html('<p>'+response.rates_count + ' ' + quizLangObj.votes + ', ' + response.avg_score + ' ' + quizLangObj.avg + ' </p>'); 2279 form.find('.for_quiz_rate_reason').fadeIn(250); 2280 } 2281 2282 var review_ty_message = form.find('.ays-quiz-review-thank-you-message'); 2283 if ( review_ty_message.length > 0 ) { 2284 if ( review_ty_message.hasClass('ays_display_none') ) { 2285 review_ty_message.removeClass('ays_display_none'); 2286 } 2287 } 2288 2289 if(myOptions.enable_quiz_rate == 'on' && myOptions.enable_rate_comments == 'on'){ 2290 var data = {}; 2291 data.action = 'ays_get_rate_last_reviews'; 2292 data.quiz_id = response.quiz_id; 2293 $.ajax({
2294 url: quiz_maker_ajax_public.ajax_url, 2295 method: 'post', 2296 crossDomain: true, 2297 data: data, 2298 success: function(response){ 2299 var response_arr = JSON.parse(response); 2300 var responseHTML = (response_arr.quiz_rate_html && response_arr.quiz_rate_html != '') ? response_arr.quiz_rate_html : ''; 2301 2302 form.find('.quiz_rate_reasons_body').html(responseHTML); 2303 form.find('.lds-spinner2').addClass('lds-spinner2-none').removeClass('lds-spinner2'); 2304 form.find('.quiz_rate_reasons_container').slideDown(500); 2305 form.find('.ays-quiz-rate-link-box .ays-quiz-rate-link').slideUp(500); 2306 form.on('click', 'button.ays_load_more_review', function(e){ 2307 form.find('.quiz_rate_load_more [data-role="loader"]').addClass(form.find('.quiz_rate_load_more .ays-loader').data('class')).removeClass('ays-loader'); 2308 var startFrom = parseInt($(e.target).attr('startfrom')); 2309 var zuyga = parseInt($(e.target).attr('zuyga')); 2310 $.ajax({
2311 url: quiz_maker_ajax_public.ajax_url, 2312 method: 'post', 2313 crossDomain: true, 2314 data:{ 2315 action: 'ays_load_more_reviews', 2316 quiz_id: quizId, 2317 start_from: startFrom, 2318 zuyga: zuyga 2319 }, 2320 success: function(resp){ 2321 if(zuyga == 0){ 2322 zuyga = 1; 2323 }else{ 2324 zuyga = 0; 2325 } 2326 2327 form.find('.quiz_rate_load_more [data-role="loader"]').addClass('ays-loader').removeClass(form.find('.quiz_rate_load_more .ays-loader').data('class')); 2328 form.find('.quiz_rate_reasons_container').append(resp); 2329 form.find('.quiz_rate_more_review:last-of-type').slideDown(500); 2330 $(e.target).attr('startfrom', startFrom + 5 ); 2331 $(e.target).attr('zuyga', zuyga); 2332 if(form.find('.quiz_rate_reasons_container p.ays_no_more').length > 0){ 2333 $(e.target).remove(); 2334 } 2335 } 2336 }); 2337 }); 2338 }, 2339 error: function(jqXHR, textStatus, errorThrown) {} 2340 }); 2341 } 2342 },1000); 2343 } 2344 } 2345 }); 2346 }); 2347 } 2348 2349 function redirect_timer(timer, args) { 2350 if( typeof args == 'undefined' ){ 2351 args = {}; 2352 } 2353 2354 var tabTitle = document.title; 2355 2356 var countDownDate = new Date().getTime() + (timer * 1000); 2357 2358 var x = setInterval(function () { 2359 var now = new Date().getTime(); 2360 var distance = countDownDate - Math.ceil(now/1000)*1000; 2361 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); 2362 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); 2363 var seconds = Math.floor((distance % (1000 * 60)) / 1000); 2364 var timeForShow = ""; 2365 if(hours <= 0){ 2366 hours = null; 2367 }else if (hours < 10) { 2368 hours = '0' + hours; 2369 } 2370 if (minutes < 10) { 2371 minutes = '0' + minutes; 2372 } 2373 if (seconds < 10) { 2374 seconds = '0' + seconds; 2375 } 2376 timeForShow = ((hours==null)? "" : (hours + ":")) + minutes + ":" + seconds; 2377 if(distance <=1000){ 2378 timeForShow = ((hours==null) ? "" : "00:") + "00:00"; 2379 $(document).find('.ays-quiz-container').find('div.ays-quiz-redirection-timer').html(timeForShow); 2380 document.title = timeForShow + " - " + tabTitle; 2381 }else{ 2382 $(document).find('.ays-quiz-container').find('div.ays-quiz-redirection-timer').html(timeForShow); 2383 document.title = timeForShow + " - " + tabTitle; 2384 } 2385 $(document).find('.ays-quiz-container').find('div.ays-quiz-redirection-timer').slideDown(500); 2386 var ays_interval_element_redirect_url = args.redirectUrl; 2387 2388 if (distance <= 1000) { 2389 clearInterval(x); 2390 if (window.location != window.parent.location) { 2391 window.parent.location = ays_interval_element_redirect_url; 2392 } else { 2393 window.location = ays_interval_element_redirect_url; 2394 } 2395 } 2396 }, 1000); 2397 } 2398 2399 function redirectAction(redirectUrl, redirectDelay, blockElement, redirectAfter, form, myOptions, redirectMessageFlag){ 2400 var timer = parseInt(redirectDelay); 2401 if(timer === NaN){ 2402 timer = 0; 2403 } 2404 2405 if( timer == 0 ){ 2406 if (window.location != window.parent.location) { 2407 window.parent.location = redirectUrl; 2408 } else { 2409 window.location = redirectUrl; 2410 } 2411 return false; 2412 } 2413 2414 if ( redirectMessageFlag ) { 2415 var quizId = form.parents('.ays-quiz-container').find('input[name="ays_quiz_id"]').val(); 2416 // Message before redirect timer 2417 var quiz_message_before_redirect_timer = (myOptions.quiz_message_before_redirect_timer && myOptions.quiz_message_before_redirect_timer != "") ? ( myOptions.quiz_message_before_redirect_timer ) : ''; 2418 2419 if ( quiz_message_before_redirect_timer != '' ) { 2420 quiz_message_before_redirect_timer = quiz_message_before_redirect_timer.replace(/(["'])/g, "\\$1") + " "; 2421 2422 $(document).find('html > head').append('<style> #ays-quiz-container-'+ quizId +' div.ays-quiz-redirection-timer:before{content: "'+ quiz_message_before_redirect_timer +'"; }</style>'); 2423 } 2424 } 2425 2426 var tabTitle = document.title; 2427 var timerText = $('<section class="ays_quiz_redirection_timer_container">'+ 2428 '<div class="ays-quiz-redirection-timer">'+ 2429 quizLangObj.redirectAfter + ' ' + redirectAfter + 2430 '</div><hr></section>'); 2431 form.parents('.ays-quiz-container').prepend(timerText); 2432 blockElement.find('.ays_quiz_redirection_timer_container').css({ 2433 height: 'auto' 2434 }); 2435 setTimeout(function(){ 2436 if (timer !== NaN) { 2437 timer += 2; 2438 if (timer !== undefined) { 2439 blockElement.find('div.ays-quiz-redirection-timer').slideUp(500); 2440 redirect_timer( timer, { 2441 redirectUrl: redirectUrl 2442 }); 2443 } 2444 } 2445 }, 2000); 2446 2447 return true; 2448 } 2449 2450 function aysQuizSetCustomEvent() { 2451 if ( typeof window.CustomEvent === "function" ) return false; //If not IE 2452 2453 function CustomEvent ( event, params ) { 2454 params = params || { bubbles: false, cancelable: false, detail: undefined }; 2455 var evt = document.createEvent( 'CustomEvent' ); 2456 evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail ); 2457 return evt; 2458 } 2459 2460 CustomEvent.prototype = window.Event.prototype; 2461 2462 window.CustomEvent = CustomEvent; 2463 } 2464 2465 function checkQuestionTimer( container, quizId ){ 2466 if( window.aysQuizQuestionTimers[quizId] ) { 2467 var questions = container.find('div[data-question-id]'); 2468 var remainingQuestionsEmpty = []; 2469 for (var i = 0; i < questions.length; i++) { 2470 var questionID = questions[i].dataset.questionId; 2471 2472 if( 2473 window.aysQuizQuestionTimers[quizId][questionID] 2474 && 2475 ( 2476 window.aysQuizQuestionTimers[quizId][questionID].ended === true 2477 || 2478 window.aysQuizQuestionTimers[quizId][questionID].stopped === true 2479 ) 2480 ){ 2481 continue; 2482 }else{ 2483 if ( ays_quiz_is_question_empty( $(questions[i]) ) === false ) { 2484 remainingQuestionsEmpty.push({ 2485 item: $(questions[i]), 2486 id: questionID 2487 }); 2488 } 2489 } 2490 } 2491 2492 if( remainingQuestionsEmpty.length > 0 ){ 2493 return remainingQuestionsEmpty[0].id; 2494 }else{ 2495 return false; 2496 } 2497 } 2498 } 2499 2500 function stopQuestionTimer( questionID, quizId, myOptions ){ 2501 if( myOptions.enable_timer && myOptions.enable_timer === 'on' ) { 2502 if (myOptions.quiz_timer_type && myOptions.quiz_timer_type === 'question_timer') { 2503 if (window.aysQuizQuestionTimers && window.aysQuizQuestionTimers[quizId]) { 2504 if (window.aysQuizQuestionTimers[quizId][questionID] !== null) { 2505 clearInterval(window.aysQuizQuestionTimers[quizId][questionID].timeout); 2506 window.aysQuizQuestionTimers[quizId][questionID].stopped = true; 2507 window.aysQuizQuestionTimers[quizId][questionID].ended = true; 2508 } 2509 } 2510 } 2511 } 2512 } 2513 2514 // function stopQuestionTimer( container, questionID, myOptions ){ 2515 // if( myOptions.enable_timer && myOptions.enable_timer === 'on' ) { 2516 // if (myOptions.quiz_timer_type && myOptions.quiz_timer_type === 'question_timer') { 2517 // if (window.aysQuizQuestionTimers && window.aysQuizQuestionTimers[quizId]) { 2518 // if (window.aysQuizQuestionTimers[quizId][questionID] !== null) { 2519 // // clearInterval(window.aysQuizQuestionTimers[quizId][questionID].timeout); 2520 // window.aysQuizQuestionTimers[quizId][questionID].stopped = true; 2521 // var qid = checkQuestionTimer( container, quizId ); 2522 // if (qid === false) { 2523 // container.find('input.ays_finish').addClass('ays-quiz-after-timer-end'); 2524 // } 2525 // } 2526 // } 2527 // } 2528 // } 2529 // } 2530 2531 2532})(jQuery);
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.