var Activity_manuscript = Activity.extend({
get_question_number: function(q) {
// always use q.index here
return q.index;
},
submit_question: function(question_index) {
this._super(question_index);
// if we're on the last page and user has answered all queries, show completion message
if (player.showing_last_section() && player.activity.answered_all_queries) {
player.show_completion_message();
}
},
show_grade_saved_message: function() {
this._super();
// if activity is complete, show the completion div
// (in addition to doing an alert, which super does)
if (player.activity.answered_all_queries) {
player.user_has_received_completion_alert = true;
$("#grade_submitted_message").show();
}
}
});
var Player_manuscript = Player.extend({
tab_jq: null,
// have to overwrite and simplify show_section here compared to player.js,
// to use jquery ui's standard tab functions.
show_section: function(section_to_show) {
if (section_to_show == "previous") {
section_to_show = this.section_currently_showing - 1;
} else if (section_to_show == "next") {
section_to_show = this.section_currently_showing + 1;
}
if (section_to_show == null || isNaN(section_to_show) || section_to_show < 0 || section_to_show >= this.sections.length) {
return;
}
// callling jquery ui's tabs() here will call tab_selected below,
// which will take care of calling update_section_status and updating
// the navigation (in this case, showing the right tab).
player.tab_jq.tabs( "select" , section_to_show );
// but for some reason tab_selected isn't running properly when we first start,
// so make sure player.section_currently_showing got updated
if (player.section_currently_showing != section_to_show) {
player.section_currently_showing = section_to_show;
// and call update_section_status in this case too
player.update_section_status();
}
// process iframes for the section, unless all were preloaded
if (player.md.preload_all_iframes != "true") {
this.figures.process_iframes(this.get_current_section().jq); // iframes
}
},
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_navigation: function() {
// this._super(); return;
var html = "
"
+ "
" + this.md.activity_type_title + "
"
+"
"
;
for (var i = 0; i < this.sections.length; ++i) {
var s = this.sections[i];
html += "
"
;
// also insert a "next" button at the bottom of each section, unless it's the last one
if (i < this.sections.length - 1) {
s.jq.append("
");
}
}
html += "
";
$("[data-type=chapter]").prepend(html).tabs({
select: player.tab_selected
, fx: { opacity: 'toggle', duration:100 }
});
$('.next_button').button({
icons: {
secondary: "ui-icon-circle-triangle-e"
}
});
player.tab_jq = $("[data-type=chapter]");
},
update_navigation: function() {
if (this.showing_last_section() && player.activity.answered_all_queries) {
player.show_completion_message();
}
},
show_completion_message: function() {
// player.activity.grade_activity will always have been called before this fn
// so we'll have access to the properly-calculated activity properties below
var html = "You've completed this activity."
+ "
"
;
// section should have a block_type=activity_report paragraph to receive this info
$("[data-block_type=activity_report]").html(html).show();
// show the grade submitted message if user_has_received_completion_alert is true
if (player.user_has_received_completion_alert == true) {
$("#grade_submitted_message").show();
}
},
extract_activity_metadata: function() {
this._super();
this.required_metadata_val("activity_type_title", "Activity Type Title");
// by default we do not require students to go through tabs in order,
// but we do restore them to the tab they were last on when they return to the activity
this.required_metadata_val("sequenced_sections", "false");
this.required_metadata_val("restore_last_viewed_section", "true");
// if an activity sets sequenced_sections to true, set an appropriate message
this.required_metadata_val("section_sequence_message", "You must read each tab, and complete any questions on the tab, in sequence.");
},
initialize: function() {
// extract metadata
this.extract_activity_metadata();
// hide section numbers, but show the titles -- except for the first one (introduction)
$("h2").each(function(index, element) {
if (index == 0) return;
$(this).find("[data-type=number]").hide();
$(this).show();
});
// also get rid of chapter numbers in question numbers
$("h3").each(function(index, element) {
var html = $(this).html();
html = html.replace(/^Question/, "");
html = html.replace(/\d+\.(\d+)/, "$1.");
$(this).html(html);
});
this._super();
// after we call this.super, re-initialize the activity to the custom
// activity type for this manuscript
this.activity = new Activity_manuscript();
},
initialize2: function() {
this._super();
},
init: function() {
this._super();
}
});
player = new Player_manuscript();