var Figures_manuscript = Figures.extend({
// enable the quiz button once the animation is done.
media_player_done: function(id) {
player.quiz_enabled = true;
player.start_quiz();
}
});
var Activity_manuscript = Activity.extend({
current_question: null,
get_question_number: function(q) {
// always use q.index here
return q.index;
},
show_first_question: function() {
if (this.current_question == null) {
this.current_question = 1;
} else {
++this.current_question;
}
player.position_questions_dialog();
$(".questions_dialog").find("[data-type=question]").first().show();
},
show_next_question: function(question) {
// all questions should be in a sequence; error if otherwise
if (question.question_sequence == null) {
alert("Error in activity: question not in sequence");
return;
}
// hide current question
question.jq.hide();
// now show next question in sequence, or complete sequence
var qs = question.question_sequence;
var next_qs_index = question.question_sequence_index + 1;
var next_question = qs.questions[next_qs_index];
if (next_question != null) {
++this.current_question;
next_question.jq.show();
player.position_questions_dialog();
} else {
// move dialog to top-right
player.position_questions_dialog(0,0);
var jq = $(".questions_dialog");
jq.find("[data-type=question]").addClass("question_in_review_mode").show();
// if showing second-to-last section, quiz is done
if (player.section_currently_showing == player.sections.length - 2) {
var html = "
"
+ "Total Activity Score: " + player.activity.total_points_earned
+ " out of " + player.activity.total_points_possible
+ " points (" + player.activity.grade_percent + "%)"
+ "
"
+ UI_Elements.get_button_html({
label: "Show Full Animation"
, extra_class: "next_button"
, fn: 'player.show_section("next")'
});
;
jq.find("[data-block_type=question_sequence]").append(html);
$('.next_button').button({icons: {secondary: "ui-icon-circle-triangle-e"}});
// otherwise show button to move on to next section
} else {
var html = UI_Elements.get_button_html({
label: player.md.next_part_button_label
, extra_class: "next_button"
, fn: 'player.show_section("next")'
});
jq.find("[data-block_type=question_sequence]").append(html);
$('.next_button').button({icons: {secondary: "ui-icon-circle-triangle-e"}});
}
}
}
});
var Player_manuscript = Player.extend({
activity_title: null,
// this will be set to true when the user is allowed to take the quiz
quiz_enabled: false,
// this will be set to true when the quiz starts, so it can't be restarted
quiz_started: false,
show_section_animate: function(section_to_show, direction) {
// hide currently showing section
if (this.section_currently_showing != null) {
this.get_current_section_jq().hide();
}
this.section_currently_showing = section_to_show;
// Remove existing questions if there
$(".questions_dialog").remove();
// show next section
var jq = this.get_current_section_jq();
// if the section doesn't have questions...
if (jq.find("[data-block_type=question_sequence]").length == 0) {
jq.find(".start_quiz_link").hide();
jq.find(".activity_instructions").html("Here you can view the entire animation.");
}
jq.show();
// if this isn't the first section, auto-play the animation
if (this.section_currently_showing > 0) {
var id = jq.find("object").attr("id");
safe_log("found " + id);
jwplayer(id).play();
}
this.quiz_started = false;
},
// no navigation to show, since we only have one section per activity
show_navigation: function() {
var html = "";
// Show activity type and title, unless activity data says to hide it
html += "";
if (this.md.activity_type_title != null) {
html += "
" + this.md.activity_type_title + "
";
}
html += this.activity_title
+ "
"
;
// insert this at the top of the manuscript
$("#manuscript").prepend(html);
// Instructions for starting the quiz
html = ""
+ this.md.activity_instructions
+ "
"
;
// insert this before figure blocks
$("[data-type=figure]").before(html);
// button for starting the quiz -- at the start of each figure block
html = ""
+ UI_Elements.get_button_html({
id: "start_quiz_button"
, label: this.md.quiz_start_button_label
, fn: "player.start_quiz()"
})
+ "
"
$("[data-type=figure]").prepend(html);
UI_Elements.activate_buttons();
},
start_quiz: function() {
// if the quiz is not yet enabled...
if (!this.quiz_enabled) {
// if user has instructor-level access, tell them students won't see it
// but let them through
if (player.activity.is_instructor() == true) {
alert("Please note: Students will not be able to view these questions until they have completed the activity. Instructors, however, can view the questions at any time.");
// otherwise don't let them start the quiz!
} else {
alert(this.md.quiz_premature_warning);
return;
}
}
// hide the "show quiz" link
var jq = this.get_current_section_jq();
jq.find(".start_quiz_link").hide();
// hide the movie player and show the static image for the figure
jq.find(".qimg").show();
jq.find("object").hide();
if (this.quiz_started) {
$(".questions_dialog").show();
return;
}
// show questions in a dialog
safe_log(jq.find("[data-block_type=question_sequence]").length);
jq.find("[data-block_type=question_sequence]").dialog({dialogClass:"questions_dialog", title:"Questions", width:450, position:['right','top'], close: player.questions_dialog_closed});
// reveal first question
this.activity.show_first_question();
this.quiz_started = true;
},
position_questions_dialog: function(right, top) {
if (right == null) {
var q = player.activity.questions[player.activity.current_question];
if (q.md.position != null) {
var arr = q.md.position.split(",");
right = $.trim(arr[0]) * 1;
top = $.trim(arr[1]) * 1;
} else {
right = top = 0;
}
}
var jq = $(".questions_dialog");
if (right < 0) {
jq.css("left", right * -1);
} else {
jq.css("right", right);
}
if (top < 0) {
jq.css("bottom", top * -1);
} else {
jq.css("top", top);
}
},
// if user closes the questions dialog, re-show the "show quiz" button
questions_dialog_closed: function() {
var jq = player.get_current_section_jq();
jq.find(".qimg").hide();
jq.find("object").show();
jq.find(".start_quiz_link").show();
},
extract_activity_metadata: function() {
this._super();
// optional metadata val: activity_type_title
this.required_metadata_val("enable_quiz_time", 30);
this.required_metadata_val("activity_instructions", "After you've completed the activity, click the button below to answer questions about what you've learned.");
this.required_metadata_val("quiz_title", "Activity Comprehension Quiz");
this.required_metadata_val("quiz_start_button_label", "Begin the " + this.md.quiz_title);
this.required_metadata_val("next_part_button_label", "Next");
this.required_metadata_val("quiz_premature_warning", "You must complete the activity before you can take the " + this.md.quiz_title + ".");
// if enable_quiz_time is > 2000, it's almost certainly specified in milliseconds, so convert to seconds
if (this.md.enable_quiz_time > 2000) {
this.md.enable_quiz_time = Math.round(this.md.enable_quiz_time / 1000);
}
},
initialize: function() {
// extract metadata
this.extract_activity_metadata();
// activity title is data-type="title" inside h1
this.activity_title = $("h1").find("[data-type=title]").html();
// before we process movies, extract "qsrc" attributes
$("[data-attr]").each(function(index, element) {
var jq = $(element);
var attr = jq.attr("data-attr");
if (attr.search(/qsrc=(\S*)/) > -1) {
safe_log("found " + RegExp.$1);
// TODO: clean this up -- e.g. set width and height
var html = "";
jq.parent().append(html);
}
});
this._super();
// first call this.super, then re-initialize the activity to the custom
// activity type for this manuscript
this.activity = new Activity_manuscript();
// also figures
this.figures = new Figures_manuscript();
// start a timer that determines when the user is allowed to take the quiz
// setTimeout("player.enable_quiz()", (this.md.enable_quiz_time * 1000));
},
initialize2: function() {
this._super();
$("#manuscript").show();
},
init: function() {
this._super();
}
});
player = new Player_manuscript();