PageSourceSearch

http://www.kyobunkwan.co.jp/themes/kyobunkwan@site/js/search_list_page.js?date=20260928092350

js kyobunkwan.co.jp collected 2026-10-01 10:34:17 UTC 8,044 bytes, 208 lines download raw bytes

1(function() {
2  'use strict';
3
4  // --- 環境設定 ---
5  const getRootPath = () => {
6    const path = window.location.pathname;
7    if (path.startsWith('/kyobunkwan_corp_dev/')) {
8      return window.location.origin + '/kyobunkwan_corp_dev/';
9    }
10    return window.location.origin + '/';
11  };
12
13  // --- 補助関数 ---
14  const waitForHtmx = (callback, count = 0) => {
15    if (typeof htmx !== 'undefined') {
16      document.body.addEventListener('htmx:configRequest', (event) => {
17        const token = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');
18        if (token) {
19          event.detail.headers['X-Csrf-Token'] = token;
20        }
21      });
22      callback(htmx);
23    } else if (count < 50) {
24      setTimeout(() => waitForHtmx(callback, count + 1), 100);
25    } else {
26      console.error('HTMXのタイムアウト');
27    }
28  };
29
30  const CHILD_BLOGS = ['jbook', 'xbook', 'ein-karem', 'narnia'];
31
32  const isChildBlogPage = () => {
33    const path = window.location.pathname;
34    return CHILD_BLOGS.some(b => path.includes(`/${b}/`));
35  };
36
37  const getEntrySummaryHtmxPath = (baseUrl) => {
38    const module = isChildBlogPage()
39      ? 'Entry_Summary_Eventnews_List.html'
40      : 'Entry_Summary_Eventnews-parent_List.html';
41    return baseUrl.replace(/\/$/, '') + '/tpl/include/htmx/' + module;
42  };
43
44  const buildFetchUrl = (blogCode, categoryCode, tagName) => {
45    const root = getRootPath();
46    const blogPart = blogCode ? `${blogCode}/` : '';
47    const catPart = (categoryCode && categoryCode !== 'event-news') ? `${categoryCode}/` : '';
48    const tagPart = tagName ? `tag/${encodeURIComponent(tagName)}/` : '';
49    let url = `${root}${blogPart}event-news/${catPart}${tagPart}`;
50    return url.replace(/([^:])\/{2,}/g, '$1/');
51  };
52
53  // --- 現在のフィルター条件をDOMから読み取る共通関数 ---
54  const getCurrentFilters = () => {
55    const path = window.location.pathname;
56    const pathBlog = CHILD_BLOGS.find(b => path.includes(`/${b}/`)) || '';
57    const blogEl = document.querySelector('.sort_blog .active');
58    const catEl  = document.querySelector('.sort_category .active');
59    const tagEl  = document.querySelector('.sort_tag .active');
60    return {
61      blogCode:     blogEl ? blogEl.getAttribute('data-blog-code') : pathBlog,
62      categoryCode: catEl  ? catEl.getAttribute('data-category-code') : '',
63      tagName:      tagEl  ? tagEl.textContent.trim() : '',
64    };
65  };
66
67  // --- 実行処理 ---
68  document.addEventListener('DOMContentLoaded', function() {
69    const path = window.location.pathname;
70    if (path.endsWith('.html') || !path.includes('/event-news/')) return;
71
72    const params = new URLSearchParams(window.location.search);
73    const blogParam     = params.get('blog') || '';
74    const categoryParam = params.get('category') || '';
75    const tagParam      = params.get('tag') || '';
76
77    if (window.location.search) {
78      window.history.replaceState({}, '', path);
79    }
80
81    if (!blogParam && !categoryParam && !tagParam) return;
82
83    if (blogParam) {
84      const el = document.querySelector(`[data-blog-code="${blogParam}"]`);
85      if (el) el.classList.add('active');
86    }
87    if (categoryParam) {
88      const el = document.querySelector(`[data-category-code="${categoryParam}"]`);
89      if (el) el.classList.add('active');
90    }
91    if (tagParam) {
92      const el = Array.from(document.querySelectorAll('.filter_tag_list'))
93        .find(e => e.textContent.trim() === tagParam);
94      if (el) el.classList.add('active');
95    }
96
97    const fetchUrl = buildFetchUrl(blogParam, categoryParam, tagParam);
98    const htmxPath = getEntrySummaryHtmxPath(fetchUrl);
99    waitForHtmx(htmx => {
100      htmx.ajax('GET', htmxPath, { target: '#entry_list_htmx', swap: 'innerHTML' });
101    });
102  });
103
104  document.addEventListener('click', function(e) {
105
106    // :ページャーのクリック処理 ↓↓↓
107    const pagerEl = e.target.closest('.js-pager-link');
108    if (pagerEl) {
109      e.preventDefault();
110
111      const pagerUrl = pagerEl.getAttribute('data-pager-url');
112      const page     = pagerEl.getAttribute('data-page');
113      const { blogCode, categoryCode, tagName } = getCurrentFilters();
114
115      // ACMSが生成した正しいページURLにtplパスを付加
116      const htmxPath = getEntrySummaryHtmxPath(pagerUrl);
117
118      // ブラウザ表示用URLにフィルター条件+ページ番号をクエリで付加
119      const qp = new URLSearchParams();
120      if (blogCode)                                      qp.set('blog', blogCode);
121      if (categoryCode && categoryCode !== 'event-news') qp.set('category', categoryCode);
122      if (tagName)                                       qp.set('tag', tagName);
123      if (page)                                          qp.set('page', page);
124      const displayUrl = window.location.origin + window.location.pathname + (qp.toString() ? `?${qp}` : '');
125
126      waitForHtmx(htmx => {
127            htmx.ajax('GET', htmxPath, { target: '#entry_list_htmx', swap: 'innerHTML' });
128            window.history.pushState(null, '', displayUrl);
129            window.scrollTo({ top: 0, behavior: 'smooth' });
130          });
131      return;
132    }
133
134// フィルターボタンのクリック処理
135// フィルターボタンのクリック処理
136const el = e.target.closest('.js-blog-select, .js-category-link, .filter_tag_list');
137if (!el) return;
138e.preventDefault();
139
140const isAllBtn = el.classList.contains('all_category') &&
141  (el.classList.contains('js-blog-select') || el.getAttribute('data-category-code') 
141=== 'event-news');
142
143const group = el.closest('.sort_blog, .sort_category, .sort_tag');
144
145if (isAllBtn) {
146  // 全件ボタン:すべてのactiveをリセット
147  document.querySelectorAll('.sort_blog .active, .sort_category .active, .sort_tag .active')
148    .forEach(e => e.classList.remove('active'));
149  el.classList.add('active');
150
151} else if (el.closest('.sort_blog')) {
152  // ブログ:排他制御(外せない)
153  group.querySelectorAll('.active').forEach(e => e.classList.remove('active'));
154  el.classList.add('active');
155
156} else {
157  // カテゴリー・タグ:排他制御+トグル(外せる)
158  const isActive = el.classList.contains('active');
159  group.querySelectorAll('.active').forEach(e => e.classList.remove('active'));
160  if (!isActive) {
161    el.classList.add('active');
162  }
163}
164
165    const path = window.location.pathname;
166    const pathBlog = CHILD_BLOGS.find(b => path.includes(`/${b}/`)) || '';
167    const blogEl = document.querySelector('.sort_blog .active');
168    const catEl  = document.querySelector('.sort_category .active');
169    const tagEl  = document.querySelector('.sort_tag .active');
170    const blogCode     = isAllBtn ? pathBlog : (blogEl ? blogEl.getAttribute('data-blog-code') : pathBlog);
171    const categoryCode = catEl ? catEl.getAttribute('data-category-code') : '';
172    const tagName      = tagEl ? tagEl.textContent.trim() : '';
173
174    const fetchUrl = buildFetchUrl(blogCode, categoryCode, tagName);
175    const htmxPath = getEntrySummaryHtmxPath(fetchUrl);
176
177    const qp = new URLSearchParams();
178    if (blogCode) qp.set('blog', blogCode);
179    if (categoryCode && categoryCode !== 'event-news') qp.set('category', categoryCode);
180    if (tagName) qp.set('tag', tagName);
181    const qs = qp.toString();
182    const displayUrl = window.location.origin + path + (qs ? `?${qs}` : '');
183
184    waitForHtmx(htmx => {
185      htmx.ajax('GET', htmxPath, { target: '#entry_list_htmx', swap: 'innerHTML' });
186      window.history.pushState(null, '', displayUrl);
187    });
188  });
189
190  // More button
191  const moreBtnInit = () => {
192    const btn = document.getElementById('more_btn');
193    if (btn) {
194      btn.addEventListener('click', function() {
195        const list = document.querySelector('.category_lists');
196        if (list) {
197          this.classList.toggle('open');
198          list.classList.toggle('is-active');
199        }
200      });
201    }
202  };
203  if (document.readyState === 'loading') {
204    document.addEventListener('DOMContentLoaded', moreBtnInit);
205  } else {
206    moreBtnInit();
207  }
208})();

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.