(function($) { /** * GetUserAgent: IE/Edge判別 */ var GetUserAgent = function(element, options) { this.$window = $(window); this.$body = $('body'); this.init(options); }; GetUserAgent.prototype = { defaults: { }, init: function(options) { this.options = $.extend({}, this.defaults, options); this.initializeEvent(); }, initializeEvent: function() { var _this = this; var userAgent = window.navigator.userAgent.toLowerCase(); if(userAgent.indexOf('msie') !== -1 || userAgent.indexOf('trident') !== -1) { _this.$body.addClass('ie'); } else if (userAgent.indexOf('edge') !== -1) { _this.$body.addClass('edge'); } } }; $.fn.GetUserAgent = function(options) { return this.each(function() { new GetUserAgent(this, options); }); }; /** * check Width */ var checkWidth = function(element, options) { this.$window = $(window); this.$target = $('body'); this.init(options); }; checkWidth.prototype = { defaults: { pc: 'is-pc', sp: 'is-sp', breakpoint: 812 }, init: function(options) { this.options = $.extend({}, this.defaults, options); this.initialiseEvent(); }, initialiseEvent: function() { var _this = this; _this.$window.on('load resize', $.proxy(_this.checkHandler, _this)); }, checkHandler: function() { var _this = this, width = _this.$window.outerWidth(); if( width > _this.options.breakpoint) { // pc _this.$target.removeClass(_this.options.sp).addClass(_this.options.pc); } else { _this.$target.removeClass(_this.options.pc).addClass(_this.options.sp); } } }; $.fn.checkWidth = function(options) { return this.each(function() { new checkWidth(this, options); }); }; /** * smooth scroll */ var smoothScroll = function(element, options) { this.$window = $(window); this.$element = $(element); this.jump; this.init(options); }; smoothScroll.prototype = { defaults: { topBtn: '.btn-pagetop', topHash: '#pagetop', fadePoint: 100, fixedHeader: '.header', scrollSpead: 'slow', scrollEasing: 'ease', breakpoint: 812 }, init: function(options) { this.options = $.extend({}, this.defaults, options); this.initialiseEvent(); }, initialiseEvent: function() { var _this = this; $.proxy(_this.urlHashHandler, _this)(); _this.$window.on('load scroll', $.proxy(_this.fadeHandler, _this)); $('a[href^=\\#]:not([href=\\#])').on('click', $.proxy(_this.clickHandler, _this)); $(_this.options.topBtn).on('click', $.proxy(_this.clickHandler, _this)); }, fadeHandler: function() { var _this = this; var currentPos = _this.$window.scrollTop(); var fadePoint = _this.options.fadePoint; if (fadePoint <= currentPos) { $(_this.options.topBtn).fadeIn(); } else { $(_this.options.topBtn).fadeOut(); } }, clickHandler: function(e) { var _this = this; var $target = $(e.currentTarget); var winWidth =_this.$window.outerWidth(); var targetClass = $target.attr('class'); if ('.' + targetClass == _this.options.topBtn) { _this.jump = 0; } else { // クリックしたものnのhrefを取得 var hash = $target.attr('href'); var jump = $(hash).offset().top; _this.jump = jump; } _this.jump -= $(_this.options.fixedHeader).outerHeight(true); $.proxy(_this.scrollHandler, _this)(); return false }, urlHashHandler: function() { var _this = this; var winWidth =_this.$window.outerWidth(); var urlHash = location.hash; if(urlHash) { $('body, html').stop().scrollTop(0); setTimeout(function() { _this.jump = $(urlHash).offset().top; _this.jump -= $(_this.options.fixedHeader).outerHeight(true); $.proxy(_this.scrollHandler, _this)(); }, 1000 ); } }, scrollHandler: function() { var _this = this; $('html, body').animate({ scrollTop: _this.jump }, _this.options.scrollSpead, _this.options.scrolleasing); } }; $.fn.smoothScroll = function(options) { return this.each(function() { new smoothScroll(this, options); }); }; /** * TEL LINK only SP */ var telOnlySP = function(element, options) { this.$window = $(window); this.$element = $(element); this.init(options); }; telOnlySP.prototype = { init: function(options) { this.options = $.extend({}, this.defaults, options); this.winWidth; this.winWidthResize; this.initialiseEvent(); }, initialiseEvent: function() { var _this = this; if(navigator.userAgent.match(/(iPhone|iPad|iPod|Android)/)){ $.proxy(_this.checkHandler, _this)(); } }, checkHandler: function() { var _this = this; _this.$element.each(function() { var str = $(this).html(); if ($(this).children().is('img')) { $(this).html($('').attr('href', 'tel:' + $(this).children().attr('alt').replace(/-/g, '')).attr('title', $(this).children().attr('alt').replace(/-/g, '') + 'に発信します').append(str + '')); } else { $(this).html($('').attr('href', 'tel:' + $(this).text().replace(/-/g, '')).attr('title', $(this).text().replace(/-/g, '') + 'に発信します').append(str + '')); } }); } }; $.fn.telOnlySP = function(options) { return this.each(function() { new telOnlySP(this, options); }); }; /** * SetCurrentNav */ var SetCurrentNav = function(element, options) { this.$window = $(window); this.$nav = $(element); this.$navItem = this.$nav.find('a'); this.$header = $('.header'); this.targetArray = []; this.init(options); }; SetCurrentNav.prototype = { defaults: { currentClass: 'is-current', }, init: function(options) { this.options = $.extend({}, this.defaults, options); this.headerHeight = this.options.header ? this.options.header.outerHeight() : 0; this.initializeEvent(); }, initializeEvent: function() { var _this = this; _this.$window.on('resize', $.proxy(_this.getOffset, _this)).triggerHandler('resize'); _this.$window.on('scroll', $.proxy(_this.scrollHandler, _this)); _this.$nav.find('.js-anchor-modal').on('click', $.proxy(_this.clickHandler, _this)); }, getOffset: function() { var _this = this, length = _this.$navItem.length, first = _this.$navItem.eq(1).attr('href'), targetID, targetTop, targetBottom; _this.targetArray[0] = [0, $(first).offset().top - 1]; for (var i = 1; i < length; i++) { targetID = _this.$navItem.eq(i).attr('href'); targetTop = $(targetID).offset().top; targetBottom = targetTop + $(targetID).outerHeight(true) - 1; _this.targetArray[i] = [targetTop, targetBottom]; } }, scrollHandler: function(e) { var _this = this, winScroll = _this.$window.scrollTop(); $.proxy(_this.getOffset, _this)(); for (var i = 0; i < _this.targetArray.length; i++) { if (_this.targetArray[i][0] <= winScroll + _this.$header.outerHeight(true) + 1 && _this.targetArray[i][1] >= winScroll + _this.$header.outerHeight(true) + 1) { _this.$navItem.removeClass(_this.options.currentClass); _this.$navItem.eq(i).addClass(_this.options.currentClass); } } } }; $.fn.SetCurrentNav = function(options) { return this.each(function() { new SetCurrentNav(this, options); }); }; /** * gnav */ var gnav = function(element, options) { this.$window = $(window); this.$element = $(element); // this.$target = this.$element.find('a'); this.$openBtn = $('.js-gnav-open'); this.$closeBtn = $('.js-gnav-close'); this.$pos; // this.$body = $('body'); // this.$notCloseArea = $('.l-gnav'); this.init(options); }; gnav.prototype = { defaults: { openedClass: 'is-opened', activeClass: 'is-active', breakpoint: '640' }, init: function(options) { this.options = $.extend({}, this.defaults, options); this.initializeEvent(); }, initializeEvent: function() { var _this = this; _this.winWidth = _this.$window.innerWidth(); // _this.$window.on('load resize', $.proxy(_this.resizeHandler, _this)); _this.$openBtn.on('click', $.proxy(_this.openHandler, _this)); _this.$closeBtn.on('click', $.proxy(_this.closeHandler, _this)); _this.$target.on('click', $.proxy(_this.resetHandler, _this)); _this.$element.on('click', $.proxy(_this.notCloseHandler, _this)); _this.$body.on('click', $.proxy(_this.resetHandler, _this)); }, notCloseHandler: function(e) { var _this = this; e.stopPropagation(); }, resetHandler: function() { var _this = this; _this.$element.removeClass(_this.options.openedClass); _this.$openBtn.addClass(_this.options.activeClass); _this.$closeBtn.removeClass(_this.options.activeClass); $('html, body').css({'overflow': 'auto'}); }, resizeHandler: function() { var _this = this; _this.winResizeWidth =_this.$window.innerWidth(); if( _this.WinWidth != _this.winResizeWidth && _this.winResizeWidth > _this.options.breakpoint) { $.proxy(_this.resetHandler, _this)(); } }, openHandler: function(e) { var _this = this, status = $(e.currentTarget).attr('class'); if(status.indexOf(_this.options.activeClass) != -1 ) { _this.$element.addClass(_this.options.openedClass); _this.$openBtn.removeClass(_this.options.activeClass); _this.$closeBtn.addClass(_this.options.activeClass); } else { _this.$element.removeClass(_this.options.openedClass); _this.$openBtn.addClass(_this.options.activeClass); _this.$closeBtn.removeClass(_this.options.activeClass); } $('html, body').css({'overflow': 'hidden'}); }, closeHandler: function(e) { var _this = this, status = $(e.currentTarget).attr('class'); if(status.indexOf(_this.options.activeClass) != -1 ) { _this.$element.removeClass(_this.options.openedClass); _this.$openBtn.addClass(_this.options.activeClass); _this.$closeBtn.removeClass(_this.options.activeClass); } else { _this.$element.addClass(_this.options.openedClass); _this.$openBtn.removeClass(_this.options.activeClass); _this.$closeBtn.addClass(_this.options.activeClass); } $('html, body').css({'overflow': 'auto'}); } }; $.fn.gnav = function(options) { return this.each(function() { new gnav(this, options); }); }; /** * switch images */ var switchImage = function(element, options) { this.$window = $(window); this.$trigger = $(element); this.init(options); }; switchImage.prototype = { defaults: { pc: '_pc', sp: '_sp', replacepoint: 812 }, init: function(options) { this.options = $.extend({}, this.defaults, options); this.initialiseEvent(); }, initialiseEvent: function() { var _this = this; _this.$window.on('load resize', $.proxy(_this.switchHandler, _this)); }, switchHandler: function() { var _this = this, replaceWidth = _this.options.replacepoint, pc = _this.options.pc, sp = _this.options.sp, windowWidth = _this.$window.outerWidth(); _this.$trigger.each(function(){ var $this = $(this); if(windowWidth > replaceWidth) { $this.attr('src', $this.attr('src').replace(sp, pc)); } else { $this.attr('src', $this.attr('src').replace(pc, sp)); } }); } }; $.fn.switchImage = function(options) { return this.each(function() { new switchImage(this, options); }); }; $(function() { // $('.js-slider').slick({ // centerMode: true, // centerPadding: '30px', // variableWidth: true, // slidesToShow: 1, // dots: true, // responsive: [{ // breakpoint: 768, // settings: { // centerMode: false, // variableWidth: false // } // }] // }); // $('.tel').telOnlySP(); // $('.gnav').SetCurrentNav(); // $(window).smoothScroll(); // $('.gnav').gnavSp(); // $(window).GetUserAgent(); $('.js-switch-image').switchImage(); $('.js-gnav').gnav(); }); })(jQuery);