1(function($, Drupal) { 2 const mobileWidth = window.matchMedia("(max-width: 570px)"); 3 4 Drupal.behaviors.showButtons = { 5 attach(context) { 6 $(".intimina-quiz-ajax", context).on("change", function() { 7 let buttonWrapper = $(".quiz__next-btn"); 8 buttonWrapper.addClass("btn-visible"); 9 }); 10 } 11 }; 12 13 Drupal.behaviors.titlePosition = { 14 attach(context) { 15 if (mobileWidth.matches) { 16 $(".intimina-quiz-ajax", context) 17 .once("intimina-quiz") 18 .each(function() { 19 const questionTitle = $(".intimina-quiz-ajax").find( 20 ".fieldset-legend" 21 ); 22 if (questionTitle.length) { 23 const questionHeight = -(questionTitle.height() + 75); 24 questionTitle.css({ 25 "margin-top": `${questionHeight}px` 26 }); 27 } 28 dropletsAlive(); 29 lastQuestionTitle(); 30 }); 31 } 32 } 33 }; 34 35 const numOfQuestions = $(".intimina-quiz-ajax") 36 .attr("class") 37 .match(/\d+/)[0]; 38 39 function progressStep() { 40 41 const stepWidth = (100 / (parseInt(numOfQuestions) + 2)).toFixed(2); 42 return parseFloat(stepWidth); 43 } 44 45 function questionFinder() { 46 const quiz_questions = $(".quiz__questions > .form-item"); 47 if (quiz_questions.length) { 48 return quiz_questions.attr("data-drupal-selector").match(/\d+/)[0]; 49 } 50 } 51 52 const progressStepValue = progressStep(); 53 let progressIncrement = 0; 54 55 let previousQuestion; 56 57 Drupal.behaviors.progressBar = { 58 attach(context) { 59 $(".intimina-quiz-ajax", context) 60 .once("intimina-quiz-progress") 61 .each(function() { 62 let currentQuestion = questionFinder(); 63 if (currentQuestion < previousQuestion) { 64 progressIncrement = progressIncrement - progressStepValue; 65 $(".progress-bar-step").css("width", `${progressIncrement}%`); 66 previousQuestion = questionFinder(); 67 } else if (currentQuestion === previousQuestion) { 68 $(".progress-bar-step").css("width", `${progressIncrement}%`); 69 } else { 70 progressIncrement = progressIncrement + progressStepValue; 71 $(".progress-bar-step").css("width", `${progressIncrement}%`); 72 previousQuestion = questionFinder(); 73 } 74 }); 75 } 76 }; 77 78 function lastQuestionTitle() { 79 const lastTitle = $(".quiz__result-general-title"); 80 if (lastTitle.length) { 81 const tempTitle = lastTitle.detach(); 82 $(".quiz__content").prepend(tempTitle); 83 } 84 } 85 86 function dropletsAlive() { 87 if ($(".droplet-wrapper").length) { 88 $(".droplet-wrapper").remove(); 89 } 90 } 91 92 function randomDuration() { 93 return (Math.random() * (3.5 - 3) + 3).toFixed(2); 94 } 95 96 function randomDelay() { 97 return (Math.random() * (0.5 - 0.01) + 0.01).toFixed(2); 98 } 99 100 function dropletSpawner(num) { 101 const container = $("<div />", { class: "droplet-wrapper" }); 102 for (let index = 0; index < num; index++) { 103 const randDurationNum = randomDuration().toString(); 104 const randDelayNum = randomDelay().toString(); 105 $("<div />", { 106 class: "quiz-droplet" 107 }) 108 .appendTo(container) 109 .css({ 110 "transition-duration": `${randDurationNum}s`, 111 "transition-delay": `${randDelayNum}s` 112 }); 113 } 114 $(".quiz").prepend(container); 115 116 setTimeout(() => { 117 $(".quiz-droplet").each(function() { 118 $(this).addClass("droplet-animated"); 119 }); 120 }, 100); 121 } 122 123 Drupal.behaviors.quizAnimation = { 124 attach() { 125 if ( 126 mobileWidth.matches && 127 $(".intimina-quiz-ajax").hasClass("animated-question") 128 ) { 129 $(".animated-question").on("click", ".option", function() { 130 dropletsAlive(); 131 const optionClicked = $(this) 132 .parent() 133 .index(); 134 let dropletsSpawned; 135 136 switch (optionClicked) { 137 case 0: 138 dropletsSpawned = 16; 139 break; 140 case 1: 141 dropletsSpawned = 12; 142 break; 143 case 2: 144 dropletsSpawned = 8; 145 break; 146 default: 147 dropletsSpawned = 8; 148 }
149 dropletSpawner(dropletsSpawned); 150 }); 151 } 152 } 153 }; 154})(jQuery, Drupal);
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.