//jquery UI stubs to prevent errors
jQuery.fn.extend({
button: function(){},
dialog: function(){}
});
//global helper functions
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
Standard_Dialog.alert = function(message){
$("
Notice:
" + message + "
").modal("show");
}
//dom manipulations for Bootstrap styling
$(document).ready(function(){
$("[data-type=chapter]").addClass("container");
$("[data-block_type=row]").addClass("row");
});
$("[data-block_type=instructions]").addClass("bs-callout bs-callout-info");
$("[data-block_type=row]").each(function(index, element){
$(element).find("[data-type=box]").each(function(index, boxElement){
var block_type = $(boxElement).attr("data-block_type");
if(block_type.indexOf("col") == 0){
//its a special column box and we need to set the bootstrap class
$(boxElement).addClass(block_type);
}
});
});
$("[data-type=question]").addClass("form-group")
;
var Activity_gore = Activity_manuscript_type.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 all questions
Please answer all of the questions before submitting.
").modal("show");
//alert("answer all questions!");
return false;
}
this._super(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;
}
//loop through the queries in the question
function getIndexFromMeasureKey(key){
for (var i = 0; i= 0) {
// if resubmissions are allowed...
if (player.md.allow_resubmission == "true") {
// if due date has not passed, give the student the option of resubmitting or reviewing
if (!due_date_passed) {
msg = "
You have completed this activity, and your grade (" + grade + "%) has been submitted. Would you like to:
"
+ "
Keep your current grade and review your previous answers
"
+ "
Or reset your submission and try the activity again?
You have completed this activity, and your grade (" + grade + "%) has been submitted. Since the due date for the activity has now passed, you cannot re-submit answers to the activity questions.
"
buttons = [ {text:"OK", click: player.activity.ARGA_initialization_final} ];
}
// resubmissions are not allowed
} else {
//msg = "
You have completed this activity, and your grade (" + grade + "%) has been submitted.
"
// ;
//buttons = [ {text:"OK", click: player.activity.ARGA_initialization_final} ];
player.activity.ARGA_initialization_final();
}
// grade has not been submitted
} else {
// if due date has passed, tell the user "tough luck". Otherwise show nothing.
if (due_date_passed) {
msg = "
The due date for this activity has passed. You can still review the activity, but no answers will be submitted and no grade will be recorded.
"
;
buttons = [ {text:"OK", click: player.activity.ARGA_initialization_final} ];
}
}
// if we need a message, show it in a jquery UI dialog
if (msg != "") {
msg = "
" + msg + "
";
$("body").append(msg);
$("#arga_init_dialog").dialog({title:"Please Note", width:450, modal:true, buttons: buttons});
} else {
player.activity.ARGA_initialization_final();
}
}
});
var Player_gore = Player_manuscript_type.extend({
/*
measure_names:[
{key:"critical_thinking",value: "Critical Thinking/Goal Setting"},
{key:"motivation", value:"Motivation/Personal Responsibility"},
{key:"learning_preferences", value:"Learning Preferences"},
{key:"time_management", value:"Time Management"},
{key:"reading", value:"Reading"},
{key:"note_taking", value:"Note Taking"},
{key:"memory", value:"Memory/Studying"},
{key:"exam_performance", value:"Performing on Exams"},
{key:"information", value:"Finding and Communicating Information"},
{key:"interpersonal_skills", value:"Interpersonal Skills"},
{key:"health", value:"Personal and Financial Health"},
{key:"planning", value:"Academic and Career Planning"}
],
measure_names:[
{attempts:0,key:"Mechanics and Punctuation",value: "Mechanics and Punctuation", score:0},
{attempts:0,key:"Pronouns", value:"Pronouns", score:0},
{attempts:0,key:"Verbs", value:"Verbs", score:0},
{attempts:0,key:"Modifiers", value:"Modifiers", score:0},
{attempts:0,key:"Sentence Structure", value:"Sentence Structure", score:0},
{attempts:0,key:"Subject-Verb Agreement", value:"Subject-Verb Agreement", score:0},
{attempts:0,key:"Multilingual Writers", value:"Multilingual Writers", score:0},
{attempts:0,key:"Wrong Word", value:"Wrong Word", score:0},
{attempts:0,key:"Hyphens", value:"Hyphens", score:0}
],
*/
isInstructor: false,
questions:[],
measure_names:[],
class_data:{},
class_average_data:{},
student_review_questions: function(){
player.show_section(1);
},
get_section_by_title: function(title){
for (var i = 0; i < player.sections.length; i++){
if(player.sections[i].title == title){
return player.sections[i];
}
}
},
instructor_report_data_is_initialized: false,
initialize_instructor_report_data: function(){
//first order of business is to calculate the overall scores for each student
//while we're at it, tally up for class totals too.
player.class_data["Total"] = {name:"Entire Class", scores:{}};
//we'll populate the topic dropdown too...
var topic_dropdown = $("#class_data_topic_dropdown");
for (var i = 0; i < player.measure_names.length; i++){
player.class_data["Total"].scores[player.measure_names[i].key] = {attempts:0, score:0};
topic_dropdown.append("");
}
player.class_data["Total"].scores["Total"] = {attempts:0, score:0};
var student_dropdown = $("#class_data_student_dropdown");
for (var key in player.class_data){ // loop over each student
if (player.class_data.hasOwnProperty(key)) {
//add to the dropdown
if (key !== "Total"){
student_dropdown.append("");
var student = player.class_data[key];
var totalCorrect = 0;
var totalAttempted = 0;
for(var scale in student.scores){
if (student.scores.hasOwnProperty(scale)){
totalCorrect = totalCorrect + student.scores[scale].score;
totalAttempted = totalAttempted + student.scores[scale].attempts;
player.class_data["Total"].scores[scale].attempts += student.scores[scale].attempts;
player.class_data["Total"].scores[scale].score += student.scores[scale].score;
// player.class_average_data[scale].attempts += student.scores[scale].attempts;
// player.class_average_data[scale].score += student.scores[scale].score;
}
}
student.scores["Total"] = {attempts: totalAttempted, score: totalCorrect};
player.class_data["Total"].scores["Total"].attempts += totalAttempted;
player.class_data["Total"].scores["Total"].score += totalCorrect;
}
}
}
student_dropdown.select2();
player.instructor_report_data_is_initialized = true;
player.current_student_for_report = "Total";
},
generate_instructor_roster_report: function(){
var container_element = $("[data-block_type='class_results_roster']")[0];
$(container_element).empty();
var selectedTopic = player.current_topic;
var rowOrder = [];
var rowCollection = [];
for (var key in player.class_data){ // loop over each student
if (player.class_data.hasOwnProperty(key)) {
var html = "";
var row = {};
var shortName = key;
var longName = key;
row.shortName = shortName;
row.longName = longName;
var scoreObject = player.class_data[key].scores[selectedTopic];
var percentage = "0%";
var numPercentage = 0;
if(scoreObject.attempts > 0){
percentage = (scoreObject.score / scoreObject.attempts * 100).toFixed(0) + "%";
numPercentage = scoreObject.score / scoreObject.attempts;
}
row.percentage = numPercentage;
var details = "(" + scoreObject.score + "/" + scoreObject.attempts + ")";
var encodedName = encodeURIComponent(longName);
html+="
";
$(container_element).append(rowHTML);
}
//now the text to show
for(var i = 0; i < player.measure_names.length; i++){
}
},
get_section_by_title: function(title){
for (var i = 0; i < player.sections.length; i++){
if(player.sections[i].title == title){
return player.sections[i];
}
}
},
show_question_list: function(){
var s = player.get_section_by_title("Questions");
var target = s.jq.find("[data-block_type=question_list]");
target.empty();
var labels = [];
$("[data-type=question]").each(function (index, element) {
//check the queries in this question and find thier metadata
var question = player.activity.questions[index + 1];
$(element).clone().appendTo(target);
for (var i = 0; i < question.queries.length; i++) {
var label = question.queries[i].md.measure;
labels.push(label);
//indicate correct answer
var correct_index = question.queries[i].correct_answer_index;
$(target).find("[for=query_answer_" + question.queries[i].query_index + "_" + correct_index + "]").addClass("preview_question_correct_choice");
}
});
target.find(".question_list_question").each(function(index, element){
var label = labels[index];
$(element).append("
";
for (var i = 0; i < player.activity.queries.length; i++){
var shortName = player.activity.queries[i].md.measure;
var isReversed = player.activity.queries[i].md.reverse_score == "true";
var longName = "";
for (var j = 0; j";
listHtml+="
";
}
var s = player.get_section_by_title("Questions");
var target = s.jq.find("[data-block_type=question_list]");
target.append(listHtml);
player.show_section(s.index);
},
*/
show_section: function(section_to_show) {
//window.alert(section_to_show);
var direction = "right";
if (section_to_show == "previous") {
section_to_show = this.section_currently_showing - 1;
direction = "left";
} 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;
}
// if user has to view sections in sequence and hasn't gotten up to this one, don't allow it
/*
if (this.md.sequenced_sections == "true" && section_to_show > this.last_available_section) {
// but let instructors through
if (player.activity.is_instructor()) {
Standard_Dialog.alert("Please note: Students need to read and complete each section of the activity before moving on to the next section. Instructors, however, can skip around between sections as they choose.");
} else {
Standard_Dialog.alert(this.md.section_sequence_message);
return;
}
}
*/
this.show_section_animate(section_to_show, direction);
// 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
}
this.update_section_status();
this.update_navigation();
safe_log(player.get_current_section().all_questions_answered);
if (player.get_current_section().all_questions_answered === false){
$("#next_button").hide();
}else{
$("#next_button").show();
}
if(player.get_current_section_jq().find("[data-block_type='individual_student_results']").length > 0){
if(!player.isInstructor){
//show results
player.generate_student_report(player.get_current_section_jq().find("[data-block_type='individual_student_results']")[0]);
$("#next_button").hide();
}
}
if (player.get_current_section_jq().find("[data-block_type='class_results_summary']").length > 0){
if(player.isInstructor){
player.generate_instructor_report(player.get_current_section_jq().find("[data-block_type='class_results_summary']")[0]);
$("#next_button").hide();
}
}
if(player.get_current_section_jq().find("[data-block_type='class_results_roster']").length > 0){
if(player.isInstructor){
$("#next_button").hide();
}
}
//this._super(section_to_show);
//if there are questions in this section, hide the next button
safe_log(player.get_current_section().all_questions_answered);
/*
if (!player.get_current_section().all_questions_answered){
$("#next_button").hide();
}else{
$("#next_button").show();
}
*/
if(player.get_current_section().index + 1 == player.sections.length){
$("#next_button").hide();
}
},
show_section_animate: function(section_to_show, direction) {
this._super(section_to_show, direction);
//if there are questions in this section, hide the next button
window.scrollTo(0,0);
if (typeof window.parent != "undefined"){
window.parent.scrollTo(0,0);
}
},
export_class_csv: function(){
var csv = "Name";
for (var i = 0; i < player.measure_names.length; i++){
csv+= "," + player.measure_names[i].value;
}
for (var key in player.class_data){
if (player.class_data.hasOwnProperty(key)) {
var student = player.class_data[key];
var line = "\"" + student.name + "\"" + ",";
for(var scale in student.scores){
if (student.scores.hasOwnProperty(scale)){
line += ((student.scores[scale].score / student.scores[scale].attempts) * 100).toFixed(2) + ",";
}
}
line = line.substring(0, line.length - 1);
csv+= "\n" + line;
}
}
safe_log(csv);
var form = $("[data-block_type=hidden_form]").find("iframe");
form.contents().find("#data").val(csv);
form.contents().find("#file_name").val("diagnostic_quiz_results.csv");
form.contents().find("#data_form").submit();
},
show_navigation: function() {
/*
var html = "
Home";
// $("[data-type=chapter]").before(html);
// button at the bottom of the manuscript to go on to the next step
var next_button_html = "";
$("[data-type=chapter]").append(next_button_html);
//$("#navbar").collapse({toggle:false});
//$("#navbar_toggle_button").click(function(){
//$("#navbar").collapse("toggle");
//});
},
show_instructor_home: function(){
var s = player.get_section_by_title("Instructor Home");
player.show_section(s.index);
},
make_fake_data: function(){
player.generate_fake_class_data();
for (var i = 0; i < player.measure_names.length; i++){
player.measure_names[i].score = Math.floor(Math.random() * 11);
player.measure_names[i].attempts = 10;
}
//go to results, assume the last section
var s = player.get_section_by_title("Results");
player.show_section(s.index);
},
generate_fake_class_data: function(){
for (var s = 0; s < 200; s++){
for (var i = 0; i < player.measure_names.length; i++){
var student = {};
student.name = "Last, First #" + s;
student.scores = {};
for (var j = 0; j < player.measure_names.length; j++){
student.scores[player.measure_names[j].key] = {score: Math.floor(Math.random() * 11), attempts: 10};
}
player.class_data[student.name] = student;
}
}
},
measure_names_only : ["Total"],
initialize_topics: function(){
var topics = player.md.topics.split(",");
for (var i = 0; i < topics.length; i++){
player.measure_names.push({key: topics[i].trim(), value: topics[i].trim(), score:0, attempts:0});
player.measure_names_only.push(topics[i].trim());
}
},
update_navigation: function() {
// show/hide the "next" button as appropriate
if (this.last_available_section > this.section_currently_showing && this.showing_last_section() == false) {
UI_Elements.toggle_button("step_button", true);
} else {
UI_Elements.toggle_button("step_button", false);
}
if (this.showing_last_section() && player.activity.answered_all_queries) {
player.show_completion_message();
}
},
current_topic:"Total",
initialize: function(id, panel){
// this._super();
//console.log("player.initialize");
this.manuscript_id = id;
//this.initial_displayed_panel = 0;
if(typeof panel !== 'undefined'){
//initial_section_index = panel;
//window.alert(this.initial_displayed_panel);
}
// extract metadata (this might be already done by the activity-specific
// player, but that's OK; we'll just re-do it here, which is no problem.)
this.extract_activity_metadata();
// have to do variables first because that replaces the body html
this.variables = new Variables();
this.figures = new Figures();
this.xrefs = new XRefs();
this.idxrefs = new IdXRefs();
this.links = new Links();
this.activity = new Activity();
this.interactions = new Interactions();
this.tables = new Tables();
this.glossary = new Glossary();
// Prepare for activity functionality by getting ARGA data;
// that fn will call Initialize_ARGA_Session_Callback (see below)
var success = false;
if (window.Initialize_ARGA_Session != null) {
success = Initialize_ARGA_Session({
"fail_silently": (this.md.ARGA_fail_silently != "false"),
"retrieve_class_data": 1,
"retrieve_class_data_rights": "3_instructor",
"cancel_initialization_alert": true
});
}
if (!success) {
this.ARGA_running = false;
safe_log("running in non-ARGA mode");
// We need to initialize the player after a timeout (mimicking what would happen
// if ARGA was initialized and initialize2 was called on a callback) so that
// inherited players will be called in the proper order.
setTimeout("player.initialize2()", 1);
} else {
this.ARGA_running = true;
}
// hide section numbers and titles
$("h2").hide();
// also get rid of chapter numbers in question numbers
$("[data-type=question]").find("h3").each(function(index, element) {
var html = $(this).html();
//html = html.replace(/^Question/, "");
html = html.replace(/\d+\.(\d+)/, "$1.");
$(this).html(html);
});
// activity title is data-type="title" inside h1
this.activity_title = $("h1").find("[data-type=title]").html();
// extract thumbnail
var jq = $('[data-block_type="thumbnail"]');
this.activity_thumbnail_src = jq.find("img").attr("src");
jq.hide();
// assign classes to chapter
$("[data-type='chapter']").addClass("ui-widget-content").addClass("ui-corner-all");
// after we call this.super, re-initialize the activity to the custom
// activity type for this manuscript
this.activity = new Activity_manuscript_type();
this.activity = new Activity_gore();
player.initialize_topics();
//initialize routie routes
routie({
"topic/:topic": function(topic){
player.current_topic = $("#class_data_topic_dropdown").val();
player.generate_instructor_roster_report();
player.show_instructor_roster_report();
}
,
"user/:user": function(user){
player.current_student_for_report = decodeURIComponent(user);
$("#class_data_student_dropdown").val(player.current_student_for_report);
$("#class_data_student_dropdown").select2("val", player.current_student_for_report);
player.generate_instructor_report();
player.show_instructor_class_report();
}
,
"home" : function(){
player.show_instructor_home();
},
"quizHome" : function(){
player.show_section(0);
}
});
//event handlers for results page controls that are added via rawhtml
$("#class_data_sort_order").change(function(){
player.class_results_sort_order= $("#class_data_sort_order").val();
player.generate_instructor_report();
});
$("#roster_data_sort_order").change(function(){
player.roster_data_sort_order = $("#roster_data_sort_order").val();
player.generate_instructor_roster_report();
});
$("#class_data_student_dropdown").change(function(){
player.current_student_for_report = $("#class_data_student_dropdown").val();
player.generate_instructor_report();
});
$("#class_data_topic_dropdown").change(function(){
player.current_topic = $("#class_data_topic_dropdown").val();
player.generate_instructor_roster_report();
});
},
show_instructor_roster_report: function(){
player.generate_instructor_roster_report();
var s = player.get_section_by_title("Class Results");
player.show_section(s.index);
},
get_class_data_from_ARGA: function(){
if(player.ARGA_running){
var scores = Get_ARGA_Data_Class("scores");
var names = Get_ARGA_Data_Class("learner_name");
for (var i = 0; i < scores.length; i++){
if (typeof scores[i] != "undefined"){
var object = {};
object.name = names[i];
object.scores = JSON.parse(scores[i]);
player.class_data[object.name] = object;
}
}
}
},
get_user_data_from_ARGA: function(){
if(player.ARGA_running){
var scoresString = Get_ARGA_Data("scores");
if(scoresString != ""){
var score = JSON.parse(scoresString);
for(var i = 0; i < player.measure_names.length; i++){
var measure = player.measure_names[i].value;
player.measure_names[i].attempts = score[measure].attempts;
player.measure_names[i].score = score[measure].score;
}
player.generate_student_report($("[data-block_type='individual_student_results']")[0]);
}
}
},
show_instructor_class_report: function(){
var s = player.get_section_by_title("Results");
player.show_section(s.index);
},
html_to_print:"",
print_element: function(selector){
var element = $(selector);
player.html_to_print = element.html();
var win = window.open("asset/print_page.html", "printwindow");
//win.document.write(html);
},
add_query_numbers: function(){
if(player.md.add_query_numbers == "true"){
$(".question_number").remove();
$("[data-type=question] h3").hide();
$("[data-type=query]").each(function(index, element){
var number = index + 1;
$(element).prepend("Question " + number + " ");
$(element).addClass("question_list_question");
});
}else{
$("[data-type=query]").each(function(index, element){
$(element).addClass("question_list_question");
});
}
},
initialize2: function(){
this._super();
//check for debug mode
if(getParameterByName("debug") == "true"){
player.generate_fake_class_data();
}
$(".class_data_export").click(function(){
player.export_class_csv();
});
$(".question_submit_button").addClass("btn btn-primary btn-lg");
//this is where we learn whether the user is an instructor or a student
player.isInstructor = false;
if(player.ARGA_running){
if (Get_ARGA_Data("user_rights") == "3_instructor") {
player.isInstructor = true;
}}else{
player.isInstructor = (getParameterByName("isInstructor") == "true");
}
player.get_user_data_from_ARGA();
if(player.isInstructor){
this.get_class_data_from_ARGA();
this.initialize_instructor_report_data();
this.generate_instructor_report();
this.generate_instructor_roster_report();
$(".instructor_results_info").show();
$(".instructor_nav").show();
routie("home");
}
this.add_query_numbers();
}
});
player = new Player_gore();
//to not show the letters for MC choices
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;
}
},
// mode should be "delivery" or "review"; "delivery" is assumed
getHTML: function (mode) {
// initialize imagemap elements
if (this.imagemap_initialized === false) {
var question_jq = this.jq.parent();
this.im_init(question_jq);
this.imagemap_initialized = true;
}
// start with the query text, if there
var html = this.query_text_html();
// wrap answers in a p tag
html += "
";
// Build answer selection
var is_correct = false;
for (var z = 0; z < this.choices.length; z++) {
var index = this.choice_order[z];
// if this is review mode...
var checked = "";
var disabled = "";
var radio_style = "query_mc_other_choice";
if (mode == 'review' || mode == 'review_correct_incorrect' || mode == 'preview') {
// if it's the correct choice, it should be marked in green
if (index == this.correct_answer_index) {
// but only if we're *not* in review_correct_incorrect mode or this is the user's choice
if (mode != 'review_correct_incorrect' || index == this.user_answer_index) {
radio_style = "query_mc_correct_choice";
}
// if this is what the user chose, he got it correct
if (index == this.user_answer_index) {
is_correct = true;
}
// else if it's the user's choice (and this.md.no_correct_answer is not true), it should be marked in red
} else if (index == this.user_answer_index && this.md.no_correct_answer != "true") {
radio_style = "query_mc_incorrect_user_choice";
}
// and the input should be disabled, unless we're in review_correct_incorrect mode
if (mode != "review_correct_incorrect") {
disabled = "disabled";
}
}
// if this is the choice the user clicked, it's checked (regardless of mode)
if (index == this.user_answer_index) {
checked = "checked";
}
// Create radio button input plus label
html += "
"
+ "
"
+ "
"
//+ "
" + this.choice_ids[z] + ".
"
+ "
"
+ "
";
}
// get a possible feedback string; this fn will take account of mode
html += this.correct_incorrect_feedback(mode, is_correct);
html += "";
return html;
}
});
var DD_Query = Query.extend({
// ========================================
// define and set defaults for variables specific to this query type
choices: new Array(),
choice_order: new Array(),
correct_answer_index: null,
user_answer_index: null,
// ========================================
// initialization
parseSource: function() {
// initialize vars
this.choices = new Array();
this.correct_answer_index = null;
this.user_answer_index = null;
// DD's are always one line only -- if query_text is specified, it's via metadata (see below)
this.query_text = "";
// the line might start with "DD:"; if so, strip it out
var s = jQuery.trim(this.query_source.replace(/^DD:\s*/, ""));
// if line ends with "~~\d+", that's points
if (s.search(/(.*)~~([\.\d]+)$/) > -1) {
s = RegExp.$1;
this.points_possible = RegExp.$2;
}
// if the line starts with "!!", don't scramble
if (s.substr(0, 2) == "!!") {
this.md.never_scramble = "true";
// strip the !! out of answer
s = s.replace(/^\!\!/, "");
}
// if the line ends with "??", any answer is correct
if (s.substr(-2, 2) == "??") {
this.md.no_correct_answer = "true";
// strip the ?? out of answer
s = s.replace(/\?\?$/, "");
}
// if any commas were sent in as "\,", turn them into ,
s = s.replace(/\\,/g, ",");
// likewise, turn "\*" into *
s = s.replace(/\\\*/g, "*");
// we might have "'s indicating double quotes in the answers;
// convert these to actual double quotes so that they display properly (though it might not matter)
s = s.replace(/\"/g, '"');
// answer string should be something like "choice 1, choice2, *correct choice"
// so split it and find the correct answer
var answers = s.split(/,\s*/);
var correctChoice = -1;
for (var i = 0; i < answers.length; ++i) {
var ans = answers[i];
// look for points...
if (ans.search(/^_points:\s*(\d+)/i) > -1) {
this.points_possible = RegExp.$1;
// skip to the next answer
continue;
// or query text
} else if (ans.search(/^_query_text:\s*(.*)/i) > -1) {
this.query_text = RegExp.$1;
// skip to the next answer
continue;
// or metadata -- starts with "_[a-zA-Z]"
} else if (ans.search(/^\_[a-zA-Z]/) > -1) {
this.extractMetadata(ans);
// skip to the next answer
continue;
// if we've found the correct answer...
} else if (ans.substr(0,1) == "*") {
// if we already got a correctChoice, there's an error
if (this.correct_answer_index != null) {
return "error in pulldown answer (too many correct answers): " + s + "";
}
// otherwise this one is correct
this.correct_answer_index = i;
// strip the leading *
ans = ans.substr(1);
}
// convert *s to literal *'s now; also convert commas
ans = ans.replace(/\*/g, '*');
ans = ans.replace(/\,/g, ',');
// transfer to choices, trimming in the process
this.choices.push(jQuery.trim(ans));
}
// note: answers will be coded 0, 1, 2, 3, etc., with correctChoice numbered accordingly
// (e.g. if first answer is correct, correctChoice is 0)
// if we didn't get a correct choice, or if there aren't enough items,
// that's an error
if (this.correct_answer_index == null) {
return "error in pull down answer (no correct answer specified): " + s + "";
} else if (this.choices.length <= 1) {
return "error in pulldown answer (0 or 1 choices specified): " + s + "";
}
// shuffle choices, unless md.never_scramble is true
this.choice_order = new Array();
for (var j = 0; j < this.choices.length; ++j) this.choice_order[j] = j;
if (this.md.never_scramble != "true") {
this.choice_order.shuffle();
}
// deal with error handling...
},
// ========================================
// extend query functions
setQueryData: function(qd) {
this._super(qd);
// for DD queries, if we get query_data, that's the user's answer index
if (qd != "" && qd != null && !isNaN(qd * 1)) {
this.user_answer_index = qd * 1;
}
},
restoreAnswerFromARGA: function(answer) {
// find the choice that the user gave
for (var i = 0; i < this.choices.length; ++i) {
if (this.choices[i] == answer) {
this.user_answer_index = i;
return;
}
}
},
getQueryTypeForARGA: function() {
return 'drop-down';
},
getCorrectAnswerForARGA: function() {
return this.choices[this.correct_answer_index];
},
getUserAnswerForARGA: function() {
if (this.user_answer_index == null || this.choices[this.user_answer_index] == null) {
return 'Not answered';
} else {
return this.choices[this.user_answer_index];
}
},
// mode should be "delivery" or "review" or "review_correct_incorrect"; "delivery" is assumed
getHTML: function(mode) {
var html = "";
// DD's never have query text
// Start a nobr tag for the item
html = '
';
// if we're in preview mode or
// (a student answer has been given and we're not in review_correct_incorrect mode),
// or the student got it correct
// disable the select
var disabled = "";
if (mode == 'preview' || (mode != 'review_correct_incorrect' && this.user_answer_index != null) || this.isCorrect()) {
disabled = "disabled";
}
html += ''
html += this.finish_inline_query(this.choices[this.correct_answer_index], mode);
// Close off the nobr tag for the item
html += '
';
return html;
},
evaluateAnswer: function() {
// get the user's selected answer, which will be 0-based
this.user_answer_index = $('#query_answer_' + this.query_index).val() * 1;
// set grade accordingly (if this.md.no_correct_answer is true, any answer is correct)
if (this.user_answer_index == this.correct_answer_index || this.md.no_correct_answer == "true") {
this.setGrade(100);
} else {
this.setGrade(0);
}
return true;
},
user_has_answered: function () {
var x = $('#query_answer_' + this.query_index).val();
if ($('#query_answer_' + this.query_index).val() != -1) {
return true;
} else {
return false;
}
}
});
/*!
* routie - a tiny hash router
* v0.3.2
* http://projects.jga.me/routie
* copyright Greg Allen 2013
* MIT License
*/
(function(n){var e=[],t={},r="routie",o=n[r],i=function(n,e){this.name=e,this.path=n,this.keys=[],this.fns=[],this.params={},this.regex=a(this.path,this.keys,!1,!1)};i.prototype.addHandler=function(n){this.fns.push(n)},i.prototype.removeHandler=function(n){for(var e=0,t=this.fns.length;t>e;e++){var r=this.fns[e];if(n==r)return this.fns.splice(e,1),void 0}},i.prototype.run=function(n){for(var e=0,t=this.fns.length;t>e;e++)this.fns[e].apply(this,n)},i.prototype.match=function(n,e){var t=this.regex.exec(n);if(!t)return!1;for(var r=1,o=t.length;o>r;++r){var i=this.keys[r-1],a="string"==typeof t[r]?decodeURIComponent(t[r]):t[r];i&&(this.params[i.name]=a),e.push(a)}return!0},i.prototype.toURL=function(n){var e=this.path;for(var t in n)e=e.replace("/:"+t,"/"+n[t]);if(e=e.replace(/\/:.*\?/g,"/").replace(/\?/g,""),-1!=e.indexOf(":"))throw Error("missing parameters for url: "+e);return e};var a=function(n,e,t,r){return n instanceof RegExp?n:(n instanceof Array&&(n="("+n.join("|")+")"),n=n.concat(r?"":"/?").replace(/\/\(/g,"(?:/").replace(/\+/g,"__plus__").replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g,function(n,t,r,o,i,a){return e.push({name:o,optional:!!a}),t=t||"",""+(a?"":t)+"(?:"+(a?t:"")+(r||"")+(i||r&&"([^/.]+?)"||"([^/]+?)")+")"+(a||"")}).replace(/([\/.])/g,"\\$1").replace(/__plus__/g,"(.+)").replace(/\*/g,"(.*)"),RegExp("^"+n+"$",t?"":"i"))},s=function(n,r){var o=n.split(" "),a=2==o.length?o[0]:null;n=2==o.length?o[1]:o[0],t[n]||(t[n]=new i(n,a),e.push(t[n])),t[n].addHandler(r)},h=function(n,e){if("function"==typeof e)s(n,e),h.reload();else if("object"==typeof n){for(var t in n)s(t,n[t]);h.reload()}else e===void 0&&h.navigate(n)};h.lookup=function(n,t){for(var r=0,o=e.length;o>r;r++){var i=e[r];if(i.name==n)return i.toURL(t)}},h.remove=function(n,e){var r=t[n];r&&r.removeHandler(e)},h.removeAll=function(){t={},e=[]},h.navigate=function(n,e){e=e||{};var t=e.silent||!1;t&&l(),setTimeout(function(){window.location.hash=n,t&&setTimeout(function(){p()},1)},1)},h.noConflict=function(){return n[r]=o,h};var f=function(){return window.location.hash.substring(1)},c=function(n,e){var t=[];return e.match(n,t)?(e.run(t),!0):!1},u=h.reload=function(){for(var n=f(),t=0,r=e.length;r>t;t++){var o=e[t];if(c(n,o))return}},p=function(){n.addEventListener?n.addEventListener("hashchange",u,!1):n.attachEvent("onhashchange",u)},l=function(){n.removeEventListener?n.removeEventListener("hashchange",u):n.detachEvent("onhashchange",u)};p(),n[r]=h})(window);