/********************************************* * main.js * ------------------------------------------- * @init * @plugin *********************************************/ var u = new EPOS_CARD.Util(); /* ------------------------------------------- * @init ------------------------------------------- */ $(function(){ $.referrerCheck(); $.mainSlider(); $.toggleExpansion(); $.modalInvi(); $.parameter_control(); u.$win.on("load",function(){ $.scrollAnimationFunc(); $.floatingControl(); $.equalWidth(); $.floatingMenuControl(); }); u.$win.on("scroll",function(){ $.scrollAnimationFunc(); }); }); /* ------------------------------------------- * @plugin ------------------------------------------- */ (function($){ /* * referrerCheck */ $.referrerCheck = function(){ /* * vars */ var $body = $("body"), ref = document.referrer, htmlNm = ref.replace(/^(http|https):\/\/.+?\//g,"/").replace(/\?.+$/g,""), baseDir = "/goldcard/", toAnc01 = "point", toAnc02 = "travel", toAnc03 = "hotel", fromNoIndex = new RegExp(baseDir + "$"), fromIndex = new RegExp(baseDir + "index.html|point.html|travel.html|hotel.html"), fromIndex02 = new RegExp(baseDir + "index02.html|point02.html|travel02.html|hotel02.html"), fromIndex03 = new RegExp(baseDir + "index03.html|point03.html|travel03.html|hotel03.html"), fromIndex04 = new RegExp(baseDir + "index04.html"), fromIndex05 = new RegExp(baseDir + "index05.html"), fromIndexNm = "fromIndex", fromIndex02Nm = "fromIndex02", fromIndex03Nm = "fromIndex03", fromIndex04Nm = "fromIndex04", fromIndex05Nm = "fromIndex05", removeNmBase = "-remove", webkit = /webkit/; /* * function */ // elmRemove var elmRemove = function(elm){ $("." + elm + removeNmBase).remove(); }; // anchorAnimation var anchorAnimation = function(elm){ $("html, body").animate({ scrollTop: $(elm).offset().top - 40 }, 300); }; /* * trigger */ if(htmlNm.match(fromIndex) || htmlNm.match(fromNoIndex)){ $body.addClass(fromIndexNm); elmRemove(fromIndexNm); } else if(htmlNm.match(fromIndex03)) { $body.addClass(fromIndex03Nm); elmRemove(fromIndex03Nm); } else if(htmlNm.match(fromIndex04)) { $body.addClass(fromIndex04Nm); elmRemove(fromIndex04Nm); } else if(htmlNm.match(fromIndex05)) { $body.addClass(fromIndex05Nm); elmRemove(fromIndex05Nm); } else if(htmlNm.match(fromIndex02) || typeof(ref) === "undefined" || ref === ""){ $body.addClass(fromIndex02Nm); elmRemove(fromIndex02Nm); } else { $body.addClass(fromIndex02Nm); elmRemove(fromIndex02Nm); } // リダイレクトアンカー設定 u.$win.on("load",function(){ setTimeout(function(){ if(htmlNm.indexOf(toAnc01) !== -1){ anchorAnimation("#anc01"); } else if(htmlNm.indexOf(toAnc02) !== -1){ anchorAnimation("#anc02"); } else if(htmlNm.indexOf(toAnc03) !== -1){ anchorAnimation("#anc03"); } else { return false; } },500); }); }, $.mainSlider = function(){ /*----------------メインスライダー----------------*/ // 初回表示時 $('.main_sliderCap').on('init',function(){ $('.slick-current ').addClass('sl-on'); }); $('.main_sliderImg').on('init',function(){ $('.slick-current', this).addClass('sl-first'); $('.slick-current', this).removeClass('slick-active'); }); $('.main_sliderText').slick({ slidesToShow: 1, slidesToScroll: 1, autoplay: true, autoplaySpeed: 2100, arrows: false, pauseOnFocus: false, pauseOnHover: false, fade: true, speed: 800, swipe: false, }); $('.main_sliderCap').slick({ slidesToShow: 1, slidesToScroll: 1, autoplay: true, autoplaySpeed: 2100, arrows: false, pauseOnFocus: false, pauseOnHover: false, fade: true, speed: 800, swipe: false, }); $('.main_sliderImg').slick({ slidesToShow: 1, slidesToScroll: 1, autoplay: true, autoplaySpeed: 2100, arrows: false, pauseOnFocus: false, pauseOnHover: false, fade: true, speed: 800, swipe: false, }); // スライド切り替え前 $('.main_sliderCap').on('beforeChange',function(){ $('.slick-current', this).removeClass('sl-on'); $('.slick-current', this).addClass('sl-off'); }); // スライド切り替え後 $('.main_sliderCap').on('afterChange',function(){ $('.slick-slide', this).removeClass('sl-off'); $('.slick-current ', this).addClass('sl-on'); }); $('.main_sliderImg').on('afterChange',function(){ $('.slick-slide', this).removeClass('sl-first'); }); /*----------------コンテンツスライダー----------------*/ $('.gold-support_slider').slick({ autoplay: false, variableWidth: true, slidesToScroll: 1, slidesToShow: 1, centerMode: true, centerPadding: '0px', autoplaySpeed: 4200, dots: true, }); var t = $('.gold-support_slider').offset().top; var p = t - $(window).height(); $(window).on('scroll load',function(){ if($(window).scrollTop() > p && !$('.gold-support_slider').hasClass('play')){ $('.gold-support_slider').slick('slickPlay'); $('.gold-support_slider').addClass('play'); } }); if(u.isRangeSP()){ $('.gold-pre_layout').slick({ autoplay: false, slidesToScroll: 1, slidesToShow: 1, centerMode: true, centerPadding: '30px', infinite:false }); } }, $.toggleExpansion = function(config) { var c = $.extend({ elm: ".toggleWrap", trigger: ".toggleTrigger", target: ".toggleContent", openNm: "open" },config); // vars var $elm =$(c.elm), $trg =$(c.trigger); if($elm.length === 0){ return false; } $trg.on("click",function(){ var self = $(this); if(self.hasClass(c.openNm)){ $("html, body").stop(); } }); }, $.modalInvi = function() { var $elm = $('.cb_invitation_step_modal01'), $elm02 = $('.cb_invitation_application_modal01'); if($elm.length === 0 && $elm02.length === 0){ return false; } $elm.colorbox({ inline: true, maxWidth: "100%", maxHeight: "100%", fixed: true, onComplete: function(){ EPOS_CARD.module.equalHeight(true, true); EPOS_CARD.module.sizeFix(); } }); $elm02.colorbox({ inline: true, maxWidth: "100%", minWidth: "700px", maxHeight: "100%", fixed: true, onComplete: function(){ EPOS_CARD.module.equalHeight(true, true); EPOS_CARD.module.sizeFix(); } }); }, /* * parameter_control */ $.parameter_control = function(config){ var c = $.extend({ elm: ".js-paramHide", elm02: ".js-paramShow" },config); // vars var $elm = $(c.elm), $elm02 = $(c.elm02); if($elm.length === 0 && $elm02.length === 0){ return false; } // trigger var paramName = 'fra_ln_rp', paramName02 = 'mla_rf_rp'; function getParam(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); } if(getParam('cid') == paramName || getParam('cid') == paramName02) { $elm.hide(); $elm02.show(); } else { $elm02.remove(); } }, $.scrollAnimationFunc = function() { var scrollAnimationClass = 'sa'; var scrollAnimationShowClass = 'show'; var scrollAnimationElm = document.querySelectorAll('.' + scrollAnimationClass); for(var i = 0; i < scrollAnimationElm.length; i++) { var elm = scrollAnimationElm[i]; var showPos = 0; showPos = elm.getBoundingClientRect().top; if (window.innerHeight > showPos) { setTimeout(function(index) { scrollAnimationElm[index].classList.add(scrollAnimationShowClass); }.bind(null, i)); } } }, /* * floatingControl */ $.floatingControl = function(){ // vars var $elm = $("#cvFloating"); if($elm.length === 0){ return false; } var dsClass = "fixed", $items = $elm.find(".conversionInner"), speed = 300; // function var fdOut = function(){ $elm.hide().removeClass(dsClass); $items.slideUp(speed); }; var fdIn = function(){ if($elm.hasClass(dsClass)) { // 既にスクロールが始まっていたら処理しない return; } else { $elm.show().addClass(dsClass); $items.slideDown(speed); } }; var scrollAct = function(){ var top = u.$win.scrollTop(), scrTop = $(".gold-main_lead").offset().top; if (top <= scrTop){ fdOut(); } else { fdIn(); } }; // trigger scrollAct(); u.$win.on("scroll",function(){ scrollAct(); }); }, /* * @method equalWidth * - 幅揃え * @param {Boolean} * - 文字可変・リサイズに対応するかどうか */ $.equalWidth = function(fsCheck, wsCheck){ /* vars ------------------------------- */ var $elm = $(".equalWidth"), $children = $elm.children(), childBaseName = "equalChild", fsCheck = fsCheck || false, wsCheck = wsCheck || false; if($elm.length === 0 || $children.length < 2){ return false; } /* function ------------------------------- */ /* 各要素ごとにグループ化 */ var grouping = function(){ var $groupedChildren = $elm.find('*[class*=' + childBaseName + ']'), classNames = {},groups = []; $groupedChildren.each(function(){ var splitClass = $(this).attr("class").split(" "), splitClassNum = splitClass.length, newClassName; for(var i = 0; i < splitClassNum; i++){ newClassName = splitClass[i].match(RegExp(childBaseName + "[a-z0-9]+", 'i')); if(!newClassName){ continue; } else { newClassName.toString(); classNames[newClassName] = newClassName; } } }); for(var c in classNames){ groups.push($elm.find("." + c)); } groups.push($children); return groups; }; /* 各要素の幅を揃える */ var equalWidth = function(elm){ var maxWidth = 0; elm.css("width", "auto"); elm.each(function(){ if($(this).width() > maxWidth){ maxWidth = $(this).width() + 5; } }); return elm.width(maxWidth); }; /* init */ var init = function(){ var groups = grouping(), w = [], child = [], maxWidth = 0; $.each(groups, function(){ var $group = $(this); $group.each(function(i){ $(this).css("width", "auto"); w[i] = $(this).width(); child.push(this); }); }); if(child.length > 1){ equalWidth($(child)); } }; /* init ------------------------------- */ // 文字可変・リサイズへの対応可否 fsCheck ? u.isFontSizeCheck(init) : init(); wsCheck ? u.isWindowSizeCheck(init) : init(); }, /* * floatingMenuControl */ $.floatingMenuControl = function(){ // vars var $elm = $(".gold-sidenav"); if($elm.length === 0){ return false; } var dsClass = "active", onColass = "on", $navBtn = $(".gold-sidenav_btn"), $inner = $(".sidenav_inner"), HTML_SKIN = '
', CSS_SKIN = { display: "none", position: "absolute", width: "100%", height: "100%", top: 0, left: 0, background: "rgba(255, 255, 255, 0.5)", "z-index": "90" }, $bg = $(HTML_SKIN).css(CSS_SKIN), $navElm = $(".sidenav_inner .nav > li"), speed = 300; $bg.appendTo("body #pageContainer"); var noScrollBackContents = function(f, callback){ f = f || false; var open = 'js-fixed', scroll_top; switch (f){ case true: scroll_top = $(window).scrollTop(); $("body").css({ "top": "-" + scroll_top + "px", }); $("body #pageContainer").css({ "padding-right": window.innerWidth - $(window).width() + "px" }); $("body").addClass(open); break; case false: scroll_top = $("body").css('top'); $("body").css({ "top": "", }); $("body #pageContainer").css({ "padding-right": "" }); $("body").removeClass(open); scroll_top = scroll_top.replace(/\-(.+)px/, '$1'); Number(scroll_top); $(window).scrollTop(scroll_top); break; } if(callback != undefined){ callback(); } return } // click $navBtn.on("click", function(){ if($(this).hasClass(onColass)){ $(this).removeClass(onColass); $inner.stop().animate({width:'toggle'},speed).addClass(onColass); $bg.stop().fadeOut(speed); noScrollBackContents(false); } else { $(this).addClass(onColass); $inner.stop().animate({width:'toggle'},speed).addClass(onColass); $bg.stop().fadeIn(speed); noScrollBackContents(true); } }); $bg.on("click", function(){ $navBtn.removeClass(onColass); $inner.stop().animate({width:'toggle'},speed).addClass(onColass); $bg.stop().fadeOut(speed); noScrollBackContents(false); }); // click $navElm.not('.type02').on("click", function(){ if($(this).hasClass(onColass)){ $(this).removeClass(onColass); $(this).find("dd").slideUp(speed); } else { $(this).addClass(onColass); $(this).find("dd").slideDown(speed); } }); // click $navElm.find("dd ul li a").on("click", function(){ $navBtn.removeClass(onColass); $inner.stop().animate({width:'toggle'},speed).addClass(onColass); $bg.fadeOut(speed); noScrollBackContents(false); var href = $(this).attr("href"); if(href.search(/^#anc/) >= 0){ var target = $(href), position = target.offset().top, speed = 300, easing = "swing"; $("html, body").animate({ scrollTop: position }, speed, easing); } return false }); // function var fdOut = function(){ $navBtn.fadeOut(speed).removeClass(dsClass); }; var fdIn = function(){ if($navBtn.hasClass(dsClass)) { // 既にスクロールが始まっていたら処理しない return; } else { $navBtn.fadeIn(speed).addClass(dsClass); } }; var scrollAct = function(){ var top = u.$win.scrollTop(), scrTop = $(".gold-main_lead").offset().top; if (top <= scrTop){ fdOut(); } else { fdIn(); } }; // trigger scrollAct(); u.$win.on("scroll",function(){ scrollAct(); }); }; })(jQuery);