Commit 04ff6370 by Chris Rodriguez

PR feedback on JS

parent 1d07b278
...@@ -9,64 +9,53 @@ var edx = edx || {}, ...@@ -9,64 +9,53 @@ var edx = edx || {},
if ($('#accordion').length) { if ($('#accordion').length) {
navigation.openAccordion(); navigation.openAccordion();
navigation.checkForCurrent();
navigation.listenForClick();
} }
}, },
openAccordion: function() { openAccordion: function() {
$('#open_close_accordion a').click(); $('#open_close_accordion a').click();
$('.course-wrapper').toggleClass('closed'); $('.course-wrapper').removeClass('closed');
$('#accordion').show(); $('#accordion').show();
navigation.checkForCurrent();
navigation.listenForClick();
}, },
checkForCurrent: function() { 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) { navigation.closeAccordions();
active = 0; navigation.openAccordionSection(activeSection);
}
if (active > 0) {
$('#accordion').find('.button-chapter:eq(' + active + ')').trigger('click');
}
}, },
listenForClick: function() { listenForClick: function() {
$('#accordion').on('click', '.button-chapter', function(event) { $('#accordion').on('click', '.button-chapter', function(event) {
// close and reset all accrdions navigation.closeAccordions();
navigation.resetAllAccordions();
// open this accordion and send focus
navigation.openAccordionSection(event.currentTarget); 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').hide();
$('.chapter-content-container .chapter-menu').hide(); $('.chapter-content-container .chapter-menu').hide();
$('#accordion .button-chapter').each(function(event) { $('#accordion .button-chapter').each(function(event) {
$(this).removeClass('is-open').attr('aria-pressed', 'false'); var el = $(this);
$(this).next('.chapter-content-container').attr('aria-expanded', 'false');
$(this).children('.group-heading').removeClass('active'); el.removeClass('is-open').attr('aria-pressed', 'false');
$(this).children('.group-heading').find('.icon').addClass('fa-caret-right').removeClass('fa-caret-down'); 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) { openAccordionSection: function(section) {
$(section).next('.chapter-content-container').show().focus(); var elSection = $(section).next('.chapter-content-container');
$(section).next('.chapter-content-container').find('.chapter-menu').show();
navigation.setAriaAttrs(section); elSection.show().focus();
}, elSection.find('.chapter-menu').show();
setAriaAttrs: function(section) {
$(section).addClass('is-open').attr('aria-pressed', 'true'); $(section).addClass('is-open').attr('aria-pressed', 'true');
$(section).next('.chapter-content-container').attr('aria-expanded', 'true'); $(section).next('.chapter-content-container').attr('aria-expanded', 'true');
$(section).children('.group-heading').addClass('active'); $(section).children('.group-heading').addClass('active');
......
...@@ -159,7 +159,7 @@ from branding import api as branding_api ...@@ -159,7 +159,7 @@ from branding import api as branding_api
<%block name="js_extra"/> <%block name="js_extra"/>
<script type="text/javascript" src="${static.url('js/vendor/noreferrer.js')}" charset="utf-8"></script> <script type="text/javascript" src="${static.url('js/vendor/noreferrer.js')}" charset="utf-8"></script>
<script type="text/javascript" src="${static.url('coffee/src/navigation.js')}" charset="utf-8"></script> <script type="text/javascript" src="${static.url('js/utils/navigation.js')}" charset="utf-8"></script>
</body> </body>
</html> </html>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment