var triesQuestion11=0;
var check;
var player_6 = Player_manuscript_type.extend({
update_section_status: function() {
if (this.section_currently_showing != null && this.last_available_section <= this.section_currently_showing ) {
if( this.section_completed !== undefined && !this.section_completed ) return;
var s = this.get_current_section();
s.all_questions_answered = true;
// if the current section has any questions, see if they've all been answered
var qs_to_check = [];
s.jq.find("[data-type=question]").each(function(index, element) {
var q_index = $(element).attr("data-question_index");
var question = player.activity.questions[q_index];
s.all_questions_answered = s.all_questions_answered && question.is_complete();
if (question.question_sequence != null) {
for (var i = 0; i < qs_to_check.length; ++i) {
if (qs_to_check[i] == question.question_sequence) break;
}
if (i == qs_to_check.length) {
qs_to_check.push(question.question_sequence);
}
}
});
// now check question sequences to make sure they're done too
s.all_question_sequences_completed = true;
for (var i = 0; i < qs_to_check.length; ++i) {
s.all_question_sequences_completed = s.all_question_sequences_completed && (qs_to_check[i].sequence_complete == "complete");
}
if (s.all_questions_answered && s.all_question_sequences_completed) {
this.last_available_section = this.section_currently_showing + 1;
}
}
this.fill_in_previous_query_responses();
// if ARGA is initialized and we need to restore the user to his last position when he returns,
if (this.ARGA_running && player.md.restore_last_viewed_section == "true") {
// if we're viewing a page other than the one currently saved as LVS (last-viewed section)
var lvs = Get_ARGA_Data("LVSX");
if (this.section_currently_showing != null && this.section_currently_showing != lvs) {
// store LVS/LAS to register the last-viewed/last-available page,
// and save ARGA so it gets registered
Set_ARGA_Data("LVSX", this.section_currently_showing);
Set_ARGA_Data("LASX", this.last_available_section);
this.activity.ARGA_submit_data(false);
}
}
},
update_navigation: function() {
// show/hide the "next" button as appropriate
var last_section = this.showing_last_section();
if (this.last_available_section > this.section_currently_showing && !last_section ) {
UI_Elements.toggle_button("step_next_button", true);
} else {
UI_Elements.toggle_button("step_next_button", false);
}
var currentSection = this.sections[this.section_currently_showing];
if( currentSection && currentSection.section_completed !== undefined ){
if( currentSection.section_completed ){
UI_Elements.toggle_button("step_next_button", true);
} else {
UI_Elements.toggle_button("step_next_button", false);
}
}
},
show_section: function( section_to_show ) {
'use strict';
this._super();
var current_section = null;
if ( this.section_currently_showing !== null ) {
current_section = window.player.sections[ this.section_currently_showing ];
}
if( section_to_show > this.last_available_section){
window.Standard_Dialog.open( "
You must complete previous sections.
", {
"draggable" : false,
"width" : 290,
"buttons" : [
{ text : 'OK', click : window.Standard_Dialog.close }
]
} );
return;
}
// If click previous button
if ( section_to_show === "previous" ) {
if ( current_section !== null && current_section.md && !isNaN( current_section.md.previous_section ) ) {
section_to_show = Number( current_section.md.previous_section );
}
else {
section_to_show = this.section_currently_showing - 1;
}
}
var currentSection = this.sections[this.section_currently_showing];
if( currentSection && currentSection.section_completed !== undefined && !currentSection.section_completed ){
if( section_to_show === "next" ) {
window.Standard_Dialog.open( "" + popupMesage +"
", {
"draggable" : false,
"width" : 444,
"buttons" : [
{ text : 'OK', click : window.Standard_Dialog.close }
]
} );
return;
}
}
// If click next button
if ( section_to_show === "next" && currentSection.all_questions_answered ) {
if ( current_section !== null && current_section.md && !isNaN( current_section.md.next_section ) ) {
section_to_show = Number( current_section.md.next_section );
}
else {
section_to_show = this.section_currently_showing + 1;
}
}
else if( section_to_show === "next" && !currentSection.all_questions_answered ){
window.Standard_Dialog.open( "" + popupMesage +"
", {
"draggable" : false,
"width" : 444,
"buttons" : [
{ text : 'OK', click : window.Standard_Dialog.close }
]
} );
}
if ( section_to_show === null || isNaN( section_to_show ) || section_to_show < 0 || section_to_show >= this.sections.length ) {
return;
}
var section = this.sections[ section_to_show ];
if ( section.md.section_type && window.mheAdditionalActivities[ section.md.section_type ] ) {
if ( window.mheAdditionalActivities[ section.md.section_type ].show ) {
window.mheAdditionalActivities[ section.md.section_type ].show( section );
}
}
window.player.hide_section( current_section );
this.show_section_animate( section_to_show );
var continueBtn = $("#step_next_button .ui-button-text");
if( player.section_currently_showing === 14 ){
continueBtn.text("Submit to IRB");
} else {
continueBtn.text("Continue");
};
if( player.section_currently_showing === 20 ){
continueBtn.text("Access Data");
} else {
continueBtn.text("Continue");
};
this.update_section_status();
this.update_navigation();
}
});
var Activity_manuscript_type = Activity.extend( {
submit_question: function(question_index) {
// the arg may be a number or an event object; in the latter case...
if (typeof question_index == "object") {
// extract the question_index from the object
question_index = question_index.data.question_index;
}
var t = player.activity;
var question = t.questions[question_index];
// showMyFeedback(question,true,false);
var all_answers_correct = true;
// for each query in the question...
for (var i = 0; i < question.queries.length; ++i) {
var query = question.queries[i];
// evaluate the answer. If evaluateAnswer returns false, the answer isn't submittable at this time --
// most likely because it's a free-response answer that needs to be evaluated via MAVE.
var answer_submittable = query.evaluateAnswer(question_index);
if (answer_submittable === false) {
// as soon as we get an unsubmittable answer, we return. submit_question
// will be called again, either by the callback fn of MAVE or because the student
// resubmits. At that point we'll catch any additional free-response answers that need
// checking, or we'll finish this loop here and move on.
return;
}
all_answers_correct = all_answers_correct && query.isCorrect() &&(query.user_answer_index >= 0);
}
// if we made it to here, we're at least going to show which items are correct and incorrect
// we might overwrite with review mode below, but that's OK
var myquery;
for (var i = 0; i < question.queries.length; ++i) {
var query = question.queries[i];
myquery=query;
query.jq.html(query.getHTML("review_correct_incorrect"));
}
// update question tries
++question.tries;
function showMyFeedback (messageFeedback,is_correct,try_again){
// function(question, is_correct, try_again) {
// remove prior feedback if there
$("#question_feedback_" + question.index).remove();
// if we don't have any feedback at all, return
if (messageFeedback.length == 0) {
return;
}
var html = ""
+ "
" + 'Feedback' + "
";
// include general feedback if there
// if (question.md.feedback != null) {
html += "
" + messageFeedback + "
";
// }
// var UserAnswerIndex = question.queries[0].user_answer_index,
// correctAnswerIndex = question.queries[0].correct_answer_index;
// include correct feedback if there and the answer is correct
// if (is_correct && question.md.feedback_correct != null) {
//!==null
// if( question.queries[0].choices_fb[UserAnswerIndex] != null ){
// html += "
" + question.md.feedback_correct+
// ' '+ question.queries[0].choices_fb[UserAnswerIndex] + "
";
// } else {
// html += "
" + messageFeedback+ "
";
// }
// }
// include incorrect or hint feedback if there and the answer is incorrect
if (!is_correct) {
var found_feedback_string = false;
// if user gets to try again...
if (try_again) {
// check for feedback_conditional's
if (question.md.feedback_conditional.length > 0) {
for (var i in question.md.feedback_conditional) {
var fbc = question.check_conditional(question.md.feedback_conditional[i]);
if (fbc != "") {
html += "
" + fbc + "
";
found_feedback_string = true;
break;
}
}
}
// if we didn't find a feedback string to use above, check for feedback_hint
if (!found_feedback_string && question.md.feedback_hint != null && !isNaN(UserAnswerIndex) ) {
html += "
" + question.queries[0].choices_fb[UserAnswerIndex]
+' ' + question.md.feedback_hint + "
";
found_feedback_string = true;
} else if(!found_feedback_string && question.md.feedback_hint != null){
html += "
" + question.md.feedback_hint + "
";
found_feedback_string = true;
}
}
// if we didn't find a feedback string to use above, check for feedback_incorrect
// if( !isNaN( UserAnswerIndex ) && !try_again){
// var correctAnswerId = question.queries[0].choice_order.indexOf(correctAnswerIndex);
// html += "
" + question.queries[0].choices_fb[UserAnswerIndex] +
// ' The correct answer is '+ question.queries[0].choice_ids[correctAnswerId] +
// '. '+question.queries[0].choices_fb[correctAnswerIndex] + "
";
// } else if (!found_feedback_string && question.md.feedback_incorrect != null) {
// var correctAnswerId = question.queries[0].choice_order.indexOf(correctAnswerIndex);
// html += "
" +
// ' The correct answer is '+ question.queries[0].choice_ids[correctAnswerId] +
// '. '+question.queries[0].choices_fb[correctAnswerIndex] + "
";
// }
}
// close question_feedback div
html += "
";
// append the div, then fade it in
$("#question_action_div_" + question.index).prepend(html);
$("#question_feedback_" + question.index).fadeIn("fast", function() {
// What I'd like to do here is check to make sure the feedback is all showing on the screen,
// and scroll if necessary so that the feedback is all visible. But just doing "scrollTo"
// isn't working properly in all situations.
// $(window).scrollTo($(this), 0);
});
}
if(question_index == 10){
check = document.querySelectorAll('#digfir_section_10 .query_essay_ta').valueOf();
}
if(question_index == 21) {
var $checkboxes = $('#first_section_question_1 table input');
var md_feedbacks = [
'A. This would be a good behavior to observe, as it is easy to identify and is a clear sign of affection between adults.',
'B. This is not the best option. Although this behavior would be easy to identify, it does not necessarily indicate affection between two adults. Strangers often smile at each other as a polite gesture.',
'C. This would be a good behavior to observe, as it is easy to identify and is a clear sign of affection between adults.',
'D. This would be a good behavior to observe, as it is easy to identify and is a clear sign of affection between adults.',
'E. This is not a good option. This behavior would be hard to detect as an outside observer, as eye contact is often subtle and hard to determine.'
];
var txt = '';
for (var i = 0; i < 5; i++) {
if ($checkboxes[i].checked == true) {
txt += md_feedbacks[i] + '';
}
}
//check answers
if (($checkboxes[0].checked == true) &&
($checkboxes[1].checked == false) &&
($checkboxes[2].checked == true) &&
($checkboxes[3].checked == true) &&
($checkboxes[4].checked == false)) {
$('#question_submit_button_11').hide();
$('#step_next_button').show();
$('.query_cb').attr('disabled', true);
// $('td [data-type="query"]').css("border","solid 2px red");
$('td [data-type="query"] [checked]').parent().css("border", "solid 2px green");
updateQuestion();
showMyFeedback(txt, false, true);
} else {
$checkboxes.attr("checked", false);
triesQuestion11++;
$checkboxes.attr("disabled", false);
showMyFeedback(txt, false, true);
if (triesQuestion11 >= 3) {
$('#question_submit_button_18').hide();
$('#step_next_button').show();
// $('td [data-type="query"]').css("border","solid 2px red");
$($checkboxes[0]).attr("checked", true);
$($checkboxes[1]).attr("checked", false);
$($checkboxes[2]).attr("checked", true);
$($checkboxes[3]).attr("checked", true);
$($checkboxes[4]).attr("checked", false);
// $checkboxes.parent().css("border","solid 2px darkred");
$($checkboxes[0]).parent().css("border", "solid 2px green");
$($checkboxes[2]).parent().css("border", "solid 2px green");
$($checkboxes[3]).parent().css("border", "solid 2px green");
$('.query_cb').attr('disabled', true);
updateQuestion();
txt = '';
txt += md_feedbacks[0] + '' + md_feedbacks[2];
showMyFeedback(txt, false, true);
// showMyFeedback(txt,true,false);
}
}
}else {
updateQuestion();
}
function updateQuestion(){
// if answer is incorrect, and max_tries is set, and # of tries is less than max_tries
// (and the user didn't just give up)
if ((!all_answers_correct && question.md.max_tries != null && question.tries < question.md.max_tries) && question.gave_up != true) {
// tell user he can try again
t.show_question_feedback(question, false, true);
return;
} else {
t.show_question_feedback(question, all_answers_correct, false);
}
// if we make it to here we need to set ARGA info for the question, and show queries in review mode
// if md.question_report_text is set, we submit the question as a whole, rather than as individual queries
var query_correct_answers = "";
var query_responses = "";
var query_responses_for_questionData = "";
var query_grade_sum = 0;
// for each query in the question...
for (var i = 0; i < question.queries.length; ++i) {
var query = question.queries[i];
// establish a question number to use
var query_number = t.get_query_number(question, i);
//show final score popup
// if(t.questions.length-2<=query_number){
// window.Standard_Dialog.open( " Number of correct answers: " +countCorrectAnswers+" Number of incorrect answers: "+ countIncorrectAnswers+"
", {
// "draggable" : false,
// "width" : 444,
// "buttons" : [
// { text : 'OK', click : window.Standard_Dialog.close }
// ]
// } );
// }
// get a query weight
var query_weight = question.get_weight();
// if the question has more than one query, divide weight accordingly
if (question.queries.length > 1) {
query_weight = Math.round(query_weight / question.queries.length);
}
// if credit_after_max_tries is set, give at least that credit now, as long as the student tried
if (question.md.credit_after_max_tries != null) {
var query_grade = query.getGradeForARGA();
if (query_grade >= 0 && query_grade < question.md.credit_after_max_tries) {
query.overrideGrade(question.md.credit_after_max_tries * 1);
}
}
// set the ARGA response, unless we're saving one response for the whole question
if (!question.md_set("question_report_text")) {
t.ARGA_set_query_response(query, query_number, query_weight);
// otherwise compose query roll-ups
} else {
if (query_correct_answers != "") {
query_correct_answers += " / ";
query_responses += " / ";
query_responses_for_questionData += t.query_responses_separator;
}
query_correct_answers += query.getCorrectAnswerForARGA();
query_responses += query.getUserAnswerForARGA();
// see restore_saved_answers for how this is used later
query_responses_for_questionData += query.getUserAnswerForARGA()
+ t.query_responses_grade_separator
+ query.getOriginalGrade();
query_grade_sum += query.getGradeForARGA() * 1;
}
// show in review mode, unless question metadata says not to show correct answers
//tooltip
//&&(question.md.show_correct_answers != undefined)
if ((question.md.show_correct_answers != false)&&(question_index!=21)) {
query.jq.html(query.getHTML("review"));
var qIndex = query.query_index+1;
var $labels = $('[data-question_index='+qIndex+'] label ');
for(var i = 0; i < $labels.length; i++){
if((query.choices_fb[i]!=null)&&(query.choices_fb[i] != undefined)) {
var tIndex = query.choice_order[i];
if(query.correct_answer_index == query.choice_order[i])
$labels[i].setAttribute('title', query.choices_fb[tIndex]);
}
}
}
}
// if we're saving one response for the whole question, save here
if (question.md_set("question_report_text")) {
var question_grade = Math.round(query_grade_sum / question.queries.length);
t.ARGA_set_question_response(question, query_correct_answers, query_responses, question_grade, query_responses_for_questionData);
}
// grade the activity
t.grade_activity();
// then if ARGA is running, submit data; show_grade_saved_message will be called on completion.
if (player.ARGA_running) {
t.ARGA_submit_data();
}
// update the question_action_div
t.update_question_action_div(question_index);
// if the item is in a sequence, show the next question
t.show_next_question(question);
// update section status
player.update_section_status();
var s = player.get_current_section();
// if all questions are answered and all sequences are complete
// (these are set by _super)
if (s.all_questions_answered && s.all_question_sequences_completed) {
// if we're not on the final step
if (s.index < player.sections.length - 1) {
// then show the buttona
UI_Elements.toggle_button("step_next_button", true);
// otherwise we're done!
} else {
player.show_completion_message();
}
}
}
},
show_question_feedback: function(question, is_correct, try_again) {
// remove prior feedback if there
$("#question_feedback_" + question.index).remove();
// if we don't have any feedback at all, return
if (question.md.feedback == null && question.md.feedback_correct == null && question.md.feedback_incorrect == null && question.md.feedback_hint == null) {
return;
}
var html = ""
+ "
" + this.feedbackTitle + "
";
// include general feedback if there
if (question.md.feedback != null) {
html += "
" + question.md.feedback + "
";
}
var UserAnswerIndex = question.queries[0].user_answer_index,
correctAnswerIndex = question.queries[0].correct_answer_index;
// include correct feedback if there and the answer is correct
if (is_correct && question.md.feedback_correct != null) {
//!==null
if( question.queries[0].choices_fb[UserAnswerIndex] != null ){
html += "
" + question.md.feedback_correct+
' '+ question.queries[0].choices_fb[UserAnswerIndex] + "
";
} else {
html += "
" + question.md.feedback_correct+ "
";
}
}
// include incorrect or hint feedback if there and the answer is incorrect
if (!is_correct) {
var found_feedback_string = false;
// if user gets to try again...
if (try_again) {
// check for feedback_conditional's
if (question.md.feedback_conditional.length > 0) {
for (var i in question.md.feedback_conditional) {
var fbc = question.check_conditional(question.md.feedback_conditional[i]);
if (fbc != "") {
html += "
" + fbc + "
";
found_feedback_string = true;
break;
}
}
}
// if we didn't find a feedback string to use above, check for feedback_hint
if (!found_feedback_string && question.md.feedback_hint != null && !isNaN(UserAnswerIndex) ) {
html += "
" + question.queries[0].choices_fb[UserAnswerIndex]
+' ' + question.md.feedback_hint + "
";
found_feedback_string = true;
} else if(!found_feedback_string && question.md.feedback_hint != null){
html += "
" + question.md.feedback_hint + "
";
found_feedback_string = true;
}
}
// if we didn't find a feedback string to use above, check for feedback_incorrect
if( !isNaN( UserAnswerIndex ) && !try_again){
var correctAnswerId = question.queries[0].choice_order.indexOf(correctAnswerIndex);
html += "
" + question.queries[0].choices_fb[UserAnswerIndex] +
' The correct answer is '+ question.queries[0].choice_ids[correctAnswerId] +
'. '+question.queries[0].choices_fb[correctAnswerIndex] + "
";
} else if (!found_feedback_string && question.md.feedback_incorrect != null) {
var correctAnswerId = question.queries[0].choice_order.indexOf(correctAnswerIndex);
html += "
" +
' The correct answer is '+ question.queries[0].choice_ids[correctAnswerId] +
'. '+question.queries[0].choices_fb[correctAnswerIndex] + "
";
}
}
// close question_feedback div
html += "
";
// append the div, then fade it in
$("#question_action_div_" + question.index).prepend(html);
$("#question_feedback_" + question.index).fadeIn("fast", function() {
// What I'd like to do here is check to make sure the feedback is all showing on the screen,
// and scroll if necessary so that the feedback is all visible. But just doing "scrollTo"
// isn't working properly in all situations.
// $(window).scrollTo($(this), 0);
});
}
} );
window.player = new player_6();
// multiple-choice
(function(){
function ReviewSlide( section ){
this.section = section;
this.section.points_possible = 1;
this.section.points_earned = 0;
this.section.section_completed = false;
this.trows = section.jq[0].querySelectorAll( "table tbody tr" );
this.container = section.jq[0].querySelector( ".multiple_choice" );
this.questionsFeedback = [];
this.correctAnswers = [];
this.inputs = [];
this.userAnswers = [];
this.letters = [ "A", "B", "C", "D", "E", "F", "G", "H", "K" ];
this.generateHTML();
}
ReviewSlide.prototype.generateHTML = function(){
var td, newtd, input, fb, text;
for( var i = 0; i < this.trows.length; i++ ){
td = this.trows[i].querySelector( "td" );
newtd = document.createElement( "td" );
input = document.createElement( "input" );
input.setAttribute( "type", "checkbox" );
newtd.appendChild( input );
this.trows[i].insertBefore( newtd, td );
text = td.innerHTML;
fb = text.slice( text.indexOf( "{" ) + 1, -1 );
td.innerHTML = ( text.indexOf( "*" ) == -1 ) ?
text.slice( 0, text.indexOf( "{" ) ) :
text.slice( 1, text.indexOf( "{" ) );
this.correctAnswers.push( text.indexOf( "*" ) + 1 );
this.questionsFeedback.push( fb );
this.inputs.push( input );
}
var btnContainer = document.createElement( "div" );
var submitBtn = document.createElement( "input" );
btnContainer.className = "question_action_div";
submitBtn.className = "standard_button question_submit_button ui-button ui-widget ui-state-default ui-corner-all";
submitBtn.setAttribute( "type", "button" );
submitBtn.setAttribute( "value", "Submit" );
submitBtn.setAttribute( "role", "button" );
submitBtn.setAttribute( "aria-disabled", "false" );
btnContainer.appendChild( submitBtn );
var fbHead = document.createElement( "div" );
fbHead.className = "question_feedback_head";
fbHead.innerHTML = "Feedback";
this.fbPart = document.createElement( "div" );
this.fbPart.className = "question_feedback_part";
this.fbContainer = document.createElement( "div" );
this.fbContainer.className = "question_feedback";
this.fbContainer.style.display = "none";
this.fbContainer.appendChild( fbHead );
this.fbContainer.appendChild( this.fbPart );
this.container.appendChild( this.fbContainer );
this.container.appendChild( btnContainer );
var self = this;
submitBtn.addEventListener( "click", function(){
self.setFeedback();
self.checkAnswer();
});
};
ReviewSlide.prototype.setFeedback = function(){
this.fbContainer.style.display = "block";
this.fbPart.innerHTML = "";
this.userAnswers = [];
this.showingFeedbacks = [];
this.paragraphs = [];
var p, i, checkFB;
for( i = 0; i < this.inputs.length; i++ ){
this.userAnswers[i] = 0;
this.inputs[i].className = "";
if( this.inputs[i].checked ){
this.userAnswers[i] = 1;
checkFB = this.checkFeedback( i );
if( checkFB.complete ){
p = document.createElement( "p" );
p.innerHTML += this.letters[i] + ". ";
p.innerHTML += this.questionsFeedback[i];
this.fbPart.appendChild( p );
this.showingFeedbacks.push( this.questionsFeedback[i] );
this.paragraphs.push( p );
}
else if( this.questionsFeedback.length ){
var text = this.paragraphs[ checkFB.index].innerHTML;
var dotPosition = text.indexOf( "." );
text = text.substring( 0, dotPosition ) +
", " + this.letters[i] + text.substr( dotPosition );
this.paragraphs[ checkFB.index].innerHTML = text;
}
this.inputs[i].className = this.correctAnswers[i] ? "correct" : "incorrect";
}
}
if( this.fbPart.innerHTML == "" ){
this.fbPart.innerHTML = "Try again."
}
};
ReviewSlide.prototype.checkFeedback = function( index ){
var questionsFeedback = this.questionsFeedback.slice();
var fb = questionsFeedback.splice( index, 1 )[0];
for( var i = 0; i < this.showingFeedbacks.length; i++ ){
if( this.showingFeedbacks[i] == fb ){
return { index: i, complete: false };
}
}
return { complete: true };
};
ReviewSlide.prototype.checkAnswer = function(){
if( this.correctAnswers.length !== this.userAnswers.length ){
throw new Error( "Arrays must have equals length" );
}
var i, end = true;
for( i = 0; i < this.correctAnswers.length; i++ ){
if( this.correctAnswers[i] !== this.userAnswers[i] ){
end = false;
return;
}
}
this.finishSlide();
};
ReviewSlide.prototype.showSlide = function( section ){
//if( !this.section_completed ){
// section.all_question_sequences_completed = false;
// section.all_questions_answered = false;
//}
};
ReviewSlide.prototype.finishSlide = function(){
this.section.points_earned = this.section.points_possible;
this.section.section_completed = true;
player.activity.grade_activity();
player.update_section_status();
player.update_navigation();
};
window.mheAdditionalActivities = window.mheAdditionalActivities || {};
window.mheAdditionalActivities["multiple_choice"] = {
initialize: function( section ){
section.slide = new ReviewSlide( section );
},
show: function( section ){
section.slide.showSlide( section );
}
}
})();
// video
(function(){
var firstTime = true;
function ReviewSlide( section ){
this.section = section;
this.section.points_possible = 1;
this.section.points_earned = 0;
this.section.section_completed = false;
}
ReviewSlide.prototype.showSlide = function( section ){
if ( firstTime ) {
firstTime = false;
var self = this;
var fidureId = section.jq.find( '[data-type="figure"]' ).data( 'figure-id' );
setTimeout( function() {
var videoPlayer = brightcove.api.getExperience( fidureId );
var playerModule = videoPlayer.getModule( brightcove.api.modules.APIModules.VIDEO_PLAYER );
playerModule.addEventListener( brightcove.api.events.MediaEvent.COMPLETE, function() {
self.finishSlide();
});
}, 3000 );
}
};
ReviewSlide.prototype.finishSlide = function(){
this.section.points_earned = this.section.points_possible;
this.section.section_completed = true;
player.activity.grade_activity();
player.update_section_status();
player.update_navigation();
};
window.mheAdditionalActivities = window.mheAdditionalActivities || {};
window.mheAdditionalActivities["video_activity"] = {
initialize: function( section ){
section.slide = new ReviewSlide( section );
},
show: function( section ){
section.slide.showSlide( section );
}
}
})();
// multiple-choice
(function(){
var firstTime = true;
var video = false;
var mc = false;
function ReviewSlide( section ){
this.section = section;
this.section.points_possible = 1;
this.section.points_earned = 0;
this.section.section_completed = false;
this.trows = section.jq[0].querySelectorAll( "table tbody tr" );
this.container = section.jq[0].querySelector( ".multiple_choice" );
this.questionsFeedback = [];
this.correctAnswers = [];
this.inputs = [];
this.userAnswers = [];
this.letters = [ "A", "B", "C", "D", "E", "F", "G", "H", "K" ];
this.generateHTML();
}
ReviewSlide.prototype.generateHTML = function(){
var td, newtd, input, fb, text;
for( var i = 0; i < this.trows.length; i++ ){
td = this.trows[i].querySelector( "td" );
newtd = document.createElement( "td" );
input = document.createElement( "input" );
input.setAttribute( "type", "checkbox" );
newtd.appendChild( input );
this.trows[i].insertBefore( newtd, td );
text = td.innerHTML;
fb = text.slice( text.indexOf( "{" ) + 1, -1 );
td.innerHTML = ( text.indexOf( "*" ) == -1 ) ?
text.slice( 0, text.indexOf( "{" ) ) :
text.slice( 1, text.indexOf( "{" ) );
this.correctAnswers.push( text.indexOf( "*" ) + 1 );
this.questionsFeedback.push( fb );
this.inputs.push( input );
}
var btnContainer = document.createElement( "div" );
var submitBtn = document.createElement( "input" );
btnContainer.className = "question_action_div";
submitBtn.className = "standard_button question_submit_button ui-button ui-widget ui-state-default ui-corner-all";
submitBtn.setAttribute( "type", "button" );
submitBtn.setAttribute( "value", "Submit" );
submitBtn.setAttribute( "role", "button" );
submitBtn.setAttribute( "aria-disabled", "false" );
btnContainer.appendChild( submitBtn );
var fbHead = document.createElement( "div" );
fbHead.className = "question_feedback_head";
fbHead.innerHTML = "Feedback";
this.fbPart = document.createElement( "div" );
this.fbPart.className = "question_feedback_part";
this.fbContainer = document.createElement( "div" );
this.fbContainer.className = "question_feedback";
this.fbContainer.style.display = "none";
this.fbContainer.appendChild( fbHead );
this.fbContainer.appendChild( this.fbPart );
this.container.appendChild( this.fbContainer );
this.container.appendChild( btnContainer );
var self = this;
submitBtn.addEventListener( "click", function(){
self.setFeedback();
self.checkAnswer();
});
};
ReviewSlide.prototype.setFeedback = function(){
this.fbContainer.style.display = "block";
this.fbPart.innerHTML = "";
this.userAnswers = [];
this.showingFeedbacks = [];
this.paragraphs = [];
var p, i, checkFB;
for( i = 0; i < this.inputs.length; i++ ){
this.userAnswers[i] = 0;
this.inputs[i].className = "";
if( this.inputs[i].checked ){
this.userAnswers[i] = 1;
checkFB = this.checkFeedback( i );
if( checkFB.complete ){
p = document.createElement( "p" );
p.innerHTML += this.letters[i] + ". ";
p.innerHTML += this.questionsFeedback[i];
this.fbPart.appendChild( p );
this.showingFeedbacks.push( this.questionsFeedback[i] );
this.paragraphs.push( p );
}
else if( this.questionsFeedback.length ){
var text = this.paragraphs[ checkFB.index].innerHTML;
var dotPosition = text.indexOf( "." );
text = text.substring( 0, dotPosition ) +
", " + this.letters[i] + text.substr( dotPosition );
this.paragraphs[ checkFB.index].innerHTML = text;
}
this.inputs[i].className = this.correctAnswers[i] ? "correct" : "incorrect";
}
}
if( this.fbPart.innerHTML == "" ){
this.fbPart.innerHTML = "Try again."
}
};
ReviewSlide.prototype.checkFeedback = function( index ){
var questionsFeedback = this.questionsFeedback.slice();
var fb = questionsFeedback.splice( index, 1 )[0];
for( var i = 0; i < this.showingFeedbacks.length; i++ ){
if( this.showingFeedbacks[i] == fb ){
return { index: i, complete: false };
}
}
return { complete: true };
};
ReviewSlide.prototype.checkAnswer = function(){
if( this.correctAnswers.length !== this.userAnswers.length ){
throw new Error( "Arrays must have equals length" );
}
var i, end = true;
for( i = 0; i < this.correctAnswers.length; i++ ){
if( this.correctAnswers[i] !== this.userAnswers[i] ){
end = false;
return;
}
}
mc = true;
this.finishSlide();
};
ReviewSlide.prototype.showSlide = function( section ){
if ( firstTime ) {
firstTime = false;
var self = this;
var fidureId = section.jq.find( '[data-type="figure"]' ).data( 'figure-id' );
setTimeout( function() {
var videoPlayer = brightcove.api.getExperience( fidureId );
var playerModule = videoPlayer.getModule( brightcove.api.modules.APIModules.VIDEO_PLAYER );
playerModule.addEventListener( brightcove.api.events.MediaEvent.COMPLETE, function() {
video = true;
self.finishSlide();
} );
}, 3000 );
}
};
ReviewSlide.prototype.finishSlide = function(){
if( video && mc ) {
this.section.points_earned = this.section.points_possible;
this.section.section_completed = true;
player.activity.grade_activity();
player.update_section_status();
player.update_navigation();
}
};
window.mheAdditionalActivities = window.mheAdditionalActivities || {};
window.mheAdditionalActivities["multiple_choice-video_activity"] = {
initialize: function( section ){
section.slide = new ReviewSlide( section );
},
show: function( section ){
section.slide.showSlide( section );
}
}
})();