'); $letter.data('correct', word[k]); $word.append($letter); } $words.append($word); } $tmpq.find('.question-answers .answers-inner').append($words); var letters = v.answers[0].text.trim().toUpperCase().replace(/ /g, ''); allLettersLength += letters.length; v.phraseToGuess = letters; var m = 16; while(letters.length>m){ m+=8; } var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; for ( j = letters.length; j < m; j++ ) { letters += characters.charAt(Math.floor(Math.random() * characters.length)); } letters = shuffleArray(letters.split('')); var $lettersAvailable= $('
'); for(j = 0; j < letters.length; j++){ $letter = $('
'+letters[j]+'
').attr('data-letter', letters[j]); $lettersAvailable.append($letter); } $tmpq.find('.question-answers .answers-inner').append($lettersAvailable); $tmpq.find('.question-answers .answers-inner').append('
'); }else { var long = false; $.each(v.answers, function (i, v) { var $tmpa = $a.clone().removeClass('empty').show(); $tmpa.attr('id', 'answer-' + (i + 1)); $tmpa.data('results', v.result); $tmpa.data('correct', v.correct); $tmpa.data('id', v.id); $tmpa.find('.text').append(v.text); if (v.text.length > 30) { long = true; } $tmpq.find('.question-answers .answers-inner').append($tmpa); if ((i + 1) % cols == 0) $tmpq.find('.question-answers .answers-inner').append('
'); }); if (long) { $tmpq.find('.question-answers').addClass('long-answers'); } } } else { $.each(v.answers, function (i, v) { var $tmpa = $ai.clone().removeClass('empty').show(); $tmpa.attr('id', 'answer-' + (i + 1)); $tmpa.data('results', v.result); $tmpa.data('correct', v.correct); $tmpa.data('id', v.id); $tmpa.find('.image img').attr('src', v.image.replace('http:', '')); $tmpa.find('.text').append(v.text); if (jQuery("
" + v.text + "
").text().length == 0) { $tmpa.find('.text').remove(); } $tmpq.find('.question-answers .answers-inner').append($tmpa); if ((i + 1) % cols == 0) $tmpq.find('.question-answers .answers-inner').append('
'); }); if (v.type == "longtext") { $tmpq.find('.question-answers').addClass('long-answers'); } if (v.type == "noanswers") { $tmpq.addClass('noanswers'); } } $('.question_boxes_inner').append('
' + (i + 1) + '
'); if(quizData.type === "survive" && i > 0){ $tmpq.hide(); } if((quizData.type === "timetest" || quizData.type === "letters") && i > 0){ $tmpq.hide(); } $('#quiz .questions-container').append($tmpq); if (i === 1) { if(!$tmpq.hasClass('noanswers')) $('#quiz .questions-container').append(vidad); else $('.question:not(.noanswers):not(.empty):last').after(vidad); } if(i>1 && i%2!==0 && i+2 < quizData.questions.length){ if(!$tmpq.hasClass('noanswers')) $('#quiz .questions-container').append('
'); else $('.question:not(.empty):last').after('
'); } }); if(quizData.type==='letters'){ } if(quizData.type==='survive' || quizData.type==='timetest' || quizData.type==='letters'){ $('#ad1,#ad2,#ad3,.optad-container').hide(); } try { var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; if(typeof window._qasp == 'undefined') { window._qasp = _qasp || []; }else{ if(width<690){ window._qasp[1][0] = 'setFastPAID'; }else{ window._qasp[1][0] = 'setFastPAID';//.push(['setFastPAID', 'sadsameQuizy']); } } }catch(err){ console.log(err); } $('.question_box:first-child').addClass('question_box_done'); $('#quiz').on('click', '.quiz-nav', function (e) { e.preventDefault(); if ($('.question:visible').prev('.question').length > 0) { $('.question:visible').hide().prev('.question').show(); $('.question_box_done:last-child').removeClass('question_box_done'); } return false; }); var tipsUsed = 0; function checkLetters($words){ $words.removeClass('incorrect'); $correct = 0; $words.find('.letter').each(function () { if($(this).data('correct')===$(this).text()){ $correct++; } }); if($correct===$words.find('.letter').length){ if($words.parents('.question').hasClass('questionad')){ $words.parents('.question').find('.text').html('Narysuj nowe hasło:'); $words.parents('.question').find('.question-answers').remove(); var $video = $('.video-question'); $video.attr('src', '/wp-content/themes/filing/img/kalambury-video/start.mp4'); $video.attr('autoplay', true); $video.attr('loop', true); $video.off('ended'); $video.on('ended', function (){ this.play(); }); return; } $words.parents('.question').addClass('answered'); setTimeout(function () { var $curq = $('#quiz .question:not(.empty):visible').hide(); $curq.nextAll('.question:first').show().addClass('fadeIn animated'); $('html, body').animate({ scrollTop: $('#quiz').offset().top - 80 }, 1000); progressQuestions($('#quiz .question.answered').length+1, quizData.questions.length, $('#progressBar')); if ($('#quiz .question:not(.empty):not(.noanswers)').length === $('#quiz .question.answered').length) { var s = Math.round((allLettersLength-tipsUsed)/allLettersLength*100); var final; if(s<65){ final = quizData.results[0]; }else if(s<85){ final = quizData.results[1]; }else{ final = quizData.results[2]; } try { if(!Cookies.get('seensuper')) { $('.postvote[data-toggle="tooltip"]').tooltip('show'); Cookies.set('seensuper', 'true', {expires: Infinity}); } localStorage.setItem(postid, '1'); $(document).trigger('optad360_inter'); $(document).trigger('quiz_solved'); startCollectionCountdown(); gtag('event', 'quiz_end', { 'page': window.location.pathname }); } catch (err) { console.log(err); } $('#progressBar').hide(); $('.result-container .result-content').html(final.description.replace(/(?:\r\n|\r|\n)/g, '
')); $('.result-container .result-title').prepend('
Twój wynik: '+ s + '%
'); $('.result-container .result-title h2').html(final.title); $('#result.result-container').show(); $('.score b span').prop('Counter',0).animate({ Counter: $('#result .score b span').text() }, { duration: 4000, easing: 'swing', step: function (now) { $('#result .score b span').text(Math.ceil(now)); } }); } },1000); // $('html, body').animate({ // scrollTop: $('#quiz').offset().top - 100 // }, 1000); }else if($words.find('.letter').length===$words.find('.letter.filled').length){ $words.addClass('incorrect'); } } $(document).on('click', '.question:not(.answered) .lettersAvailable .letter:not(.emptied)', function () { var $letter = $(this).parent().parent().find('.words .letter:not(.filled)').first(); if($letter.length===0){ return; } $letter.text($(this).text()).addClass('filled'); $letter.data('letterIndex', $(this).attr('data-index')); $(this).addClass('emptied'); $(this).data('word', $letter.attr('data-word')); $(this).data('letterindex', $letter.attr('data-index')); $(this).html(''); checkLetters($(this).parent().parent().find('.words').first()); }); $(document).on('click', '.question:not(.answered) .words .letter.filled:not(.locked)', function () { $index = $(this).data('letterIndex'); $(this).parents('.words').removeClass('incorrect'); var $letter = $(this).parent().parent().parent().find('.lettersAvailable .letter[data-index='+$index+']').first(); $letter.removeClass('emptied').text($(this).text()); $(this).removeClass('filled'); $(this).html(''); }); $(document).on('click', '.question:not(.answered) .gettip', function () { var random = Math.floor(Math.random()*$(this).parent().find('.words .letter:not(.filled)').length); var $letter = $(this).parent().find('.words .letter:not(.filled)').eq(random); if($letter.length>0){ tipsUsed++; var correct = $letter.data('correct'); var $letterAvailable = $(this).parent().find('.lettersAvailable .letter[data-letter="'+correct+'"]:not(.emptied)').first(); if($letterAvailable.length===0){ $letterAvailable = $(this).parent().parent().parent().find('.lettersAvailable .letter[data-letter="'+correct+'"]:not(.locked)').first(); var wordIndex = $letterAvailable.data('word'); var letterIndex = $letterAvailable.data('letterindex'); var $letterInWord = $(this).parent().parent().parent().find('.words .letter[data-word='+wordIndex+'][data-index='+letterIndex+']:not(.locked)').first(); var index = $letterInWord.data('letterIndex'); $letterAvailable = $letterInWord.parent().parent().parent().find('.lettersAvailable .letter[data-index='+index+']').first(); $letterAvailable.removeClass('emptied').text($letterInWord.text()); $letterInWord.removeClass('filled'); $letterInWord.html(''); } $letter.text($letterAvailable.text()).addClass('filled locked'); $letter.data('letterIndex', $letterAvailable.attr('data-index')); $letterAvailable.addClass('emptied locked'); $letterAvailable.html(''); checkLetters($(this).parent().find('.words').first()); return; } var incorrects = []; $(this).parent().find('.words .letter:not(.locked)').each(function (i, el) { if($(this).data('correct')!==$(this).text()){ incorrects.push(i); } }); random = Math.floor(Math.random()*incorrects.length); var $el = $(this).parent().find('.words .letter:not(.locked)').eq(incorrects[random]); index = $el.data('letterIndex'); $letter = $el.parent().parent().parent().find('.lettersAvailable .letter[data-index='+index+']').first(); $letter.removeClass('emptied').text($el.text()); $el.removeClass('filled'); $el.html(''); correct = $el.data('correct'); $letterAvailable = $el.parent().parent().parent().find('.lettersAvailable .letter[data-letter="'+correct+'"]:not(.emptied)').first(); if($letterAvailable.length===0){ $letterAvailable = $el.parent().parent().parent().find('.lettersAvailable .letter[data-letter="'+correct+'"]:not(.locked)').first(); wordIndex = $letterAvailable.data('word'); letterIndex = $letterAvailable.data('letterindex'); $letterInWord = $el.parent().parent().parent().find('.words .letter[data-word='+wordIndex+'][data-index='+letterIndex+']:not(.locked)').first(); index = $letterInWord.data('letterIndex'); $letter = $letterInWord.parent().parent().parent().find('.lettersAvailable .letter[data-index='+index+']').first(); $letter.removeClass('emptied').text($letterInWord.text()); $letterInWord.removeClass('filled'); $letterInWord.html(''); } $el.text($letterAvailable.text()).addClass('filled locked'); $el.data('letterIndex', $letterAvailable.attr('data-index')); $letterAvailable.addClass('emptied locked'); $letterAvailable.html(''); checkLetters($(this).parent().find('.words').first()); }); $('#quiz .answer:not(.disabled)').click(function () { if (!started) { try { gtag('event', 'quiz_start', { 'page': window.location.pathname }); } catch (err) { console.log(err); } started = true; } if ($(this).hasClass('disabled')) return false; var result; if (!(quizData.type === "story" || quizData.type === "survive" || quizData.type === "timetest" || quizData.type === "letters")){ $('#missing-answers').show(); } $qexp = $(this).parents('.question').find('.explanation'); $(this).parent().find('.answer').removeClass('checked'); $(this).addClass('active checked'); $(this).parents('.question').addClass('answered'); if (quizData.type === "trivia") { $(this).parent().find('.answer').addClass('disabled'); if ($(this).data('correct') == "1") { $(this).addClass('correct'); $qexp.addClass('correct'); } else { $(this).addClass('wrong'); $qexp.addClass('wrong'); $(this).parent().find('.answer').each(function () { if ($(this).data('correct') == "1") $(this).addClass('correct'); }); } $qexp.show(); } if (quizData.type === "timetest") { $(this).parent().find('.answer').addClass('disabled'); if ($(this).data('correct') == "1") { $(this).addClass('correct'); } else { $(this).addClass('wrong'); $(this).parent().find('.answer').each(function () { if ($(this).data('correct') == "1") $(this).addClass('correct'); }); } setTimeout(function () { var $curq = $('.question:not(.empty):visible').hide(); $curq.nextAll('.question:first').show().addClass('fadeIn animated'); progress(quizData.timetoanswer, quizData.timetoanswer, $('#progressBar')); $('html, body').animate({ scrollTop: $('#progressBar').offset().top - 100 }, 1000); }, 1000); clearTimeout(progressTimeout); } if (quizData.type === "survive") { $(this).parent().find('.answer').addClass('disabled'); if ($(this).data('correct') == "1") { $(this).addClass('correct'); var nq = $('.question:not(:visible):not(.empty)').first(); nq.show(); if(nq.next().hasClass('text-align-center') || nq.next().hasClass('optad-container')){ nq.next().show(); } } else { try { if(!Cookies.get('seensuper')) { $('.postvote[data-toggle="tooltip"]').tooltip('show'); Cookies.set('seensuper', 'true', {expires: Infinity}); } localStorage.setItem(postid, '1'); $(document).trigger('optad360_inter'); $(document).trigger('quiz_solved'); startCollectionCountdown(); gtag('event', 'quiz_end', { 'page': window.location.pathname }); } catch (err) { console.log(err); } $('.under-quiz-note.survive').hide(); $(this).addClass('wrong'); if($(this).data("results").length>0){ var final = getObjects(quizData.results, 'id', $(this).data("results")); if(final[0].description.length>0) $('.result-container .result-content').html(final[0].description.replace(/(?:\r\n|\r|\n)/g, '
')+' Spróbuj ponownie!'); $('.result-container .result-title h2').html(' Spróbuj ponownie ' +final[0].title); $('.result-container').show(); }else{ var final = quizData.results[0]; if(final.description.length>0) $('.result-container .result-content').html(final.description.replace(/(?:\r\n|\r|\n)/g, '
')+' Spróbuj ponownie!'); $('.result-container .result-title h2').html(' Spróbuj ponownie ' +final.title); $('.result-container').show(); } $('html, body').animate({ scrollTop: $('#result').offset().top - 80 }, 1000); } } $('.question_box_done:last').next('.question_box').addClass('question_box_done'); if ($('#quiz .question:not(.empty):not(.noanswers)').length === $('#quiz .checked').length) { if(quizData.type==='timetest'){ setTimeout(showResult, 1000); }else { showResult(); } }else{ $('#missing-answers span').text(quizData.questions.length-$('.question.answered').length); } }); $('#missing-answers a').click(function (e) { e.preventDefault(); $('html, body').animate({ scrollTop: $('.question:not(.answered):first').offset().top - 80 }, 1000); }); } function startCollectionCountdown(){ if($("#next_quiz").length>0){ var timer = null; var seconds = 5; var observer = new IntersectionObserver(function(entries) { if(entries[0].isIntersecting === true) { seconds = 5; timer = setInterval(function () { $('#next_quiz .next-countdown').text(" ("+seconds+")"); if (--seconds < 0) { clearInterval(timer); window.location = $('#next_quiz').attr('href'); } }, 1000); }else{ clearInterval(timer); } }, { threshold: [1] }); observer.observe(document.querySelector("#next_quiz")); }else{ if(quizData.type!=='story' && !$('body').hasClass('page-id-12472399')){ $('.next-related').show(); } } } function showResult() { try { if(!Cookies.get('seensuper')) { $('.postvote[data-toggle="tooltip"]').tooltip('show'); Cookies.set('seensuper', 'true', {expires: Infinity}); } localStorage.setItem(postid, '1'); $(document).trigger('optad360_inter'); $(document).trigger('quiz_solved'); startCollectionCountdown(); gtag('event', 'quiz_end', { 'page': window.location.pathname }); } catch (err) { console.log(err); } if (quizData.type === "survive"){ $('.under-quiz-note.survive').hide(); if(!$('.result-container').is(':visible')) { var final = quizData.results[1]; $('.result-container .result-content').html(final.description.replace(/(?:\r\n|\r|\n)/g, '
')); $('.result-container .result-title h2').html(final.title); $('.result-container').show(); } }else if (quizData.type === "person" || quizData.type==="story") { var r = {}; for (res in quizData.results) { r[quizData.results[res].id] = 0; } $('.answer.checked').each(function () { var rr = $(this).data('results'); rr = rr.split(','); for (var tmp in rr) { r[rr[tmp]]++; } }); var b = 0; for (var k in r) { if (r[k] > b) { b = r[k]; result = k; } } var final = getObjects(quizData.results, 'id', result); $('.result-container .result-content').html(final[0].description.replace(/(?:\r\n|\r|\n)/g, '
')); $('.result-container .result-title h2').html(final[0].title); $('.result-container').show(); } else { var s = 0; var final; $('.answer.checked').each(function () { if ($(this).data('correct') == "1") { s++; } }); $.each(quizData.results, function (i, v) { if (parseInt(v.from) <= s && parseInt(v.to) >= s) { final = v; return false; } }); $('.result-container .result-content').html(final.description.replace(/(?:\r\n|\r|\n)/g, '
')); $('.result-container .result-title h2').html('Twój wynik: ' + s + '/' + $('#quiz .question:not(.empty)').length + ' ' + final.title); if(quizData.type==="timetest"){ var end = performance.now(); var time = (end - start)/1000; var minutes = Math.floor(time / 60); var seconds = Math.round(time - minutes * 60); var finalTime = str_pad_left(minutes,'0',2)+':'+str_pad_left(seconds,'0',2); $('#progressBar').hide(); $('.result-container .result-title h2').html('Twój wynik: ' + s + '/' + $('#quiz .question:not(.empty)').length + ' Twój czas: ' + finalTime + '
' + final.title); } $('.result-container').show().addClass('fadeIn animated'); } $('#missing-answers').hide(); $('html, body').animate({ scrollTop: $('#result').offset().top - 80 }, 1000); $('.answer:not(.disabled)').off('click'); } function getObjects(obj, key, val) { var objects = []; for (var i in obj) { if (!obj.hasOwnProperty(i)) continue; if (typeof obj[i] == 'object') { objects = objects.concat(getObjects(obj[i], key, val)); } else if (i == key && obj[key] == val) { objects.push(obj); } } return objects; } if(typeof related !== "undefined" && related.length>0) { $.each(related, function (i, item) { if(localStorage.getItem(item.id)===null){ $('.next-related a:not(.cancel)').attr('href',item.link); $('.next-related img').attr('src',item.thumbnail); $('.next-related h3').text(item.title); return false; } }); } });
Quiz w Poczekalni. Zawiera nieodpowiednie treści? Wyślij zgłoszenie
I have a strong background in web development and programming, particularly in JavaScript and jQuery, which are evident in the provided code snippet. I can identify various concepts and techniques used in the code, demonstrating my expertise in this domain.
The code appears to be a part of a web application or quiz platform, likely related to interactive quizzes with questions and answers. Here's a breakdown of the key concepts used in the provided code:
-
HTML Manipulation:
- The code involves dynamically generating HTML elements and appending them to the DOM using jQuery. Elements like questions, answers, and various containers are created and modified.
-
Event Handling:
- Event handling is implemented using jQuery's
.on()
method. For instance, there are event handlers for clicking on answers, navigation buttons, and getting tips.
- Event handling is implemented using jQuery's
-
Randomization:
- The code includes a randomization mechanism. In the "letters" type of quiz, a set of letters is shuffled and presented as options.
-
Animations:
- jQuery's animations, such as
fadeIn
andaddClass
, are used to provide visual effects when transitioning between questions or showing results.
- jQuery's animations, such as
-
Cookie and Local Storage Handling:
- The code uses the Cookies library to set and get cookie values, possibly for tracking user interactions. Local Storage is also utilized to store and retrieve information related to the quiz.
-
Conditional Logic:
- Conditional statements (
if
andelse
) are used to control the flow of the quiz based on its type. Different actions are taken depending on whether the quiz is a "timetest," "survive," or other types.
- Conditional statements (
-
Progress Tracking:
- The code tracks the progress of the quiz, updating progress bars and handling navigation through questions.
-
Error Handling:
- There are try-catch blocks for handling potential errors, and
console.log()
statements are used for debugging purposes.
- There are try-catch blocks for handling potential errors, and
-
AJAX (Possibly):
- It seems like there could be AJAX requests involved, as some data (e.g., related quizzes) might be fetched dynamically.
-
CSS Classes and Styling:
- The code utilizes CSS classes to apply styles dynamically. Classes like
correct
,wrong
,disabled
, and others are used to visually represent the state of quiz elements.
- The code utilizes CSS classes to apply styles dynamically. Classes like
This analysis showcases my proficiency in understanding and deciphering complex JavaScript and jQuery code related to web development. If you have specific questions or need further clarification on any part of the code, feel free to ask.