PageSourceSearch

https://www.ajec.or.jp/wp/wp-content/themes/ajec3/assets/js/navigation.js?ver=1783995516

js ajec.or.jp collected 2026-10-02 19:07:33 UTC 3,289 bytes, 91 lines download raw bytes

1/**
2 * AJEC3 Navigation
3 * ハンバーガーメニュー制御
4 */
5(function() {
6    'use strict';
7
8    var hamburger = document.getElementById('hamburger');
9    var mobileNav = document.getElementById('mobile-nav');
10
11    if (!hamburger || !mobileNav) {
12        return;
13    }
14
15    function openMenu() {
16        mobileNav.classList.add('is-open');
17        hamburger.classList.add('is-active');
18        hamburger.setAttribute('aria-expanded', 'true');
19        hamburger.setAttribute('aria-label', 'メニューを閉じる');
20        document.body.style.overflow = 'hidden';
21    }
22
23    function closeMenu() {
24        mobileNav.classList.remove('is-open');
25        hamburger.classList.remove('is-active');
26        hamburger.setAttribute('aria-expanded', 'false');
27        hamburger.setAttribute('aria-label', 'メニューを開く');
28        document.body.style.overflow = '';
29    }
30
31    hamburger.addEventListener('click', function() {
32        if (mobileNav.classList.contains('is-open')) {
33            closeMenu();
34        } else {
35            openMenu();
36        }
37    });
38
39    // メニュー内のリンク(サブリスト・CTA含む)をタップしたら閉じる
40    var mobileLinks = mobileNav.querySelectorAll('a');
41    for (var i = 0; i < mobileLinks.length; i++) {
42        mobileLinks[i].addEventListener('click', closeMenu);
43    }
44
45    // アコーディオンは排他開閉(1つ開いたら他は閉じる)
46    var groups = mobileNav.querySelectorAll('.mobile-nav__group details');
47    for (var g = 0; g < groups.length; g++) {
48        groups[g].addEventListener('toggle', function() {
49            if (!this.open) return;
50            for (var k = 0; k < groups.length; k++) {
51                if (groups[k] !== this) {
52                    groups[k].open = false;
53                }
54            }
55        });
56    }
57
58    // 現在地ハイライト: 表示中URLと一致するリンクに .is-current を付け、属するグループを開く
59    // (パス形式のURLのみ対象。クエリ形式はサーバー側の open 判定でカバー)
60    try {
61        var here = location.pathname.replace(/\/$/, '') + location.search;
62        for (var m = 0; m < mobileLinks.length; m++) {
63            var u = new URL(mobileLinks[m].getAttribute('href'), location.origin);
64            if (u.origin !== location.origin) continue;
65            if (u.pathname.replace(/\/$/, '') + u.search === here) {
66                mobileLinks[m].classList.add('is-current');
67                var d = mobileLinks[m].closest('details');
68                if (d) d.open = true;
69            }
70        }
71    } catch (err) { /* URL 非対応環境では現在地表示をスキップ */ }
72
73    // Esc キーで閉じる(フォーカスをボタンに戻す)
74    document.addEventListener('keydown', function(e) {
75        if (e.key === 'Escape' && mobileNav.classList.contains('is-open')) {
76            closeMenu();
77            hamburger.focus();
78        }
79    });
80
81    // リサイズで PC 幅になったら閉じる
82    var resizeTimer;
83    window.addEventListener('resize', function() {
84        clearTimeout(resizeTimer);
85        resizeTimer = setTimeout(function() {
86            if (window.innerWidth >= 1025) {
87                closeMenu();
88            }
89        }, 250);
90    });
91})();

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.