var Activity_manuscript_type = Activity.extend({
current_question: null,
get_question_number: function(q) {
// always use q.index here
return q.index;
},
show_next_question: function() {
if (this.current_question == null) {
this.current_question = 1;
} else {
this.questions[this.current_question].jq.hide();
++this.current_question;
}
if (this.current_question >= this.questions.length) {
this.complete_quiz();
return;
}
this.questions[this.current_question].jq.show();
window.scrollTo(0,2000);
},
submit_question: function(question_index) {
this._super(question_index);
},
complete_quiz: function() {
// show questions
for (var i = 1; i < this.questions.length; ++i) {
this.questions[i].jq.show();
}
var html = "
"
+ "Total Score: " + player.activity.total_points_earned
+ " out of " + player.activity.total_points_possible
+ " points (" + player.activity.grade_percent + "%)"
+ "
"
;
$("[data-block_type=questions]").append(html);
// scroll to bottom of screen
window.scroll(0, 1000);
}
});
var Player_manuscript_type = 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,
// metadata
md: new Object(),
// This shouldn't be necessary at all, since we only have one section per activity
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;
this.get_current_section_jq().show(300);
// scroll to top
window.scrollTo(0,0);
},
// 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 before the first figure block
$("[data-type=figure]").first().before(html);
// Instructions for starting the quiz
if (this.md.activity_instructions != null) {
html = ""
+ this.md.activity_instructions
+ "
"
;
// insert this before the first figure block
$("[data-type=figure]").first().before(html);
}
// button for starting the quiz -- after the 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]").first().after(html);
UI_Elements.activate_buttons();
// Show title for questions at start of questions block
html = "";
$("[data-block_type=questions]").prepend(html);
},
enable_quiz: function() {
this.quiz_enabled = true;
},
start_quiz: function() {
if (this.quiz_started) {
return;
}
// 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;
}
}
$("#activity_instructions").hide();
$("#start_quiz_link").hide();
$("[data-block_type=questions]").show();
this.activity.show_next_question();
this.quiz_started = true;
},
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("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();
this._super();
// first call this.super, then re-initialize the activity to the custom
// activity type for this manuscript
this.activity = new Activity_manuscript_type();
// 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_type();