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;
}
//force all queries to be answered before doing anything.
var allQueriesAnswered = true;
for (var i = 0; i < player.activity.questions[question_index].queries.length; i++) {
var x = player.activity.questions[question_index].queries[i].user_has_answered();
if (!x) {
allQueriesAnswered = false;
}
}
if (!allQueriesAnswered) {
$("
Please answer the question before submitting.
").dialog({
buttons: [{
text: "OK",
click: function () {
$(this).dialog("close");
}
}]
});
//alert("answer all questions!");
return false;
}
this._super(question_index);
MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
},
show_next_question: function (question) {
// if the item is in a sequence, show the next question
if (question.question_sequence != null) {
var qs = question.question_sequence;
var next_qs_index = question.question_sequence_index + 1;
var next_question = qs.questions[next_qs_index];
// what we do next is a little different
// depending on whether this is a one-at-a-time sequence
if (qs.one_at_a_time === false) {
// for *not* one at a time, just slide down the next item
if (next_question != null) {
/*
next_question.jq.slideDown("fast", function () {
// when we're done showing the new question, scroll down to it
$(window).scrollTo($(this));
});
*/
question.jq.before(next_question.jq.show());
$(window).scrollTo(next_question.jq);
// update the sequence navigator
var index = e.data.next_question.question_sequence_index + 1;
var qs = e.data.question.question_sequence.index;
$("#question_sequence_index_" + qs).html(index);
// if there is no next_question, sequence is complete.
} else {
qs.sequence_complete = "complete";
}
// for one-at-a-time, ...
} else {
// if we have a next question, change the question submit button
// to a button for showing the next item
if (next_question != null) {
$("#question_submit_button_" + question.index).val("Next Question")
.unbind('click')
.click({ "question": question, "next_question": next_question }, function (e) {
// on click of this button, hide the current question and fade in the next one
//e.data.question.jq.hide();
// use the below animation instead of fadeIn because it doesn't completely hide the item first
// and thus doesn't cause the window to scroll to the top.
e.data.question.jq.before(e.data.next_question.jq.show());
//e.data.next_question.jq.show()
//.css({ opacity: 0.25 })
//.animate({ opacity: 1.0 }, 500);
//$.scroll_item_onto_screen(e.data.next_question.jq, { duration: 10, additional_padding: 50 });
// update the sequence navigator
e.data.next_question.jq[0].scrollIntoView();
var index = e.data.next_question.question_sequence_index + 1;
var qs = e.data.question.question_sequence.index;
$("#question_sequence_index_" + qs).html(index);
})
.show();
// make sure the button is visible
$.scroll_item_onto_screen($("#question_submit_button_" + question.index), { duration: 10, additional_padding: 50 });
// else we're done with the sequence, so if sequence_complete is false...
} else if (qs.sequence_complete === false) {
var points_possible = 0;
var points_awarded = 0;
for (var i = 0; i < qs.questions.length; ++i) {
for (var j = 0; j < qs.questions[i].queries.length; ++j) {
var query = qs.questions[i].queries[j];
points_awarded += query.getPointsAwarded();
points_possible += query.getPointsPossible();
}
}
// round to at most two decimal places
points_awarded = Math.round(points_awarded * 100) / 100;
points_possible = Math.round(points_possible * 100) / 100;
var html = "
"
+ "Total points awarded for this question sequence: " + points_awarded + " out of " + points_possible + " "
+ "
"
;
safe_log(qs.closing_material);
if (qs.closing_material != null) {
// if student is reviewing (i.e. came back to the activity after completing in an earlier
// session), the show_closing_material function will be called by restore_saved_answers
var show_summary_text = "Show Summary"
html += ""
// if there's closing material we're *kind of* done with the sequence now;
// set to "partial" so we won't add this html again
qs.sequence_complete = "partial";
// if there's no closing material, we're completely through with the sequence now.
} else {
qs.sequence_complete = "complete";
// in this case we need to show the question_sequence_review right away
html = html.replace(/class='question_sequence_review'/, "class='question_sequence_review' style='display:none'");
}
qs.inner_jq.append(html);
$("#closing_material_button_" + qs.index).button();
}
}
}
},
add_question_sequence: function (index, element) {
var a = player.activity; // this fn gets called within the scope of a jquery each, so we can't refer to "this"
var index = a.question_sequences.length;
var qs = a.question_sequences[index] = new Object();
var jq = $(element);
jq.attr("question_sequence_index", index);
qs.index = index;
qs.jq = jq;
qs.inner_jq = jq.find("[data-type=box_inner]").first();
qs.questions = new Array();
qs.sequence_complete = false;
// note whether this is a "one-at-a-time" sequence
qs.one_at_a_time = (jq.attr("data-block_type").search("one_at_a_time") > -1);
// if it *is* a one-at-a-time sequence, then ...
if (qs.one_at_a_time === true) {
// anything below the questions is considered "closing material". Wrap this stuff in a div and hide it
var question_found = false;
qs.inner_jq.children().each(function (index, element) {
var cjq = $(element);
if (cjq.attr("data-type") == "question") {
question_found = true;
} else if (question_found == true) {
if (jq.closing_material == null) {
var html = "";
qs.inner_jq.append(html);
qs.closing_material = jq.find(".question_sequence_closing_material").first();
}
qs.closing_material.append(cjq.detach());
}
});
}
// also show a navigator for the question sequence
var html = "
"
+ "Question "
+ "1"
+ " of "
+ "?"
+ "
"
;
qs.inner_jq.prepend(html);
},
add_question: function (index, element) {
var a = player.activity; // this fn gets called within the scope of a jquery each, so we can't refer to "this"
var jq = $(element);
// see if we're in a question_pool or question_sequence block
var qs_parent = jq.parents("[data-block_type=question_sequence], [data-block_type=question_sequence_one_at_a_time]");
var q = a.questions[a.questions.length] = new Question({
"index": a.questions.length
, "number": jQuery.trim($("[data-type='number']", jq).html())
, "title": jQuery.trim($("[data-type='title']", jq).html())
, "jq": jq
, "points_possible": 0
});
// store the question index in the DOM too
jq.attr("data-question_index", q.index);
// get question queries
a.question_being_initialized = q;
$("[data-type='query']", jq).each(a.add_query);
// if the question has queries, add bling to the bottom
if (q.queries.length > 0) {
var html = "
";
var submit_handler;
// add a submit button if we're supposed to have one
// (image map and matching questions, which should contain one and only one query, don't have submit buttons)
if (q.queries[0].hasSubmitButton === true) {
// "answer_one" pool mode (yet to be fully implemented...)
if (q.pool_mode == 'answer_one') {
html += "";
submit_handler = player.activity.Show_Submit;
} else {
html += a.question_submit_button(q);
submit_handler = player.activity.submit_question;
}
}
// add a "give up" button if we're supposed to have one
// (image map questions, which should contain one and only one query, should have this button)
if (q.queries[0].hasGiveUpButton === true) {
html += "";
submit_handler = player.activity.give_up_question;
}
html += "
";
jq.append(html);
jq.prepend("
Question " + q.index + " of
");
// bind the submit_handler function to the button, passing in the question_index
$("#question_submit_button_" + q.index).click({ question_index: q.index }, submit_handler);
// float instructor controls to right of action button
jq.prepend(a.instructor_question_controls(q));
// also, determine question points and weight at this time
for (var i = 0; i < q.queries.length; ++i) {
q.points_possible += q.queries[i].getPointsPossible();
}
// round to two decimal places, in case there are decimals
q.points_possible = Math.round(q.points_possible * 100) / 100;
}
// now that the question has been created, deal with sequences and pools
if (qs_parent.length > 0) {
// get sequence index and item
var qs_index = qs_parent.attr("question_sequence_index") * 1;
var qs = a.question_sequences[qs_index];
// place in sequence
var sequence_num = qs.questions.length;
qs.questions[sequence_num] = q;
// place reference to sequence in question
q.question_sequence = qs;
q.question_sequence_index = sequence_num;
// if this isn't #1, hide the question
if (sequence_num > 0) {
jq.hide();
}
// update the sequence navigator if it's there
$("#question_sequence_max_index_" + qs.index).html(sequence_num + 1);
$(".numQuestions").html(sequence_num + 1);
}
},
});
var Player_manuscript_type = Player.extend({
initialize_review_button: function () {
$("[data-block_type=final_figure]").each(function (index, element) {
var id = $(element).attr("id");
var buttonHtml = UI_Elements.get_button_html({ label: "View Completed Equation", fn: 'player.show_review("' + id + '");', extra_class: "final_figure_button" });
$(element).before(buttonHtml);
UI_Elements.activate_buttons();
});
},
show_primer: function (id) {
var primer_section = "From the " + $("#" + id).find("[data-block_type=primer_section_name]").find("p").html() + " primer";
$("#" + id).dialog({
dialogClass: "primer",
height: "500",
title: primer_section,
position: { my: "left", at: "center" },
buttons: [
{
text: "Close",
click: function () { $(this).dialog("close"); }
}
]
});
},
show_key_terms: function (id) {
$("#" + id).dialog({
dialogClass: "key_terms",
height: "auto",
title: "Key Terms",
position: { my: "left", at: "center" },
buttons: [
{
text: "Close",
click: function () { $(this).dialog("close"); }
}
]
});
},
initialize: function () {
this._super();
this.activity = new Activity_manuscript_type();
jQuery.getScript("http://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML", function () {
//optional code to execute after mathjax library has been loaded can go here
});
$("[data-block_type=key_terms]").each(function (index, element) {
var title = "Key Terms";
var id = $(element).attr("id");
var buttonHTML = "";
$(element).before(buttonHTML);
$("#button_for_" + id).button();
});
$("[data-block_type=primer]").each(function (index, element) {
var title = "Primer Section";
var id = $(element).attr("id");
var buttonHTML = "";
$(element).before(buttonHTML);
$("#button_for_" + id).button();
});
}
});
player = new Player_manuscript_type();
MC_Query = MC_Query.extend({
user_has_answered: function () {
if (typeof $('input:radio[name=query_answer_' + this.query_index + ']:checked').val() != "undefined") {
return true;
} else {
return false;
}
}
});