(function() {
var Player_ch12 = Player_ays.extend({
show_navigation: function () {
var title = "Assess Your Strengths
";
var html = "
"
+ "
" + title + "
" + this.md.activity_type_title + "
"
+ "
"
;
for (var i = 0; i < this.sections.length; ++i) {
var s = this.sections[i];
html += "- "
+ s.title
+ "
"
;
// also insert a "next" button at the bottom of each section, unless it's the last one
var nextButton = "
";
var referenceButton = s.jq.find('[data-block_type="references"]');
if(referenceButton.length > 0) {
referenceButton.after(nextButton);
} else if (i < this.sections.length - 1) {
s.jq.append(nextButton);
}
}
html += "
";
var self = this;
$("[data-type=chapter]").prepend(html).tabs({
select: self.tab_selected,
fx: {opacity: 'toggle', duration: 100}
});
var LEFT_ARROW_KEY = 37;
var RIGHT_ARROW_KEY = 39;
var CustomTabs = function( $jq ) {
this.$jq = $jq;
this.$li = $jq.find('li a');
this.index = 0;
// Disable all tabindex attr on $jq
this._disableAll();
this.$jq.attr('role', 'tablist');
this.$li.attr('role', 'tab');
// Attach listeners
var cTabs = this;
this.$li.click( function(){
if ( cTabs.stopEvents ) {
return false;
}
cTabs._disableAll();
// Get index of node was clicked by
var index = cTabs.$li.index( this );
cTabs.setMenuActive( index, true );
});
this.$li.keydown( function( event ){
var key = event.keyCode;
var l = cTabs.$li.length;
var newIndex = cTabs.index;
var changes = false;
if ( key === LEFT_ARROW_KEY && cTabs.index >= 1 ) {
--newIndex;
changes = true;
}
if ( key === RIGHT_ARROW_KEY && cTabs.index < l - 1 ) {
++newIndex;
changes = true;
}
if ( changes ) {
cTabs.setMenuActive( newIndex );
}
});
$(".next_button").click( function() {
var newIndex = cTabs.index;
++newIndex;
cTabs.setMenuActive( newIndex );
});
// Set first menu as active element
this.setMenuActive( 0 );
};
CustomTabs.prototype.setMenuActive = function( index, fake ) {
var cTabs = this;
this.stopEvents = true;
this.prevIndex = this.index;
this.index = index;
this.$li[this.prevIndex].setAttribute('tabindex', '-1');
this.$li[this.index].setAttribute('tabindex', '0');
this.$li[this.prevIndex].setAttribute('aria-selected', 'false');
this.$li[this.index].setAttribute('aria-selected', 'true');
if ( !fake ) {
this.$li[this.index].click();
}
if ( this.index <= player.last_available_section && completeVideo ) {
this.$li[this.index].focus();
} else {
Standard_Dialog.onceCallback = function(){
cTabs.setMenuActive( cTabs.prevIndex, true );
}
}
this.stopEvents = false;
};
CustomTabs.prototype._disableAll = function(){
$.each( this.$li, function( index, node ) {
node.setAttribute('tabindex', '-1');
node.setAttribute('aria-selected', 'false');
} );
};
//var $tabs = $("li.ui-state-default a");
var $tabs = $("#activity_top ul");
new CustomTabs( $tabs );
player.tab_jq = $("[data-type=chapter]");
},
update_section_status: function () {
this._super();
var curSectionIndex = player.section_currently_showing;
var curSection = player.sections[curSectionIndex];
if( curSection.slide && !curSection.slide.isPassed ) {
player.last_available_section = curSectionIndex;
}
}
});
player = new Player_ch12();
FB_Query = FB_Query.extend({
user_has_answered: function () {
var x = jQuery.trim($("#query_answer" +
"" +
"_" + this.query_index).val());
if (jQuery.trim($("#query_answer_" + this.query_index).val()) != "") {
return true;
} else {
return false;
}
},
getHTML: function(mode) {
var html = "";
// start with the query text, if there is any
html += this.query_text_html();
// determine how big the response blank should be, unless one was specified
var blank_size = this.md.blank_size;
if (blank_size == "" || blank_size == null || isNaN(blank_size * 1)) {
var s = "" + this.correct_answer;
blank_size = (s.length + 2);
}
// if student hasn't answered or we're in preview mode, use an empty string for the input value
var val, disabled;
var fb_string = "";
if (!this.userHasAnswered() || mode == 'preview') {
val = "";
disabled = "";
// otherwise we have an answer, so fill it in
} else {
// make sure we convert double quotes to " for placement in 'value="xxx"' attributes
val = this.user_answer.replace(/\"/g, """);
// also disable the input in this case, if we're not in review_correct_incorrect mode
// or if the user got it right
if (mode != "review_correct_incorrect" || this.isCorrect()) {
disabled = "disabled";
}
}
var label = this.jq.closest('td').prev('td').find('p');
var labelId = label.attr('id');
html += ''
+ ''
;
html += this.finish_inline_query(this.correct_answer, mode);
html += '';
$('.query_fb_input').keypress(function(e) {
if ( !( e.charCode >= 65 && e.charCode <= 90 || e.charCode >= 97 && e.charCode <= 122 || e.charCode >= 48 && e.charCode <= 57 || e.charCode == 32 )
&& e.charCode ){
return false;
}
});
return html;
}
});
function Activity( section ){
this.createNextScreenBtn( section );
this.isPassed = false;
}
Activity.prototype.createScreens = function( initScreen, finalScreen ) {
this.initScreen = initScreen;
this.finalScreen = finalScreen;
this.screenName = [];
for( var i = 0; i < this.initScreen; i++ ) {
this.screenName[i] = "";
}
for( i = this.initScreen; i <= this.finalScreen; i++ ) {
this.screenName[i] = '[data-block_type="screen_' + i + '"]';
$(this.screenName[i]).hide();
}
$(this.screenName[this.initScreen]).show();
};
Activity.prototype.showNextScreen = function( index ) {
//var curSection = player.get_current_section();
//curSection.slide.hideNextBtn(curSection);
player.show_variables(index);
//$(this.screenName[index]).hide();
$(this.screenName[index + 1]).show();
//$(this.screenName[index + 1]).focus();
if($(this.screenName[index + 1]).find("[data-type=question]").length > 0) {
$(this.nextScreenBtn).hide();
}
this.index++;
if( this.index == this.finalScreen ) {
$(this.nextScreenBtn).remove();
if($(this.screenName[index + 1]).find(".question_submit_button").length == 0
&& $(this.screenName[index + 1]).find(".next_screen_button").length == 0) {
$(".next_button").show();
player.last_available_section = player.section_currently_showing + 1;
}
this.isPassed = true;
}
$(this.screenName[index + 1]).attr('tabindex', '0');
$(this.screenName[index + 1]).focus();
$(this.screenName[index + 1]).attr('tabindex', '-1');
//var curSection = player.sections[player.section_currently_showing];
//curSection.jq.focus();
};
Activity.prototype.createNextScreenBtn = function( section ) {
this.nextScreenBtn = document.createElement("button");
this.nextScreenBtn.classList.add("next_screen_button");
this.nextScreenBtn.textContent = "NEXT";
section.jq.append(this.nextScreenBtn);
};
window.mheAYS = window.mheAYS || {};
window.mheAYS['build_section'] = {
initialize: function( section ) {
section.slide = new Activity( section );
section.slide.initScreen = 0;
section.slide.finalScreen = 1;
section.slide.index = section.slide.initScreen;
section.slide.createScreens( section.slide.initScreen, section.slide.finalScreen );
$(section.slide.nextScreenBtn).click( function() { section.slide.showNextScreen(section.slide.index); } );
},
hide: function( section ){
if(this.isPassed) {
$(section.slide.nextScreenBtn).remove();
}
},
show: function( section ){
$(section.slide.nextScreenBtn).show();
$(section).focus();
player.last_available_section = player.section_currently_showing;
}
};
})();