1/** 2 * ãããã¼ãåºåãã颿° 3 * @param {string} rootPath - ç»åããªã³ã¯ã®åºæºã¨ãªããã¹ï¼ä¾: "." ã¾ã㯠".."ï¼ 4 * @param {string} activePage - ç¾å¨ã®ãã¼ã¸IDï¼'home', 'about', 'menu', 'contact', 'coupon'ï¼ 5 */ 6function writeHeader(rootPath, activePage) { 7 8 // ããã²ã¼ã·ã§ã³ã®è¨å® 9 // id: ãã¼ã¸ID, name: ç»åãã¡ã¤ã«åã®ãã¼ã¹, text: ã¹ããç¨ããã¹ã, link: ãªã³ã¯å 10 const navList = [ 11 { id: 'home', name: 'navi_home', text: 'HOME', link: rootPath + '/index.html' }, 12 { id: 'about', name: 'navi_about', text: 'ãåºã®ç´¹ä»', link: rootPath + '/about/index.html' }, 13 { id: 'menu', name: 'navi_menu', text: 'ã¡ãã¥ã¼', link: rootPath + '/menu/index.html' }, 14 { id: 'contact', name: 'navi_contact', text: 'ãåãåãã', link: rootPath + '/contact/index.html' }, 15 { id: 'coupon', name: 'navi_coupon', text: 'ã¯ã¼ãã³', link: rootPath + '/coupon/index.html' } 16 ]; 17 18 // ããã²ã¼ã·ã§ã³ã®HTMLãçæ 19 let navHtml = ''; 20 navList.forEach(function(item) { 21 // ç¾å¨ã®ãã¼ã¸ãªã _1.jpg (ã¢ã¯ãã£ã)ããã以å¤ã¯ _2.jpg 22 const imgSuffix = (item.id === activePage) ? '_1.jpg' : '_2.jpg'; 23 const imgSrc = rootPath + '/common/' + item.name + imgSuffix; 24 25 navHtml += ` 26 <li> 27 <a href="${item.link}"> 28 <img src="${imgSrc}" alt="${item.text}" class="nav-img"> 29 <span class="nav-text">${item.text}</span> 30 </a> 31 </li> 32 `; 33 }); 34 35 // ãããã¼å ¨ä½ã®HTML 36 const headerHtml = ` 37 <header> 38 <button class="hamburger-btn" id="js-hamburger"> 39 <span></span> 40 <span></span> 41 <span></span> 42 </button> 43 44 <div class="header-visual"> 45 <img src="${rootPath}/common/top_1.jpg" alt="åºå ã®æ§å"> 46 <img src="${rootPath}/common/top_2.jpg" alt="調ç風æ¯"> 47 <img src="${rootPath}/common/top_3.jpg" alt="æç"> 48 </div> 49 50 <nav class="global-nav" id="js-nav"> 51 <ul> 52 ${navHtml} 53 </ul> 54 </nav> 55 </header> 56 `; 57 58 // HTMLãåºå 59 document.write(headerHtml); 60 61 // ãã³ãã¼ã¬ã¼ã¡ãã¥ã¼ã®åä½ã¹ã¯ãªããï¼DOMèªã¿è¾¼ã¿å¾ã«å®è¡ï¼ 62 document.addEventListener('DOMContentLoaded', function() { 63 const hamburgerBtn = document.getElementById('js-hamburger'); 64 const globalNav = document.getElementById('js-nav'); 65 66 if(hamburgerBtn && globalNav) { 67 hamburgerBtn.addEventListener('click', function() { 68 hamburgerBtn.classList.toggle('active'); 69 globalNav.classList.toggle('active'); 70 }); 71 72 const navLinks = globalNav.querySelectorAll('a'); 73 navLinks.forEach(function(link) { 74 link.addEventListener('click', function() { 75 hamburgerBtn.classList.remove('active'); 76 globalNav.classList.remove('active'); 77 }); 78 }); 79 } 80 }); 81}
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.