Created
          August 26, 2022 12:38 
        
      - 
      
 - 
        
Save mwhiteley16/3052d5b67693a0430b0a732bc8c54818 to your computer and use it in GitHub Desktop.  
    ACF block.json script example
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | (function($){ | |
| // front end render on first instance of block only | |
| $(document).ready(function(){ | |
| $('.block-faq').each(function(){ | |
| faqBlockInit(); | |
| return false; | |
| }); | |
| }); | |
| // back end trigger | |
| if( window.acf ) { | |
| window.acf.addAction( 'render_block_preview/type=wd/acf-faq', acfFaqBlockInit ); | |
| } | |
| // set inital block counter | |
| let blockCountFaq = 0; | |
| // back end render for first instance of block only | |
| function acfFaqBlockInit(block) { | |
| blockCountFaq++ | |
| if (blockCountFaq > 1) return; | |
| faqBlockInit(); | |
| } | |
| // the jQuery | |
| function faqBlockInit() { | |
| $('.block-faq__toggle-question').on( 'click', function() { | |
| $(this).children('.block-faq__toggle-question-icons').attr('aria-selected', function (i, attr) { | |
| return attr == 'true' ? 'false' : 'true' | |
| }); | |
| $(this).children('.block-faq__toggle-question-icons').attr('aria-expanded', function (i, attr) { | |
| return attr == 'true' ? 'false' : 'true' | |
| }); | |
| $(this).siblings('.block-faq__toggle-answer').slideToggle().attr('aria-expanded', function (i, attr) { | |
| return attr == 'true' ? 'false' : 'true' | |
| }); | |
| }); | |
| } | |
| })(jQuery); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment