var Activity_chapter = Activity_datavis.extend({
show_question_feedback: function(question, is_correct, try_again) {
// remove prior feedback if there
$("#question_feedback_" + question.index).remove();
// if we don't have any feedback at all, return
if (question.md.feedback == null && question.md.feedback_correct == null && question.md.feedback_incorrect == null && question.md.feedback_hint == null) {
return;
}
var hint_fdb = $( question.jq ).find( '.query_mc_feedback_correct_incorrect' );
var hint_fdb_text = $( hint_fdb ).text();
$( hint_fdb ).html('');
var html = "
"
+ "
" + this.feedbackTitle + "
";
// include general feedback if there
if (question.md.feedback != null) {
html += "
" + question.md.feedback + "
";
}
// include correct feedback if there and the answer is correct
if (is_correct && question.md.feedback_correct != null) {
html += "
" + question.md.feedback_correct + "
";
}
// include incorrect or hint feedback if there and the answer is incorrect
if (!is_correct) {
var found_feedback_string = false;
// if user gets to try again...
if (try_again) {
// check for feedback_conditional's
if (question.md.feedback_conditional.length > 0) {
for (var i in question.md.feedback_conditional) {
var fbc = question.check_conditional(question.md.feedback_conditional[i]);
if (fbc != "") {
html += "
" + fbc + "
";
found_feedback_string = true;
break;
}
}
}
// if we didn't find a feedback string to use above, check for feedback_hint
if (!found_feedback_string && question.md.feedback_hint != null) {
html += "
" + question.md.feedback_hint + "
";
found_feedback_string = true;
}
}
// if user didn't choose option from the list
if( !hint_fdb_text ){
html += "
" + question.md.feedback_incorrect + "
";
}
// if we didn't find a feedback string to use above, check for feedback_incorrect
if (!found_feedback_string && question.md.feedback_incorrect != null && hint_fdb_text ) {
html += "
" + hint_fdb_text + "
";
}
}
// close question_feedback div
html += "
";
// append the div, then fade it in
$("#question_action_div_" + question.index).prepend(html);
$("#question_feedback_" + question.index).fadeIn("fast", function() {
// What I'd like to do here is check to make sure the feedback is all showing on the screen,
// and scroll if necessary so that the feedback is all visible. But just doing "scrollTo"
// isn't working properly in all situations.
// $(window).scrollTo($(this), 0);
});
}
});
var Player_chapter = Player_datavis.extend( {
initialize: function() {
var title = $('h1.section-title');
var newTitle = title.find('[data-type=title]');
this.activity_title= newTitle.text();
this._super();
this.activity = new Activity_chapter();
}
});
window.player = new Player_chapter();
player.setNavigationCallback = (function(){
var currentGraph, graphs;
function initEvents(){
var select, radio, pyramid_parts, i;
pyramid_parts = document.querySelectorAll( ".pyramid-part" );
/* Fix from Safari iPad */
var colors = [
"#A35DA5",
"#33A3DC",
"#39BB9D",
"#A35DA5",
"#33A3DC",
"#39BB9D",
"#A35DA5",
"#33A3DC",
"#39BB9D"
];
function setColor( index ){
this.style.color = colors[index];
}
function resetColor(){
this.style.color = "#fff";
}
for( i = 0; i < pyramid_parts.length; i += 1 ){
pyramid_parts[i].addEventListener("mouseover", setColor.bind( pyramid_parts[i], i ) );
pyramid_parts[i].addEventListener("mouseout", resetColor );
}
select = document.getElementById("graph-select");
radio = select.querySelectorAll("input");
for( i = 0; i < radio.length; i += 1 ){
radio[i].addEventListener("change", changeList );
}
graphs = document.querySelectorAll(".graph-container");
currentGraph = graphs[ 0 ];
}
function changeList(){
var index = this.value;
index = parseInt( index, 10 );
currentGraph._removeClass( "active" );
currentGraph = graphs[ index ];
currentGraph.className += " active";
}
Node.prototype._removeClass = function( cls ){
var cssClass = this.className.split(" ");
var i;
for( i = 0; i < cssClass.length; i += 1 ){
if( cssClass[i] === cls ){
cssClass.splice( i, 1 );
i -= 1;
}
}
this.className = cssClass.join(" ");
};
initEvents();
player.setNavigationCallback = null;
});