Widget:FaqViewer: Difference between revisions
Jump to navigation
Jump to search
Matt Pijoan (talk | contribs) Created page with "<includeonly> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script>..." |
Matt Pijoan (talk | contribs) No edit summary |
||
Line 701: | Line 701: | ||
var cleanJSON = {}; | var cleanJSON = {}; | ||
var questionList = []; | |||
$.each(faqArray['Sheet1'], function(key, value){ | $.each(faqArray['Sheet1'], function(key, value){ | ||
var main = value["Main category"]; | var main = $.trim(value["Main category"]); | ||
var sub = value["Sub category"]; | var sub = $.trim(value["Sub category"]); | ||
var ques = value["Question"]; | var ques = $.trim(value["Question"]); | ||
var ans = value["Answer"]; | var ans = $.trim(value["Answer"]); | ||
if(main.indexOf(',') != -1){ | if(main.indexOf(',') != -1){ | ||
var split = main.split(','); | var split = main.split(','); | ||
Line 713: | Line 713: | ||
var subSplit = sub.split(','); | var subSplit = sub.split(','); | ||
$.each(subSplit, function(subI, subVal){ | $.each(subSplit, function(subI, subVal){ | ||
pushToClean(val, subVal, ques, ans); | pushToClean($.trim(val), $.trim(subVal), ques, ans); | ||
}); | }); | ||
} else { | |||
pushToClean($.trim(val), sub, ques, ans); | |||
} | } | ||
}); | }); | ||
} else if(sub.indexOf(',' != -1)){ | } else if(sub.indexOf(',' != -1)){ | ||
var subSplit = sub.split(','); | var subSplit = sub.split(','); | ||
console.log(subSplit); | |||
$.each(subSplit, function(subI, subVal){ | $.each(subSplit, function(subI, subVal){ | ||
pushToClean(main, subVal, ques, ans); | pushToClean(main, $.trim(subVal), ques, ans); | ||
}); | }); | ||
} else { | } else { | ||
Line 730: | Line 732: | ||
}); | }); | ||
function | function fuckWhitespace(string){ | ||
return $.trim(string); | |||
} | } | ||
function pushToClean(main, sub, ques, ans){ | function pushToClean(main, sub, ques, ans){ | ||
Line 742: | Line 744: | ||
if(cleanJSON[main][sub].length){ | if(cleanJSON[main][sub].length){ | ||
cleanJSON[main][sub].push({"question": ques, "answer":ans}); | cleanJSON[main][sub].push({"question": ques, "answer":ans}); | ||
questionList.push(ques); | |||
} else { | } else { | ||
cleanJSON[main][sub] =[{"question": ques, "answer":ans}]; | cleanJSON[main][sub] =[{"question": ques, "answer":ans}]; | ||
if(!$.inArray(ques, questionList)){ | |||
questionList.push(ques); | |||
} | |||
} | } | ||
} | } | ||
var html = ""; | var html = ""; | ||
$.each(cleanJSON, function(mainKey, mainValue){ | $.each(cleanJSON, function(mainKey, mainValue){ | ||
html += "<h3>"+mainKey+"</h3><div class=' | html += "<h3>"+mainKey+"</h3><div class='accordion'>"; | ||
$.each(mainValue, function(subKey, subValue){ | $.each(mainValue, function(subKey, subValue){ | ||
html += "<h3>"+subKey+"</h3><div class=' | html += "<h3>"+subKey+"</h3><div class='accordion'>"; | ||
$.each(subValue, function(qKey, qValue){ | $.each(subValue, function(qKey, qValue){ | ||
html += "<h3>"+qValue.question+"</h3><div>"+qValue.answer+"</div>"; | html += "<h3>"+qValue.question+"</h3><div>"+qValue.answer+"</div>"; | ||
Line 759: | Line 765: | ||
}); | }); | ||
$("#display").html(html); | $("#display").html(html); | ||
$( ". | $( ".accordion" ).accordion({ | ||
collapsible: true, | collapsible: true, | ||
heightStyle: "content" | active:false, | ||
heightStyle: "content" | |||
}); | }); | ||
$( "#questions" ).autocomplete({ | |||
source: questionList, | |||
select: function (event, ui){ | |||
showQuestion(ui.item.label); | |||
} | |||
}); | |||
function showQuestion(stringToFind){ | |||
$("h3:contains('"+stringToFind+"')").parent().parent().prev().trigger("click"); | |||
$("h3:contains('"+stringToFind+"')").parent().prev().trigger("click"); | |||
$("h3:contains('"+stringToFind+"')").trigger("click"); | |||
} | |||
}); | }); | ||
</script> | </script> | ||
<div id="display" class=" | <div class="ui-widget"> | ||
<input id="questions" default="Type here to search for a question" style="width:75%;"> | |||
</div> | |||
<div id="display" class="accordion"> | |||
</div> | </div> | ||
</includeonly> | </includeonly> |