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