1/* eslint-disable no-undef */ 2(function ($) { 3 const groupAccordions = $(".wp-block-aab-group-accordion"); 4 let id = 0; 5 // step 6 $.each(groupAccordions, function (index, item) { 7 const accordionId = $(item).attr('id'); 8 const parentDiv = $(`#${accordionId}`); 9 10 const accordionItems = $(parentDiv).children('.wp-block-aab-accordion-item.aagb__accordion_container.step'); 11 12 const accordionCompletionStatus = {}; 13 const accordionStatusCookie = JSON.parse(getCookie(`aab-completion-status-${accordionId}`)); 14 15 $.each(accordionItems, function (index, accordionItem) { 16 const accordionHead = $(accordionItem).children('.aagb__accordion_head'); 17 const accordionBody = $(accordionItem).children('.aagb__accordion_body'); 18 const accordionBodyContinue = $(accordionBody).children('.continue'); 19 const completeSign = $(accordionHead).find('.complete-sign'); 20 const aagbIcon = $(accordionHead).find('.aagb__icon'); 21 const $stepResult = $("#" + accordionId).find('> .step-result'); 22 23 24 /* cookie work's here */ 25 if (accordionStatusCookie !== null) { 26 accordionCompletionStatus[index] = accordionStatusCookie[index] || false; 27 if (accordionCompletionStatus[index]) { 28 completeSign.show(); 29 aagbIcon.hide(); 30 accordionBodyContinue.hide(); 31 } 32 } else { 33 accordionCompletionStatus[index] = false; 34 } 35 36 accordionBodyContinue.on('click', function (e) { 37 completeSign.show(); 38 accordionHead.click(); 39 accordionCompletionStatus[index] = true; 40 aagbIcon.hide(); 41 accordionBodyContinue.hide(); 42 setCookie('aab-completion-status-' + accordionId, JSON.stringify(accordionCompletionStatus), 30); 43 updateProgressBasedOnActiveSection(accordionId, parentDiv.find("#progressBarFill")); 44 if (allAccordionsCompleted(accordionCompletionStatus, accordionItems)) { 45 $stepResult.css('display', 'block'); 46 setTimeout(() => { 47 $stepResult.hide(); 48 }, 5000) 49 50 } else { 51 let nextIndex = index + 1; 52 53 while (nextIndex < accordionItems.length) { 54 if (!accordionCompletionStatus[nextIndex]) { 55 accordionItems.eq(nextIndex).find("> .aagb__accordion_head").click(); 56 break; 57 } 58 nextIndex++; 59 } 60 61 if (nextIndex >= accordionItems.length) { 62 nextIndex = 0; 63 while (nextIndex < index) { 64 if (!accordionCompletionStatus[nextIndex]) { 65 accordionItems.eq(nextIndex).find('> .aagb__accordion_head').click(); 66 break; 67 } 68 nextIndex++; 69 } 70 } 71 } 72 }) 73 }) 74 75 // Select and modify last accordion item 76 const lastAccordionItem = accordionItems.last(); 77 const lastAccordionItemStepText = lastAccordionItem.find('> .aagb__accordion_body').children('.continue').find('.step-text'); // Select the content of the last accordion item 78 79 if (lastAccordionItemStepText.length > 0) { // Check if the last child element exists 80 lastAccordionItemStepText.text("End"); // Change its text content 81 } 82 83 // Check list 84 const accordionCheckListItems = $(parentDiv).children('.wp-block-aab-accordion-item.aagb__accordion_container.check-list'); 85 86 if (accordionCheckListItems.length) { 87 let checklistItems = []; 88 const checklistItemsCookie = JSON.parse(getCookie(`aab-checklist-status-${accordionId}`)); 89 90 if (checklistItemsCookie !== null) { 91 checklistItems = checklistItemsCookie; 92 } 93 94 $.each(accordionCheckListItems, function (index, item) { 95 96 const checklistBox = $(item).find('> .aagb__accordion_head .checklist-box'); 97 const aagb__accordion_title = $(item).find('> .aagb__accordion_head .aagb__accordion_title'); 98 let isChecked = false;
99 if (checklistItemsCookie == null) { 100 const checklistItemsObj = {[`${index}`]: false}; 101 checklistItems.push(checklistItemsObj); 102 } else { 103 $.each(checklistItems, function (checklistItemsIndex, checklistItem) { 104 105 if (index === checklistItemsIndex) { 106 if (checklistItem[checklistItemsIndex] === true) { 107 checklistBox.prop('checked', true); 108 aagb__accordion_title.toggleClass('line-through'); 109 } 110 } 111 }); 112 113 } 114 115 checklistBox.change(function () { 116 aagb__accordion_title.toggleClass('line-through'); 117 isChecked = checklistBox.is(':checked'); 118 119 checklistItems[index] = {[`${index}`]: isChecked}; 120 121 setCookie('aab-checklist-status-' + accordionId, JSON.stringify(checklistItems), 30); 122 // checklist completion status 123 const checklistStatus = {}; 124 checklistItems.forEach((item, idx) => { 125 checklistStatus[idx] = item[idx]; 126 }); 127 updateProgressBasedOnActiveSection(accordionId, parentDiv.find("#progressBarFill")); 128 129 }); 130 }); 131 } 132 }) 133 134 function allAccordionsCompleted(status, items) { 135 for (let i = 0; i < items.length; i++) { 136 if (!status[i]) { 137 return false; 138 } 139 } 140 return true; 141 } 142 143 // Read More button 144 // Set the maximum number of characters to display initially 145 $(".aagb__accordion_component.read-more-btn").each(function () { 146 const textMax = $(this).data('contentcount'); 147 const paragraph = $(this).find("p:first"); 148 const fullText = paragraph.text(); 149 if (paragraph.text().length > textMax) { 150 const slicedText = fullText.slice(0, textMax); 151 paragraph.text(slicedText + '...').show(); 152 paragraph.data("full-text", fullText); 153 $(this).children().not(paragraph).not('.aagb_overlay').fadeOut();
154 $(this).siblings(".aagb_button_toggle").click(function (e) { 155 e.preventDefault(); 156 const $btn = $(this); 157 const $body = $btn.closest(".aagb__accordion_body"); 158 const $component = $body.find(".aagb__accordion_component"); 159 const $overlay = $body.find(".aagb_overlay"); 160 161 // Current (collapsed) height of the content area. 162 const startHeight = $component.height(); 163 164 // Restore the full text and reveal every hidden block instantly 165 // (no per-element animation) so we can measure the final height. 166 paragraph.text(fullText); 167 $component.children().not('.aagb_overlay').show(); 168 const endHeight = $component.height(); 169 170 // Animate the whole content area from collapsed to full height as a 171 // single smooth reveal, so all the content grows together. 172 $component 173 .css({ height: startHeight, overflow: "hidden" }) 174 .animate({ height: endHeight }, "slow", function () { 175 $component.css({ height: "", overflow: "" }); 176 }); 177 178 // Fade the button and overlay out at the same time as the reveal. 179 $btn.fadeOut("slow"); 180 $overlay.fadeOut("slow").removeClass("aagb_overlay"); 181 }); 182 } else { 183 $(this).siblings(".aagb_button_toggle").remove(); 184 $(this).closest(".aagb__accordion_body").find(".aagb_overlay").remove(); 185 } 186 }); 187 188 //End of Read More button 189 function setCookie(name, value, days) { 190 let expires = ""; 191 if (days) { 192 let date = new Date(); 193 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 194 expires = "; expires=" + date.toUTCString(); 195 } 196 document.cookie = name + "=" + (value || "") + expires + "; path=/"; 197 } 198 199 function getCookie(name) { 200 let nameEQ = name + "="; 201 let ca = document.cookie.split(';'); 202 203 for (let i = 0; i < ca.length; i++) { 204 let c = ca[i]; 205 while (c.charAt(0) == ' ') c = c.substring(1, c.length); 206 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); 207 } 208 return null; 209 } 210 211 if ($('.wp-block-aab-group-accordion').length) { 212 $(".wp-block-aab-group-accordion").each(function () { 213 const $groupAccordion = $(this); 214 const $accordionItems = $groupAccordion.find('> .wp-block-aab-accordion-item'); 215 const $searchContainer = $groupAccordion.find('> .aagb_form_inner'); 216 const $search = $searchContainer.find('> .aagb_form_group .aagb-search-control'); 217 const $searchHelp = $searchContainer.find('> .help-block'); 218 const $searchWrapperBtn = $groupAccordion.find('> .aagb_accordion_wrapper_btn'); 219 const $showMoreBtn = $groupAccordion.find('> .aab-show-more-btn-container .show-more-btn'); 220 const $showLessBtn = $groupAccordion.find('> .aab-show-more-btn-container .show-less-btn'); 221 222 let itemsPerClick = Number($showMoreBtn.data('items-to-show')); 223 let itemsToShow = itemsPerClick; 224 let filterClass = ''; 225 let searchTxt = ''; 226 227 let searchTimeout; 228 $search.on('input', function () { 229 clearTimeout(searchTimeout); 230 searchTimeout = setTimeout(() => { 231 searchTxt = $search.val(); 232 loadAccordions(); 233 }, 300); 234 }); 235 236 // Cache search content 237 $search.one('focus input', function () { 238 $accordionItems.each(function () { 239 if (!$(this).data('search-content')) { 240 $(this).data('search-content', $(this).text().toLowerCase()); 241 } 242 }); 243 }); 244 245 function loadAccordions() { 246 let _targetItems = $accordionItems; 247 _targetItems.hide(); 248 249 if (filterClass) _targetItems = _targetItems.filter(`.${filterClass}`); 250 251 $searchContainer.removeClass('has-success has-error'); 252 $groupAccordion?.unmark?.(); 253 $searchHelp.hide(); 254 255 if(searchTxt) { 256 $searchHelp.show(); 257 const searchLower = searchTxt.toLowerCase(); 258 259 _targetItems = _targetItems.filter(function() { 260 const content = $(this).data('search-content') || $(this).text().toLowerCase(); 261 return content.includes(searchLower); 262 }); 263 264 if(_targetItems.length) { 265 $searchHelp.text(`${_targetItems.length} question(s) found.`); 266 $searchContainer.addClass('has-success'); 267 _targetItems?.mark?.(searchTxt);
268 $searchWrapperBtn.show(); 269 } else { 270 $searchContainer.addClass('has-error'); 271 $searchHelp.text('No questions found.'); 272 $searchWrapperBtn.hide(); 273 } 274 } 275 276 $showMoreBtn.parent()?.show(); 277 278 // if not greater than zero, all accordions are shown (covers the case of showMoreBtn feature not being activated) 279 if (itemsToShow > 0) { 280 let loaded = 0; 281 _targetItems.each(function () { 282 $(this).hide(); 283 284 if (loaded < itemsToShow) { 285 $(this).show(); 286 loaded++; 287 } 288 }); 289 290 if(loaded >= _targetItems.length) { 291 $showMoreBtn.hide(); 292 293 $showLessBtn.show(0, function () { 294 $(this).css("display", "flex"); 295 }); 296 $showLessBtn.parent()?.css("background-color", "#ffffff00"); 297 298 if(loaded <= itemsPerClick) $showMoreBtn.parent()?.hide(); 299 } else { 300 $showMoreBtn.show(); 301 $showLessBtn.hide(); 302 } 303 } else { // show-more-btn feature is not activated (or invalid items-per-click value) 304 _targetItems.show(); 305 $showMoreBtn?.parent()?.hide(); 306 } 307 308 } 309 310 var filterButtons = $(this).find('> .aab-filter-button-group button'); 311 var allButton = $(this).find('> .aab-filter-button-group .cat_all_item'); // Select the "All" button 312 313 filterButtons.on('click', function () { 314 filterClass = $(this).data('filter'); 315 316 filterButtons.removeClass('active'); 317 allButton.removeClass('active'); 318 $(this).addClass('active'); 319 320 loadAccordions(); 321 }); 322 323 allButton.on('click', function () { 324 filterButtons.removeClass('active'); 325 $(this).addClass('active'); 326 filterClass = ''; 327 loadAccordions(); 328 }); 329 330 // Initially activate "All" button, and load accordions 331 allButton.click(); 332 loadAccordions(); 333 334 $showMoreBtn.on('click', function () { 335 itemsToShow += itemsPerClick; 336 loadAccordions(); 337 $showLessBtn.focus(); 338 }); 339 340 $showLessBtn.on('click', function () { 341 itemsToShow = itemsPerClick; 342 loadAccordions(); 343 $showMoreBtn.focus(); 344 }); 345 }); 346 } 347 348 // Update progress bar based on active section 349 function updateProgressBasedOnActiveSection(accordionId, $progressBarFill) { 350 const $groupAccordion = $('#' + accordionId); 351 const $stepAccordionItems = $groupAccordion.children( 352 '.wp-block-aab-accordion-item.aagb__accordion_container.step' 353 ); 354 const $checklistAccordionItems = $groupAccordion.children( 355 '.wp-block-aab-accordion-item.aagb__accordion_container.check-list' 356 ); 357 const $progressText = $groupAccordion.find('.aab-progress-text'); 358 359 let completedCount = 0, 360 totalCount = 0, 361 percentage = 0; 362 363 if ($stepAccordionItems.length && $stepAccordionItems.is(':visible')) { 364 const stepStatus = JSON.parse( 365 getCookie(`aab-completion-status-${accordionId}`) || '{}' 366 ); 367 totalCount = $stepAccordionItems.length; 368 for (let i = 0; i < totalCount; i++) 369 if (stepStatus[i]) completedCount++; 370 } else if ( 371 $checklistAccordionItems.length && 372 $checklistAccordionItems.is(':visible') 373 ) { 374 const checklistStatus = JSON.parse( 375 getCookie(`aab-checklist-status-${accordionId}`) || '[]' 376 ); 377 totalCount = $checklistAccordionItems.length; 378 for (let i = 0; i < totalCount; i++) 379 if (checklistStatus[i] && checklistStatus[i][i]) 380 completedCount++; 381 } 382 383 percentage = totalCount > 0 ? (completedCount / totalCount) * 100 : 0; 384 385 // Only update THIS progress bar 386 $progressBarFill.css('width', `${percentage}%`); 387 $progressText.text(`${Math.round(percentage)}%`); 388 setCookie(`aab-progress-${accordionId}`, percentage, 30); 389 } 390 391 /* ================================ 392 INIT ON PAGE LOAD 393 ==================================*/ 394 $(document).ready(function () { 395 $('.wp-block-aab-group-accordion').each(function () { 396 const accordionId = $(this).attr('id'); 397 updateProgressBasedOnActiveSection( 398 accordionId, 399 $(this).find('#progressBarFill') 400 ); 401 }); 402 }); 403 404})(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.