;(function($){ // プラグイン名 var PLUGIN_NAME = "tabboxManager"; //// 編集禁止↓ /////////////////////////////////////////////////////// var ImplementationClass; ImplementationClass = function (target, config) { var settings = $.extend({}, $[PLUGIN_NAME].defaults, config); var myself = this; $(target).data(PLUGIN_NAME, myself); //// 編集禁止↑ /////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // Private Properties /////////////////////////////////////////////////////////////////////////// var $contents = null; var $tabButtons = null; var $tabButtonLI = null; var currentTabIndex = 0; var timeoutID = null; /////////////////////////////////////////////////////////////////////////// // コンストラクタ /////////////////////////////////////////////////////////////////////////// /** * constructor */ function _constructor_() { $(target).on('createChildren', initialize); $(target).on('destroyChildren', destroy); if (settings.slideShow) { $(target).hover(function () { if (timeoutID != null) { clearTimeout(timeoutID); } }, function () { if (timeoutID != null) { timeoutID = setTimeout(slideShow, settings.pause); } }); } } /** * * @param event */ function initialize(event) { var $box = $(".tabboxContentsBox", $(target)); $contents = $(".tabboxContents", $(target)); var contentsHeight = 0; $contents.each(function () { var h = $(this).height(); if (h > contentsHeight) { contentsHeight = h; } $(this).css({ position: "absolute", top: 0 }); }); $box.css({ position: "relative" }); $box.height(contentsHeight); $tabButtons = $(".tab_btn"); $tabButtonLI = $("li", $tabButtons); $tabButtonLI.on('click', changeTab); var isSet = false; if (settings.activeTabName) { $tabButtonLI.each(function () { if ($(this).attr('data-tab-name') == settings.activeTabName) { var index = $tabButtonLI.index($(this)); activateTab(index); isSet = true; } }); } if (!isSet) { currentTabIndex = -1; slideShow(); } } /** * * @param event */ function destroy(event) { if (timeoutID != null) { clearTimeout(timeoutID); } if ($tabButtonLI != null) { $tabButtonLI.off(); } timeoutID = null; } /////////////////////////////////////////////////////////////////////////// /*// 編集禁止 ⇒//////////////////////////////*/ $.extend(myself, { //// /*// 編集禁止 ⇒//////////*/ havingnopoint: "" }); _constructor_(); //// /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // Private Methods /////////////////////////////////////////////////////////////////////////// /** * * @param event */ function changeTab(event) { event.preventDefault(); var index = $tabButtonLI.index($(this)); if (currentTabIndex == index) { return; } if (timeoutID != null) { clearTimeout(timeoutID); } timeoutID = null; activateTab(index); } function getAreaUrl(areaName) { var areainfo = earthInfo.selectAreaOptions.areaInfo[areaName]; return $("#con01").attr('data-base-url') + "&dep=" + areainfo.fright_start_name; } /** * @param index */ function activateTab(index) { if (currentTabIndex >= 0) { $("a", $tabButtonLI.eq(currentTabIndex)).removeClass("active"); $contents.eq(currentTabIndex).animate({ opacity: 'hide' }, { duration: settings.duration, easing: 'swing' }); } $contents.eq(index).animate({ opacity: 'show' }, { duration: settings.duration, easing: 'swing' }); $("a", $tabButtonLI.eq(index)).addClass("active"); $(".con01Recommend a").attr('href', getAreaUrl($tabButtonLI.eq(index).attr('data-tab-name'))); currentTabIndex = index; } /** * */ function slideShow() { var nextIndex = currentTabIndex + 1; if (nextIndex >= $tabButtonLI.length) { nextIndex = 0; } activateTab(nextIndex); if (settings.slideShow) { timeoutID = setTimeout(slideShow, settings.pause); } } /////////////////////////////////////////////////////////////////////////// /*// 編集禁止 ⇒//////////////////////////////*/ }; $[PLUGIN_NAME] = { //// /////////////////////////////////////////////////////////////////////////// // Default Settings /////////////////////////////////////////////////////////////////////////// defaults : { pause : 3000 , duration : 500 , slideShow : true , activeTabName: null } /////////////////////////////////////////////////////////////////////////// //// 編集禁止↓ /////////////////////////////////////////////////////////// }; $.fn[PLUGIN_NAME] = function(config){ return this.each(function(i){ new ImplementationClass(this, config); }); }; })(jQuery);