PluginProbe
Echo Knowledge Base – Documentation, FAQs, Chat & Smart Search / trunk
Echo Knowledge Base – Documentation, FAQs, Chat & Smart Search vtrunk
17.214.0 17.213.1 17.212.0 17.211.0 17.210.0 17.200.0 11.0.0 12.0.0 13.10.0 14.0.0 15.0.0 16.011.0 16.20.0 17.0.1 17.0.4 17.1.0 17.1.2 17.111.0 17.3.0 17.4.0 trunk
echo-knowledge-base / js / faq-shortcode-scripts.js

faq-shortcode-scripts.js in Echo Knowledge Base – Documentation, FAQs, Chat & Smart Search trunk, at js/faq-shortcode-scripts.js

78 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * FAQs shortcode
3 */
4 jQuery(document).ready(function($) {
5
6 // Mode 'Accordion' - collapse articles by default, expand/collapse article on click event
7 // click triggered only if data-faqs-type is 'faqs'
8 $( document ).on( 'click keydown', '.epkb-faqs-accordion-mode .epkb-faqs__item__question[data-faq-type="faqs"]', function ( e ) {
9
10 // Only proceed if it's a click or Enter/Space key (WCAG Accessibility)
11 if ( e.type === 'keydown' && e.keyCode !== 13 && e.keyCode !== 32 ) {
12 return;
13 }
14
15 // Prevent default for Space key to avoid page scroll
16 if ( e.type === 'keydown' && e.keyCode === 32 ) {
17 e.preventDefault();
18 }
19
20 // Get current article container
21 const container = $( this ).closest( '.epkb-faqs__item-container' ).eq( 0 );
22 let isExpanding = !container.hasClass( 'epkb-faqs__item-container--active' );
23
24 // Hide the current article
25 if ( container.hasClass( 'epkb-faqs__item-container--active' ) ) {
26 container.find( '.epkb-faqs__item__answer' ).stop().slideUp( 400 );
27 container.removeClass( 'epkb-faqs__item-container--active' );
28 $( this ).attr( 'aria-expanded', 'false' );
29 return;
30 }
31
32 // Show the current article
33 container.find( '.epkb-faqs__item__answer' ).stop().slideDown( 400 );
34 container.addClass( 'epkb-faqs__item-container--active' );
35
36 // Update aria-expanded attribute (WCAG Accessibility)
37 $( this ).attr( 'aria-expanded', 'true' );
38 } );
39
40 // Mode 'Toggle' - show only one article at the same time (collapse previous article before show new article)
41 $( document ).on( 'click keydown', '.epkb-faqs-toggle-mode .epkb-faqs__item__question[data-faq-type="faqs"]', function ( e ) {
42
43 // Only proceed if it's a click or Enter/Space key (WCAG Accessibility)
44 if ( e.type === 'keydown' && e.keyCode !== 13 && e.keyCode !== 32 ) {
45 return;
46 }
47
48 // Prevent default for Space key to avoid page scroll
49 if ( e.type === 'keydown' && e.keyCode === 32 ) {
50 e.preventDefault();
51 }
52
53 // Get current article container
54 const container = $( this ).closest( '.epkb-faqs__item-container' ).eq( 0 );
55 let isExpanding = !container.hasClass( 'epkb-faqs__item-container--active' );
56
57 // Collapse other opened articles and update their aria-expanded
58 $( '.epkb-faqs__item-container--active' ).not( container ).removeClass( 'epkb-faqs__item-container--active' )
59 .find( '.epkb-faqs__item__answer' ).stop().slideUp( 400 );
60 $( '.epkb-faqs__item-container--active' ).not( container ).find( '.epkb-faqs__item__question' ).attr( 'aria-expanded', 'false' );
61
62 // Show the current article
63 if ( container.hasClass( 'epkb-faqs__item-container--active' ) ) {
64 container.find( '.epkb-faqs__item__answer' ).stop().slideUp( 400 );
65 container.removeClass( 'epkb-faqs__item-container--active' );
66 $( this ).attr( 'aria-expanded', 'false' );
67 return;
68 }
69
70 // Hide the current article
71 container.find( '.epkb-faqs__item__answer' ).stop().slideDown( 400 );
72 container.addClass( 'epkb-faqs__item-container--active' );
73
74 // Update aria-expanded attribute (WCAG Accessibility)
75 $( this ).attr( 'aria-expanded', 'true' );
76 } );
77 });
78