PageSourceSearch

https://babakagu.co.jp/cms/wp-content/themes/bestday2023/assets/js/util.js?20261009-0:17:14

js babakagu.co.jp collected 2026-10-09 00:17:37 UTC 12,420 bytes, 363 lines download raw bytes

1"use strict";
2
3/*
4 *  util.js is setting up common rule.
5 */
6if (window.matchMedia("(max-width: 374px)").matches) {
7  new ViewportExtra(375);
8}
9/*===============================================================
10共通タブ切り替え
11parent => 切り替えスイッチとコンテンツの親
12ankerlink => タブ切り替え後にスクロールアニメーションする場所
13===============================================================*/
14
15
16function cmntabInit(parent, ankerlink) {
17  var cmntab_parent = parent;
18  var cmntab_switch = cmntab_parent + " > .js-tab__switch";
19  var cmntab_switch_item = cmntab_parent + " > .js-tab__switch .js-tab__switchItem";
20  var cmntab_main = cmntab_parent + " > .js-tab__main";
21  var cmntab_main_item = cmntab_parent + " > .js-tab__main .js-tab__mainItem";
22  $(cmntab_switch_item).on("click", function () {
23    var cmntabIndex = $(this).data("tabindex");
24    $(cmntab_switch_item).removeClass("is-active");
25    $(this).addClass("is-active");
26    $(this).parents(cmntab_switch).next(cmntab_main).children(cmntab_main_item).removeClass("is-active");
27    $(this).parents(cmntab_switch).next(cmntab_main).children(cmntab_main_item).eq(cmntabIndex).addClass("is-active");
28
29    if (ankerlink) {
30      if ($(this).hasClass("disable-anker")) {
31        return false;
32      }
33
34      var speed = 500;
35      var position = $(ankerlink).offset().top;
36      var headerHeight = 0;
37
38      if (window.matchMedia("(max-width: 767px)").matches) {
39        headerHeight = $("#header").height();
40      }
41
42      $("html, body").animate({
43        scrollTop: position - headerHeight
44      }, speed, "swing");
45      return false;
46    }
47  });
48}
49/*===============================================================
50タブ切り替え
51スイッチ上下連動
52下のスイッチにクラス「dir-prev」を設定する
53.js-tab__switch_item.dir-prev
54parent => 切り替えスイッチとコンテンツの親
55ankerlink => タブ切り替え後にスクロールアニメーションする場所
56===============================================================*/
57
58
59function cmntabLinkageInit(parent, ankerlink) {
60  var cmntab_parent = parent;
61  var cmntab_switch = cmntab_parent + " > .js-tab__switch";
62  var cmntab_switch_item = cmntab_parent + " > .js-tab__switch .js-tab__switchItem";
63  var cmntab_main = cmntab_parent + " > .js-tab__main";
64  var cmntab_main_item = cmntab_parent + " > .js-tab__main .js-tab__mainItem";
65  $(cmntab_switch_item).on("click", function (e) {
66    var cmntabIndex = $(this).data("tabindex");
67    $(cmntab_switch).each(function (index, elm) {
68      $(elm).find(".js-tab__switchItem").removeClass("is-active");
69      $(elm).find(".js-tab__switchItem").eq(cmntabIndex).addClass("is-active");
70    });
71
72    if ($(this).hasClass("dir-prev")) {
73      $(this).parents(cmntab_switch).prev(cmntab_main).children(cmntab_main_item).removeClass("is-active");
74      $(this).parents(cmntab_switch).prev(cmntab_main).children(cmntab_main_item).eq(cmntabIndex).addClass("is-active");
75    }
76
77    $(this).parents(cmntab_switch).next(cmntab_main).children(cmntab_main_item).removeClass("is-active");
78    $(this).parents(cmntab_switch).next(cmntab_main).children(cmntab_main_item).eq(cmntabIndex).addClass("is-active");
79
80    if (ankerlink) {
81      if ($(this).hasClass("disable-anker")) {
82        return false;
83      }
84
85      var speed = 500;
86      var position = $(ankerlink).offset().top;
87      var headerHeight = 0;
88
89      if (window.matchMedia("(max-width: 767px)").matches) {
90        headerHeight = $("#header").height();
91      }
92
93      $("html, body").animate({
94        scrollTop: position - headerHeight
95      }, speed, "swing");
96      return false;
97    }
98
99    e.preventDefault();
100  });
101}
102/*===============================================================
103タブの中のタブ切り替え
104parent => 切り替えスイッチとコンテンツの親
105ankerlink => タブ切り替え後にスクロールアニメーションする場所
106===============================================================*/
107
108
109function cmntabInrInit(parent, ankerlink) {
110  var cmntab_parent = parent;
111  var cmntab_switch = cmntab_parent + " > .js-tabInr__switch";
112  var cmntab_switch_item = cmntab_parent + " > .js-tabInr__switch .js-tabInr__switchItem";
113  var cmntab_main = cmntab_parent + " > .js-tabInr__main";
114  var cmntab_main_item = cmntab_parent + " > .js-tabInr__main .js-tabInr__mainItem";
115  $(cmntab_switch_item).on("click", function () {
116    var cmntabIndex = $(this).data("tabindex");
117    $(cmntab_switch_item).removeClass("is-active");
118    $(this).addClass("is-active");
119    $(this).parents(cmntab_switch).next(cmntab_main).children(cmntab_main_item).removeClass("is-active");
120    $(this).parents(cmntab_switch).next(cmntab_main).children(cmntab_main_item).eq(cmntabIndex).addClass("is-active");
121
122    if (ankerlink) {
123      if ($(this).hasClass("disable-anker")) {
124        return false;
125      }
126
127      var speed = 500;
128      var position = $(ankerlink).offset().top;
129      var headerHeight = 0;
130
131      if (window.matchMedia("(max-width: 767px)").matches) {
132        headerHeight = $("#header").height();
133      }
134
135      $("html, body").animate({
136        scrollTop: position - headerHeight
137      }, speed, "swing");
138      return false;
139    }
140  });
141}
142/*===================================================
143簡易版matchHeight セレクターは詳細に書く
144例 : matchHeight("#consultation .sec2_tab_list > li");
145========================================================*/
146
147
148function matchHeight(target) {
149  var hList = [];
150  $(target).each(function (index, elm) {
151    var h = $(elm).outerHeight();
152    hList[index] = h;
153  });
154  var hListMax = Math.max.apply(null, hList);
155  $(target).each(function (index, elm) {
156    $(elm).css("height", hListMax + "px");
157  });
158}
159/*================================================
160共通トグル
161parent => トグルスイッチと開閉するコンテンツの親
162ankerlink => トグル後にスクロールアニメーションする場所
163=================================================*/
164
165
166function cmntoggleInit(parent, ankerlink) {
167  if ($(parent).length) {
168    var cmntoggle_switch = parent + " > .js-toggle__switch";
169    var cmntoggle_next = ".js-toggle__next";
170    $(cmntoggle_switch).on("click", function () {
171      $(this).toggleClass("is-active");
172      $(this).next(cmntoggle_next).slideToggle(300);
173
174      if (ankerlink) {
175        if ($(this).hasClass("disable-anker")) {
176          return false;
177        }
178
179        var speed = 500;
180        var position = $(ankerlink).offset().top;
181        var headerHeight = 0;
182
183        if (window.matchMedia("(max-width: 767px)").matches) {
184          headerHeight = $("#header").height();
185        }
186
187        $("html, body").animate({
188          scrollTop: position - headerHeight
189        }, speed, "swing");
190        return false;
191      }
192    });
193  }
194}
195/*━━━━━━━━━━━━━━━━━━━━━━━━━
196ページ内スクロール
197━━━━━━━━━━━━━━━━━━━━━━━━━━━*/
198//function clickScroll() {
199//  $('a[href^="#"]').on("click", function () {
200//    var speed = 500;
201//    var href = $(this).attr("href");
202//    if ($(this).hasClass("disable-transition")) {
203//      return;
204//    }
205//    if ($(this).attr("[data-lity]")) {
206//      return;
207//    }
208//    var target = $(href == "#" || href == "" ? "html" : href);
209//    var position = target.offset().top;
210//    var headerHeight = 0;
211//    if (window.matchMedia("(max-width: 767px)").matches) {
212//      headerHeight = $("#header").height();
213//    }
214//    $("html, body").animate(
215//      { scrollTop: position - headerHeight },
216//      speed,
217//      "swing"
218//    );
219//    return false;
220//  });
221//}
222
223/*━━━━━━━━━━━━━━━━━━━━━━━━━
224スクロールトップ
225━━━━━━━━━━━━━━━━━━━━━━━━━━━*/
226
227
228function scrollTop() {
229  var pagetop = $(".m-pagetop");
230  $(window).on("scroll", function () {
231    if ($(this).scrollTop() > 500) {
232      pagetop.fadeIn();
233    } else {
234      pagetop.fadeOut();
235    }
236  });
237  pagetop.on("click", function () {
238    $("body, html").animate({
239      scrollTop: 0
240    }, 500);
241    return false;
242  });
243}
244/*==========================
245urlに?idがあるとき
246ページ内スクロール
247==========================*/
248//function loadLocation() {
249//  var speed = 500;
250//  var url = location.href;
251//  if (url.match("id=")) {
252//    var target = "#" + url.split("?id=").pop();
253//    if (url.match("id")) {
254//      var target = "#" + url.split("?id=").pop();
255//      var position = $(target).offset().top;
256//      var headerHeight = $("#header").height();
257//      $("html, body").animate(
258//        { scrollTop: position - headerHeight },
259//        speed,
260//        "swing"
261//      );
262//      return false;
263//    }
264//  }
265//}
266// /*━━━━━━━━━━━━━━━━━━━━━━━━━
267// メガメニュー
268// ━━━━━━━━━━━━━━━━━━━━━━━━━━━*/
269// function megaMenu() {
270//   var $gnav = $(".l-header__gnav a[data-megamenu]");
271//   var $megamenu = $(".l-header__megamenu");
272//   var $header = $("#header");
273//   var data = "";
274//   $gnav.hover(
275//     function () {
276//       data = $(this).data("megamenu");
277//       $header.addClass("js-modal");
278//       $megamenu.addClass("is-active");
279//       $megamenu.find(".l-header__megamenuItem-" + data).addClass("is-active");
280//     },
281//     function () {
282//       $megamenu.removeClass("is-active");
283//       $header.removeClass("js-modal");
284//       $megamenu.find(".l-header__megamenuItem").removeClass("is-active");
285//       $megamenu.find(".l-header__megamenuItem-" + data).removeClass("is-active");
286//     }
287//   );
288//   $megamenu.hover(
289//     function () {
290//       $megamenu.addClass("is-active");
291//       $header.addClass("js-modal");
292//       $megamenu.find(".l-header__megamenuItem-" + data).addClass("is-active");
293//     },
294//     function () {
295//       $megamenu.removeClass("is-active");
296//       $header.removeClass("js-modal");
297//       $megamenu.find(".l-header__megamenuItem").removeClass("is-active");
298//     }
299//   );
300// }
301// /*━━━━━━━━━━━━━━━━━━━━━━━━━
302// ヘッダー スクロール表示
303// ━━━━━━━━━━━━━━━━━━━━━━━━━━━*/
304// function headerScroll() {
305//   var
306//     startPos = 0,
307//     winScrollTop = 0,
308//     $header = $("#header"),
309//     $jsdrwNav = $("#js-drwNav"),
310//     headerHeight = $header.height(),
311//     timer = null;
312//   $(window).on("scroll", function () {
313//     clearTimeout( timer );
314//     timer = setTimeout(function () {
315//       winScrollTop = $(this).scrollTop();
316//       if ($jsdrwNav.hasClass("is-active")) {
317//         return;
318//       } else {
319//         if (winScrollTop >= startPos) {
320//           if (winScrollTop >= headerHeight) {
321//             $header.addClass("js-hide");
322//           }
323//         } else if(winScrollTop <= startPos) {
324//           $header.removeClass("js-hide");
325//         }
326//       }
327//       startPos = winScrollTop;
328// 		}, 30 );
329//   });
330// }
331
332/*━━━━━━━━━━━━━━━━━━━━━━━━━
333日付のフォーマット
334━━━━━━━━━━━━━━━━━━━━━━━━━━━*/
335
336
337function setFormatDate(date) {
338  var newDate = new Date(date);
339  var result = newDate.getFullYear() + '.' + (newDate.getMonth() + 1).toString().padStart(2, "0") + '.' + newDate.getDate().toString().padStart(2, "0");
340  return result;
341}
342/*━━━━━━━━━━━━━━━━━━━━━━━━━
343スクロールしたらクラスを付与する
344━━━━━━━━━━━━━━━━━━━━━━━━━━━*/
345// 追従メニューの関数
346
347
348var FixedNav = function FixedNav() {
349  var scroll = $(window).scrollTop();
350  var header = $('.l-header');
351  var fixed = $('.l-header__flexNav');
352  var isHeaderVisible = header.height() >= scroll - 60;
353  header.css('visibility', isHeaderVisible ? 'visible' : 'hidden').attr('aria-hidden', !isHeaderVisible);
354  fixed.css({
355    'top': isHeaderVisible ? '-100%' : '0',
356    'visibility': isHeaderVisible ? 'hidden' : 'visible'
357  }).attr('aria-hidden', isHeaderVisible);
358}; // 画面をスクロールをしたら発火
359
360
361$(window).on('scroll', function () {
362  FixedNav();
363});

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.