PageSourceSearch

https://p-iwasaki.com/wp-content/themes/main/js/common.js

js p-iwasaki.com collected 2026-10-05 05:23:08 UTC 20,184 bytes, 529 lines download raw bytes

1jQuery(function($){
2
3  /* -----------------------------------------------
4  breakpoint
5  -------------------------------------------------- */
6  const breakpoint = window.matchMedia("(max-width: 500px)");
7
8  /* -----------------------------------------------
9  UA
10  -------------------------------------------------- */
11  function userAgent() {
12    const ua = navigator.userAgent;
13    if (ua.indexOf('iPhone') != -1 || ua.indexOf('iPod') != -1 || ua.indexOf('Android') != -1 && ua.indexOf('Mobile') != -1) {
14      //sp
15      $('body').addClass('is-view-sp');
16    } else if (ua.indexOf('iPad') != -1 || ua.indexOf('Android') != -1) {
17      //tab
18      $('body').addClass('is-view-tab');
19    } else {
20      // pc
21      $('body').addClass('is-view-pc');
22    }
23  }
24
25  // IE
26  function userAgentIE() {
27    const ua = window.navigator.userAgent.toLowerCase();
28    const uaVersion = window.navigator.appVersion.toLowerCase();
29    //ie
30    if (ua.indexOf('msie') != -1 || ua.indexOf('trident') !== -1) {
31      $('body').addClass('is-view-ie');
32    }
33  }
34
35  $(function(){
36    userAgent();
37    userAgentIE();
38  });
39
40
41  /* -----------------------------------------------
42  ハンバーガーメニュー
43  -------------------------------------------------- */
44  $('#js-buttonHamburger, .header__closeBtn').click(function (){
45    // スクロール位置
46    if($('body').hasClass('is-drawerActive')){
47      $('body').removeClass('is-drawerActive').css('top',0 + 'px');
48      window.scrollTo( 0 , scrollPos );
49    }else{
50      scrollPos = $(window).scrollTop();
51      $('body').addClass('is-drawerActive').css('top',-scrollPos + 'px');
52    }
53
54    // 展開
55    if ($(this).attr('aria-expanded') == 'false') {
56      //開いたとき
57      $(this).attr('aria-expanded', true);
58      $(".header__closeBtn").attr('aria-expanded', true);
59      $('#js-drawer').attr('aria-hidden', false);
60    } else {
61      //閉じたとき
62      $(this).attr('aria-expanded', false);
63      $(".header__closeBtn").attr('aria-expanded', false);
64      $('#js-drawer').attr('aria-hidden', true);
65    };
66
67    // ハンバーガー内の最後のリンクやボタンを過ぎたら閉じるキーイベント
68    $('#js-drawer a:last, #js-drawer button:last').focusout(function(e) {
69      $('#js-buttonHamburger').attr('aria-expanded', false);
70      $('#js-drawer').attr('aria-hidden', true);
71      $('body').removeClass('is-drawerActive');
72    });
73  });
74
75
76  /* -----------------------------------------------
77  ページ最上部へ戻るリンク
78  -------------------------------------------------- */
79  $("#js-pageTop").hide();
80  $(window).scroll(function () {
81    if ($(this).scrollTop() > 100) {
82      $('#js-pageTop').fadeIn();
83    } else {
84      $('#js-pageTop').fadeOut();
85    }
86  });
87  $('#js-pageTop a').click(function () {
88    $('body,html').animate({
89      scrollTop: 0
90    }, 550);
91    $('a').first().focus();// 最初のリンクにフォーカスを移す
92    return false;
93  });
94
95
96
97  /* -----------------------------------------------
98  指定リンクに別タブ設定
99  -------------------------------------------------- */
100  $('a[href*="goobike.com/shop/client_8300450/showroom.html"]:not(.icon-none)').attr({target:"_blank"}).append('<svg class="icon icon-win _black" role="img" aria-label="新しいタブで開く"><use xlink:href="#icon-win"></use></svg>');
101
102
103  /* -----------------------------------------------
104  ブロックエディタのコンポーネントにクラス付与
105  -------------------------------------------------- */
106  //1段階下げる
107  $(".wp-post h2").addClass("heading3");
108  $(".wp-post h3").addClass("heading4");
109  $(".wp-post h4").addClass("heading5");
110  $(".wp-post h5").addClass("heading6");
111  $(".wp-post h6").addClass("heading7");
112  $(".wp-post ul").addClass("list-bullet");
113  $(".wp-post ol").addClass("list-number");
114
115
116  /* -----------------------------------------------
117  Webアクセシビリティ:アイコン
118  -------------------------------------------------- */
119  $("a[href$=pdf]")
120    .not('.icon-none, .wp-block-file__button')
121    .append('<svg class="icon icon-file icon-pdf" role="img" aria-label="PDFファイル"><use xlink:href="#icon-pdf"></use></svg>');
122  $("a[href$=doc], a[href$=docx]")
123    .not('.icon-none')
124    .append('<svg class="icon icon-file icon-doc" role="img" aria-label="Wordファイル"><use xlink:href="#icon-doc"></use></svg>');
125  $("a[href$=xls], a[href$=xlsx]")
126    .not('.icon-none')
127    .append('<svg class="icon icon-file icon-xls" role="img" aria-label="Excelファイル"><use xlink:href="#icon-xls"></use></svg>');
128  $("a[href$=ppt], a[href$=pptx]")
129    .not('.icon-none')
130    .append('<svg class="icon icon-file icon-ppt" role="img" aria-label="PPTファイル"><use xlink:href="#icon-ppt"></use></svg>');
131  $(".content a[target='_blank']")
132    .not("a[href$=pdf], a[href$=xls], a[href$=xlsx], a[href$=doc], a[href$=docx], .icon-none, .share__nav__link, .others-item__link")
133    .append('<svg class="icon icon-win" role="img" aria-label="新しいタブで開く"><use xlink:href="#icon-win"></use></svg>');
134
135
136
137  /* -----------------------------------------------
138  スムーススクロール
139  -------------------------------------------------- */
140  var headerHight = $('.header').height(); //ヘッダの高さ
141  // alert(headerHight); //debug
142  $('a[href^="#"]').on('click', function () {
143    var href = $(this).attr("href");
144    var target = $(href == "#" || href == "" ? 'html' : href);
145    var position = target.offset().top-headerHight; //ヘッダの高さ分位置をずらす
146    $("html, body").animate({scrollTop: position}, 550, "swing");
147    return false;
148  });
149
150
151  /* -----------------------------------------------
152  Webアクセシビリティ:「コンテンツへスキップ」のフォーカス移動
153  -------------------------------------------------- */
154  $('.skipLink').on('click', function() {
155    $('#container a, #container button').eq(0).focus();
156  });
157
158
159  /* -----------------------------------------------
160  リンクにカレントクラス付与
161  -------------------------------------------------- */
162  // リンクにカレントクラス付与
163  $('a').not('.zoomImg').each(function(){
164    if(this.href == location.href) $(this).addClass("is-current");
165  });
166  // gnavのaria-label
167  var url = window.location.pathname;
168  $('.gnav li a[href="'+url+'"]').attr('aria-label','page');
169
170
171  /* -----------------------------------------------
172  クラス付与
173  -------------------------------------------------- */
174  // フッタ内リンク
175  $('.footer-link__nav__item a').addClass('footer-link__nav__link');
176
177  // top fittingリンク
178  $('.fitting-area__block, .others-item__link').hover(
179    function () {
180      $(this).find('.btn-arrow').addClass('hover');
181    },
182    function () {
183      $(this).find('.btn-arrow').removeClass('hover');
184    }
185  );
186
187  // カード型リンク
188  $('.entry-card__item__link').hover(
189    function () {
190      $(this).find('.btn-arrow').addClass('hover');
191    },
192    function () {
193      $(this).find('.btn-arrow').removeClass('hover');
194    }
195  );
196
197  // コンタクトエリア
198  $('.contactArea-txt').hover(
199    function () {
200      $(this).closest('.contactArea').addClass('hover');
201    },
202    function () {
203      $(this).closest('.contactArea').removeClass('hover');
204    }
205  );
206
207
208  /* -----------------------------------------------
209  アイコン付与
210  -------------------------------------------------- */
211  //btn-arrow
212  $('.btn-arrow, .btn-band').append('<svg class="arrow1"><use xlink:href="#arrow1"></use></svg>');
213
214  //[SP]header menu link
215  if (breakpoint.matches) {
216    $('.header__drawer-item__link').append('<svg class="arrow1"><use xlink:href="#arrow1"></use></svg>');
217  }
218
219
220  /* -----------------------------------------------
221  カテゴリ名変更
222  -------------------------------------------------- */
223  /*if($('body').hasClass('home') || $('body').hasClass('post-type-archive-news')){
224  $(".entry-list__item__category").each(function(i) {
225      //var hasClassName = $(this).attr('class');
226      //console.log(hasClassName);
227      if($(this).hasClass('cat_partsland_takamatsu') || $(this).hasClass('cat_reparts_takamatsu')){
228        $(this).text("高松店");
229      } else if($(this).hasClass('cat_partsland_matsuyama') || $(this).hasClass('cat_reparts_matsuyama')){
230        $(this).text("松山店");
231      }
232    });
233  }*/
234
235
236  /* -----------------------------------------------
237  カテゴリ絞り込み時に記事がない場合
238  -------------------------------------------------- */
239  if($("body").hasClass("archive") && $("body").hasClass("tax-news_category")) {
240    var breadcrumbCat = $("#breadcrumb li:nth-child(2)").text();
241    if(breadcrumbCat == ''){
242      $('#breadcrumb li:nth-child(2) a').attr('href', '/news/').text('お知らせ');
243    }
244  } else if($("body").hasClass("archive") && $("body").hasClass("tax-product_category")) {
245    var breadcrumbCat = $("#breadcrumb li:nth-child(2)").text();
246    if(breadcrumbCat == ''){
247      $('#breadcrumb li:nth-child(2) a').attr('href', '/product/').text('商品情報');
248    }
249  }
250
251
252  /* -----------------------------------------------
253  タブ内リンク
254  -------------------------------------------------- */
255  $(window).on('load', function() {
256    var nowUrl = location.href;
257    if(nowUrl.match('tab=')){
258      //取得したURLから情報取得
259      var params = nowUrl.split("?");
260      var selectInfo = params[1].split("&");
261      var selectTab = selectInfo[0];
262      var selectAnchor = selectInfo[1];
263      //*タブ
264      var selectTabInfo = selectTab.split("=");
265      var selectTabName = selectTabInfo[1];
266      //*アンカーリンク
267      var selectAnchorInfo = selectAnchor.split("=");
268      var selectAnchorName = selectAnchorInfo[1];
269
270      //タブ切り替え
271      $('.tab').removeClass('is-active');
272      $('.panel').removeClass('is-show');
273      var tabNo = '#tab' + selectTabName;
274      var panelNo = '#panel' + selectTabName;
275      $(tabNo).addClass('is-active');
276      $(panelNo).addClass('is-show');
277
278      //アンカーリンク移動
279      var selectAnchorPosition = $('#'+ selectAnchorName).offset().top - 30;
280      if (breakpoint.matches) {
281        var selectAnchorPosition = selectAnchorPosition - 70;
282      }
283      $('body,html').animate({scrollTop:selectAnchorPosition}, 700, 'swing');
284    }
285  });
286
287
288
289  /* -----------------------------------------------
290  FAQのアコーディオン
291  -------------------------------------------------- */
292  if(document.URL.match(/faq/)){
293    $('html').attr('itemscope itemtype="https://schema.org/FAQPage"');
294  };
295  $(".faq__item > dt > h3 > button, .faq__item > dt > button").on("click", function() {
296    $(this).closest('dt').next().slideToggle();
297    if($(this).find('.faq__item--toggle').text() === '+'){
298      $(this).find('.faq__item--toggle').text('―');
299      $(this).find('.faq__item--toggle').attr('title', '中身を閉じる');
300      $(this).attr('aria-expanded', true);
301      $(this).closest('dt').next('dd').attr('aria-hidden', false);
302    } else {
303      $(this).find('.faq__item--toggle').text('+');
304      $(this).find('.faq__item--toggle').attr('title', '中身を開く');
305      $(this).attr('aria-expanded', false);
306      $(this).closest('dt').next('dd').attr('aria-hidden', true);
307    }
308  });
309
310
311  /* -----------------------------------------------
312  .acListのアコーディオン
313  -------------------------------------------------- */
314  $(".acList__item > button").on("click", function() {
315    $(this).next().slideToggle();
316    if($(this).hasClass('show')){
317      $(this).removeClass('show');
318      $(this).attr('title', '詳細を開く');
319      $(this).attr('aria-expanded', false);
320      $(this).next('.acList__item__inner').attr('aria-hidden', true);
321    } else {
322      $(this).addClass('show');
323      $(this).attr('title', '詳細を閉じる');
324      $(this).attr('aria-expanded', true);
325      $(this).next('.acList__item__inner').attr('aria-hidden', false);
326    }
327  });
328
329
330
331  /* -----------------------------------------------
332  アーカイブページの見出しレベル調整
333  -------------------------------------------------- */
334  $('.post-type-archive article h3').replaceWith(function() {
335    return $("<h2>", {
336      class: this.className,
337      html: $(this).html()
338    });
339  });
340
341
342  /* -----------------------------------------------
343  Googleマップのレスポンシブ化
344  -------------------------------------------------- */
345  //記事詳細ページのみ
346  if($('body').hasClass('single')){
347    $("iframe[src^='https://www.google.com/maps/']")
348    .attr('title','Googleマップ')
349    .wrap('<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper"></div></figure>');
350  }
351
352  // iframe frameborder削除
353  $('iframe').removeAttr('frameborder');
354
355
356  /* -----------------------------------------------
357  Luminous
358  -------------------------------------------------- */
359  $.when(
360    // 先にエントリ内の画像リンクに .zoomImg 付与
361    $('.content__main a[href$=jpg], .content__main a[href$=png], .content__main a[href$=gif], .content__main a[href$=webp]').addClass('zoomImg')
362  ).done(function() {
363    // ギャラリー表示かつキャプション表示
364    const luminousOpts = {
365      caption: (trigger) => {
366        return trigger.querySelector("img").getAttribute("alt");
367      }
368    };
369    // 矢印キーで画像切り替え
370    const galleryOpts = {
371      arrowNavigation: true
372    };
373
374    // LuminousGallery の引数指定
375    new LuminousGallery(
376      document.querySelectorAll(".zoomImg"), //ポップアップ表示するa要素
377      galleryOpts, //ギャラリー表示のオプション
378      luminousOpts //オプション
379    );
380  });
381
382
383  /* -----------------------------------------------
384  問い合わせフォーム
385  -------------------------------------------------- */
386  // 数字キーボード
387  $('.contactForm input[name="zip"], .contactForm input[name="tel"], .contactForm input[name="phone"], .contactForm input[name="fax"]').not("[type=hidden], body.confirm").attr('type', 'tel');
388  // aria属性
389  $('.contactForm .required dd input, .contactForm .required dd textarea').attr('aria-required', 'true');
390  $('.addrHint').attr('aria-describedby', 'addrHint');
391  // エラーメッセージ
392  $(".form__error")
393    .attr({"role":"alert","aria-live":"assertive"})
394    .prepend('<svg class="icon"><use xlink:href="#icon-notice"></use></svg>');;
395  $('.form__error').each(function(span) {
396    $(this).prev('input, textarea').addClass('form__error__input');
397  });
398  // エラー画面で最初のエラー項目にフォーカス
399  if(document.URL.match(/error/)){
400    $('.form__error__input').first().focus();
401  };
402
403
404  /* -----------------------------------------------
405  Webアクセシビリティ:その他コンポーネント
406  -------------------------------------------------- */
407  // ボタン
408  $('a.wp-block-button__link').attr({"role":"button"});
409
410
411  /* -----------------------------------------------
412  サービス - フィッティング
413  -------------------------------------------------- */
414  if(document.URL.match(/fitting/)){
415    /* SPスライダー */
416    if (breakpoint.matches) {
417      const mySwiperFitting = new Swiper ('.service-fitting-slider', {
418        slidesPerView: '1.02', //何枚表示するか
419        spaceBetween: 30, //余白(px)
420        speed: 500, // スライドアニメーションのスピード(ミリ秒)
421        centeredSlides : false, //アクティブなスライドを中央にするか
422        //スクロールバー表示の設定
423        scrollbar: { 
424          el: '.service-fitting-slider__scrollbar', //要素の指定
425        },
426      });
427    }
428
429    /* タブ切り替えによる画像変更 */
430    function switchTab() {
431      if($('.tabA').hasClass('is-active')){
432        $('.elem013__img__item').addClass('_shoei').removeClass('_arai');
433      } else if ($('.tabB').hasClass('is-active')){
434        $('.elem013__img__item').addClass('_arai').removeClass('_shoei');
435      }
436    }
437    $(window).on('load', function() {
438      switchTab();
439    });
440    $(".tab-item").on("click", function() {
441      switchTab();
442    });
443  }
444
445  /* -----------------------------------------------
446  サービス - 採用情報:スライダー
447  -------------------------------------------------- */
448  if(document.URL.match(/recruit/)){
449    const mySwiperDelimiter = new Swiper ('.delimiter-slider', {
450      loop: true,
451      slidesPerView: '2',
452      spaceBetween: 0,
453      centeredSlides : true,
454      allowTouchMove: false,
455      breakpoints: {
456        351: {
457          slidesPerView: '2.3',
458        },
459        401: {
460          slidesPerView: '2.5',
461        },  
462        501: {
463          slidesPerView: '5.2',
464        }
465      }
466    });
467  }
468
469}); //jquery
470
471
472  /* -----------------------------------------------
473  タブ切り替え
474  -------------------------------------------------- */
475  document.addEventListener('DOMContentLoaded', function(){
476    // タブに対してクリックイベントを適用
477    const tabs = document.getElementsByClassName('tab');
478    for(let i = 0; i < tabs.length; i++) {
479      tabs[i].addEventListener('click', tabSwitch);
480    }
481    // タブをクリックすると実行する関数
482    function tabSwitch(){
483      // 引数で指定したセレクターと一致する直近の祖先要素を取得
484      const ancestorEle = this.closest('.tab-panel');
485      // タブのclassの値を変更
486      ancestorEle.getElementsByClassName('is-active')[0].classList.remove('is-active');
487      this.classList.add('is-active');
488      // コンテンツのclassの値を変更
489      ancestorEle.getElementsByClassName('is-show')[0].classList.remove('is-show');
490      const groupTabs = ancestorEle.getElementsByClassName('tab');
491      const arrayTabs = Array.prototype.slice.call(groupTabs);
492      var index = arrayTabs.indexOf(this);
493      ancestorEle.getElementsByClassName('panel')[index].classList.add('is-show');
494    };
495  });
496
497
498  /* -----------------------------------------------
499  追従バナーをCookieで一定期間非表示に
500  -------------------------------------------------- */
501  var period = 1000 * 60 * 1; // 保存期間:60分(1000ミリ秒 * 60秒 * 60分) IF:30日(1000ミリ秒 * 60秒 * 60分 * 24時間 * 30日)
502  // localStorageで使用するkey名
503  var storage_key = 'ad_close'; // 広告バナー管理で使用する値
504  var storage_period_key = 'ad_close_time'; // 保存期間で使用する値
505
506  var ad = document.getElementById('ad-bnr');
507
508  // 保存期間の値が保存されている場合
509  if(localStorage.getItem(storage_period_key) !== null) {
510    // 保存されている値と現在の値の差を見て、期間を過ぎていないか確認
511    var df = Date.now() - parseFloat(localStorage.getItem(storage_period_key));
512    if(df > period) {
513      // 期間を過ぎている場合はlocalStorageの値を削除
514      localStorage.removeItem(storage_key);
515      localStorage.removeItem(storage_period_key);
516    }
517  }
518  // 広告バナー管理の値が保存されていない場合はバナー表示
519  if(localStorage.getItem(storage_key) === null) {
520    ad.classList.add('is-show');
521  }
522  document.getElementById('ad-bnr_close').addEventListener('click', ad_close, false);
523  // 広告バナーを閉じる際の処理
524  function ad_close() {
525    ad.classList.remove('is-show');
526    // localStorageに必要な値を保存
527    localStorage.setItem(storage_key, 'on');
528    localStorage.setItem(storage_period_key, Date.now());
529  }

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.