1var edx = edx || {}, 2 3 Navigation = (function() { 4 var navigation = { 5 6 init: function() { 7 if ($('.accordion').length) { 8 navigation.loadAccordion(); 9 } 10 }, 11 12 loadAccordion: function() { 13 navigation.checkForCurrent(); 14 navigation.listenForClick(); 15 navigation.listenForKeypress(); 16 }, 17 18 getActiveIndex: function() { 19 var index = $('.accordion .button-chapter:has(.active)').index('.accordion .button-chapter'), 20 button = null; 21 22 if (index > -1) { 23 button = $('.accordion .button-chapter:eq(' + index + ')'); 24 } 25 26 return button; 27 }, 28 29 checkForCurrent: function() { 30 var button = navigation.getActiveIndex(); 31 32 navigation.closeAccordions(); 33 34 if (button !== null) { 35 navigation.setupCurrentAccordionSection(button); 36 } 37 }, 38 39 listenForClick: function() { 40 $('.accordion').on('click', '.button-chapter', function(event) { 41 event.preventDefault(); 42 43 var button = $(event.currentTarget), 44 section = button.next('.chapter-content-container'); 45 46 navigation.closeAccordions(button, section); 47 navigation.openAccordion(button, section); 48 }); 49 }, 50 51 listenForKeypress: function() { 52 $('.accordion').on('keydown', '.button-chapter', function(event) { 53 // because we're changing the role of the toggle from an 'a' to a 'button' 54 // we need to ensure it has the same keyboard use cases as a real button. 55 // this is useful for screenreader users primarily. 56 if (event.which == 32) { // spacebar 57 event.preventDefault(); 58 $(event.currentTarget).trigger('click'); 59 } else { 60 return true; 61 } 62 }); 63 }, 64 65 closeAccordions: function(button, section) { 66 var menu = $(section).find('.chapter-menu'), toggle; 67 68 $('.accordion .button-chapter').each(function(index, element) { 69 toggle = $(element); 70 71 toggle 72 .removeClass('is-open') 73 .attr('aria-expanded', 'false'); 74 75 toggle 76 .children('.group-heading') 77 .removeClass('active') 78 .find('.icon') 79 .addClass('fa-caret-right') 80 .removeClass('fa-caret-down'); 81 82 toggle 83 .next('.chapter-content-container') 84 .removeClass('is-open') 85 .find('.chapter-menu').not(menu) 86 .removeClass('is-open') 87 .slideUp(); 88 }); 89 }, 90 91 setupCurrentAccordionSection: function(button) { 92 var section = $(button).next('.chapter-content-container'); 93 94 navigation.openAccordion(button, section); 95 }, 96 97 openAccordion: function(button, section) { 98 var sectionEl = $(section), 99 firstLink = sectionEl.find('.menu-item').first(), 100 buttonEl = $(button); 101 102 buttonEl 103 .addClass('is-open') 104 .attr('aria-expanded', 'true'); 105 106 buttonEl 107 .children('.group-heading') 108 .addClass('active') 109 .find('.icon') 110 .removeClass('fa-caret-right') 111 .addClass('fa-caret-down'); 112 113 sectionEl 114 .addClass('is-open') 115 .find('.chapter-menu') 116 .addClass('is-open') 117 .slideDown(); 118 } 119 }; 120 121 return { 122 init: navigation.init 123 }; 124 })(); 125 126edx.util = edx.util || {}; 127edx.util.navigation = Navigation; 128edx.util.navigation.init();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.