File: /var/www/selfanalyse/emu-personality-test/tet_assign_question.js
var jQ = jQuery.noConflict();
jQ(document).ready(function () {
var notVisited = jQ('.not_visit').length;
jQ('#McountNot').text(notVisited);
jQ('#ppcountNot').text(notVisited);
jQ('.quess input[type="radio"]').on('click', function () {
var buttonId = this.id;
var id = parseInt(buttonId.substring(7));
var radioName = 'rd_ans' + id;
if (jQ('input[name=' + radioName + ']:checked').length) {
var removeId = "tt_pend_q" + id;
jQ("#" + removeId).addClass("answered");
var countAnswered = jQ('.answered').length;
jQ('#McountAn').text(countAnswered);
jQ('#pcountA').text(countAnswered);
jQ("#" + removeId).css({ 'background-color': '#00CC00', 'border': '1 px solid #00CC00' });
if ((jQ("#" + removeId).hasClass('not_select'))) {
jQ("#" + removeId).removeClass('not_select');
var countNotAnswered = jQ('.not_select').length;
jQ('#McountNotAns').text(countNotAnswered);
jQ('#ppcountNotAns').text(countNotAnswered);
}
}
else {
jQ("#" + removeId).addClass("not_select");
var countNotAnswered = jQ('.not_select').length;
jQ('#McountNotAns').text(countNotAnswered);
jQ('#ppcountNotAns').text(countNotAnswered);
}
});
setCountDown();
//-------------Next button click -----------------
jQ('.tet_mock_next').on('click', function () {
var timee = (document.getElementById("tt_timer").innerHTML).replace(/\s/g, '');
var buttonId = this.id;
var current_ques = parseInt(buttonId.substring(7));
var id = parseInt(buttonId.substring(7));
var prevId = 'ques_' + id;
var radioName = 'rd_ans' + id;
if (jQ('input[name=' + radioName + ']:checked').length) {
var ques_status = "";
var removeId = "tt_pend_q" + id;
jQ("#" + removeId).css({ 'background-color': '#00CC00', 'border': '1 px solid #00CC00' });
jQ("#" + removeId).removeClass("not_select");
jQ("#" + removeId).removeClass("not_visit");
var notVisited = jQ('.not_visit').length;
jQ('#countNot').text(notVisited);
jQ('#McountNot').text(notVisited);
jQ('#ppcountNot').text(notVisited);
jQ("#" + removeId).addClass("answered");
var countAnswered = jQ('.answered').length;
jQ('#McountAn').text(countAnswered);
jQ('#pcountA').text(countAnswered);
}
else {
var ques_status = "NA";
var removeId = "tt_pend_q" + id;
jQ("#" + removeId).css({ 'background-color': 'rgb(255, 51, 0)', 'border': '1 px solid rgb(255, 51, 0)' });
jQ("#" + removeId).addClass("not_select");
var countNotAnswered = jQ('.not_select').length;
jQ('#McountNotAns').text(countNotAnswered);
jQ('#ppcountNotAns').text(countNotAnswered);
jQ("#" + removeId).removeClass("not_visit");
var notVisited = jQ('.not_visit').length;
jQ('#McountNot').text(notVisited);
jQ('#ppcountNot').text(notVisited);
}
++id;
var nextId = 'ques_' + id;
jQ('#' + prevId).css({ 'display': 'none', 'width': '100%' });
jQ('#' + nextId).css({ 'display': 'block', 'width': '100%' });
jQ('#tet_previous' + id).css({ 'display': 'block' }); // show previous button
jQ('#tet_previous_disable' + id).css({ 'display': 'none' }); // show previous button
jQ("#currentQuestionId").val(id);
var MaxQuestionNo = jQ("#MaxQuestionNo").val();
if (id == MaxQuestionNo) // hide the next button
{
var removeId = "tt_pend_q" + id;
jQ('#tet_mock_next' + id).css({ 'display': 'none' });
jQ('#tet_mock_next_disable' + id).css({ 'display': 'block' }); // show next disable button
jQ("#" + removeId).removeClass("not_visit");
jQ("#" + removeId).css({ 'background-color': 'rgb(255, 51, 0)', 'border': '1 px solid rgb(255, 51, 0)' });
jQ("#" + removeId).addClass("not_select");
var countNotAnswered = jQ('.not_select').length;
jQ('#McountNotAns').text(countNotAnswered);
jQ('#ppcountNotAns').text(countNotAnswered);
var notVisited = jQ('.not_visit').length;
jQ('#McountNot').text(notVisited);
jQ('#ppcountNot').text(notVisited);
}
jsonQues[current_ques].time_taken = timee;
jsonQues[current_ques].tag_status = ques_status;
jsonQues[id].entered_time = timee;
jsonQues[id].time_taken = 0;
});
//-------------End of next button click -----------------
//------------ PREVIOUS BUTTON CLICK--------------------
// previous click
jQ('.tet_prevoius').on('click', function () {
var timee = (document.getElementById("tt_timer").innerHTML).replace(/\s/g, '');
var buttonId = this.id;
var id = parseInt(buttonId.substring(7));
var current_ques = parseInt(buttonId.substring(7));
var curId = 'ques_' + id;
var radioName = 'rd_ans' + id;
if (jQ('input[name=' + radioName + ']:checked').length) // button is checked mark thsi question as attempted
{
var ques_status = "";
var removeId = "tt_pend_q" + id;
jQ("#" + removeId).css({ 'background-color': '#00CC00' });
}
else {
var ques_status = "NA";
}
--id;
var prevId = 'ques_' + id;
jQ('#' + curId).css({ 'display': 'none', 'width': '100%' });
jQ('#' + prevId).css({ 'display': 'block', 'width': '100%' });
if (id == 1) {
jQ('#tet_previous' + id).css({ 'display': 'none' });
jQ('#tet_previous_disable' + id).css({ 'display': 'block' }); // show previous button
}
else {
jQ('#tet_previous' + id).css({ 'display': 'block' });
jQ('#tet_previous_disable' + id).css({ 'display': 'none' }); // show previous button
}
jQ("#currentQuestionId").val(id);
var MaxQuestionNo = jQ("#MaxQuestionNo").val();
if (id == MaxQuestionNo) // hide the next button
{
jQ('#tet_mock_next' + id).css({ 'display': 'none' });
jQ('#tet_mock_next_disable' + id).css({ 'display': 'block' }); // show next disable button
}
jsonQues[id].entered_time = timee;
jsonQues[current_ques].tag_status = ques_status;
jsonQues[id].entered_time = timee;
jsonQues[current_ques].time_taken = timee;
jsonQues[id].time_taken = 0;
});
//-------------END OF PREVIOUS BUTTON CLICK-------------
//------------- clear selection code---------------------
jQ('.tet_clear').on('click', function () {
var buttonId = this.id;
var id = parseInt(buttonId.substring(7));
var radioName = 'rd_ans' + id;
if (jQ('input[name=' + radioName + ']:checked').length) // button is checked mark thsi question as pending
{
var removeId = "tt_pend_q" + id;
var bgcolor = jQ("#" + removeId).css('background-color');
if (bgcolor == "rgb(0, 204, 0)") // check if this element bg color is green then change the color to white
{
jQ("#" + removeId).css({ 'background-color': '#FFFFFF' });
}
jQ("#" + removeId).removeClass("answered");
var countAnswered = jQ('.answered').length;
jQ('#McountAn').text(countAnswered);
jQ('#pcountA').text(countAnswered);
toastr["success"]("Option is cleared", "Clear Option", { 'closeButton': 'true', 'positionClass': 'toast-bottom-right', 'progressBar': 'true' }).show();
}
jQ('#' + 'rd_ans1' + id).removeAttr("checked");
jQ('#' + 'rd_ans2' + id).removeAttr("checked");
jQ('#' + 'rd_ans3' + id).removeAttr("checked");
jQ('#' + 'rd_ans4' + id).removeAttr("checked");
jQ('#' + 'rd_ans5' + id).removeAttr("checked");
});
jQ('#tt_pend_div').on('click', '.tt_pend_q', function () {
var timee = (document.getElementById("tt_timer").innerHTML).replace(/\s/g, '');
var buttonId = this.id;
var id = parseInt(buttonId.substring(9));
var currentId = jQ("#currentQuestionId").val();
var active_question = currentId;
var currentQuestionId = 'ques_' + currentId;
var radioName = 'rd_ans' + id;
if (jQ('input[name=' + radioName + ']:checked').length) // button is checked mark thsi question as attempted
{
var ques_status = "";
var removeId = "tt_pend_q" + id;
jQ("#" + removeId).css({ 'background-color': '#00CC00' });
if (jQ("#" + removeId).hasClass('answered')) {
jQ("#" + removeId).addClass('answered');
var countAnswered = jQ('.answered').length;
jQ('#McountAn').text(countAnswered);
jQ('#pcountA').text(countAnswered);
}
} else {
var ques_status = "NA";
var removeId = "tt_pend_q" + id;
jQ("#" + removeId).css({ 'background-color': 'rgb(255, 51, 0)', 'border': '1 px solid rgb(255, 51, 0)' });
jQ("#" + removeId).removeClass("not_visit");
var notVisited = jQ('.not_visit').length;
jQ('#McountNot').text(notVisited);
jQ('#ppcountNot').text(notVisited);
jQ("#" + removeId).addClass("not_select");
}
var targetQuestionId = 'ques_' + id;
var next_question = id;
jQ('#' + currentQuestionId).css({ 'display': 'none', 'width': '100%' }); // hide current question
jQ('#' + targetQuestionId).css({ 'display': 'block', 'width': '100%' }); // display target question
jQ("#currentQuestionId").val(id);
var MaxQuestionNo = jQ("#MaxQuestionNo").val();
if (id == 1) // hide the previous button
{
jQ('#tet_previous' + id).css({ 'display': 'none' });
jQ('#tet_previous_disable' + id).css({ 'display': 'block' }); // show previous button
}
else {
jQ('#tet_previous' + id).css({ 'display': 'block' });
jQ('#tet_previous_disable' + id).css({ 'display': 'none' }); // show previous button
}
if (id == MaxQuestionNo) // hide the next button
{
jQ('#tet_mock_next' + id).css({ 'display': 'none' });
jQ('#tet_mock_next_disable' + id).css({ 'display': 'block' }); // show next disable button
}
jsonQues[active_question].time_taken = timee;
jsonQues[active_question].tag_status = ques_status;
jsonQues[next_question].entered_time = timee;
jsonQues[next_question].time_taken = 0;
});
jQ("#tt_at_q_hd").click(function () {
jQ("#tt_pend_div").slideToggle("slow");
});
jQ('.tt_test_option').on('click', function () {
var buttonId = this.name;
var answer = jQ('#' + this.id).val();
var id = parseInt(buttonId.substring(6));
jsonQues[id].answer = answer;
console.log(jsonQues);
});
jQ('#fin_ex').on('click', function () {
var timee = (document.getElementById("tt_timer").innerHTML).replace(/\s/g, '');
var url = jQ("#siteUrl").val();
jQ('#t_l').text(timee);
});
});
function saveSubmitTest(idd) {
var test_percent = localStorage.getItem("test_percent");
var divs = document.getElementsByClassName("check_id");
for (var i = 0; i < divs.length; i++) {
display = divs[i].style.display;
if (display == 'block') {
// alert(divs[i].getAttribute('id'));
var current_quesID = divs[i].getAttribute('id');
var current_ques = parseInt(current_quesID.substring(5));
//alert(current_ques);
var timee = (document.getElementById("tt_timer").innerHTML).replace(/\s/g, '');
var radioName = 'rd_ans' + current_ques;
if (jQ('input[name=' + radioName + ']:checked').length) // button is checked mark thsi question as attempted
{
var ques_status = "";
} else {
var ques_status = "NA";
}
jsonQues[current_ques].time_taken = timee;
jsonQues[current_ques].tag_status = ques_status;
}
}
var type_mock = idd;
var time_taken_in_seconds = document.getElementById("time_taken").value;
jQ.ajax({
type: "POST",
url: "/emu-personality-test/test_save.php",
dataType: 'json',
data: { "type": type_mock, "time_taken_in_seconds": time_taken_in_seconds, "param": jsonQues },
success: function (data) {
data.map(function (item) {
localStorage.removeItem("test_percent");
if (item.status == 'success') {
if (item.type_test == 'complete') {
window.location = "/emu-personality-test/test-report?testId=" + item.test_taken_id;
}
} else {
}
});
}
});
return false;
clearInterval(myVar);
}
var myVar = setInterval(saveSubmitTest, 1200000);
function changeFontSize(target) {
var demo = document.getElementsByClassName("fontControl");
var fontSize;
for (var i = 0; i < demo.length; i++) {
var computedStyle = window.getComputedStyle
? getComputedStyle(demo[i]) // Standards
: demo[i].currentStyle; // Old IE
if (computedStyle) { // This will be true on nearly all browsers
fontSize = parseFloat(computedStyle && computedStyle.fontSize);
if (target == document.getElementById("button1")) {
fontSize += 1;
} else if (target == document.getElementById("button2")) {
fontSize -= 1;
}
demo[i].style.fontSize = fontSize + "px";
}
}
}
jQ(function () {
jQ('form[onload]').trigger('onload');
});
/********exam timing************ */