Last active
August 29, 2015 14:01
-
-
Save adamellsworth/df8329077b153a3f5161 to your computer and use it in GitHub Desktop.
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
var question = new Array(), | |
answer = new Array(); | |
/* | |
Push the questions and answers into their respective arrays | |
by checking if the 'i' index is odd or even as the matrix only has two fields. | |
*/ | |
$('#faq-container table.matrix tbody tr td').find('textarea').each(function(i) { | |
if (!(i % 2)) { | |
question.push($(this).val()); | |
} else { | |
answer.push($(this).val()); | |
} | |
}); | |
if (question.length != 0) { // If there are questions... | |
$('.faq-out').html(''); // Clear the content if any | |
$('.faq-out').show(); | |
$('.faq-out').append('<div></div>').addClass('panel-group').attr('id', 'faq-accordion'); | |
$('.faq-out > div').append('<div></div>').addClass('panel panel-default'); | |
for (var k = 0; k <= question.length; k++) { | |
if (typeof question[k] != 'undefined') { | |
// Generate the FAQ accordion panels | |
$('.faq-out > div > div').append( | |
'<div class="panel-heading"><h4 class="panel-title"><a data-toggle="collapse" data-parent="#faq-accordion" href="#faq-collapse-' + k +'">' + question[k] + '</a></h4></div>' + | |
'<div id="faq-collapse-' + k + '" class="panel-collapse collapse in"><div class="panel-body">' + answer[k] + '</div></div>' | |
); | |
} | |
} | |
} else { | |
$('.faq-out').hide(); // Hide the FAQ section altogether because there was nothing entered into the Q&A matrix | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment