1export function MenuHorizontal(aria) { 2 (function () { 3 aria.MenuHorizontal = function (domNode) { 4 this.domNode = domNode; 5 }; 6 7 aria.MenuHorizontal.prototype.init = function () { 8 const menuItems = this.domNode.querySelectorAll('a'); 9 const getItemsFromMenu = Array.from(menuItems); 10 11 getItemsFromMenu.forEach((button) => { 12 if(button.classList.contains('c-menu-horizontal__active')) { 13 this.activateElement(button.id); 14 } 15 }) 16 }; 17 18 aria.MenuHorizontal.prototype.activateElement = function (elementActive) { 19 this.domNode.querySelectorAll('a').forEach((element) => { 20 if (element.id === elementActive) { 21 this.wrapActiveElement(element); 22 } else { 23 this.deactivateElement(element); 24 } 25 }); 26 }; 27 28 aria.MenuHorizontal.prototype.wrapActiveElement = function (elementActive) { 29 if (!elementActive.getAttribute('aria-current')) { 30 elementActive.setAttribute('aria-current', 'page'); 31 elementActive.classList.add('c-menu-horizontal__active'); 32 elementActive.innerHTML = `<strong class="font-bold">${elementActive.innerHTML}</strong>`; 33 } 34 }; 35 36 aria.MenuHorizontal.prototype.deactivateElement = function (elementDeactivated) { 37 elementDeactivated.removeAttribute('aria-current'); 38 elementDeactivated.classList.remove('c-menu-horizontal__active'); 39 if(elementDeactivated.querySelector('strong')) { 40 const replaceStrong = elementDeactivated.innerHTML.replace('<strong class="font-bold">', '').replace('<strong/>', ''); 41 elementDeactivated.innerHTML = `${replaceStrong}`; 42 } 43 }; 44 45 window.activateItemMenuHorizontal = function (menuId, activeItemId) { 46 const menu = document.getElementById(menuId); 47 if (menu) { 48 const activeItem = document.querySelector(`#${menuId} #${activeItemId}`); 49 if (activeItem) { 50 const menuInstance = new aria.MenuHorizontal(menu); 51 menuInstance.activateElement(activeItemId); 52 return [menu, activeItem]; 53 } else { 54 console.log('There is no element with this id in the menu.'); 55 return null; 56 } 57 } else { 58 console.log('There is no menu with this id in the document.'); 59 return null; 60 } 61 }; 62 }()); 63}
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.