var isPassed = false,
currentIndex;
var countCorrectAnswer=0;
var countAnswer = [];
var chapter_5 = window.Player_manuscript.extend({
initialize_sections: function(){
this._super();
//image
var $bigImage = $('#idp-bigimage');
$bigImage.unbind();
$bigImage.click(onClickImage.bind($bigImage));
var isAnswered;
var questions = player.activity.questions;
questions.forEach(function(item,i){
countAnswer[i]=2;
});
$('.question_submit_button').click(function(){
var currentId = this.getAttribute('id');
currentIndex = parseInt(currentId.slice( currentId.length-1,currentId.length ));
player.show_question_feedback( player.activity.queries[ currentIndex ], false ,false);
isAnswered = player.sections[1].all_questions_answered;
if(( isAnswered )&&(countCorrectAnswer>=questions.length-1)){
$('#digfir_section_1 .next_button').show();
isPassed = true;
}
});
},
show_section: function( section_to_show ) {
this._super( section_to_show );
if( !isPassed ) {
$('#digfir_section_1 .next_button').hide();
}
},
tab_selected: function(event, ui){
// we don't actually use event;
// it's just there because it's part of the standard jquery ui fn prototype
var section_to_show = ui.index;
// if user has to view sections in sequence and hasn't gotten up to this one, don't allow it
if (player.md.sequenced_sections == "true" && section_to_show > player.last_available_section) {
alert(player.md.section_sequence_message);
return false;
}
player.section_currently_showing = section_to_show;
// process iframes for the section, unless all were preloaded
if (player.md.preload_all_iframes != "true") {
player.figures.process_iframes(player.get_current_section().jq); // iframes
}
player.update_section_status();
player.update_navigation();
window.scrollTo(0,0);
},
show_question_feedback: function( question ) {
var html = "
"
+ "
Feedback
";
html += "
";
// append the div, then fade it in
$("[ data-question_index = " + currentIndex + " ] .query_mc_feedback_correct_incorrect").prepend(html);
//add label try again
var checkedInput = $("[ data-question_index = " + currentIndex + " ] .query_mc_other_choice [checked]");
var checkInputDiv = $("[ data-question_index = " + currentIndex + " ] .query_mc_other_choice [checked]").parent();
//query_mc_other_choice
var value = checkedInput[0].value;
if(value>=0){
countAnswer[ currentIndex] --;
}
//checkInputDiv.attr( 'data-state', 'true' );
var correctValue = player.activity.queries[currentIndex-1].correct_answer_index;
var tryAgainText;
checkInputDiv.attr( 'data-state', 'false' );
if((countAnswer[currentIndex]>0)&&(player.activity.queries[currentIndex-1].correct_answer_index!=value)){
//first check
html = " Please try again.";
tryAgainText = $("[ data-question_index = " + currentIndex + " ] .query_mc_feedback_correct_incorrect");
tryAgainText.append(html);
}else{
if(correctValue!=value) {
//check after 2 tryes
var replaceText= 'The correct answer is ';
replaceText+= player.activity.queries[currentIndex - 1].choices[correctValue];
replaceText+='.';
html = player.activity.queries[currentIndex - 1].choices_fb[correctValue];
html = html.replace('Correct!',replaceText);
tryAgainText = $("[ data-question_index = " + currentIndex + " ] .query_mc_feedback_correct_incorrect");
tryAgainText.append('
' +html);
//return correct answer
var correctInput = $("[ data-question_index = " + currentIndex + " ] .query_mc_other_choice [value="+ correctValue +"]").parent();
correctInput.attr( 'data-state', 'true' );
countCorrectAnswer++;
}else{
//check true answer
checkInputDiv.attr( 'data-state', 'true' );
countCorrectAnswer++;
}
}
String.prototype.replaceAt=function(index, character) {
return this.substr(0, index) + character + this.substr(index+character.length);
}
}
});
window.player = new chapter_5();