1/** 2 * FAQ Widget Accordion Functionality 3 */ 4(function($) { 5 'use strict'; 6 7 function initFAQWidget($widget) { 8 if ($widget.hasClass('faq-initialized')) { 9 return; 10 } 11 12 var animationDuration = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : 300; 13 14 $widget.addClass('faq-initialized'); 15 16 $widget.find('.faq-widget__question').on('click keydown', function(e) { 17 if (e.type === 'keydown' && e.which !== 13 && e.which !== 32) { 18 return; 19 } 20 21 e.preventDefault(); 22 23 var $item = $(this).parent(); 24 var $answer = $(this).next('.faq-widget__answer'); 25 var $arrow = $(this).find('.faq-widget__arrow'); 26 var isExpanded = $(this).attr('aria-expanded') === 'true'; 27 28 if (isExpanded) { 29 $item.removeClass('faq-widget__item--active'); 30 $answer.slideUp(animationDuration); 31 $(this).attr('aria-expanded', 'false'); 32 $arrow.removeClass('faq-widget__arrow--expanded'); 33 } else { 34 // Close all other items in this widget 35 $widget.find('.faq-widget__item').removeClass('faq-widget__item--active'); 36 $widget.find('.faq-widget__answer').slideUp(animationDuration); 37 $widget.find('.faq-widget__question').attr('aria-expanded', 'false'); 38 $widget.find('.faq-widget__arrow').removeClass('faq-widget__arrow--expanded'); 39 40 // Open this item 41 $item.addClass('faq-widget__item--active'); 42 $answer.slideDown(animationDuration); 43 $(this).attr('aria-expanded', 'true'); 44 $arrow.addClass('faq-widget__arrow--expanded'); 45 } 46 }); 47 48 // Open first item by default 49 var $firstItem = $widget.find('.faq-widget__item').first(); 50 var $firstQuestion = $firstItem.find('.faq-widget__question'); 51 var $firstAnswer = $firstItem.find('.faq-widget__answer'); 52 var $firstArrow = $firstItem.find('.faq-widget__arrow'); 53 54 $firstItem.addClass('faq-widget__item--active'); 55 $firstAnswer.show(); 56 $firstQuestion.attr('aria-expanded', 'true'); 57 $firstArrow.addClass('faq-widget__arrow--expanded'); 58 } 59 60 // Initialize on document ready 61 $(document).ready(function() { 62 $('.faq-widget').each(function() { 63 initFAQWidget($(this)); 64 }); 65 }); 66 67 // Re-initialize for Elementor editor 68 $(window).on('elementor/frontend/init', function() { 69 if (typeof elementorFrontend !== 'undefined' && elementorFrontend.hooks) { 70 elementorFrontend.hooks.addAction('frontend/element_ready/faq-widget.default', function($scope) { 71 initFAQWidget($scope.find('.faq-widget')); 72 }); 73 } 74 }); 75 76})(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.