// ============================================================ // メイン処理 // // %use / jquery // ============================================================ var COMMON = COMMON || {}; (function(){ 'use strict'; /*タッチデバイスにclass追加 ----------------------------*/ COMMON.addClassTouchDevice = function() { if (window.ontouchstart === null) { $('.l_pageArea').addClass('s_touchDevice'); }else{ $('.l_pageArea').removeClass('s_touchDevice'); } }; COMMON.addClassTouchDevice(); /*タッチデバイスの判定 ----------------------------*/ COMMON.isTouchDevice = function() { if (window.ontouchstart === null) { return true; }else{ return false; } }; /*ヘッダー開閉 ----------------------------*/ (function () { var isSwitch = null; //画面768pxの切り替え判定 var isSp; //画面768px以下の判定 $('.l_header__toggle').click(function () { $('.l_header__menuWrap').slideToggle(300); $(this).toggleClass('s_open'); }); $(window).on("load resize", function () { isSp = window.matchMedia("(max-width: 768px)").matches; if ((isSwitch === null || !isSwitch) && isSp) { $('.l_header__toggle').removeClass('s_open'); $('.l_header__menuWrap').stop().slideUp(); isSwitch = true; } else if ((isSwitch === null || isSwitch) && !isSp) { $('.l_header__toggle').addClass('s_open'); $('.l_header__menuWrap').stop().slideDown(); isSwitch = false; } }); })(); /*メニューカレント ----------------------------*/ COMMON.gnaviCur = function(){ var path = location.pathname.replace('/index.html', '/'); $('.l_header__menu a').each(function(i, ele){ if (path.split('/')[2] === $(ele).attr('href').split('/')[2]){ $(ele).closest('li').addClass('is-current'); if ($(ele).closest('li').hasClass('s_materiality')) { $(ele).addClass('s_current'); } return false; } }); }; COMMON.gnaviCur(); COMMON.fnaviCur = function(){ var path = location.pathname.replace('/index.html', '/'); $('.l_navFooter .l_navFooter__link a').each(function(i, ele){ if (path.split('/')[2] === $(ele).attr('href').split('/')[2]){ $(ele).closest('li').addClass('is-current'); return false; } }); }; COMMON.fnaviCur(); COMMON.subfnaviCur = function(){ var path = location.pathname.replace('/index.html', '/'); $('.l_navFooter__sub .l_navFooter__sub__title span').each(function(i, ele){ if (path.split('/')[2] === $(ele).data('href').split('/')[2]){ $(ele).closest('.l_navFooter__sub').addClass('is-active'); if($(ele).closest('.l_wrpContainer').siblings('.l_navFooter__sub__cat').length > 0){ $(ele).closest('.l_wrpContainer').siblings('.l_navFooter__sub__cat').find('a').each(function(j,ele){ if (path.split('/')[3] === $(ele).attr('href').split('/')[3]){ $(ele).closest('li').addClass('is-current'); if($(ele).closest('.l_navFooter__sub__cat').siblings('.l_navFooter__aux').length > 0){ $(ele).closest('.l_navFooter__sub__cat').siblings('.l_navFooter__aux').find('a').each(function(k,ele){ if (path.split('/')[4] === $(ele).attr('href').split('/')[4]){ $(ele).closest('li').addClass('is-current'); } if (path.split('/')[3] === $(ele).attr('href').split('/')[3]){ $(ele).closest('.l_navFooter__aux').addClass('is-active'); } }); } } }); } return false; } }); }; COMMON.subfnaviCur(); /*ウインドウ幅取得 ----------------------------*/ COMMON.getSizeW = function(){ var $win = $(window); return $win.width(); }; /*ウインドウ高さ取得 ----------------------------*/ COMMON.getSizeH = function(){ var $win = $(window); return $win.height(); }; /*ブレイクポイント幅判定 ----------------------------*/ COMMON.isMaxWidth = function(w){ if (window.matchMedia){ var q = window.matchMedia('(max-width: '+w+'px)'); return q.matches; } else { return (window.innerWidth<=w); //旧IE } }; /*ブレイクポイント高さ判定 ----------------------------*/ COMMON.isMaxHeight = function(h){ if (window.matchMedia){ var q = window.matchMedia('(max-height: '+h+'px)'); return q.matches; } else { return (window.innerHeight<=h); //旧IE } }; /*パララックス ----------------------------*/ COMMON.parallax = function($target,timing){ this.target = $target; this.timing = timing ? timing : 9 ; this.init(); }; COMMON.parallax.prototype = { init : function(){ this.$win = $(window); this.setParameters(); this.bindEvent(); this.showAni(); }, setParameters : function(){ this.winH = COMMON.getSizeH(); this.targetT = this.target.offset().top; this.targetShow = false; }, bindEvent : function(){ var _this = this; this.$win.on('scroll resize',function(){ _this.winH = COMMON.getSizeH(); _this.targetT = _this.target.offset().top; _this.showAni(); }); }, showAni : function(){ var scrl = this.$win.scrollTop(); if (!this.targetShow && scrl+(this.winH*this.timing/10) > this.targetT){ this.target.addClass('s_aniShow'); this.targetShow = true; } } }; $('.js_parallax').each(function () { var timing = $(this).data('timing'); new COMMON.parallax($(this),timing); }); /*PC/SPの画像切り替え ----------------------------*/ COMMON.changeImg = function($target){ this.$target = $target; this.init(); }; COMMON.changeImg.prototype = { init : function(){ this.setParameters(); this.bindEvent(); this.setChangeImg(); }, setParameters : function(){ this.$win = $(window); this.initFlag = false; }, bindEvent : function(){ var myself = this; this.$win.on('resize',function(){ myself.setChangeImg(); }); }, setChangeImg : function(){ var flag = COMMON.isMaxWidth(767); this.$target.addClass('s_show'); if(flag && !this.initFlag){ this.$target.attr("src",this.$target.attr("src").replace('_pc.', '_sp.')); this.initFlag = true; }else if(!flag && this.initFlag){ this.$target.attr("src",this.$target.attr("src").replace('_sp.', '_pc.')); this.initFlag = false; } }, }; $('.js_imgChange').each(function(){ new COMMON.changeImg($(this)); }); /*画像サイズ調整 ----------------------------*/ COMMON.adjustSizeImg = function($target) { $target.find('.m_centerImg__image').css('max-width',$target.find('.m_centerImg__image img')[0].naturalWidth); }; $(window).on('load',function(){ $('.m_centerImg.js_adjust').each(function(){ new COMMON.adjustSizeImg($(this)); }); }); /*ポップアップ表示 ----------------------------*/ COMMON.popup = function($target){ this.$target = $target; this.init(); }; COMMON.popup.prototype = { init : function(){ this.setParameters(); this.bindEvent(); }, setParameters : function(){ this.w = this.$target.attr('data-width') || 900; this.h = this.$target.attr('data-height') || screen.height*0.85; }, bindEvent : function(){ var _this = this; this.$target.on('click',function(){ window.open($(this).attr('href'), '_blank', 'width='+_this.w+',height='+_this.w+',location=yes,status=no,resizable=yes,scrollbars=yes'); return false; }); }, }; $('.js_popup').each(function(){ new COMMON.popup($(this)); }); /*タブ ----------------------------*/ COMMON.tab = function($target){ this.target = $target; this.init(); }; COMMON.tab.prototype = { init : function(){ this.setParameters(); this.setTab(); this.bindEvent(); }, setParameters : function(){ this.$tabBtn = this.target.find('.js_tabBtn'); this.$tabContents = this.target.find('.js_toggleContents'); this.hash = location.hash; }, setTab : function(){ if (this.target.find(this.hash).length>0){ if(this.$tabBtn.find('a[href^="'+this.hash+'"]').length>0){ this.$tabBtn.find('a[href^="'+this.hash+'"]').parent().addClass('s_current').siblings().removeClass('s_current'); this.target.find(this.hash).show(); }else{ $(this.$tabBtn.find('a').eq(0).attr('href')).show(); } }else{ $(this.$tabBtn.find('a').eq(0).attr('href')).show(); } }, bindEvent : function(){ this.$tabBtn.find('a').on('click',function(){ $(this).parent().addClass('s_current').siblings().removeClass('s_current'); $(this).closest('.js_tabArea').find('.js_tabContents').hide(); $($(this).attr('href')).show(); return false; }); }, }; $('.js_tabArea').each(function(){ new COMMON.tab($(this)); }); /*モーダル ----------------------------*/ COMMON.modal = function($target){ this.target = $target; this.init(); }; COMMON.modal.prototype = { init : function(){ this.setParameters(); this.bindEvent(); }, setParameters : function(){ this.$root = $('html,body'); this.$modal = $('#' + this.target.data('modal')); this.$close = this.$modal.find('.js_closeModal'); }, bindEvent : function(){ var _this = this; this.target.on('click',function(e){ e.preventDefault(); _this.showModal($(this)); }); this.$close.on('click',function(){ _this.hideModal($(this)); }); }, showModal : function(){ this.$modal.fadeIn(200); this.$root.addClass('s_modalShow'); if(this.isMovie){ this.$movie[0].currentTime = 0; this.$movieBtn.removeClass('c_hide'); } }, hideModal : function(){ $('.m_modal:visible').fadeOut(200); this.$root.removeClass('s_modalShow'); if(this.isMovie){ this.$movie[0].pause(); } }, }; $('.js_showModal').each(function(){ new COMMON.modal($(this)); }); /*非活性ボタン ----------------------------*/ COMMON.disabledBtn = function(){ $('.m_btn').on('click', function () { if ($(this).hasClass('s_disabled')) { return false; } }); }; COMMON.disabledBtn(); /*スムーススクロール ----------------------------*/ COMMON.smoothScroll = function($target){ this.target = $target; this.init(); }; COMMON.smoothScroll.prototype = { init : function(){ this.setParameters(); this.bindEvent(); if(this.target.closest('.l_pagetop').length > 0){ this.fixPageTop(); } }, setParameters : function(){ this.$win = $(window); this.$pagetop = $('.l_pagetop'); this.showPagetop = false; this.winH = COMMON.getSizeH(); this.flag = COMMON.isMaxWidth(767); this.ftPosTop = null; this.scrollTimer = null; }, bindEvent : function(){ var _this = this; this.$win.on('resize',function(){ _this.winH = COMMON.getSizeH(); _this.flag = COMMON.isMaxWidth(767); }); this.$win.on('scroll',function(){ if(_this.target.closest('.l_pagetop').length > 0){ _this.fixPageTop(); } }); this.target.on('click',function(){ _this.moveScroll($(this)); }); }, fixPageTop : function(){ var scrl = this.$win.scrollTop(); if (scrl === 0){ this.$pagetop.stop().fadeOut(300); this.showPagetop = false; } else if (!this.showPagetop){ this.$pagetop.stop().fadeIn(300); this.showPagetop = true; } }, moveScroll : function($this){ var href= $this.attr('href'); var movePos; if (href==='#'){ movePos = 0; } else { movePos = $(href).offset().top; } $('body, html').animate({ scrollTop: movePos }, 500); return false; }, }; $('a.js_smScroll[href^="#"],.l_pagetop a').each(function(){ new COMMON.smoothScroll($(this)); }); // smooth scroll ページを跨ぐ場合 $(window).on('load', function () { var urlHash = location.hash; if (urlHash) { $('body,html').stop().scrollTop(0); setTimeout(function(){ var target = $(urlHash); var position = target.offset().top; $('body,html').stop().animate({scrollTop:position}, 500); $('body,html').scrollTop(position); }, 100); } }); //smooth scroll rootAnc $('a.js_rootAnc').click(function () { var href = $(this).attr('href'); var target= href.substr(href.indexOf('#')) var target2 = $(target == "#" || target == "" ? 'html' : target); var position = target2.offset().top; $('body,html').animate({ scrollTop: position }, 500); return false; }); $(function() { var footer__floatBtn = $('.l_footer__floatBtn'); $(window).scroll(function () { if ($(this).scrollTop() > 0) { footer__floatBtn.fadeIn(300); }else { footer__floatBtn.fadeOut(300); } }); }); /*高さ揃え ----------------------------*/ ;(function () { var aryHeightData; var fncAdjust = function(){ aryHeightData = [-1, 0]; $('.jsAddHeight').each(function(i, ele) { var numThisTop = parseInt($(ele).offset().top); if(aryHeightData[0] === -1) aryHeightData[0] = numThisTop; if(Math.abs(numThisTop - aryHeightData[0]) < 2){ aryHeightData[1] = Math.max($(ele).outerHeight(), aryHeightData[1]); $(ele).addClass('jsAddHeightTarget' + aryHeightData[0]); } }); $('.jsAddHeightTarget' + aryHeightData[0]) .css('height', aryHeightData[1] + 'px') .removeClass('jsAddHeightTarget' + aryHeightData[0]) .removeClass('jsAddHeight'); if($('.jsAddHeight').length !== 0) fncAdjust(); }; $('.js_heightFix').css('height', '').addClass('jsAddHeight'); fncAdjust(); $(window).on('resize', function(){ $('.js_heightFix').css('height', '').addClass('jsAddHeight'); fncAdjust(); }); })(); })();