(function (win, doc) { 'use strict'; var Lib = {}; Lib.AdjustHeight = (function () { var classNames = { structure: 'js-adjustHeight-structure' }; var idNames = { content: 'js-adjustHeight-conetnt' }; var SMALL_SCREEN = 1024; var timerWindowResize = null; var AdjustHeight = function (options) { this.options = { breakpoint: (options && options.breakpoint) || SMALL_SCREEN }; this.structureElements = null; this.contentElement = null; this.mql = matchMedia('(max-width: ' + this.options.breakpoint + 'px)'); }; AdjustHeight.prototype.init = function () { this.setElements(); if (this.existsElements()) { this.bindEvents(); this.initHeightAttributes(this.mql); } }; AdjustHeight.prototype.setElements = function () { this.structureElements = doc.querySelectorAll('.' + classNames.structure); this.contentElement = doc.getElementById(idNames.content); }; AdjustHeight.prototype.existsElements = function () { if ((this.structureElements && this.structureElements.length) && this.contentElement) { return true; } return false; }; AdjustHeight.prototype.calcContentHeight = function () { var contentHeight = 0; var totalHeight = 0; totalHeight = this.calcHeightTotal(); if (totalHeight) { contentHeight = (win.innerHeight - totalHeight) - 1; } return contentHeight; }; AdjustHeight.prototype.calcHeightTotal = function () { var total = 0; if (this.existsElements()) { Array.prototype.forEach.call(this.structureElements, function (elm) { var height = elm.clientHeight; if (height) { total += win.parseFloat(height); } }); } return total; }; AdjustHeight.prototype.bindEvents = function () { this.bindMatchMedia(); this.bindResizeWindow(); }; AdjustHeight.prototype.bindMatchMedia = function () { this.mql.addListener(this.initHeightAttributes.bind(this)); this.mql.self = this; }; AdjustHeight.prototype.bindResizeWindow = function () { win.addEventListener('resize', this.handlers.resize); win.adjustHeight = this; }; AdjustHeight.prototype.initHeightAttributes = function (mql) { if (mql.matches) { this.destroy(); } else { this.exec(); } }; AdjustHeight.prototype.handlers = { resize: function () { var adjustHeight = this.adjustHeight; if (timerWindowResize !== null) { win.clearTimeout(timerWindowResize); } timerWindowResize = win.setTimeout(function () { if (!adjustHeight.isSmallScreen()) { adjustHeight.exec(); } }, 300); } }; AdjustHeight.prototype.isSmallScreen = function () { if (window.innerWidth <= this.options.breakpoint) { return true; } return false; }; AdjustHeight.prototype.exec = function () { if (this.existsElements()) { this.contentElement.style.height = this.calcContentHeight() + 'px'; } }; AdjustHeight.prototype.destroy = function () { if (this.existsElements()) { this.contentElement.removeAttribute('style'); } }; return AdjustHeight; }()); Lib.TabPage = (function () { var classNames = { button: 'js-tabButton', panel: 'js-tabPannel', resetAnimation: 'js-resetAnimation', isShow: 'is-show', isCurrent: 'is-current' }; var SMALL_SCREEN = 1024; var TabPage = function (options) { this.options = { breakpoint: (options && options.breakpoint) ? options.breakpoint : SMALL_SCREEN }; this.panelElements = null; this.buttonElements = null; this.initialIndex = 0; this.mql = matchMedia('(max-width: ' + this.options.breakpoint + 'px)'); this.callbacks = { onChange: (options && options.callbacks) ? options.callbacks.onChange : null }; this.idList = []; this.currentIndex = 0; }; TabPage.prototype.init = function () { this.setElements(); if (this.existsElements()) { this.idList = this.getIDList(); this.bindEvents(); this.showFirstPanel(); } }; TabPage.prototype.setElements = function () { this.buttonElements = doc.querySelectorAll('.' + classNames.button); this.panelElements = doc.querySelectorAll('.' + classNames.panel); }; TabPage.prototype.existsElements = function () { if ( (this.buttonElements && this.buttonElements.length) && (this.panelElements && this.panelElements.length) ) { return true; } return false; }; TabPage.prototype.getIDList = function () { var list = []; if (this.existsElements()) { Array.prototype.forEach.call(this.panelElements, function (elm) { var id = elm.id; if (id) { list.push(id); } }); } return list; }; TabPage.prototype.bindEvents = function () { this.bindMatchMedia(); if (!this.mql.matches) { this.bindClickButtons(); win.addEventListener('keyup', this.handlers.keyup, false); win.tabPage = this; } }; TabPage.prototype.bindClickButtons = function (isRemove) { var self = this; if (this.existsElements()) { Array.prototype.forEach.call(this.buttonElements, function (button) { if (isRemove) { button.removeEventListener('click', self.handlers.clickButton, false); } else { button.addEventListener('click', self.handlers.clickButton, false); button.self = self; } }); } }; TabPage.prototype.removeEvents = function () { var isRemove = true; this.bindClickButtons(isRemove); win.removeEventListener('keyup', this.handlers.keyup, false); }; TabPage.prototype.handlers = { clickButton: function (e) { var self = this.self; var id; e.preventDefault(); if (TabPage.isCurrent(this)) { return; } if (this.hash) { id = TabPage.removeHash(this.hash); } if (id) { self.showPanel(id); } }, keyup: function (e) { var self = this.tabPage; var index; if (self.isNext(e)) { index = self.getTargetIndex(); } else if (self.isPrev(e)) { index = self.getTargetIndex(true); } if (typeof index === 'number') { self.showPanel(self.idList[index]); } } }; TabPage.prototype.getTargetIndex = function (isPrev) { var index = 0; if (isPrev) { if (this.currentIndex === 0) { index = this.panelElements.length - 1; } else { index = this.currentIndex - 1; } } else { if (this.currentIndex === (this.panelElements.length - 1)) { index = 0; } else { index = this.currentIndex + 1; } } return index; }; TabPage.prototype.isNext = function (event) { if (event.key === 'ArrowDown' || event.key === 'ArrowRight' || event.key === 'PageDown') { return true; } return false; }; TabPage.prototype.isPrev = function (event) { if (event.key === 'ArrowUp' || event.key === 'ArrowLeft' || event.key === 'PageUp') { return true; } return false; }; TabPage.isCurrent = function (element) { if (element && element.classList.contains(classNames.isCurrent)) { return true; } return false; }; TabPage.removeHash = function (str) { if (typeof str === 'string') { return str.split('#')[1]; } return null; }; TabPage.prototype.bindMatchMedia = function () { this.mql.addListener(this.onMatchMedia.bind(this)); this.mql.self = this; }; TabPage.prototype.onMatchMedia = function (mql) { if (mql.matches) { this.destroy(); if (win.screenSlider) { win.screenSlider.destroy(); } if (win.Swiper && doc.querySelector('.swiper')) { win.screenSlider = new win.Swiper('.swiper', win.screenSliderOptions); } } else { this.init(true); } }; TabPage.prototype.destroy = function () { this.removeCurrentAttribute(); this.removeRelationAttributes(); this.removeEvents(); }; TabPage.prototype.showFirstPanel = function () { var self = this; var initialiPanel; var index = 0; if (this.panelElements) { initialiPanel = this.panelElements[this.initialIndex]; initialiPanel.classList.add(classNames.isShow); if (initialiPanel.id) { index = this.idList.indexOf(initialiPanel.id); self.addCurrentAttribute(index); if (this.callbacks.onChange) { this.callbacks.onChange(initialiPanel); } } } }; TabPage.prototype.showPanel = function (id) { var panel = doc.getElementById(id); var slider; if (panel) { this.resetKeyframe(panel); panel.classList.add(classNames.isShow); this.hidePanel(id); if (this.idList.length) { this.currentIndex = this.idList.indexOf(id); this.removeCurrentAttribute(); this.addCurrentAttribute(this.currentIndex); } if (this.callbacks.onChange) { this.callbacks.onChange(panel); } slider = panel.querySelector('.swiper'); if (slider && win.Swiper) { win.screenSlider = new win.Swiper('.swiper', win.screenSliderOptions); } } }; TabPage.prototype.resetKeyframe = function (root) { var elements = {}; if (root) { elements = root.getElementsByClassName(classNames.resetAnimation); } if (elements.length) { Array.prototype.forEach.call(elements, function (elm) { var clone = elm.cloneNode(true); elm.parentNode.insertBefore(clone, elm); elm.parentNode.removeChild(elm); }); } }; TabPage.prototype.addCurrentAttribute = function (index) { if (typeof index === 'number') { this.buttonElements[index].classList.add(classNames.isCurrent); } }; TabPage.prototype.removeCurrentAttribute = function () { Array.prototype.forEach.call(this.buttonElements, function (button) { button.classList.remove(classNames.isCurrent); }); }; TabPage.prototype.removeRelationAttributes = function () { Array.prototype.forEach.call(this.panelElements, function (panel) { panel.classList.remove(classNames.isShow); }); }; TabPage.prototype.hidePanel = function (outsideID) { if (this.panelElements) { Array.prototype.forEach.call(this.panelElements, function (panel) { var slider = panel.querySelector('.swiper'); if (panel.id !== outsideID) { panel.classList.remove(classNames.isShow); } if (slider) { win.screenSlider.destroy(); } }); } }; return TabPage; }()); Lib.WidthLine = (function () { var classNames = { key: 'js-equalWidth' }; var timer = null; var WidthLine = function (options) { this.keyClass = (options && options.className) ? options.className : classNames.key; this.elements = null; this.maxWidth = 0; }; WidthLine.prototype.init = function () { this.setElements(); if (this.elements && this.elements.length) { this.maxWidth = this.getMaxHeight(); this.setMaxWidth(); this.bindEvents(); } }; WidthLine.prototype.setElements = function () { this.elements = doc.getElementsByClassName(this.keyClass); }; WidthLine.prototype.getMaxHeight = function (isUpdate) { var max = 0; Array.prototype.forEach.call(this.elements, function (elm) { var rect; var width; if (isUpdate) { elm.removeAttribute('style'); } rect = elm.getBoundingClientRect(); if (rect.width) { width = rect.width + 1; if (max < width) { max = width; } } }); return max; }; WidthLine.prototype.setMaxWidth = function () { var self = this; Array.prototype.forEach.call(this.elements, function (elm) { elm.style.width = self.maxWidth + 'px'; }); }; WidthLine.prototype.bindEvents = function () { this.bindWindowResize(); }; WidthLine.prototype.bindWindowResize = function () { win.addEventListener('resize', this.handlers.resize, false); win.swe = this; }; WidthLine.prototype.handlers = { resize: function () { var self = this.swe; if (timer !== null) { clearTimeout(timer); } timer = setTimeout(function () { self.maxWidth = self.getMaxHeight(true); self.setMaxWidth(); }, 300); } }; return WidthLine; }()); doc.addEventListener('DOMContentLoaded', function () { new Lib.AdjustHeight().init(); new Lib.TabPage().init(); }); win.addEventListener('load', function () { new Lib.WidthLine().init(); }); }(window, document)); (function (win, doc) { 'use strict'; var timer = null; win.screenSlider = null; win.screenSliderOptions = { loop: true, effect: 'fade', autoplay: { delay: 1500, }, speed: 800, allowTouchMove: false, disableOnInteraction: false, }; doc.addEventListener('DOMContentLoaded', function () { if (win.Swiper && doc.querySelector('.swiper')) { win.screenSlider = new win.Swiper('.swiper', win.screenSliderOptions); } }); win.addEventListener('resize', function () { if (timer !== null) { win.clearTimeout(timer); } if (win.screenSlider !== null) { timer = setTimeout(function () { win.screenSlider.update(); }, 300); } }); }(window, document));