diff --git a/lms/static/js/utils/navigation.js b/lms/static/js/utils/navigation.js
index 926d76ddd9..82034ce971 100644
--- a/lms/static/js/utils/navigation.js
+++ b/lms/static/js/utils/navigation.js
@@ -9,64 +9,53 @@ var edx = edx || {},
if ($('#accordion').length) {
navigation.openAccordion();
- navigation.checkForCurrent();
- navigation.listenForClick();
}
},
openAccordion: function() {
$('#open_close_accordion a').click();
- $('.course-wrapper').toggleClass('closed');
+ $('.course-wrapper').removeClass('closed');
$('#accordion').show();
+
+ navigation.checkForCurrent();
+ navigation.listenForClick();
},
checkForCurrent: function() {
- var active;
+ var active = $('#accordion .chapter-content-container .chapter-menu:has(a.active)').index('#accordion .chapter-content-container .chapter-menu') ? $('#accordion .chapter-content-container .chapter-menu:has(a.active)').index('#accordion .chapter-content-container .chapter-menu') : 0,
+ activeSection = $('#accordion .button-chapter:eq(' + active + ')');
- active = $('#accordion div div:has(a.active)').index('#accordion div div');
-
- if (typeof active === 'undefined' || active < 0) {
- active = 0;
- }
-
- if (active > 0) {
- $('#accordion').find('.button-chapter:eq(' + active + ')').trigger('click');
- }
+ navigation.closeAccordions();
+ navigation.openAccordionSection(activeSection);
},
listenForClick: function() {
$('#accordion').on('click', '.button-chapter', function(event) {
- // close and reset all accrdions
- navigation.resetAllAccordions();
-
- // open this accordion and send focus
+ navigation.closeAccordions();
navigation.openAccordionSection(event.currentTarget);
-
- // assign classes and set open aria
- navigation.setAriaAttrs(event.currentTarget);
});
},
- resetAllAccordions: function() {
+ closeAccordions: function() {
$('.chapter-content-container').hide();
$('.chapter-content-container .chapter-menu').hide();
$('#accordion .button-chapter').each(function(event) {
- $(this).removeClass('is-open').attr('aria-pressed', 'false');
- $(this).next('.chapter-content-container').attr('aria-expanded', 'false');
- $(this).children('.group-heading').removeClass('active');
- $(this).children('.group-heading').find('.icon').addClass('fa-caret-right').removeClass('fa-caret-down');
+ var el = $(this);
+
+ el.removeClass('is-open').attr('aria-pressed', 'false');
+ el.next('.chapter-content-container').attr('aria-expanded', 'false');
+ el.children('.group-heading').removeClass('active');
+ el.children('.group-heading').find('.icon').addClass('fa-caret-right').removeClass('fa-caret-down');
});
},
openAccordionSection: function(section) {
- $(section).next('.chapter-content-container').show().focus();
- $(section).next('.chapter-content-container').find('.chapter-menu').show();
+ var elSection = $(section).next('.chapter-content-container');
- navigation.setAriaAttrs(section);
- },
+ elSection.show().focus();
+ elSection.find('.chapter-menu').show();
- setAriaAttrs: function(section) {
$(section).addClass('is-open').attr('aria-pressed', 'true');
$(section).next('.chapter-content-container').attr('aria-expanded', 'true');
$(section).children('.group-heading').addClass('active');
diff --git a/lms/templates/main.html b/lms/templates/main.html
index 9bda41e64a..e1ebaff510 100644
--- a/lms/templates/main.html
+++ b/lms/templates/main.html
@@ -159,7 +159,7 @@ from branding import api as branding_api
<%block name="js_extra"/>
-
+