'use strict'; (function ($) { var $html = $('html'); var $win = $(window); var isIE8 = $html.hasClass('ie8'); var isLegacyAndroid = (function () { var ua = navigator.userAgent; switch (true) { case /Android 4\.[0123]/i.test(ua): return true; case /Android 4\.4/i.test(ua) && /Linux; U;/i.test(ua) && !/Chrome/i.test(ua): return true; default: return false; } }()); /** * throttle */ function throttle(func, wait) { var timeout; var prev = +new Date; // func(); return function () { var now = +new Date; var diff = now - prev; clearTimeout(timeout); if (diff >= wait) { func(); prev = now; } else { timeout = setTimeout(func, diff); } }; } /** * debounce */ function debounce(func, wait) { var timeout; // func(); return function () { clearTimeout(timeout); timeout = setTimeout(func, wait); }; } /** * ウィンドウ幅を取得(IE8はスクロールバーを含まない幅) * @returns {Number} ウィンドウ幅 */ function getWinWidth() { var w = window.innerWidth; return (w !== undefined) ? w : $win.width(); } /** * アコーディオン */ $('.g-acc_item').each(function () { var $btn = $(this); var $body = $($btn.data('body')); if ($body.length === 0) $body = $btn.next(); $body.css('overflow', 'hidden'); $btn.on('click', function (e, immediate) { $btn.toggleClass('g-acc_item-on'); $body.stop().slideToggle(immediate ? 0 : 400); $win.triggerHandler('resize.height'); return false; }); }) .trigger('click', [true]); /** * カルーセル */ $('.g-carousel').each(function () { var count = $(this).data('carousel') || 4; var rspConf = [{ breakpoint: 481, settings: { slidesToShow: 1, slidesToScroll: 1, centerMode: true, centerPadding: '23px' } }]; if (count > 3) { rspConf.unshift({ breakpoint: 769, settings: { slidesToShow: 3, slidesToScroll: 3 } }); } $('.g-carousel_inner', this).slick({ slidesToShow: count, slidesToScroll: count, appendArrows: '.g-carousel', prevArrow: '
', nextArrow: '
', dots: true, customPaging: function (slick, i) { return (i + 1) + '/' + slick.slideCount; }, responsive: isIE8 ? null : rspConf }); }); /** * PCローカルナビの処理 */ $('.g-lnav').each(function () { var noAnim = $(this).hasClass('g-lnav-anime') === false; var $wrapper = $('.g-wrapper'); var $curLv2; $('.g-lnav_lv2', this).each(function () { var active = 'g-lnav-active'; var $lv2 = $(this); if (Modernizr.touchevents) { $lv2.parent() .on('click', function (e) { if (getWinWidth() < 960) return undefined; if (e.target.tagName === 'A') return true; if ($curLv2 && $curLv2[0] !== this) $curLv2.trigger('click'); var $el = $(this); var clickNs = 'click.lnav'; var scrollNs = 'scroll.lnav'; $wrapper.off(clickNs); $win.off(scrollNs); $el.toggleClass(active); $lv2.stop().slideToggle(noAnim ? 0 : 400); if ($el.hasClass(active)) { var fn = function () { $el.trigger('click'); }; $curLv2 = $el; $wrapper.one(clickNs, fn); $win.one(scrollNs, fn); } else { $curLv2 = null; } return false; }); } else { $lv2.parent() .on('mouseenter', function () { if (!isIE8 && getWinWidth() < 960) return; $(this).addClass(active); $lv2.stop().slideDown(noAnim ? 0 : 400); }) .on('mouseleave', function () { if (!isIE8 && getWinWidth() < 960) return; $(this).removeClass(active); $lv2.stop().slideUp(noAnim ? 0 : 400); }); } }); /** * ローカルナビのPC/SP切り替え処理 */ (function () { var isSpView = false; function deactivateLnav() { $html.removeClass('g-lnav-sticky'); $('.g-lnav').removeClass('g-lnav-on'); $('.g-wrapper, .g-lnav_lv1').removeAttr('style'); $('.g-lnav-active').removeClass('g-lnav-active'); $('.g-lnav_accBtn').removeClass('g-lnav_accBtn-on g-lnav_lv1_hd-on') .next('.g-lnav_accBody').width('auto').height('auto').hide(); $win.add($wrapper).off('.lnav'); } $win.on('resize', debounce(function () { if (isIE8) return; $curLv2 = null; var w = getWinWidth(); if (w < 960 && !isSpView) { isSpView = true; deactivateLnav(); } else if (w >= 960 && isSpView) { isSpView = false; deactivateLnav(); } }, 100)) .trigger('resize'); }()); }); /** * SPローカルナビの処理 */ (function () { var ON = 'g-lnav-on'; var $wrapper = $('.g-wrapper'); var $main = $('.g-main'); var $lnavLv1 = $('.g-lnav_lv1'); var $btn = $('.g-lnav_hd'); var $lnav = $('.g-lnav'); var $header = $('.g-header').length ? $('.g-header') : $('#HeaderArea'); var $hnav = $('.g-hnav').length ? $('.g-hnav') : $('#GlobalNavWrap'); var $body = $('body'); var y; if ($lnav.length !== 1) return; function deactivate() { $wrapper.css({ overflow: 'visible', height: 'auto' }); $win.scrollTop(y); $lnav.removeClass(ON); $lnavLv1.hide(); $body.removeClass('subnav-open'); // EN } function activate() { if (isIE8 || getWinWidth() > 959) return; y = $win.scrollTop(); $win.scrollTop(0); $wrapper.css({ overflow: 'hidden', height: $win.height() }); $lnav.addClass(ON); $lnavLv1.show(); $body.addClass('subnav-open'); // EN } $btn.on('click', function () { if ($lnav.hasClass(ON)) deactivate(); else activate(); if (isLegacyAndroid) $main.before($lnav); }); $win.on('scroll', function () { if (isIE8 || $lnav.hasClass(ON)) return; var y1 = $win.scrollTop(); var y2 = (getWinWidth() > 959) ? ($header.outerHeight() + $hnav.outerHeight()) : $header.height(); $html.toggleClass('g-lnav-sticky', y1 >= y2); if (isLegacyAndroid) $main.before($lnav); }) .trigger('scroll'); }()); /** * SPローカルナビ内アコーディオンの処理 */ $('.g-lnav_accBtn').on('click', function (e) { if (isIE8 || getWinWidth() > 959 || e.target.tagName === 'A') return; $(this).toggleClass('g-lnav_accBtn-on').next('.g-lnav_accBody').slideToggle(); e.preventDefault(); }); /** * 動画 */ $('.g-video').each(function () { var $el = $(this); var w = $el.data('video') || '100%'; var $iframe = $('iframe', this); var per = (100 * $iframe[0].height) / $iframe[0].width; $('.g-video_el', this).css('padding-bottom', per + '%'); $(this).width(w).addClass('g-video-init'); }); /** * Google Map */ $('.g-map').each(function () { var $el = $(this); var w = $el.data('map') || '100%'; var $iframe = $('iframe', this); var per = (100 * $iframe[0].height) / $iframe[0].width; $('.g-map_el', this).css('padding-bottom', per + '%'); $(this).width(w).addClass('g-map-init'); }); /** * モーダル */ (function () { var timer; var $group; var $wrapper; var $modal; var $inner; var $box; var $body; var $close; var $print; var $prev; var $next; var $pagination; var $ctrlInner; var $slickcloned; var load = function ($anchor) { $html.removeClass('g-modal-init g-modal-multi g-modal-prev g-modal-next'); $('.g-modal_el', $body).remove(); var uri = $anchor[0].href; var $iframe = $('