//********WPサイト用(案件+kokoro-promo) 共通JS******** // ハンドシェイク受付:子からの「鍵ください」に対して、そのまま鍵を返却する window.addEventListener('message', (e) => { // データの種類を見て、ハンドシェイク要求なら即座に返信する if (e.data && e.data.type === 'HANDSHAKE_REQUEST') { e.source.postMessage({ type: 'HANDSHAKE_REPLY', token: e.data.token }, e.origin); } }, false); window.addEventListener("message", receiveRun, false); function receiveRun(e) { const trustedOrigins = [ 'https://kkr-testsite2.sakura.tv', 'https://www.bengoshi-kokoro.com', 'https://www.iframe.law-kokoro.com', 'https://www.group-iframe.com', 'https://www.inline-frame.com', 'https://www.kokoro-news.com', 'https://www.kokoro.news', 'https://www.kokoro.style' ]; if (!trustedOrigins.includes(e.origin)) return; console.log(e.data); const topUrl = $(".foot_ttl a").attr("href"); const mobile = $(window).width() < 600 ; const topSpace = (mobile) ? $(window).width() * 0.04 : 15; const navHeight = $(".nav").height(); // オブジェクト形式のデータが来た場合の処理 if (typeof e.data === 'object' && e.data !== null && !Array.isArray(e.data)) { const { type, value, option, ifid, trigger = null } = e.data; let data,btntype,id,win; switch (type) { case 'height'://iframe高さ値取得 document.getElementById(ifid + '_if').style.height = value + 'px'; return; case 'reheight'://iframe高さ値取得の再処理 if(option === 'topscr'){//スクロールあり window.scroll(0, 0); } document.getElementById(ifid + '_if').style.height = value + 'px'; return; case 'scr':{//スクロール if(option === 'valueId'){//インラインフレーム間のスクロール win = document.getElementById(ifid + "_if").contentWindow; win.postMessage( {type:'scr',value:value,ifid:ifid},"*"); }else if(option === 'parentScr'){//親ページのスクロール const ifHeight = $(value).offset().top; const scrollposition = ifHeight - navHeight - topSpace; $("html, body").animate({scrollTop:scrollposition}, 500, "linear"); }else{ const ifHeight = $('#' + ifid + '_if').offset().top ; const scrollposition = ifHeight + value - navHeight - topSpace; if (mobile && option === 'pgNav') { $('html, body').scrollTop(scrollposition); }else{ $("html, body").animate({scrollTop:scrollposition}, 500, "linear"); } } return; } case 'scrposi': {//心ニュースインラインフレームSP目次へメニューのスクロールポジション const ifHeight = $('#main_if').offset().top; globalBaseScrollPos = ifHeight + value - navHeight - topSpace; // 外の変数に代入 console.log('基準位置を更新しました:', globalBaseScrollPos); enableScrollWatch(); // スクロール監視を開始 return; } case 'btmclose': {//アコーディオンの下部閉じるボタン const ifHeight = $('#' + ifid + '_if').offset().top ; const scrollposition = ifHeight + option - navHeight - topSpace; $("html, body").animate({scrollTop:scrollposition}, 500, "linear"); document.getElementById(ifid + '_if').style.height = value + "px"; return; } case 'pgtrans'://ページ遷移 const prefixMap = { access: 'access/?', staff: 'staff/?', top: '#' }; const prefix = prefixMap[value]; const uri = prefix ? `${prefix}${option}` : '/'; window.location.href = topUrl + uri; return; case 'ifchange'://iframe切替 if(option === 'accdef'){//アクセス通常 data = value.split("_"); btntype = data[0]; id = data[1]; if(trigger === 'corp'){ const iframe = document.querySelector('#access_submenu iframe#areasub_if'); if (iframe) { const url = new URL(iframe.src); // swtypeパラメータを「corplist」にセット(上書き) url.searchParams.set('swtype', 'corplist'); // 更新したURLを設定 iframe.src = url.toString(); } } }else if(option === 'accpgtrans'){//アクセス遷移後 data = value.split("_"); btntype = data[0]; id = data[1]; const mainIf = document.getElementById("main_if"); const attrurl = mainIf.getAttribute("src"); mainIf.setAttribute("src", attrurl.replace("swtype="+ bfswtype(attrurl), "swtype=" + value)); }else if(option === 'stfdef'){//スタッフ通常 if (value.includes('_')) { data = value.split("_"); btntype = data[0]; id = data[1]; }else{ btntype = value; id = value; } const safbtn = $('#staff_submenu #stf_list_btn').length; if(mobile || safbtn > 0){ stflistLinkGen(btntype);//stf_list_btnリンク作成 } } if(id !== "staff"){ paginationLinkGen(btntype,id);//btn_pre,btn_nextリンク作成 } if($(".if_submenu").hasClass("if_hidden")){ $(".if_submenu").removeClass("if_hidden").addClass("if_show"); if($(".if_submenu_scr").hasClass("if_show")){ $(".if_submenu_scr").removeClass("if_show").addClass("if_hidden"); $("#local_if").removeClass("if_show").addClass("if_hidden"); } } if(mobile){ floatingmenudel();//floatingmenu削除 } return; default: break; } return; } // 文字列でも配列でもない場合は終了 if (typeof e.data !== 'string' && !Array.isArray(e.data)) return; if (Array.isArray(e.data)) {//iframe高さ値の処理(複数) for (const [key, value] of Object.entries(e.data)) { const idName = `${key}_if`; const ifHight = `${value}`; document.getElementById(idName).style.height = ifHight + "px"; } }else if (e.data.charAt(0) === "s") {//アンカーリンクスクロール値の処理 const ifScroll = Number(e.data.replace('&pgNav', '').slice(1)); const ifHeight = $("#main_if").offset().top ; const scrollposition = ifHeight + ifScroll - navHeight - topSpace; if (mobile && e.data.includes('&pgNav')) { $('html, body').scrollTop(scrollposition); }else{ $("html, body").animate({scrollTop:scrollposition}, 500, "linear"); } }else if (e.data.charAt(0) === "h") {//iframe高さ値の処理 document.getElementById("main_if").style.height = e.data.slice(1) + "px"; }else if (e.data.charAt(0) === "r") {//iframe高さ値取得の再処理(アコーディオン開閉時) if(e.data.indexOf("btmclose") !== -1 ){ const resendHeight = e.data.split("="); const rHeight = resendHeight[1].split("&"); const ifScroll = Number(rHeight[1]); const ifHeight = $("#main_if").offset().top ; const scrollposition = ifHeight + ifScroll - navHeight - topSpace; $("html, body").animate({scrollTop:scrollposition}, 500, "linear"); document.getElementById("main_if").style.height = rHeight[0] + "px"; }else{ document.getElementById("main_if").style.height = e.data.slice(1) + "px"; } }else if (e.data.charAt(0) === "c") {//iframe高さ値取得の再処理と親ページのurl再送信(カテゴリ選択時) window.scroll(0, 0); document.getElementById("main_if").style.height = e.data.slice(1) + "px";//iframe高さ値取得の再処理 sendParenturl();//mediainfo、massmediaページの場合url再送信(カテゴリ選択時) }else if (e.data.charAt(0) === "b") {//iframe高さ値取得の再処理(複数) if(e.data.indexOf("topscr") !== -1 ){//スクロールあり const resendHeight = e.data.split("="); const idName = resendHeight[1]; const ifHeight = resendHeight[2]; window.scroll(0, 0); document.getElementById(idName + "_if").style.height = ifHeight + "px"; }else{ const resendHeight = e.data.slice(1).split("="); const idName = resendHeight[0]; const ifHeight = resendHeight[1]; document.getElementById(idName + "_if").style.height = ifHeight + "px"; } } } function bfswtype(attrurl){//swtypeパラメータ取得 const parameters = attrurl.substr(attrurl.indexOf("?") + 1).split( "&" ); const swtypeprm = parameters.filter(function (item) { return item.indexOf("swtype") !== -1 }); const bfswtype = swtypeprm[0].split( "=" ); return bfswtype[1]; } function stflistLinkGen(btntype){//stf_list_btnリンク作成 switch(true){ case btntype === "b": case btntype === "law": var listname = "弁護士"; var btntype = "law"; break; case btntype === "z": case btntype === "ac": var listname = "税理士"; var btntype = "ac"; break; case btntype === "sr": var listname = "社会保険労務士"; //var listname = "社会保険労務士・同試験合格者"; break; case btntype === "gs": var listname = "行政書士・同試験合格者"; break; case btntype === "tk": var listname = "宅地建物取引士・同試験合格者"; break; case btntype === "fp": var listname = "FP・2級FP技能士"; break; case btntype === "sonota": case btntype === "staff": var listname = "その他のスタッフ"; var btntype = "staff"; break; case btntype.indexOf("mokuji-") !== -1: var btntype = "ichiran"; default: } const stfListBtn = document.getElementById("stf_list_btn"); const stfSubmenu = document.getElementById("staff_submenu"); const attrurl = stfListBtn.getAttribute("href"); stfListBtn.setAttribute("href", attrurl.replace("swtype=" + bfswtype(attrurl), "swtype=mokuji-" + btntype)); const text = listname+"一覧"; stfListBtn.innerHTML = text; //stfListBtn.removeAttribute("class"); stfListBtn.className = "stf_list_btn"; if( btntype === "staff" || btntype === "ichiran"){ stfListBtn.classList.add("if_hidden"); } else { stfListBtn.classList.add(btntype); } } function paginationLinkGen(btntype,id){//btn_pre,btn_nextリンク作成 const pnData_array = pnData[btntype]; console.dir(pnData_array); console.log(pnData_array); const sdata = pnData_array.find( (data) => data === id ); const prevIndex = pnData_array.indexOf(sdata) - 1; const prev = prevIndex < 0 ? pnData_array[pnData_array.length - 1] : pnData_array[prevIndex]; const nextIndex = pnData_array.indexOf(sdata) + 1; const next = nextIndex >= pnData_array.length ? pnData_array[0] : pnData_array[nextIndex]; const btnPrev = document.getElementById("btn_prev"); const btnNext = document.getElementById("btn_next"); let attrPrev = btnPrev.getAttribute("href"); let attrNext = btnNext.getAttribute("href"); const ifPagination = document.querySelector(".if_pagination"); const afswtype = btntype !== "access" ? "swtype=" + btntype + "_" : "swtype="; if(ifPagination.classList.contains("if_hidden")){ ifPagination.classList.remove("if_hidden"); ifPagination.classList.add("if_show"); } if (btntype === "grp") { attrPrev = attrPrev.replace("law/", ""); attrNext = attrNext.replace("law/", ""); const btnAll = document.getElementById("area_all_btn"); const attrAll = btnAll.getAttribute("href"); btnAll.setAttribute("href", attrAll.replace("law/", "")); } btnPrev.setAttribute("href", attrPrev.replace("swtype="+ bfswtype(attrPrev), afswtype + prev)); btnNext.setAttribute("href", attrNext.replace("swtype="+ bfswtype(attrNext), afswtype + next)); } function floatingmenudel(){//floatingmenu削除 const floatingMenu = document.querySelector(".floatingmenu"); const toTopLink = document.querySelector(".to_top a"); if(floatingMenu){ floatingMenu.classList.add("if_hidden"); const footer = document.querySelector(".footer"); if (footer) { footer.style.paddingBottom = ""; } } if (toTopLink) { toTopLink.style.paddingBottom = ""; const pagetopHeight = document.querySelector(".to_top").clientHeight; const space = window.innerWidth * 0.005; document.querySelector(".if_pagination div").style.bottom = pagetopHeight + space +"px"; } } function sendParenturl() {//mediainfo、massmediaページの場合url送信 var parentUrl = location.href; var regexp = /mediainfo|massmedia/; if(regexp.test(parentUrl)){ var win = document.getElementById("main_if").contentWindow; win.postMessage("pu," + parentUrl,"*"); } } //データ送信用 $(window).on("load",function(){ sendParenturl();//mediainfo、massmediaページの場合url送信 if( 1 < window.location.search.length ){ const id = window.location.search.substring(1); const win = document.getElementById("main_if").contentWindow; function sendToParent(data) { setTimeout(function(){ win.postMessage(data, '*'); }, 300); } if(location.href.includes("/staff/")){//staffページの場合送信なし const swtype = id; var btntype = id.replace(/\d/g, ""); if(btntype === "b"){ var btntype = "law"; }else if(btntype === "z"){ var btntype = "ac"; } const mainIf = document.getElementById("main_if"); const attrurl = mainIf.getAttribute("src"); const afswtype = btntype !=="staff" ?btntype + "_" + swtype:swtype; if(btntype.indexOf("mokuji-") === -1){ mainIf.setAttribute("src", attrurl.replace("mokuji-if","index-if").replace("swtype="+ bfswtype(attrurl), "swtype=" + afswtype)); }else{ const mokujicorp = btntype.split( "-" ); mainIf.setAttribute("src", attrurl + "-"+ mokujicorp[1]); } stflistLinkGen(btntype);//stf_list_btnリンク作成 if($(".if_submenu").hasClass("if_hidden")){ $(".if_submenu").removeClass("if_hidden").addClass("if_show"); } if(btntype !== "staff" && btntype.indexOf("mokuji-") === -1){ paginationLinkGen(btntype,id);//btn_pre,btn_nextリンク作成 } if($(window).width() < 600){ floatingmenudel();//floatingmenu削除 } }else if (location.href.includes("/access/")){//accessページの場合?以下のid送信 sendToParent({ type: 'ifchange', value: id, option: 'accpgtrans' }); }else{//?以下のid送信 sendToParent({ type: 'scr', value: id, option: 'pgNav', ifid: 'main' }); } } }); $(function(){ //選ばれる理由アコーディオン $('.riyuuttl_list .continue_btn').append(''); $('.riyuuttl_list .riyuu_on').hide(); $('.riyuuttl_list .continue_btn').click(function(){ var navHeight = $('.nav').height(); var topSpace = ($(window).width() < 600) ? $(window).width() * 0.04 : 15; var offsetTop = $(this).parent().offset().top - navHeight - topSpace; if($(window).scrollTop() > offsetTop) { $('html,body').animate({scrollTop:offsetTop}, 500); $(this).prev().delay(400).slideToggle(); } else { $(this).prev().slideToggle(); } }); });