1document.addEventListener("DOMContentLoaded", () => { 2 // --- 夿°å®ç¾© --- 3 const header = document.querySelector("header"); 4 const mainContent = 5 document.querySelector("main") || 6 document.querySelector(".wp-site-blocks > :not(header):not(footer)"); 7 const footer = document.querySelector("footer"); 8 let toTopButtonContainer = null; 9 // ç¾å¨ã®ãã¡ã¤ã³ãåå¾ (å°æååãã¦æ¯è¼ã容æã«ãã) 10 const currentHostname = location.hostname.toLowerCase(); 11 const REM_OFFSET_PX = 0; 12 const isEn = location.pathname.includes("/english/"); 13 14 const uiDict = { 15 skipNav: isEn ? "Jump to Navigation" : "ããã²ã¼ã·ã§ã³ã¸ã¸ã£ã³ã", 16 skipMain: isEn ? "Jump to Main Content" : "ã¡ã¤ã³ã³ã³ãã³ãã¸ã¸ã£ã³ã", 17 skipFooter: isEn ? "Jump to Footer" : "ããã¿ã¼ã¸ã¸ã£ã³ã", 18 skipAria: isEn ? "Quick Menu" : "ã¯ã¤ãã¯ã¡ãã¥ã¼", 19 }; 20 21 // ========================================================= 22 // ã追å ãA. ã¢ã¯ã»ã·ããªãã£ï¼ID/屿§ä»ä¸ã¨ã¹ããããªã³ã¯æ¿å ¥ 23 // ========================================================= 24 if (header) { 25 header.id = "site-navigation"; 26 header.setAttribute("tabindex", "-1"); 27 } 28 if (mainContent) { 29 mainContent.id = "main-content"; 30 mainContent.setAttribute("tabindex", "-1"); 31 } 32 if (footer) { 33 footer.id = "site-footer"; 34 footer.setAttribute("tabindex", "-1"); 35 } 36 37 const oldSkipLink = 38 document.getElementById("wp-skip-link") || 39 document.querySelector(".skip-link.screen-reader-text"); 40 if (oldSkipLink) { 41 oldSkipLink.remove(); 42 } 43 44 // ã¹ããããªã³ã¯ãbodyã®å é ã«æ¿å ¥ 45 const skipLinksHTML = ` 46 <nav class="skip-links" aria-label="${uiDict.skipAria}"> 47 <a class="skip-link screen-reader-text" href="#site-navigation">${uiDict.skipNav}</a> 48 <a class="skip-link screen-reader-text" href="#main-content">${uiDict.skipMain}</a> 49 <a class="skip-link screen-reader-text" href="#site-footer">${uiDict.skipFooter}</a> 50 </nav>`; 51 document.body.insertAdjacentHTML("afterbegin", skipLinksHTML); 52 53 // ========================================================= 54 // ãããã¼/ã¹ã¯ãã¼ã«ãªãã»ãã颿°: mainã®paddingã¨CSS夿°ãè¨å® 55 // ========================================================= 56 const setMainPaddingAndScrollOffset = () => { 57 if (header && mainContent) { 58 // 1. ãããã¼ã®æ£ç¢ºãªé«ããåå¾ 59 const headerHeight = header.offsetHeight; 60 61 // 2. 管çãã¼ï¼wpadminbarï¼ã®é«ããåå¾ï¼ãã°ã¤ã³æã®ã¿ï¼ 62 const adminBar = document.getElementById("wpadminbar"); 63 const adminBarHeight = adminBar ? adminBar.offsetHeight : 0; 64 65 // 3. å ¨ä½ã®ãªãã»ãããè¨ç® 66 // ä½è£ãæãããããã® bufferï¼20pxï¼ãè¶³ãã¦ãã¾ã 67 const buffer = 20; 68 const totalOffsetHeight = headerHeight + adminBarHeight + buffer; 69 70 // â mainè¦ç´ ã«padding-topãè¨å®ï¼ãããã¼ã§é ããé åã確ä¿ï¼ 71 // padding-topãæ¶ããã対çã¨ã㦠!important ãä½¿ç¨ 72 mainContent.style.setProperty( 73 "padding-top", 74 `${headerHeight}px`, 75 "important", 76 ); 77 78 // â¡ CSSã«ã¹ã¿ã ããããã£ã¨ãã¦ãããã¼ã®é«ããè¨å®ï¼ãã¼ã¸å ãªã³ã¯ã®ã¹ã¯ãã¼ã«ãªãã»ããç¨ï¼ 79 document.documentElement.style.setProperty( 80 "--header-height", 81 `${totalOffsetHeight}px`, 82 ); 83 } 84 }; 85 86 setMainPaddingAndScrollOffset(); 87 window.addEventListener("resize", setMainPaddingAndScrollOffset); 88 89 // ========================================================= 90 // 1. ãªã³ã¯å¦çï¼PDF/Excel/å¤é¨ãªã³ã¯ã® target="_blank" ä»ä¸ï¼ 91 // ========================================================= 92 document.querySelectorAll("a").forEach((link) => { 93 const url = link.getAttribute("href"); 94 95 // hrefããªããã¾ãã¯ã¢ã³ã«ã¼ãªã³ã¯ (#) ã®å ´åã¯ã¹ããã 96 if (!url || url.startsWith("#")) { 97 return; 98 } 99 100 // target="_blank" 㨠rel="noopener noreferrer" ãè¨å®ãããã«ãã¼é¢æ° 101 const setTargetBlank = (className) => { 102 link.setAttribute("target", "_blank"); 103 link.setAttribute("rel", "noopener noreferrer"); 104 if (className) { 105 link.classList.add(className); 106 } 107 }; 108 109 const linkText = link.textContent; 110 111 // æ£è¦è¡¨ç¾: [æ°å] ã¨ãããã¿ã¼ã³ã«ãããããã㤠M ã K ãå«ã¾ãã¦ããªãå ´å 112 // ä¾: [259] ã¯ããããããã[1M] ã [500K] ã¯ãããããªã 113 const sizeMatch = linkText.match(/\[(\d+)\]/); 114 115 if (sizeMatch) { 116 const fullMatch = sizeMatch[0]; // "[259]" 117 const numericValue = sizeMatch[1]; // "259" 118 119 // [æ°å] ã [æ°åK] ã«ç½®æãã¦ããã¹ããæ´æ° 120 link.innerHTML = link.innerHTML.replace(fullMatch, `[${numericValue}K]`); 121 } 122 // --- ãã¡ã¤ã«æ¡å¼µåã§èå¥ ---
123 const fileMatch = url.match(/\.(pdf|doc|docx|xls|xlsx|zip)$/i); 124 if (fileMatch) { 125 const extension = fileMatch[1].toLowerCase(); 126 127 // èªã¿ä¸ãç¨ã®ãããã³ã° 128 const extensionNames = { 129 pdf: "PDFãã¡ã¤ã«", 130 doc: "Wordãã¡ã¤ã«", 131 docx: "Wordãã¡ã¤ã«", 132 xls: "Excelãã¡ã¤ã«", 133 xlsx: "Excelãã¡ã¤ã«", 134 zip: "ZIPå§ç¸®ãã¡ã¤ã«", 135 }; 136 137 const fileTypeDescription = extensionNames[extension] || "ãã¡ã¤ã«"; 138 139 // ãä¿®æ£çããã©ã¦ã¶èªã¿ä¸ãã«ãèªèããããéæããã¹ãããçæ 140 const readableSuffix = document.createElement("span"); 141 readableSuffix.className = "visual-hidden-text"; // æ°ããã¯ã©ã¹å 142 readableSuffix.textContent = ` (${fileTypeDescription})`; 143 144 link.appendChild(readableSuffix); 145 146 link.classList.add("file-link", `file-link-${extension}`); 147 setTargetBlank(); 148 return; 149 } 150 151 // --- å¤é¨ãªã³ã¯ï¼ãã¡ã¤ã³ãç°ãªãå ´åï¼ã§èå¥ --- 152 // URLã http:// ã¾ã㯠https:// ã§å§ã¾ãããã¤ç¾å¨ã®ãã¡ã¤ã³ãå«ã¾ãªãå ´å 153 if ( 154 url.startsWith("http") && 155 url.toLowerCase().indexOf(currentHostname) === -1 156 ) { 157 link.classList.add("external-link"); 158 setTargetBlank(); 159 } 160 }); 161 162 // ========================================================= 163 // 2. ãããã¸æ»ããã¿ã³ã®è¿½å ã¨DOMæä½ 164 // ========================================================= 165 166 // a. ããã¿ã¼ã¸ã®ããããã¸æ»ãããã¿ã³ã®è¿½å 167 if (footer) { 168 const toTopDiv = document.createElement("div"); 169 toTopDiv.className = "to_top"; 170 toTopDiv.innerHTML = 171 '<a href="#" id="totop"><i class="fa-solid fa-arrow-up"></i></a>'; 172 footer.appendChild(toTopDiv); 173 toTopButtonContainer = toTopDiv; // å¾ã§ä½¿ç¨ããããã«ä¿å 174 } 175 176 // b. ããããã¸æ»ãããã¿ã³ã®ã¯ãªãã¯å¦ç (ã¹ã ã¼ãºã¹ã¯ãã¼ã«) 177 const toTopLink = document.getElementById("totop"); 178 if (toTopLink) { 179 toTopLink.addEventListener("click", (e) => { 180 e.preventDefault(); 181 window.scrollTo({ 182 top: 0, 183 behavior: "smooth", 184 }); 185 }); 186 } 187 188 // ========================================================= 189 // 3. ã¹ã¯ãã¼ã«ã¤ãã³ãã®å¦ç 190 // ========================================================= 191 window.addEventListener("scroll", () => { 192 const scrollY = window.scrollY; 193 194 // ããããã¼å¦çã 195 if (header) { 196 if (scrollY > 10) { 197 header.classList.add("bg"); 198 header.classList.add("hide-header"); 199 } else { 200 header.classList.remove("bg"); 201 header.classList.remove("hide-header"); 202 } 203 } 204 205 // ããããã¸æ»ããã¿ã³ã®è¡¨ç¤º/é表示ã 206 if (toTopButtonContainer) { 207 // ã¹ã¯ãã¼ã«éã300pxãè¶ ããã表示 208 if (scrollY > 300) { 209 toTopButtonContainer.classList.add("fadein"); 210 } else { 211 toTopButtonContainer.classList.remove("fadein"); 212 } 213 } 214 }); 215 216 // ========================================================= 217 // 4. ãã¼ãã«åã®ã¯ã©ã¹ä»ä¸å¦ç 218 // ========================================================= 219 const figureElement = document.querySelector("figure.wp-block-table"); 220 221 if (figureElement) { 222 const shouldSkipTable = 223 figureElement.classList.contains("nowrap") || 224 figureElement.classList.contains("timetable"); 225 226 if (!shouldSkipTable) { 227 const tableContainer = figureElement.querySelector("table"); 228 229 if (tableContainer) { 230 if (!tableContainer.classList.contains("has-fixed-layout")) { 231 applyClassToFirstAndLastColumns(tableContainer); 232 } 233 } 234 } 235 } 236 237 // ========================================================= 238 // 5. ã°ãã¼ãã«ã¡ãã¥ã¼ã®ã«ã¬ã³ã表示å¦ç 239 // ========================================================= 240 const globalMenuLinks = document.querySelectorAll(".global-menu ul li a"); 241 const currentPath = window.location.pathname.replace(/\/$/, "") || "/"; 242 243 globalMenuLinks.forEach((link) => { 244 const href = link.getAttribute("href"); 245 if (!href) return; 246 247 try { 248 const linkUrl = new URL(href, window.location.origin); 249 const linkPath = linkUrl.pathname.replace(/\/$/, "") || "/"; 250 251 if (linkPath === currentPath) { 252 link.classList.add("current"); 253 } 254 } catch (e) { 255 console.error("Invalid URL in global menu:", href); 256 } 257 }); 258 259 // ========================================================= 260 // 6. ãç¥ããã»ã¯ã·ã§ã³ã®ã¿ãåãæ¿ãï¼ãã£ã¨è¦ãæ©è½ 261 // ========================================================= 262 const newsSection = document.getElementById("news"); 263 264 if (newsSection) {
265 // ã³ã³ãã³ããããã¯ã®åå¾ 266 const contentDivs = Array.from( 267 newsSection.querySelectorAll(".news-right-col > .wp-block-group"), 268 ); 269 const tabs = newsSection.querySelectorAll( 270 ".news-left-col .wp-block-list li", 271 ); 272 273 // ãã¿ã³è¦ç´ ã®åå¾ 274 const expandBtnContainer = newsSection.querySelector(".news-expand-btn"); 275 const expandBtn = expandBtnContainer 276 ? expandBtnContainer.querySelector(".wp-block-button__link") 277 : null; 278 279 // --- åæåå¦ç --- 280 contentDivs.forEach((div) => (div.style.display = "none")); 281 282 const allContent = contentDivs.find((div) => 283 div.classList.contains("list-all"), 284 ); 285 if (allContent) allContent.style.display = "block"; 286 287 tabs.forEach((tab) => { 288 if (tab.classList.contains("list-all")) tab.classList.add("active"); 289 }); 290 291 // --- 颿°: ãã¿ã³ã®ç¶æ ããªã»ãããã --- 292 const resetExpandButton = () => { 293 if (expandBtn) { 294 expandBtn.textContent = "ãç¥ãã表示ãå¢ãã"; 295 expandBtn.classList.remove("is-open"); 296 } 297 if (expandBtnContainer) { 298 expandBtnContainer.style.display = "block"; // 常ã«è¡¨ç¤ºãã¦ãã 299 } 300 }; 301 302 // --- ã¿ãã¯ãªãã¯å¦ç ---
303 tabs.forEach((tab) => { 304 tab.addEventListener("click", function () { 305 tabs.forEach((t) => t.classList.remove("active")); 306 this.classList.add("active"); 307 308 let targetClass = null; 309 this.classList.forEach((cls) => { 310 if (cls.startsWith("list-")) targetClass = cls; 311 }); 312 313 if (targetClass) { 314 // å ¨ã³ã³ãã³ããé表示ï¼å±éç¶æ ãªã»ãã 315 contentDivs.forEach((div) => { 316 div.style.display = "none"; 317 div.classList.remove("is-expanded"); 318 }); 319 320 // ãã¿ã³ã®ç¶æ ããªã»ããï¼éè¦ï¼ã¿ããå¤ããããå¢ãããã«æ»ãï¼ 321 resetExpandButton(); 322 323 const targetDiv = contentDivs.find((div) => 324 div.classList.contains(targetClass), 325 ); 326 if (targetDiv) { 327 targetDiv.style.opacity = 0; 328 targetDiv.style.display = "block"; 329 requestAnimationFrame(() => { 330 targetDiv.style.transition = "opacity 0.5s ease"; 331 targetDiv.style.opacity = 1; 332 }); 333 } 334 } 335 }); 336 }); 337 338 // --- ããç¥ãã表示ãå¢ãã/æ¸ããããã¿ã³å¦ç --- 339 if (expandBtn) { 340 expandBtn.addEventListener("click", function (e) { 341 e.preventDefault(); 342 343 // ç¾å¨è¡¨ç¤ºããã¦ããã³ã³ãã³ããæ¢ã 344 const visibleDiv = contentDivs.find( 345 (div) => div.style.display !== "none", 346 ); 347 348 if (visibleDiv) { 349 // ãã§ã«éãã¦ããããã§ã㯠350 if (visibleDiv.classList.contains("is-expanded")) { 351 // â¼ éããã¨ãã®å¦ç 352 visibleDiv.classList.remove("is-expanded"); 353 this.textContent = "ãç¥ãã表示ãå¢ãã"; // ããã¹ã夿´ 354 this.classList.remove("is-open"); // ã¢ã¤ã³ã³ç¨ã¯ã©ã¹åé¤ 355 356 // ãªãã·ã§ã³: éããã¨ãã«ãªã¹ãã®å é ä»è¿ã¸ã¹ã¯ãã¼ã«ããããªãããã«è¨è¿° 357 // visibleDiv.scrollIntoView({ behavior: 'smooth', block: 'start' }); 358 } else { 359 // â¼ éãã¨ãã®å¦ç 360 visibleDiv.classList.add("is-expanded"); 361 this.textContent = "ãç¥ããè¡¨ç¤ºãæ¸ãã"; // ããã¹ã夿´ 362 this.classList.add("is-open"); // ã¢ã¤ã³ã³ç¨ã¯ã©ã¹è¿½å 363 } 364 } 365 }); 366 } 367 } 368 369 // ========================================================= 370 // 7. æ¤ç´¢ããã¯ã¹ã¨ãªã³ã¯å¦ç (èªåçæ & æååãæ¿ã) 371 // ========================================================= 372 const searchLinkContainer = document.querySelector(".link_search"); 373 const searchLink = searchLinkContainer 374 ? searchLinkContainer.querySelector("a") 375 : null; 376 377 if (searchLink && header) { 378 // A. æ¤ç´¢ããã¯ã¹ã®HTMLãçæãã¦ãããã¼ã«è¿½å 379 380 // 1. ããããã¼ã¸ã®URLããã´ããèªååå¾ããï¼ãªããã°ç´æ¥ /nise/ ãæå®ï¼ 381 const logoAnchor = document.querySelector(".logo-area figure a"); 382 const homeUrl = logoAnchor ? logoAnchor.getAttribute("href") : "/"; 383 384 // 2. action屿§ã« homeUrl ãåãè¾¼ã 385 const searchBoxHtml = ` 386 <div id="header-search-box" aria-hidden="true" style="display: none;"> 387 <div class="search-box-inner"> 388 <form role="search" method="get" class="search-form" action="${homeUrl}"> 389 <label> 390 <span class="screen-reader-text">æ¤ç´¢:</span> 391 <input type="search" class="search-field" placeholder="ãã¼ã¯ã¼ããå ¥å..." value="" name="s" /> 392 </label> 393 <button type="submit" class="search-submit" aria-label="æ¤ç´¢"> 394 <i class="fas fa-search"></i> 395 </button> 396 </form> 397 <button id="search-close-btn" aria-label="éãã"><i class="fas fa-times"></i></button> 398 </div> 399 </div> 400 `; 401 402 // ãããã¼ã®æ«å°¾ã«æ¿å ¥ 403 header.insertAdjacentHTML("beforeend", searchBoxHtml); 404 405 const searchBox = document.getElementById("header-search-box"); 406 const searchInput = searchBox.querySelector("input[type='search']"); 407 const closeBtn = document.getElementById("search-close-btn"); 408 409 // B. ãã¼ã¸ã¿ã¤ãã®å¤å® 410 const isHome = document.body.classList.contains("home"); 411 const isSearch = document.body.classList.contains("search"); // æ¤ç´¢çµæãã¼ã¸ãã©ãã 412 413 if (isSearch) { 414 // --- ãã¿ã¼ã³0: æ¤ç´¢çµæãã¼ã¸ã®å ´å (ã¯ãªãã¯ç¡å¹å) --- 415 searchLink.removeAttribute("href"); // ãªã³ã¯å ãåé¤ 416 searchLink.style.pointerEvents = "none"; // ã¯ãªãã¯ã§ããªãããã«ãã 417 searchLink.style.cursor = "default"; // ã«ã¼ã½ã«ãéå¸¸ã«æ»ã 418 searchLink.style.opacity = "0.5"; // å°ãèããã¦ç¡å¹æãåºã 419 searchLink.setAttribute("aria-disabled", "true"); 420 } else if (isHome) { 421 // --- ãã¿ã¼ã³1: ããããã¼ã¸ã®å ´å (ãã¼ã¸å ãªã³ã¯) --- 422 423 // hrefãæ¸ãæã 424 searchLink.setAttribute("href", "#search"); 425 426 searchLink.addEventListener("click", (e) => { 427 e.preventDefault(); 428 const targetSection = document.getElementById("search");
429 if (targetSection) { 430 // ãããã¼ã®é«ããèæ ®ãã¦ã¹ã¯ãã¼ã« 431 const headerHeight = header.offsetHeight; 432 const targetPosition = 433 targetSection.getBoundingClientRect().top + 434 window.scrollY - 435 headerHeight; 436 437 window.scrollTo({ 438 top: targetPosition, 439 behavior: "smooth", 440 }); 441 } 442 }); 443 } else { 444 // --- ãã¿ã¼ã³2: ãã®ä»ã®ä¸å±¤ãã¼ã¸ã®å ´å (æ¤ç´¢ããã¯ã¹è¡¨ç¤ºåãæ¿ã) --- 445 446 // â 追å : ã¢ã¯ã»ã·ããªãã£å¯¾çããã¼ã¸å ãªã³ã¯ãè§£é¤ãããã¿ã³ã¨ãã¦ã®å½¹å²ãæç¤ºãã 447 searchLink.setAttribute("href", "javascript:void(0);"); // ã¾ã㯠"#" ã§ãè¯ãã javascript:void(0) ãç¢ºå® 448 searchLink.setAttribute("role", "button"); // ãªã³ã¯ã§ã¯ãªããã¿ã³ã§ãããã¨ãä¼ãã 449 searchLink.setAttribute("aria-haspopup", "true"); // æ¼ãã¨ä½ãï¼æ¤ç´¢ããã¯ã¹ï¼ãåºããã¨ãä¼ãã 450 searchLink.setAttribute("aria-expanded", "false"); // ç¾å¨ã¯éãã¦ãããã¨ãä¼ãã 451 452 const toggleSearchBox = (show) => { 453 if (show) { 454 searchBox.style.display = "block"; 455 searchBox.setAttribute("aria-hidden", "false"); 456 searchLink.setAttribute("aria-expanded", "true"); // â ç¶æ ãæ´æ° 457 requestAnimationFrame(() => { 458 searchBox.classList.add("is-visible"); 459 }); 460 if (searchInput) searchInput.focus(); 461 } else { 462 searchBox.classList.remove("is-visible"); 463 searchBox.setAttribute("aria-hidden", "true"); 464 searchLink.setAttribute("aria-expanded", "false"); // â ç¶æ ãæ´æ° 465 setTimeout(() => { 466 searchBox.style.display = "none"; 467 }, 300); 468 } 469 }; 470 471 // æ¤ç´¢ã¢ã¤ã³ã³ã¯ãªãã¯æ 472 searchLink.addEventListener("click", (e) => { 473 e.preventDefault(); 474 const isHidden = searchBox.style.display === "none";
475 toggleSearchBox(isHidden); 476 }); 477 478 // éãããã¿ã³ã¯ãªãã¯æ 479 if (closeBtn) { 480 closeBtn.addEventListener("click", (e) => { 481 e.preventDefault(); 482 toggleSearchBox(false); 483 }); 484 } 485 486 // å¤å´ãã¯ãªãã¯ãããéããå¦ç 487 document.addEventListener("click", (e) => { 488 if ( 489 searchBox.style.display !== "none" && 490 !searchBox.contains(e.target) && 491 !searchLinkContainer.contains(e.target) 492 ) { 493 toggleSearchBox(false); 494 } 495 }); 496 } 497 } 498 499 // ========================================================= 500 // 8. ã¿ã°ã®ããã¹ãã«åºã¥ãã¯ã©ã¹ä»ä¸ (èªåè²åã) 501 // ========================================================= 502 const tagLinks = document.querySelectorAll(".taxonomy-post_tag a"); 503 504 // ããã¹ãã¨ä»ä¸ãããã¯ã©ã¹ã®ãããã³ã°è¨å® 505 const tagMap = { 506 ãç¥ãã: "tag-news", 507 ã¤ãã³ã: "tag-event", 508 ç ç©¶: "tag-study", 509 ç ä¿®: "tag-training", 510 æ å ±æä¾: "tag-information", 511 }; 512 513 tagLinks.forEach((link) => { 514 // åå¾ã®ç©ºç½ãåé¤ãã¦ããã¹ããåå¾ 515 const text = link.textContent.trim(); 516 const className = tagMap[text]; 517 518 if (className) { 519 // 1. ãªã³ã¯(aã¿ã°)èªä½ã«ã¯ã©ã¹ãä»ä¸ 520 link.classList.add(className); 521 522 // 2. 親㮠li.wp-block-post ã«ãã¯ã©ã¹ãä»ä¸ 523 // (ããã«ããæ¢åã®CSSè¨è¨ã§ãã li.tag-event ... ãæ©è½ãã¾ã) 524 const parentLi = link.closest("li.wp-block-post"); 525 if (parentLi) { 526 parentLi.classList.add(className); 527 } 528 } 529 }); 530 531 // ========================================================= 532 // 9. ãã´ã¨ãªã¢å ¨ä½ã¸ã®ãªã³ã¯è¿½å ï¼æ¹è¯çï¼ 533 // ========================================================= 534 const initLogoLinks = () => { 535 // ã追å ãURLã« /english/ ãå«ã¾ãã¦ããå ´åã¯å¦çã䏿ãã 536 if (window.location.pathname.includes("/english/")) { 537 return; 538 } 539 // å ¨ã¦ã®ãã´ã¨ãªã¢ã対象ã«ãã 540 const logoAreas = document.querySelectorAll(".logo-area"); 541 542 logoAreas.forEach((logoArea) => { 543 // æ¢ã«æå¹ãªãªã³ã¯ï¼ä¸èº«ããããªã³ã¯ï¼ãè¨å®ããã¦ããå ´åã¯ã¹ããã 544 if (logoArea.querySelector("a[data-custom-link='true']")) return; 545 546 // ãªã³ã¯å URLã®æ±ºå® 547 // 1. æ¢åã®aã¿ã°ãããã°ãã®hrefãåå¾ 548 // 2. ãªããã°ãµã¤ãããã (https://joc30.xsrv.jp/nise/) 549 const existingAnchor = logoArea.querySelector("a"); 550 const targetUrl = existingAnchor 551 ? existingAnchor.getAttribute("href") 552 : "/"; 553 554 // æ¢åã®ã空ã®aã¿ã°ããªã©ã¯åé¤ãã¦ä¸èº«ãæ´çãã 555 const nav = logoArea.querySelector("nav"); // ããã²ã¼ã·ã§ã³ï¼ã¡ãã¥ã¼ï¼ã¯ãªã³ã¯ã«å«ããªã 556 const figure = logoArea.querySelector("figure"); 557 const logoText = logoArea.querySelector(".logo-text"); 558 559 // ãªã³ã¯ã«å«ããè¦ç´ ï¼ç»åã¨ããã¹ãï¼ãç¹å® 560 const linkableElements = [figure, logoText].filter((el) => el !== null); 561 562 if (linkableElements.length > 0) { 563 // æ°ãããªã³ã¯ã使 564 const wrapperLink = document.createElement("a"); 565 wrapperLink.href = targetUrl; 566 wrapperLink.setAttribute("data-custom-link", "true"); 567 wrapperLink.style.display = "contents"; // ã¬ã¤ã¢ã¦ãå´©ã鲿¢ 568 wrapperLink.style.textDecoration = "none"; 569 wrapperLink.style.color = "inherit"; 570 571 // ç»åã¨ããã¹ãããªã³ã¯ã®ä¸ã«ç§»å 572 linkableElements.forEach((el) => { 573 // æ¢åã®aã¿ã°ãããã°ãã®ä¸èº«ã ãåãåºãããªããã°è¦ç´ ãã¨ç§»å 574 const innerA = el.querySelector("a"); 575 if (innerA) { 576 // 空ã®aã¿ã°ãæ¢åã®aã¿ã°ãæ¶ãã¦ä¸èº«ãç´æ¥wrapperã«ç§»å 577 while (innerA.firstChild) { 578 wrapperLink.appendChild(innerA.firstChild); 579 } 580 innerA.remove(); 581 } 582 wrapperLink.appendChild(el); 583 }); 584 585 // ãã´ã¨ãªã¢ã®å é ï¼ããã²ã¼ã·ã§ã³ã®åï¼ã«ãªã³ã¯ãæ¿å ¥ 586 logoArea.insertBefore(wrapperLink, logoArea.firstChild); 587 } 588 }); 589 }; 590 591 initLogoLinks(); 592 593 // ========================================================= 594 // 10. ãã³ãããªã¹ãã®ç§»å (h1ã®ä¸ã¸) 595 // ========================================================= 596 const breadcrumb = document.querySelector(".bread"); 597 const pageTitle = document.querySelector("h1"); 598 599 // ãã³ãããªã¹ãã¨h1ã®ä¸¡æ¹ãåå¨ããå ´åã®ã
599¿å®è¡ 600 if (breadcrumb && pageTitle) { 601 // h1è¦ç´ ã®ãç´å¾ (afterend)ãã«ãã³ãããªã¹ããæ¿å ¥ï¼ç§»åï¼ãã 602 pageTitle.insertAdjacentElement("afterend", breadcrumb); 603 } 604 605 // ========================================================= 606 // 11. H1ãJSè¨ç®(px)ã§å¼·å¶çã«å ¨å¹ ã«ãã 607 // ========================================================= 608 const mainH1 = document.querySelector("main h1"); 609 610 if (mainH1) { 611 const applyFullWidthStyles = () => { 612 // 1. ç»é¢ã®å¹ ï¼ã¹ã¯ãã¼ã«ãã¼ãå«ã¾ãªãæç»é åï¼ãåå¾ 613 const windowWidth = document.documentElement.clientWidth; 614 const halfWidth = windowWidth / 2; 615 616 // 2. ã¹ã¿ã¤ã«ã !important ä»ãã§é©ç¨ 617 // width: ç»é¢å¹ px 618 mainH1.style.setProperty("width", `${windowWidth}px`, "important"); 619 620 // ä¸å¤®é ç½®ã®ãã¸ãã¯: 親è¦ç´ ã®å¹ ã«é¢ä¿ãªãç»é¢ä¸å¤®ã«é ç½® 621 mainH1.style.setProperty("position", "relative", "important"); 622 mainH1.style.setProperty("left", "50%", "important"); 623 mainH1.style.setProperty("right", "auto", "important"); 624 625 // ãã¼ã¸ã³ã§å·¦ã«ç»é¢ååæ»ã 626 mainH1.style.setProperty("margin-left", `-${halfWidth}px`, "important"); 627 mainH1.style.setProperty("margin-right", `-${halfWidth}px`, "important"); 628 629 // ã¬ã¤ã¢ã¦ãå´©ã鲿¢ 630 mainH1.style.setProperty("box-sizing", "border-box", "important"); 631 mainH1.style.setProperty("max-width", "none", "important"); // WPãmax-widthãå ¥ãã¦ããå ´åã®å¯¾ç 632 633 // 親è¦ç´ ã®å½±é¿ã§æ¨ªã¹ã¯ãã¼ã«ãã¼ãåºãªãããã« body ã®æ¨ªã¹ã¯ãã¼ã«ãæå¶ 634 document.body.style.overflowX = "hidden"; 635 }; 636 637 // 親è¦ç´ (main)ã® overflow: hidden ãããã¨å·¦å³ãåããããè§£é¤ 638 if (mainContent) { 639 mainContent.style.setProperty("overflow", "visible", "important"); 640 } 641 642 // å®è¡ 643 applyFullWidthStyles(); 644 645 // ç»é¢ãªãµã¤ãºæã«åè¨ç®ãã¦é©ç¨ 646 window.addEventListener("resize", () => { 647 // ãªãµã¤ãºå¦çã¯é »ç¹ã«èµ°ããããrequestAnimationFrameã§æé©å 648 requestAnimationFrame(applyFullWidthStyles); 649 }); 650 } 651 652 // ========================================================= 653 // ãä¿®æ£çã12. ã¹ããç¨ãã¼ãã«ï¼ä¸é¨ã«ã¹ã¯ãã¼ã«ãã¼ã¨ãã³ãã表示 654 // ========================================================= 655 const handleTableUpperScroll = () => { 656 const isMobile = window.innerWidth <= 768; 657 const tables = document.querySelectorAll("figure.wp-block-table"); 658 659 tables.forEach((fig) => { 660 // 1. ã¹ã¯ãã¼ã«ãã³ãï¼æåï¼ã®å¦ç 661 let hint = fig.querySelector(".scroll-hint"); 662 if (isMobile && fig.scrollWidth > fig.clientWidth) { 663 if (!hint) { 664 hint = document.createElement("span"); 665 hint.className = "scroll-hint"; 666 hint.textContent = isEn ? "Scroll â¶" : "ã¹ã¯ãã¼ã« â¶"; 667 fig.prepend(hint); // ãã¼ãã«ã®ä¸é¨ï¼ä¸ï¼ã«é ç½® 668 669 fig.addEventListener( 670 "scroll", 671 function fadeHint() { 672 if (fig.scrollLeft > 20) { 673 hint.style.opacity = "0"; 674 hint.style.pointerEvents = "none"; 675 fig.removeEventListener("scroll", fadeHint); 676 } 677 }, 678 { passive: true }, 679 ); 680 } 681 } else if (hint) { 682 hint.remove(); 683 } 684 685 // 2. ä¸é¨ã¹ã¯ãã¼ã«ãã¼ï¼ããã¼ï¼ã®å¦ç 686 let doubleScroll = fig.previousElementSibling; 687 if (isMobile && fig.scrollWidth > fig.clientWidth) { 688 // ããã¼è¦ç´ ãã¾ã ãªããã°ä½æ 689 if ( 690 !doubleScroll || 691 !doubleScroll.classList.contains("double-scroll-wrapper") 692 ) { 693 doubleScroll = document.createElement("div"); 694 doubleScroll.className = "double-scroll-wrapper"; 695 doubleScroll.innerHTML = '<div class="double-scroll-inner"></div>'; 696 fig.parentNode.insertBefore(doubleScroll, fig); 697 } 698 699 const inner = doubleScroll.querySelector(".double-scroll-inner"); 700 // ãã¼ãã«ã®ãä¸èº«ã®å¹ ããããã¼ã®ä¸èº«ã«é©ç¨ 701 inner.style.width = fig.scrollWidth + "px"; 702 703 // åæå¦çï¼ä¸ãåãã°ä¸ãåã 704 doubleScroll.onscroll = () => {
705 fig.scrollLeft = doubleScroll.scrollLeft; 706 }; 707 // åæå¦çï¼ä¸ãåãã°ä¸ãåã 708 fig.onscroll = () => { 709 doubleScroll.scrollLeft = fig.scrollLeft; 710 }; 711 } else if ( 712 doubleScroll && 713 doubleScroll.classList.contains("double-scroll-wrapper") 714 ) { 715 doubleScroll.remove(); 716 } 717 }); 718 }; 719 720 handleTableUpperScroll(); 721 window.addEventListener("resize", () => { 722 requestAnimationFrame(handleTableUpperScroll); 723 }); 724 725 // ========================================================= 726 // ããããã°çã13. ããã·ã¥ãªã³ã¯ã«ããã¢ã³ã¼ãã£ãªã³ã®èªåå±é 727 // =========================================================// ========================================================= 728 // çµ±åçï¼H2ã¢ã³ã¼ãã£ãªã³å¶å¾¡ ï¼ ããã·ã¥ãªã³ã¯èªåå±é 729 // ========================================================= 730 const accordionTriggers = document.querySelectorAll( 731 "h2.js-accordion-trigger", 732 ); 733 734 accordionTriggers.forEach((trigger) => { 735 trigger.setAttribute("tabindex", "0"); 736 trigger.setAttribute("role", "button"); 737 738 // åæç¶æ ã®è¨å® 739 const shouldOpen = 740 trigger.classList.contains("is-open") || accordionTriggers.length === 1; 741 if (!trigger.hasAttribute("aria-expanded")) { 742 trigger.setAttribute("aria-expanded", shouldOpen ? "true" : "false"); 743 } 744 if (shouldOpen) { 745 trigger.classList.add("is-active"); 746 } 747 748 // ãã°ã«é¢æ° 749 const toggleAccordion = function (e) { 750 if (e && e.target && e.target.tagName.toLowerCase() === "a") return; 751 752 const isActive = trigger.classList.toggle("is-active"); 753 trigger.setAttribute("aria-expanded", isActive ? "true" : "false"); 754 755 // ãçµ±åãã¤ã³ããããç´å¾ã«WPæ¨æºã¢ã³ã¼ãã£ãªã³ãããã°ããããé£åããã 756 const nextAccordion = trigger.nextElementSibling?.querySelector( 757 "button.wp-block-accordion-heading__toggle", 758 ); 759 if (nextAccordion) { 760 // æ¨æºã¢ã³ã¼ãã£ãªã³ã®ç¶æ ã¨H2ã®ç¶æ ãåæããã 761 const isNowActive = trigger.classList.contains("is-active"); 762 if ( 763 nextAccordion.getAttribute("aria-expanded") !== String(isNowActive) 764 ) { 765 nextAccordion.click(); 766 } 767 } 768 }; 769 770 trigger.addEventListener("click", toggleAccordion); 771 trigger.addEventListener("keydown", (e) => { 772 if (e.key === "Enter" || e.key === " ") { 773 if (e.key === " ") e.preventDefault(); 774 toggleAccordion(e); 775 } 776 }); 777 }); 778 779 // --- ããã·ã¥ãªã³ã¯ãããå ´åã«èªåã§éãå¦ç --- 780 const handleInitialHash = () => { 781 const hash = window.location.hash; 782 if (!hash) return; 783 784 const target = document.querySelector(hash); 785 if (!target) return; 786 787 // 1. ã¿ã¼ã²ãããH2ï¼ããªã¬ã¼ï¼ãªããããã¯ãªã㯠788 if (target.classList.contains("js-accordion-trigger")) { 789 setTimeout(() => { 790 target.click(); // ä¸è¨ã®toggleAccordionãèµ°ã 791 }, 100); 792 } 793 }; 794 795 handleInitialHash(); 796 window.addEventListener("hashchange", handleInitialHash); 797 798 // --- DOMContentLoaded ã¤ãã³ããªã¹ãã¼ã®çµäº --- 799}); 800 801// ========================================================= 802// 颿°å®ç¾©: ãã¼ãã«ã®æåã¨æå¾ã®åã«ã¯ã©ã¹ãä»ä¸ 803// ========================================================= 804function applyClassToFirstAndLastColumns( 805 tableElement, 806 firstClassName = "first-col", 807 lastClassName = "last-col", 808) { 809 const rows = tableElement.querySelectorAll("tr"); 810 811 // 1. æå¤§åæ°ãè¨ç®ãã 812 let maxCols = 0; 813 rows.forEach((row) => { 814 const rowLength = row.querySelectorAll("th, td").length; 815 if (rowLength > maxCols) { 816 maxCols = rowLength; 817 } 818 }); 819 820 // 2. ãã©ãã«ã¼ã®åæè¨å® 821 const firstTrackers = new Map(); 822 const lastTrackers = new Map(); 823 824 rows.forEach((row) => { 825 let logicalColIndex = 0; 826 const cells = row.querySelectorAll("th, td"); 827 828 // A. First Child Logic 829 while (firstTrackers.get(logicalColIndex) > 0) { 830 firstTrackers.set( 831 logicalColIndex, 832 firstTrackers.get(logicalColIndex) - 1, 833 ); 834 logicalColIndex++; 835 } 836
837 cells.forEach((cell) => { 838 while (firstTrackers.get(logicalColIndex) > 0) { 839 firstTrackers.set( 840 logicalColIndex, 841 firstTrackers.get(logicalColIndex) - 1, 842 ); 843 logicalColIndex++; 844 } 845 846 if (logicalColIndex === 0) { 847 cell.classList.add(firstClassName); 848 } 849 850 const rowspan = parseInt(cell.getAttribute("rowspan")) || 1; 851 const colspan = parseInt(cell.getAttribute("colspan")) || 1; 852 853 if (rowspan > 1) { 854 if (colspan === 1) { 855 firstTrackers.set(logicalColIndex, rowspan - 1); 856 } else { 857 for (let c = 0; c < colspan; c++) { 858 firstTrackers.set(logicalColIndex + c, rowspan - 1); 859 } 860 } 861 } 862 logicalColIndex += colspan; 863 }); 864 865 // B. Last Child Logic 866 let lastColIndex = maxCols - 1; 867 while (lastTrackers.get(lastColIndex) > 0) { 868 lastTrackers.set(lastColIndex, lastTrackers.get(lastColIndex) - 1); 869 lastColIndex--; 870 } 871 872 let currentLogicalIndex = maxCols; 873 for (let i = cells.length - 1; i >= 0; i--) { 874 const cell = cells[i]; 875 const colspan = parseInt(cell.getAttribute("colspan")) || 1; 876 const rowspan = parseInt(cell.getAttribute("rowspan")) || 1; 877 878 currentLogicalIndex -= colspan; 879 lastColIndex = currentLogicalIndex + colspan - 1; 880 881 while (lastTrackers.get(lastColIndex) > 0) { 882 lastTrackers.set(lastColIndex, lastTrackers.get(lastColIndex) - 1); 883 lastColIndex--; 884 } 885 886 if (lastColIndex === maxCols - 1) { 887 cell.classList.add(lastClassName); 888 } 889 890 if (rowspan > 1) { 891 for (let c = 0; c < colspan; c++) { 892 lastTrackers.set(currentLogicalIndex + c, rowspan - 1); 893 } 894 } 895 } 896 897 // C. Clean up 898 const cleanUpTracker = (tracker) => { 899 for (let [key, value] of tracker.entries()) { 900 if (value <= 0) { 901 tracker.delete(key); 902 } 903 } 904 }; 905 cleanUpTracker(firstTrackers); 906 cleanUpTracker(lastTrackers); 907 }); 908}
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.