1document.addEventListener("DOMContentLoaded", function() { 2 // Declare variables at the top 3 let menuIcon = document.getElementById("btnMenu"); 4 let menuIcon2 = document.getElementById("more-button"); 5 let body = document.body; 6 let menuDrawer = document.getElementById("menuDrawer"); 7 8 // Variable to keep track of the menu state 9 let isMenuOpen = false; 10 11 // Function to open the menu 12 function openMenu(event) { 13 if (event) event.stopPropagation(); 14 if (!isMenuOpen) { 15 menuDrawer.style.opacity = "1"; 16 menuDrawer.style.transform = "scale(1)"; 17 menuDrawer.classList.remove("hidden"); 18 menuIcon.classList.add("active"); 19 body.style.overflow = "hidden"; 20 isMenuOpen = true; 21 // Add event listener to detect clicks outside the menu 22 document.addEventListener("click", clickOutsideHandler); 23 } 24 } 25 26 // Function to close the menu 27 function closeMenu(event) { 28 if (event) event.stopPropagation(); 29 if (isMenuOpen) { 30 menuDrawer.style.opacity = "0"; 31 menuDrawer.style.transform = "scale(0.8)"; 32 menuDrawer.classList.add("hidden"); 33 menuIcon.classList.remove("active"); 34 body.style.overflow = "auto"; 35 isMenuOpen = false; 36 // Remove event listener for outside clicks 37 document.removeEventListener("click", clickOutsideHandler); 38 } 39 } 40 41 // Function to toggle the menu 42 function toggleMenu(event) { 43 if (isMenuOpen) { 44 closeMenu(event); 45 } else { 46 openMenu(event); 47 } 48 } 49 50 // Function to handle clicks outside the menu 51 function clickOutsideHandler(event) { 52 if (!menuDrawer.contains(event.target) && event.target !== menuIcon && event.target !== menuIcon2) { 53 closeMenu(event); 54 } 55 } 56 57 // Attach the click event listener to the button that toggles the menu 58 if (menuIcon) { 59 menuIcon.addEventListener("click", toggleMenu); 60 } 61 62 // Attach the click event listener to the button that opens the menu 63 if (menuIcon2) { 64 menuIcon2.addEventListener("click", openMenu); 65 } 66 67 // Prevent clicks inside the menu from propagating to the document 68 menuDrawer.addEventListener("click", function(event) { 69 event.stopPropagation(); 70 }); 71});
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.