Last active
December 10, 2015 12:49
-
-
Save adatta02/4437007 to your computer and use it in GitHub Desktop.
This file contains 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 questionArray = { }; | |
var questionLabels = []; | |
var tbl = $("<table class='js-format-table'><thead><tr></tr></thead><tbody></tbody></table>"); | |
var boilerplate; | |
$('div[id^="question"]').each(function(i) { | |
if( $(this).hasClass("boilerplate") ){ | |
boilerplate = $(this); | |
return true; | |
} | |
var label = $.trim($(this).find(".questiontext:first").text()); | |
$(this).hide(); | |
if( !questionArray[label] ){ | |
questionArray[label] = []; | |
questionLabels.push(label); | |
$("<th>" + label + "</th>").appendTo($(tbl).find("thead tr")); | |
} | |
var el = $(this).find(".question").remove(); | |
questionArray[label].push( el ); | |
}); | |
var num = questionArray[questionLabels[0]].length; | |
for(var j = 0; j < num; j++){ | |
var tr = $("<tr></tr>"); | |
for(var i = 0; i < questionLabels.length; i++){ | |
var html = "<td>" + $(questionArray[questionLabels[i]].pop()).html() + "</td>"; | |
$(html).appendTo(tr); | |
} | |
$(tr).appendTo( $(tbl).find("tbody") ); | |
} | |
$(boilerplate).after(tbl); | |
$("<style>.js-format-table input[type='text'], .js-format-table select { width: 110px; padding: 2px; }</style>").appendTo("body"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment