1const isPro = !!aagb_local_object.licensing; 2 3/* eslint-disable no-undef */ 4(function ($) { 5 const iconToggleMap = new Map([ 6 ['dashicons-plus-alt2', 'dashicons-minus'], 7 ['dashicons-minus', 'dashicons-plus-alt2'], 8 ['dashicons-arrow-down-alt2', 'dashicons-arrow-up-alt2'], 9 ['dashicons-arrow-up-alt2', 'dashicons-arrow-down-alt2'], 10 ['dashicons-arrow-down', 'dashicons-arrow-up'], 11 ['dashicons-arrow-up', 'dashicons-arrow-down'], 12 ['dashicons-plus-alt', 'dashicons-dismiss'], 13 ['dashicons-dismiss', 'dashicons-plus-alt'], 14 ['dashicons-insert', 'dashicons-remove'], 15 ['dashicons-remove', 'dashicons-insert'], 16 ]); 17 18 function toggleIcon(element, target = ['expand', 'collapse'][0]) { 19 const $icon = $(element); 20 const classList = $icon.attr('class')?.split(/\s+/) || []; 21 22 for (const cls of classList) { 23 for (const [collapsedCls, expandedCls] of iconToggleMap) { 24 if (collapsedCls === cls || expandedCls === cls) { 25 const targetCls = { 26 expand: collapsedCls, 27 collapse: expandedCls, 28 }[target]; 29 30 $icon.removeClass(cls); 31 $icon.addClass(targetCls); 32 return; 33 } 34 } 35 } 36 } 37 38 function stickToTheSamePlace($accordion, stopAfter = 500) { 39 if (window.innerWidth >= 756) return; 40 41 const accordionPosition = 42 $accordion[0]?.getBoundingClientRect().top || 0; 43 44 const intervalId = setInterval(() => { 45 const accordionOffset = $accordion.offset().top; 46 const scrollTo = accordionOffset - accordionPosition; 47 window.scrollTo({ top: scrollTo }); 48 }, 5); 49 50 setTimeout(() => { 51 clearInterval(intervalId); 52 }, stopAfter); 53 } 54 55 const $groupAccordions = $('.wp-block-aab-group-accordion'); 56 $groupAccordions.each(function () { 57 const $groupAccordion = $(this); 58 const autoPlay = isPro && $groupAccordion.hasClass("autoplay"); 59 60 const $accordions = $groupAccordion.find( 61 '> .wp-block-aab-accordion-item' 62 ); 63 64 let autoPlaySpeed = $accordions.data('duration'); 65 66 if (!(autoPlaySpeed >
66 0)) { 67 autoPlaySpeed = 3000; 68 } 69 70 const Vertical = $accordions.data('progress-bar-direction'); 71 const progressBarOn = isPro && $accordions.data('progress-bar-on'); 72 const autoPlayWithProgressBar = isPro && autoPlay && progressBarOn; 73 const hasNextPrevious = $groupAccordion.hasClass('aab-next-previous-enabled'); 74 75 // const autoPlaySpeed = 6000; 76 let currentIndex = 0; 77 let interval; 78 79 const $accordionHeads = $accordions.find('> .aagb__accordion_head'); 80 const $accordionIcons = $accordionHeads.find('.aagb__icon'); 81 const $accordionBodies = $accordions.find('> .aagb__accordion_body'); 82 83 const activatorEvent = $groupAccordion.hasClass('hover') 84 ? 'mouseenter' 85 : 'click'; 86 87 function resetAll() { 88 $accordions.removeClass('aagb__accordion_active'); 89 $accordionHeads.removeClass('active'); 90 $accordionBodies 91 .removeClass('aagb__accordion_body--show') 92 .stop(true, true) 93 .slideUp(); 94 95 if (autoPlayWithProgressBar) { 96 $accordions 97 .find('.aab-progress-bar') 98 .stop(true, true) 99 .css({ width: '0%' }); 100 } 101 102 $accordionIcons.each(function () { 103 toggleIcon($(this), 'expand'); 104 }); 105 } 106 107 function activateAccordion($accordion, index) { 108 const $head = $accordion.find('> .aagb__accordion_head'); 109 const $body = $accordion.find('> .aagb__accordion_body'); 110 const $icon = $head.find('.aagb__icon'); 111 112 resetAll(); 113 114 $accordion.addClass('aagb__accordion_active'); 115 $head.addClass('active'); 116 $body.addClass('aagb__accordion_body--show').slideDown(); 117 118 toggleIcon($icon, 'collapse'); 119 // Feature image update 120 const imageUrl = $accordion.data('feature-image-url'); 121 const $accordionContainerClass = $accordion.closest('.aagb__group_accordion_container'); 122 123 const $featureImg = $($accordionContainerClass).find('.aab-feature-img'); 124 if (imageUrl) { 125 $accordionContainerClass.addClass('has_img'); 126 $featureImg.show(); 127 $featureImg.removeAttr('hidden'); 128 $featureImg.find('img').attr('src', imageUrl); 129 } else { 130 //$accordionContainerClass.removeClass('has_img'); 131 $featureImg.hide(); 132 133 $featureImg.find('img').attr('src', ''); 134 } 135 136 if (autoPlayWithProgressBar) { 137 const $progress = $accordion.find('.aab-progress-bar'); 138 139 const isVertical = Vertical === 'vertical'; 140 141 if (isVertical) { 142 $progress 143 .stop(true, true) 144 .css({ height: '0%', width: '100%', top: '0' }) 145 .animate({ height: '100%' }, autoPlaySpeed, 'linear'); 146 } else { 147 $progress 148 .stop(true, true) 149 .css({ width: '0%', height: '100%', left: '0' }) 150 .animate({ width: '100%' }, autoPlaySpeed, 'linear'); 151 } 152 } 153 154 currentIndex = index; 155 } 156 157 function startAutoplay() { 158 activateAccordion($accordions.eq(currentIndex), currentIndex); 159 interval = setInterval(function () { 160 currentIndex = (currentIndex + 1) % $accordions.length; 161 activateAccordion($accordions.eq(currentIndex), currentIndex); 162 }, autoPlaySpeed); 163 } 164 165 // Initial active body show 166 $accordionBodies.each(function () { 167 const $body = $(this); 168 if ($body.hasClass('aagb__accordion_body--show')) { 169 $body.slideDown(); 170 // Feature image update for initially active accordion 171 const imageUrl = $accordions.data('feature-image-url'); 172 const $accordionContainerClass = $accordions.closest('.aagb__group_accordion_container'); 173 const $featureImg = $($accordionContainerClass).find('.aab-feature-img'); 174 if (imageUrl) { 175 $accordionContainerClass.addClass('has_img'); 176 $featureImg.show(); 177 $featureImg.removeAttr('hidden'); 178 $featureImg.find('img').attr('src', imageUrl); 179 } else { 180 //$accordionContainerClass.removeClass('has_img'); 181 $featureImg.hide(); 182 183 $featureImg.find('img').attr('src', ''); 184 } 185 } 186 }); 187 188 // If Next Previous is enabled and no accordion is active, activate the first one 189 if (hasNextPrevious) { 190 const hasActiveAccordion = $accordions.hasClass('aagb__accordion_active'); 191 if (!hasActiveAccordion) { 192 activateAccordion($accordions.eq(0), 0); 193 } 194 } 195 196 $accordionHeads.on(activatorEvent, function () { 197 const $head = $(this); 198 const $accordion = $head.parent(); 199 const index = $accordions.index($accordion); 200 const isActive = $accordion.hasClass('aagb__accordion_active'); 201 if (isActive) { 202 resetAll(); 203 if (autoPlay) clearInterval(interval); 204 } else { 205 activateAccordion($accordion, index); 206 if (autoPlay) { 207 clearInterval(interval); 208 startAutoplay(); 209 } 210 } 211 212 updateButtonState($groupAccordion); 213 }); 214 215 // Accessibility with Keyboard 216 $accordions.each(function (index) { 217 const $accordion = $(this); 218 $accordion.addClass('aagb__accordion_head--keyboard'); 219 $accordion.on('keydown', function (e) { 220 if (!$(document.activeElement).is($accordion)) return; 221 222 if (e.code === 'Enter' || e.code === 'Space') { 223 e.preventDefault(); 224 $accordion 225 .find('> .aagb__accordion_head') 226 .trigger(activatorEvent); 227 } else if (/^Arrow(Up|Down|Left|Right)$/.test(e.code)) { 228 e.preventDefault(); 229 const nextIndex = 230 index + 231 { 232 ArrowUp: -1, 233 ArrowLeft: -1, 234 ArrowDown: +1, 235 ArrowRight: +1, 236 }[e.code]; 237 const $next = $accordions.eq(nextIndex); 238 if ($next.length) $next.focus(); 239 } else if (e.code === 'Home') { 240 e.preventDefault(); 241 $accordions.first().focus(); 242 } else if (e.code === 'End') { 243 e.preventDefault(); 244 $accordions.last().focus(); 245 } 246 }); 247 }); 248 249 // Start autoplay if applicable 250 if (autoPlay) { 251 startAutoplay(); 252 } else { 253 // Remove progress bar if no autoplay 254 $groupAccordion.find('.aab-progress-bar').remove(); 255 } 256 }); 257 258// Show All Click 259 $('.content-accordion__show-all').on('click', function (e) { 260 e.preventDefault(); 261 var $this = $(this); 262 var targetAccordion = $('.' + $this.data('opentarget')); 263 264 // Accordion expand 265 targetAccordion.find('.aagb__accordion_body') 266 .addClass('aagb__accordion_body--show') 267 .slideDown(); 268 targetAccordion.find('.panel').addClass('aagb__accordion_active'); 269 targetAccordion.find('.hasSubHeading').addClass('active'); 270 271 // Icon change 272 const $icon = targetAccordion.find('.aagb__accordion_heading .aagb__icon'); 273 updateIcon($icon, 'open'); 274 275 // Toggle Buttons 276 $this.hide(); 277 $this.siblings('.content-accordion__close-all').show(); 278 }); 279 280 // Close All Click 281 $('.content-accordion__close-all').on('click', function (e) { 282 e.preventDefault(); 283 var $this = $(this); 284 var targetAccordion = $('.' + $this.data('closetarget')); 285 286 // Accordion collapse 287 targetAccordion.find('.aagb__accordion_body') 288 .removeClass('aagb__accordion_body--show') 289 .slideUp(); 290 targetAccordion.find('.panel').removeClass('aagb__accordion_active'); 291 targetAccordion.find('.hasSubHeading').removeClass('active'); 292 293 // Icon change 294 const $icon = targetAccordion.find('.aagb__accordion_heading .aagb__icon'); 295 updateIcon($icon, 'close'); 296 297 // Toggle Buttons 298 $this.hide(); 299 $this.siblings('.content-accordion__show-all').show(); 300 }); 301 302 // Initially hide Close All button 303 $('.content-accordion__close-all').hide(); 304 305 // Icon update function 306 function updateIcon($icon, action) { 307 $icon.each(function () { 308 const $el = $(this); 309 if (action === 'open') { 310 if ($el.hasClass('dashicons-plus-alt2')) { 311 $el.removeClass('dashicons-plus-alt2').addClass('dashicons-minus'); 312 } else if ($el.hasClass('dashicons-arrow-down-alt2')) { 313 $el.removeClass('dashicons-arrow-down-alt2').addClass('dashicons-arrow-up-alt2'); 314 } else if ($el.hasClass('dashicons-arrow-down')) { 315 $el.removeClass('dashicons-arrow-down').addClass('dashicons-arrow-up'); 316 } else if ($el.hasClass('dashicons-plus-alt')) { 317 $el.removeClass('dashicons-plus-alt').addClass('dashicons-dismiss'); 318 } else if ($el.hasClass('dashicons-insert')) { 319 $el.removeClass('dashicons-insert').addClass('dashicons-remove'); 320 } 321 } else { 322 if ($el.hasClass('dashicons-minus')) { 323 $el.removeClass('dashicons-minus').addClass('dashicons-plus-alt2'); 324 } else if ($el.hasClass('dashicons-arrow-up-alt2')) { 325 $el.removeClass('dashicons-arrow-up-alt2').addClass('dashicons-arrow-down-alt2'); 326 } else if ($el.hasClass('dashicons-arrow-up')) { 327 $el.removeClass('dashicons-arrow-up').addClass('dashicons-arrow-down'); 328 } else if ($el.hasClass('dashicons-dismiss')) { 329 $el.removeClass('dashicons-dismiss').addClass('dashicons-plus-alt'); 330 } else if ($el.hasClass('dashicons-remove')) { 331 $el.removeClass('dashicons-remove').addClass('dashicons-insert'); 332 } 333 } 334 }); 335 } 336 $('.noEnterSubmit').keypress(function (e) { 337 if (e.which == 13) 338 e.preventDefault(); 339 }); 340 341 // Checklist 342 const accordionItemsChecklist = $('.aagb__accordion_container.check-list'); 343 344 if (accordionItemsChecklist.length) { 345 $.each(accordionItemsChecklist, function (index, item) { 346 const accordionHeading = $(item) 347 .children('.aagb__accordion_head') 348 .find('.aagb__accordion_heading'); 349 accordionHeading.prepend( 350 "<input type='checkbox' class='checklist-box'></input>" 351 ); 352 }); 353 } 354 355 const iconCls = { 356 next: 'aagb-accordion-next-icon', 357 previous: 'aagb-accordion-previous-icon', 358 }; 359 360 $('.aagb-accordion-next-previous').on('click', `.${iconCls.previous}, .${iconCls.next}`, function() { 361 const $this = $(this); 362 console.log('Next Previous Clicked'); 363 const parentItem = $this.closest('.wp-block-aab-group-accordion'); 364 const activatorEvent = parentItem.hasClass('hover') 365 ? 'mouseenter' 366 : 'click'; 367 368 let currentItem = parentItem.find( 369 '.wp-block-aab-accordion-item.aagb__accordion_active' 370 ); 371 let targetItem = currentItem.next('.wp-block-aab-accordion-item'); 372 373 if ($this.hasClass(iconCls.previous)) { 374 targetItem = currentItem.prev('.wp-block-aab-accordion-item'); 375 } 376 377 targetItem.find('.aagb__accordion_head').trigger(activatorEvent); 378 }) 379 380 $('.wp-block-aab-group-accordion').each(function(){ 381 const parentItem = $(this); 382 updateButtonState(parentItem); 383 }); 384 385 // update button state function 386 387 function updateButtonState(parentItem) { 388 let activeItem = parentItem.find( 389 '.wp-block-aab-accordion-item.aagb__accordion_active' 390 ); 391 let allItems = parentItem.find('.wp-block-aab-accordion-item'); 392 let currentIndex = allItems.index(activeItem); 393 394 let prevBtn = parentItem.find('.aagb-accordion-previous-icon'); 395 let nextBtn = parentItem.find('.aagb-accordion-next-icon'); 396 const nextPrevBtn = parentItem.find('.aagb-accordion-next-previous'); 397 398 prevBtn.removeClass('aagb_disabled'); 399 nextBtn.removeClass('aagb_disabled'); 400 401 if(activeItem.length === 0){ 402 nextPrevBtn.hide(); 403 return; 404 } 405 // show buttons 406 nextPrevBtn.show(); 407 408 if (currentIndex === 0) { 409 prevBtn.addClass('aagb_disabled'); 410 } else if (currentIndex === allItems.length - 1) { 411 nextBtn.addClass('aagb_disabled'); 412 } 413 } 414 415})(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.