"use strict"; (($, win, doc) => { // JQ ES6 sw Pack 21 const $win = $(win), $doc = $(doc), $html = $('html'), $body = $('body'), swns = { goToTop: function () { let $goToTop = $("#goto-top"); $goToTop.hide(); $.timeout = function (time) { return $.Deferred(function (dfd) { return setTimeout(dfd.resolve, time); }).promise(); }; $win.on("scroll", function () { if ($(this).scrollTop() > 789) { $goToTop.stop(true, true).fadeIn(); } else { $goToTop.fadeOut(); } }); $goToTop.on("click", function (e) { e.preventDefault(); $("body,html").animate({scrollTop: 0}, 200); }); } }; // swns{} /* plugin Type BlockLink */ $.fn.blocklinkAssy = function () { // bind under this $(this).on("click", function (e) { e.preventDefault(); win.open($(this).find("a").attr("href"), $(this).find("a").attr("target") || "_self"); }).css({cursor: "pointer"}); }; /*each popup(ChildList) */ const eachPopUpList = function(popFrom_UL_class) { let eachTimeout, target; eachTimeout = []; target = $(popFrom_UL_class); return target.each(function(i) { let $this, childID; $this = $(this); childID = $this.children(".popup").attr("id"); return $this.parent().hover((function() { let j; target.hide(); j = 0; while (j < eachTimeout.length) { clearTimeout(eachTimeout[j]); j++; } return $this.show(); }), (function() { if (childID === "pop0") { } else { return eachTimeout[i] = setTimeout((function() { return $this.hide(); }), 369); } })); }); }; // add current class for nav const navCurrentAdd = ()=> { let filename = $(".current-control").attr("id"); //let url = win.location.href.split("/"); //url = url[url.length -1].split(".html")[0]; $("#SideNavBase, .drawer-menu").find("> li").each(function(i, val) { $(this).removeClass("current"); let nav_id = $(this).attr("id"); nav_id = nav_id.replace(/nav-/g,''); if (nav_id === filename) { $(this).addClass("current"); } }) }; const checkMediaQuery = ()=> { // https://zenn.dev/yuki0410/articles/878f4afbff6668d4e28a-2 // window.matchMedia をちゃんと使った方法 const mediaQueryList = window.matchMedia("(max-width:767px)"); /** * イベントリスナー */ const listener = (event) => { if (event.matches) { console.log('768px未満'); } else { console.log('768px以上'); } }; mediaQueryList.addEventListener("change", listener); listener(mediaQueryList); }; const modalControl = ()=> { $('.js-modal-open').each(function () { $(this).on('click', function () { let target = $(this).data('target'); let modal = document.getElementById(target); $(modal).fadeIn(300); return false; }); }); $('.js-modal-close').on('click', function () { $('.js-modal').fadeOut(300); return false; }); }; // do it DRF $(() => { // sw classic UI's swns.goToTop(); $('.drawer').drawer(); $(".hNavi").blocklinkAssy(); // const's checkMediaQuery(); navCurrentAdd(); modalControl(); /* SideNav */ // clone SideNavBase -> SideNavClone $("#SideNavBase > li").clone().appendTo("#SideNavClone ul"); // add for WP menu-topmenu -> SideNavClone $("#menu-topmenu > li").clone().appendTo("#SideNavClone ul"); // todo popupTarget || clickTarget //eachPopUpList("ul#SideNavBase > li.popupTarget > ul"); /** * smooth scr * todo assy.jsかこっちかで。 */ $('a[href^="#"]').on("click",function(){ const adjust = 0; const speed = 321; let href= $(this).attr("href"); let target = $(href === "#" || href === "" ? 'html' : href); let position = target.offset().top + adjust; $('body,html').animate({scrollTop:position}, speed, 'easeOutCubic'); return false; }); /*// SideNavClone +++ SPハンバーガーでクリック開くかどうか。 $("nav#SideNavClone > ul > li.clickTarget").on("click", function (e) { $(this).siblings().removeClass("current"); $(this).siblings().find("ul.clickChild").removeClass("show"); $(this).toggleClass("current"); $(this).find("ul.clickChild").toggleClass("show"); e.stopPropagation(); // 親への伝播を止める }); // SideNavBase +++ PCsubメニューopenでクリックかホバーか $("ul#SideNavBase > li.clickTarget").on("click", function (e) { $(this).siblings().removeClass("hover"); $(this).addClass("hover"); $(this).parent().parent().find("ul.clickChild").removeClass("show"); $(this).find("ul.clickChild").addClass("show"); $("#re-wrapper").on("click", function (e) { $("ul.clickChild").removeClass("show"); $("ul#SideNavBase > li.clickTarget").removeClass("hover"); }); e.stopPropagation(); // 親への伝播を止める }); // SideNavClone + SideNavBase $("li.popup").on("click", function (e) { $("ul#SideNavBase > li.clickTarget").removeClass("hover"); $("nav#SideNavClone > ul > li.clickTarget").removeClass("current"); $("ul.clickChild").removeClass("show"); e.stopPropagation(); // 親への伝播を止める });*/ /** * swAnchor アンカー残し版(/#hoge) no return false; * @ fixup 外部リンクを避ける修正 & if(target.length) {} */ /*$('a.swAnchor').click(function (e) { //e.preventDefault(); let speed = 543; let href = $(this).attr("href"); if (href.indexOf("#") === 0) { let target = $(href === "#" || href === "" ? 'html' : href); if (target.length) { let position = target.offset().top; $("html, body").animate({scrollTop: position - 30}, speed, "easeOutCirc"); return false; // hide # anchorLink } } });*/ }); // DRF } /* .es6 サイドナビを固定する場合 (load) */ $win.on('load scroll', function() { // offset()で画像を読み込む前に位置を取得(DRF)してしまうことで、位置がずれる場合があり let floatMenu, lastBottomAt, lastBottomHeight, offsetTop, scrollTop; let nav = $('.list-fixed'); let bottomAt = $("#lastBottomAt"); //if (nav[0] != null) { offsetTop = nav.offset().top; } if (nav[0] != null) { offsetTop = 130 } if (bottomAt[0] != null) { lastBottomAt = bottomAt.offset().top; } scrollTop = void 0; // bottomAt あったら固定解除 ケツからの場合は下記だがGナビは上からだからいらない //if (nav[0] != null) { lastBottomHeight = bottomAt.offset().top - nav.height()- bottomAt.height(); } let scrollHeight, scrollPosition; floatMenu = () => { scrollTop = $win.scrollTop(); // https://www.softel.co.jp/blogs/tech/archives/4308 scrollHeight = $doc.height(); scrollPosition = $win.height() + scrollTop; bottomAt = lastBottomAt <= scrollPosition; // スクロール位置がメニューのtop座標を超えたら固定にする if ((scrollTop > offsetTop) && !bottomAt) { nav.addClass('add-fixed'); return nav.css({ "position": "", "top": "" }); } else if (scrollTop < offsetTop) { nav.removeClass('add-fixed'); return nav.css({ "position": "", "top": "" }); } else if (bottomAt) { // #lastBottomAt あったら固定解除する nav.removeClass('add-fixed'); return nav.css({ "position": "absolute", "top": -100 + "px" //"top": lastBottomHeight + "px" }); } }; if (nav[0] != null) { $win.on('scroll', _.throttle((function(e) { return floatMenu(); }), 77)); } }); const animateElem = ()=> { /** * js_contAnimation */ if (($(".contentsList").length)) { setTimeout(function () { $('.contentsList_item').each(function (i) { setTimeout(function () { $(".contentsList_item").eq(i).addClass("active"); }, 99 * i); }); }, 77); } /** * animate.css trigger fixup stopped */ /*let elem = $('.animated'); elem.each(function () { let isAnimate = $(this).data('animate'); let isPlay = $(this).data('playagain') || null; let elemOffset = ~~($(this).offset().top); let scrollPos = $(win).scrollTop(); let wh = $(win).height(); //if (scrollPos > elemOffset - wh + (wh / 2)) { if (scrollPos > elemOffset - wh + ~~(wh / 1.75)) { $(this).addClass(`${isAnimate} active`); } else if (isPlay === 'playagain') { $(this).removeClass(isAnimate); } // data-play="playAgain" //else { $(this).removeClass(isAnimate); } // fixme 繰り返さない場合は // });*/ }; //$win.on('load scroll', _.throttle((function(e) { return animateElem(); }), 77)); /** * sw waypoint .active * "waypoint" + animate.css trigger * "waypoint animated" data-animate="fadeInLeft" */ $(function () { $('.waypoint').waypoint(function (direction) { let isAnimate = $(this.element).data('animate') || null; let isPlay = $(this.element).data('playagain') || null; let activePoint = $(this.element); //console.info(activePoint[0], isAnimate); // #------- sw Log --(´・_・`) if (direction === 'down') { //scroll down activePoint.addClass('active'); if (isAnimate) { activePoint.addClass(`${isAnimate} active`) } animateElem(); } else { //scroll up activePoint.removeClass('active'); if (isPlay === 'playagain') { activePoint.removeClass(`${isAnimate} active`) } } }, {offset: '88%'}); // Topからの発火位置 $('#bottom-in-view').waypoint(function (direction) { let isAnimate = $(this.element).data('animate') || null; let activePoint = $(this.element); if (direction === 'down') { //scroll down activePoint.addClass(`${isAnimate} active`); } else { //scroll up activePoint.removeClass(`${isAnimate} active`); } }, {offset: 'bottom-in-view'}); // fixme elem テスト用 ↑スタイルで実用だ. /*let bottom_func =(_bottomWaypoint, direction)=> { let isAnimate = $(_bottomWaypoint).data('animate') || null; console.info(isAnimate, _bottomWaypoint, direction); // #------- sw Log --(´・_・`) if (direction === 'down') { //scroll down $(_bottomWaypoint).addClass(`${isAnimate} active`); } else { //scroll up $(_bottomWaypoint).removeClass(`${isAnimate} active`); } }; let bottomWaypoint = new Waypoint({ element: document.getElementById('bottom-in-view'), handler: function(direction) { bottom_func("#bottom-in-view", direction); }, offset: 'bottom-in-view' })*/ }); /* ========================================================= jquery.rollover.js / ver.1.1 Copyright (c) 2015 CoolWebWindow This code is released under the MIT License https://osdn.jp/projects/opensource/wiki/licenses%2FMIT_license =========================================================*/ $(function ($) { $.fn.rollover = function () { return this.each(function () { // 画像名を取得 let src = $(this).attr('src'); //すでに画像名に「_on.」が付いていた場合、ロールオーバー処理をしない if (src.match('_on.')) return; // ロールオーバー用の画像名を取得(_onを付加) let src_on = src.replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"); // 画像のプリロード(先読み込み) $('').attr('src', src_on); // スマホ対応 let onMouseover = ('ontouchstart' in document) ? 'touchstart' : 'mouseenter'; let onMouseout = ('ontouchstart' in document) ? 'touchend' : 'mouseleave'; // ロールオーバー処理 $(this).on(onMouseover, function () { $(this).attr('src', src_on); }); $(this).on(onMouseout, function () { $(this).attr('src', src); }); }); }; }); $(document).ready(function ($) { $('.ROV a img').rollover(); }); })(jQuery, window, document);