//####################################################
//Practice 1 & Practice 2
;(function () {
'use strict';
function slideInitHandler(section) {
// console.log('slideInitHandler');
section.points_possible = 1;
section.points_earned = 0;
section.section_completed = false;
var _elem = section.jq
_elem.addClass('view-parts')
//add Accessibility elements
// var ariaLabel = section.title + '. ' + section.instructions
// var ariaReader = $('
')
// .addClass('hidden_element')
// .attr('aria-label', ariaLabel)
// .attr('tabindex', '-1')
// _elem.prepend(ariaReader)
}
function completeTask(section) {
section.points_earned = 1;
section.section_completed = true;
player.activity.grade_activity();
player.update_section_status();
// document.querySelector('.navigation_button.next_button').focus();
}
function slideShowHandler(section) {
// console.log('slideShowHandler', section);
var _elem = section.jq
var ariaContainer = $('
')
.addClass('hidden_element')
.attr('aria-live', 'polite')
var descriptions = _elem.find('.view-parts__description-item')
.toArray()
.map(function(item){
return item.textContent
})
var $parts = _elem.find('.view-parts__part')
var $btns = _elem.find('.view-parts__btn')
_elem.append(ariaContainer)
$btns.unbind('click')
.bind('click', function (e) {
$(e.target).focus()
var $id = $(this).attr('data-view')
ariaContainer.empty().append(descriptions[$id])
$parts.each(function (i, item) {
if ($(item).attr('data-part') == $id) {
item.addClass('view-parts__part--shown')
item.addClass('view-parts__part--active')
} else {
item.removeClass('view-parts__part--active')
}
})
if (_elem.find('.view-parts__part--shown').length == $parts.length) {
completeTask(section)
}
})
// Set focus on next button after the last item
$btns[$btns.length - 1].addEventListener('keydown', function(e) {
e = e || window.event;
if ( !e.shiftKey && e.keyCode === 9 ) { // !Shift + Tab key
e.preventDefault();
document.querySelector('.navigation_button.next_button').focus();
}
});
}
function slideHideHandler(section) {
//console.log('slideHideHandler', section)
//add navigation
}
window.mheContpract = window.mheContpract || {};
window.mheContpract['view-parts'] = {
initialize: slideInitHandler,
show: slideShowHandler,
hide: slideHideHandler
};
})();