メニューを切り替える
個人設定メニューを切り替える
個人メニューを切り替える
ログインしていません
編集を行うと、IPアドレスが公開されます。

「テンプレート:飲食店検索/script.js」の版間の差分

提供: 川西図鑑
ページの作成:「<html> <script> document.getElementById('searchForm').addEventListener('submit', function (e) { const searchText = document.getElementById('searchText'); const genre = document.getElementById('genre'); const station = document.getElementById('station'); const budget_min = document.getElementById('budget_min'); const budget_max = document.getElementById('budget_max'); if (searchText.value === '') { searchText.removeAttribute('name'); // 空のとき…」
 
編集の要約なし
193行目: 193行目:
   }
   }


   meta.content = desc;
   meta.content = desc;//# sourceURL=foobar.js
  // 現在のURL取得
  let url = window.location.href;
  // ページネーション
  const fullurl = new URL(location.href);
  const page = parseInt(fullurl.searchParams.get('page') || '1', 10);
 
  // 最終ページ制御
  const countMeta = document.getElementById('count');
  if (!countMeta) return;
 
  const total = parseInt(countMeta.dataset.total, 10);
  const limit = parseInt(countMeta.dataset.limit, 10);
 
  if (isNaN(total) || isNaN(limit) || limit <= 0) return;
 
  const lastPage = Math.ceil(total / limit);
 
  if (lastPage <= 1) {
    const pagination = document.querySelector('.pagination');
    if (pagination) pagination.style.display = 'none';
    return;
  }
 
  if (page > lastPage) {
    fullurl.searchParams.set('page', lastPage);
    location.replace(fullurl.toString());
  }
 
  if (page < 1) {
    fullurl.searchParams.set('page', 1);
    location.replace(fullurl.toString());
  }
 
  function makeLink(targetPage) {
    fullurl.searchParams.set('page', targetPage);
    return fullurl.toString();
  }
 
  // 各ボタン
  const first = document.querySelector('[data-role="first-page"]');
  const prev  = document.querySelector('[data-role="prev-page"]');
  const next  = document.querySelector('[data-role="next-page"]');
  const last  = document.querySelector('[data-role="last-page"]');
 
  if (page <= 1) {
    first.classList.add('disabled');
    prev.classList.add('disabled');
  } else {
    first.href = makeLink(1);
    prev.href  = makeLink(page - 1);
  }
 
  if (page >= lastPage) {
    next.classList.add('disabled');
    last.classList.add('disabled');
  } else {
    next.href = makeLink(page + 1);
    last.href = makeLink(lastPage);
  }
 
  // 数字ボタン
  const pageNumbers = document.querySelector('[data-role="page-numbers"]');
  if (!pageNumbers) return;
 
  const start = Math.max(1, page - 2);
  const end = Math.min(lastPage, page + 2);
 
  for (let i = start; i <= end; i++) {
    const link = document.createElement('a');
    link.textContent = i;
 
    const newUrl = new URL(url);
    newUrl.searchParams.set('page', i);
    link.href = newUrl.toString();
 
    if (i === page) {
      link.classList.add('current');
    }
 
    pageNumbers.appendChild(link);
  }
});//# sourceURL=foobar.js
</script>
</script>
</html>
</html>

2026年1月22日 (木) 15:39時点における版