window.addEventListener("message", receiveRun, false); function receiveRun(e) { switch(e.origin){ case "https://www.bengoshi-kokoro.com": case "https://www.kokoro-news.com": console.log(e.data); const topUrl = $(".foot_ttl a").attr("href"); if (Array.isArray(e.data)) {//iframe高さ値の処理(複数) window.scroll(0,0); 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.slice(1)); const ifHeight = $("#main_if").offset().top ; const navHeight = $(".nav").height(); const topSpace = ($(window).width() < 600) ? $(window).width() * 0.04 : 15; const scrollposition = ifHeight + ifScroll - navHeight - topSpace; $("html, body").animate({scrollTop:scrollposition}, 500, "linear"); }else if (e.data.charAt(0) === "h") {//iframe高さ値の処理 window.scroll(0,0); document.getElementById("main_if").style.height = e.data.slice(1) + "px"; }else if (e.data.charAt(0) === "r") {//iframe高さ値取得の再処理(アコーディオン開閉時) document.getElementById("main_if").style.height = e.data.slice(1) + "px"; }else if (e.data.charAt(0) === "c") {//iframe高さ値取得の再処理と親ページのurl再送信(カテゴリ選択時) document.getElementById("main_if").style.height = e.data.slice(1) + "px";//iframe高さ値取得の再処理 sendParenturl();//mediainfo、massmediaページの場合url再送信(カテゴリ選択時) }else if (e.data.charAt(0) === "a") { if(location.href.indexOf("/access/")!== -1){//アクセスページの時、別インラインフレーム内スクロール const id = e.data.slice(2); const win = document.getElementById("main_if").contentWindow; win.postMessage(id,"*"); }else{//アクセスページへ移動し、スクロール window.location.href = topUrl + "access/?" + e.data.slice(2); } }else if (e.data.charAt(0) === "b") {//iframe高さ値取得の再処理(複数) const resendHeight = e.data.slice(1).split("="); const idName = resendHeight[0]; const ifHight = resendHeight[1]; document.getElementById(idName + "_if").style.height = ifHight + "px"; }else if (e.data.charAt(0) === "d") {//エリアマップアンカーリンクスクロール値の処理 const idHeight = e.data.slice(1).split("&"); const idName = idHeight[0]; const ifScroll = Number(idHeight[1]); const ifHeight = $(idName + "_if").offset().top; const navHeight = $(".nav").height(); const topSpace = ($(window).width() < 600) ? $(window).width() * 0.04 : 15; const scrollposition = ifHeight + ifScroll - navHeight - topSpace; $("html, body").animate({scrollTop:scrollposition}, 500, "linear"); }else if (e.data.charAt(0) === "e") {//インラインフレーム内からインラインフレーム外アンカーリンクへのスクロール処理 const id = e.data.slice(1); const ifHeight = $(id).offset().top; const navHeight = $(".nav").height(); const topSpace = ($(window).width() < 600) ? $(window).width() * 0.04 : 15; const scrollposition = ifHeight - navHeight - topSpace; $("html, body").animate({scrollTop:scrollposition}, 500, "linear"); }else if (e.data.charAt(0) === "f") {//トップページへ移動し、スクロール(事務所のへの行き方ボタン) window.location.href = topUrl + e.data.slice(1); }else if (e.data.charAt(0) === "g") {//インラインフレームのスクロールid送信(複数) const sendId = e.data.slice(1).split("&"); const id = sendId[0]; const idName = sendId[1]; const win = document.getElementById(idName + "_if").contentWindow; win.postMessage( id + "&mif&" + idName,"*"); }else if (e.data.charAt(0) === "i") {//インラインフレームのスクロール処理(複数) const idHeight = e.data.slice(1).split("&"); const idName = idHeight[0]; const ifScroll = Number(idHeight[1]); const ifHeight = $("#" + idName + "_if").offset().top; const navHeight = $(".nav").height(); const topSpace = ($(window).width() < 600) ? $(window).width() * 0.04 : 15; const scrollposition = ifHeight + ifScroll - navHeight - topSpace; $("html, body").animate({scrollTop:scrollposition}, 500, "linear"); } break; } } 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 ){//?以下のid送信 const id = window.location.search.substring(1); if(location.href.indexOf("/staff/")!== -1){ const idName = id === "staff"?"clerk":"expert"; const win = document.getElementById(idName + "_if").contentWindow; win.postMessage( "#"+ id + "&mif&" + idName,"*"); }else{ const win = document.getElementById("main_if").contentWindow; win.postMessage(id,"*"); } } }); //アコーディオンコンテンツ $(function() { $('.riyuuttl_list>dt>a').append(''); $('.riyuuttl_list>dd>span').append(''); $('.riyuuttl_list>dt>a').click(function() { if($(this).hasClass('close')){ $(this).text("詳しくはこちら"); $(this).append(''); } else { $(this).text("閉じる"); $(this).append(''); }; $(this).parent().next().slideToggle(); $(this).toggleClass('close'); }); $('.riyuuttl_list>dd>span').click(function() { $(this).parent().prev().children('a').text("詳しくはこちら"); $(this).parent().prev().children('a').append(''); $(this).parent().prev().children().toggleClass('close'); var offsetTop = $(this).parent().prev().offset().top; var navHeight = $('.nav').height(); var scrollPosition = offsetTop-navHeight-15; if($(window).scrollTop() > scrollPosition){ $('html,body').animate({scrollTop: scrollPosition}, 500); $(this).parent().delay(400).slideToggle(); }else{ $(this).parent().slideToggle(); } }); });