var xBookUtils = {}; //player.model["score"] = 0; var Player_subtype = Player_manuscript_type.extend({ model: {}, show_section_animate: function(section_to_show, direction){ this._super(section_to_show, direction); //player.show_variables(); //handle the next button; var section = this.get_current_section_jq(); if (section.find("[data-type=question]").length > 0) { $("#next_button2").hide(); } else { //make sure its not the last section //if (player.get_current_section() < player.sections.length) { if (player.showing_last_section()) { $("#next_button2").hide(); } } $(document).trigger('df-content-rendered'); //added as DF-57 }, show_navigation: function(){ this._super(); var navHtml = UI_Elements.get_button_html({ id: "next_button2", extra_class: "toolbar_button prev_next_buttons", label: "Next", fn: 'player.show_section("next")' }); $("[data-type=chapter]").append(navHtml); $("#next_button2").button(); }, processNextStepConditionals: function (s) { for (var i = 0; i < s.md["next_step_conditional"].length; ++i) { var c = s.md.next_step_conditional[i]; if (c.search(/\{(.*)\}\s*\{(.*)\}/) > -1) { // extract condition, section to show if it's met c = new Object(); c.condition = RegExp.$1; c.section_to_show = RegExp.$2; c.message = $.trim(RegExp.$3); c.condition = this.processCondition(c.condition); s.md.next_step_conditional[i] = c; } else { safe_log("bad conditional step: " + c); s.md.next_step_conditional[i] = { condition: "false" }; } } }, processModelUpdateConditionals: function (s) { for (var i = 0; i < s.md["model_update_conditional"].length; ++i) { var c = s.md.model_update_conditional[i]; if (c.search(/\{(.*)\}\s*(.*)/) > -1) { // extract condition, section to show if it's met, and optional message c = new Object(); c.condition = RegExp.$1; c.updateStatement = RegExp.$2; c.updateStatement = this.processCondition(c.updateStatement); c.condition = this.processCondition(c.condition); s.md.model_update_conditional[i] = c; } else { safe_log("bad conditional step: " + c); s.md.model_update_conditional[i] = { condition: "false" }; } } }, processCondition: function (condition) { // < > in condition condition = condition.replace(//g, ">"); var div = document.createElement('div'); div.innerHTML = condition; var condition = div.firstChild.nodeValue; // substitute for queries in condition... // query is correct or incorrect condition = condition.replace(/qq(\d+)\s*==\s*true/g, "qq.queries[$1-1].isCorrect()"); condition = condition.replace(/qq(\d+)\s*==\s*false/g, "!qq.queries[$1-1].isCorrect()"); //check for a certain MC answer condition = condition.replace(/qqMC(\d+)/g, "qq.queries[$1-1].user_answer_index"); // otherwise assume it's something about query.user_answer condition = condition.replace(/qq(\d+)/g, "qq.queries[$1-1].user_answer"); // note that everything is going to be a string compare unless the condition includes "*1", // i.e. qq1*1 < 4 //for update statements, get string value of a MC or DD condition = condition.replace(/qqMCValue(\d+)/g, "qq.queries[$1-1].choices[qq.queries[$1-1].user_answer_index]"); // now conditions on the entire question -- just allow correct and incorrect condition = condition.replace(/qq\s*==\s*true/g, "qq.is_correct()"); condition = condition.replace(/qq\s*==\s*false/g, "!qq.is_correct()"); return condition; }, setModel: function (key, value, loadOnInit) { if (key.match(/^userAvatar\./)) { var newkey = key.substring(11, key.length); player.model.userAvatar[newkey] = value; } else if (key.match(/^partnerAvatar\./)) { var newkey = key.substring(14, key.length); player.model.partnerAvatar[newkey] = value; } else if (key.match(/^avatar\./)) { var newkey = key.substring(7, key.length); player.model.avatar[newkey] = value; } else { player.model[key] = value; } }, initialize_sections: function() { this._super(); $('[data-type="rawhtml"]').each(function() { var $this = $(this); var raw_content = $this.contents(); $this.replaceWith(raw_content); }); $('[data-type="box_inner"] h3[data-type="title"]').each(function() { var $this = $(this); var text = $this.text(); var box_title = "what about you?"; var box_subtitle = text.replace(/what about you\? /, ""); $this.text(box_title); var $box_inner = $this.parent(); $this.insertBefore($box_inner); $box_inner.prepend("
"; // 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] + ". | " + "" + " |
" + html + "