EduardET

Untitled

Jul 14th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2. ( function( $ ) {
  3.     $( document ).ready( function() {
  4.         var person_module = $( '.wpc-person' ),
  5.             list_id = [],
  6.             fun_facts_section = $( '.fun-facts' );
  7.  
  8.         function get_person_title( el ) {
  9.             var person_index = el.parent().index(),
  10.                 person_name = el.find( '.et_pb_module_header' ).text().replace( /\s+/g, '-' ).toLowerCase();
  11.             list_id.push( person_name );
  12.         }
  13.  
  14.         //Insert into list_id title each person name
  15.         person_module.each( function() {
  16.             get_person_title( $( this ) )
  17.         } )
  18.  
  19.         //asign the css id for each Fun Fact section based on the Person Name
  20.         fun_facts_section.each( function() {
  21.             console.log( $( this ).index() - 1 );
  22.             $( this ).attr( 'id', list_id[ $( this ).index() - 1 ] );
  23.         } )
  24.  
  25.         person_module.each( function() {
  26.             $( this ).click( function() {
  27.                 var person_name = $( this ).find( '.et_pb_module_header' ).text().replace( /\s+/g, '-' ).toLowerCase();
  28.                 $( '.fun-facts' ).removeClass( 'show-fact' ).addClass( 'hide-fact' );
  29.                 $( '#' + person_name ).removeClass( 'hide-fact' ).addClass( 'show-fact' );
  30.             } )
  31.         } )
  32.     } );
  33. } )( jQuery );
  34. </script>
Advertisement
Add Comment
Please, Sign In to add comment