$(function() { $(".globalNavigationListItem").hover( function() { $(this).find(">a").addClass("active").siblings(".subMenu").addClass("subMenuOpen"); }, function() { $(this).find(">a").removeClass("active").siblings(".subMenu").removeClass("subMenuOpen"); } ); slider.init(); toggleNavigation.init("drawer"); tabNavigation.init(); productList.init(); productImage.init(); }); var slider = (function() { return { init: function() { $(".slider").each(function() { var sliderListItems = $(this).find(".sliderListItem"); var sliderPagingItems = $(this).find(".sliderPagingItem"); var currentIndex = 0; sliderListItems.eq(currentIndex).addClass("active"); sliderPagingItems.eq(currentIndex).addClass("active"); if($(this).hasClass("switchSlider")) { sliderListItems.each(function(index) { $(this).css({"z-index":sliderListItems.length - index}); }); sliderPagingItems.each(function(index) { $(this).hover(function() { sliderListItems.removeClass("active"); sliderListItems.eq(index).addClass("active"); sliderPagingItems.removeClass("active"); $(this).addClass("active"); currentIndex = index; }); $(this).find("a").on("click", function(e) { e.preventDefault(); }); }); setInterval(function() { if(currentIndex >= sliderListItems.length - 1) { currentIndex = 0; } else { currentIndex++; } sliderListItems.removeClass("active"); sliderListItems.eq(currentIndex).addClass("active"); sliderPagingItems.removeClass("active"); sliderPagingItems.eq(currentIndex).addClass("active"); }, 7000); } }); } } })(); var toggleNavigation = (function() { return { init: function(role) { switch(role) { case "drawer": $(".drawerNavigation").prepend("
"); $(".js-drawerSwitch").on("click", function(e) { e.preventDefault(); $("body").addClass("drawerOpen"); }); $(".drawerNavigationBg, .drawerNavigationClose").on("click", function(e) { e.preventDefault(); $('.toggleNavigationWrapper').scrollTop(0); $("body").removeClass("drawerOpen"); }); $(".subMenuSwitch").on("click", function(e) { e.preventDefault(); $(this).toggleClass("active").closest(".mainMenu").siblings(".subMenu").toggleClass("active"); //$(this).toggleClass("active").closest(".mainMenu").siblings(".subMenu").toggle(500); }); break; } } } })(); var tabNavigation = (function() { return { init: function() { $(".tabNavigation").each(function() { var self = $(this); var tabListItems = self.find(".tabListItem"); tabListItems.each(function() { var index = tabListItems.index(this); if(self.find(".tabBody:eq(" + index +")").is(":visible")) { $(this).addClass("active"); } $(this).on("click", function(e) { e.preventDefault(); $(this).toggleClass("active"); tabListItems.not(":eq(" + index +")").removeClass("active"); self.find(".tabBody:eq(" + index +")").toggleClass("active"); self.find(".tabBody:not(:eq(" + index +"))").removeClass("active"); }); }); }); } } })(); var productList = (function() { return { init: function() { $(".productList").each(function() { equalizeHeight($(this).find(".productListItem"), 5, 2, 600); }); var timer = false; var windowWidth = $(window).width(); var resizedWindowWidth; $(window).on("resize", function(){ if (timer !== false) { clearTimeout(timer); } timer = setTimeout(function() { resizedWindowWidth = $(window).width(); if(windowWidth != resizedWindowWidth) { productList.init(); windowWidth = $(window).width(); } }, 200); }); } } })(); function equalizeHeight($items, maxItemNumInRow, maxItemInRowOnBreakPoint, breakPoint) { // 最初に高さを開放 freeEqualizedHeight($items.find(".productListItemHeader")); freeEqualizedHeight($items.find(".productListItemBrand")); freeEqualizedHeight($items.find(".productListItemName")); freeEqualizedHeight($items.find(".productListItemRemarks")); // 行あたりのアイテム数を設定 var itemNumInRow; if($(window).width() > breakPoint) { itemNumInRow = maxItemNumInRow; } else { itemNumInRow = maxItemInRowOnBreakPoint; } // 行ごとに高さを比較し、一番高いものに合わせる for(var i = 0; i maxHeaderHeight ? headerHeight : maxHeaderHeight; maxBrandHeight = brandHeight > maxBrandHeight ? brandHeight : maxBrandHeight; maxNameHeight = nameHeight > maxNameHeight ? nameHeight : maxNameHeight; maxItemRemarksHeight = itemRemarksHeight > maxItemRemarksHeight ? itemRemarksHeight : maxItemRemarksHeight; } // 高さを揃える for (var k = 0; k < itemNumInRow; k++) { $items.eq(i*itemNumInRow + k).find(".productListItemHeader").height(maxHeaderHeight); $items.eq(i*itemNumInRow + k).find(".productListItemBrand").height(maxBrandHeight); $items.eq(i*itemNumInRow + k).find(".productListItemName").height(maxNameHeight); $items.eq(i*itemNumInRow + k).find(".productListItemRemarks").height(maxItemRemarksHeight); } } } function freeEqualizedHeight($items) { $items.css({"height":"auto"}); } var productImage = (function() { return { init: function() { $(".productImage").each(function() { var $mainImage = $(this).find(".productImageMain img"); var $subImageItems = $(this).find(".productImageSubItem"); $subImageItems.eq(0).addClass("active"); $subImageItems.find("a").click(function(e) { e.preventDefault(); $mainImage.attr("src", $("img", this).attr("src")); $subImageItems.removeClass("active"); $(this).parent().addClass("active"); }); }); } } })();