(function($) { "use strict"; function closeParent($button) { var panelId = $button.attr("aria-controls"); $button.attr("aria-expanded", "false"); $("#" + panelId).attr("hidden", "hidden"); } function openParent($button) { var panelId = $button.attr("aria-controls"); $button.attr("aria-expanded", "true"); $("#" + panelId).removeAttr("hidden"); } function sendPickupEvent($button) { window.dataLayer = window.dataLayer || []; window.dataLayer.push({ event: "faq_pickup_open", link_text: $.trim($button.find(".p-faqTop__qaTitle").text()), link_url: $button.attr("data-faq-url") || "" }); } function initPickupAccordion() { $(".js-faq-pickup-toggle").on("click", function() { var $button = $(this); if ($button.attr("aria-expanded") === "true") { closeParent($button); } else { openParent($button); sendPickupEvent($button); } }); } function initCategoryNavigation() { var $topButtons = $(".p-faqTop__catList .js-faq-parent-toggle"); var $sideButtons = $(".p-faqSidebar__panel .js-faq-parent-toggle"); var desktopQuery = window.matchMedia("(min-width: 768px)"); /* サイドバーはテンプレートが現在地のカテゴリーを開いた状態で出力する。PCに戻したときここへ戻す */ $sideButtons.each(function() { $(this).attr("data-faq-default-expanded", $(this).attr("aria-expanded")); }); // PCは常時展開、SPは閉じた状態から。ブレークポイントをまたいだときも状態を揃え直す。 function syncTopCategories() { $topButtons.prop("disabled", desktopQuery.matches); $topButtons.each(function() { if (desktopQuery.matches) { openParent($(this)); } else { closeParent($(this)); } }); } /* SPの「カテゴリーを変更」は、現在地のカテゴリーが開いたままだと 子カテゴリーが何十件も並んで一覧が長くなる。SPは全て閉じた状態から始め、 PCではテンプレートどおり現在地のカテゴリーを開いておく。 SPのパネル自体はJSで開くまで display: none なので、閉じ直しても一瞬見えることはない。 */ function syncSideCategories() { $sideButtons.each(function() { var $button = $(this); if (desktopQuery.matches && $button.attr("data-faq-default-expanded") === "true") { openParent($button); } else { closeParent($button); } }); } function syncCategories() { if ($topButtons.length) { syncTopCategories(); } if ($sideButtons.length) { syncSideCategories(); } } if ($topButtons.length || $sideButtons.length) { syncCategories(); if (desktopQuery.addEventListener) { desktopQuery.addEventListener("change", syncCategories); } else { desktopQuery.addListener(syncCategories); } } $(".js-faq-parent-toggle").on("click", function() { var $button = $(this); var shouldOpen = $button.attr("aria-expanded") !== "true"; var isFaqTop = $button.closest(".p-faqTop__catList").length > 0; if (isFaqTop) { if (desktopQuery.matches) { return; } if (shouldOpen) { openParent($button); } else { closeParent($button); } return; } $(".js-faq-parent-toggle").each(function() { closeParent($(this)); }); if (shouldOpen) { openParent($button); } }); $(".js-faq-mobile-toggle").on("click", function() { var $button = $(this); var open = $button.attr("aria-expanded") !== "true"; $button.attr("aria-expanded", open ? "true" : "false"); $("#" + $button.attr("aria-controls")).toggleClass("is-mobile-open", open); }); } function initScrollableTables() { var tableIndex = 0; $(".p-faqEntry__body table").each(function() { var $table = $(this); var maxColumnCount = 0; $table.find("tr").each(function() { var columnCount = 0; $(this).children("th, td").each(function() { columnCount += parseInt($(this).attr("colspan"), 10) || 1; }); maxColumnCount = Math.max(maxColumnCount, columnCount); }); if (maxColumnCount < 4 || $table.parent().hasClass("p-faqEntry__tableScroll")) { return; } tableIndex += 1; var noteId = "faq-table-scroll-note-" + tableIndex; var $scrollArea = $("
", { "class": "p-faqEntry__tableNote", "id": noteId, "text": "横にスクロールできます" }).insertBefore($table.parent()); }); } function getRequestedPage() { var match = window.location.search.match(/[?&]page=(\d+)/); return match ? parseInt(match[1], 10) : 1; } function getPageUrl(page) { return window.location.pathname + (page > 1 ? "?page=" + page : ""); } function createPageLink(page, label, className) { return '' + label + ""; } function buildPagination(currentPage, pageCount) { var html = '