window.addEventListener("message", receiveRun, false);
function receiveRun(e) {
switch(e.origin){
case "https://www.bengoshi-kokoro.com":
case "https://www.iframe.law-kokoro.com":
case "https://www.kokoro-news.com":
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 (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") {//アンカーリンクスクロール値の処理
if(e.data.indexOf("$") !== -1){
var ifScroll = Number(e.data.slice(2));
}else{
var ifScroll = Number(e.data.slice(1));
}
const ifHeight = $("#main_if").offset().top ;
var scrollposition = ifHeight + ifScroll - navHeight - topSpace;
if(mobile ){
if(e.data.indexOf("$") !== -1){
setTimeout(function() {
window.scroll(0, scrollposition);
}, 100);
}else{
$("html, body").animate({scrollTop:scrollposition}, 500, "linear");
}
}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再送信(カテゴリ選択時)
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高さ値取得の再処理(複数)
if(e.data.indexOf("topscr") !== -1 ){//スクロールあり
const resendHeight = e.data.split("=");
const idName = resendHeight[1];
const ifHeight = resendHeight[2];
if(mobile){
const ifoffset = $(".main_col").offset().top ;
if($(".if_submenu").hasClass("show")){
const submenuheight = $(".if_submenu").outerHeight(true);
var heightposition = ifoffset - submenuheight;
var maincolTopSpace = $(window).width() * 0.03;
console.log("maincolTopSpace"+maincolTopSpace);
}else{
var heightposition = ifoffset;
var maincolTopSpace = $(window).width() * 0.035;
console.log("maincolTopSpace"+maincolTopSpace);
}
const scrollposition = heightposition - navHeight - maincolTopSpace;
$("html, body").scrollTop(scrollposition);
}else{
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";
}
}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 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 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 scrollposition = ifHeight + ifScroll - navHeight - topSpace;
$("html, body").animate({scrollTop:scrollposition}, 500, "linear");
}else if (e.data.charAt(0) === "j") {//別ページへ遷移
window.location.href = topUrl + e.data.slice(2);
}else if (e.data.charAt(0) === "k") {//インラインフレーム切替
if(e.data.indexOf("access") !== -1 ){
if($("#access_submenu").hasClass("hidden")){
$("#access_submenu").removeClass("hidden").addClass("show");
}
}else{
const receiveData = e.data.slice(1).split("_");
const btntype = receiveData[0];
const id = receiveData[1];
stflistLinkGen(btntype);//stf_list_btnリンク作成
if(id !== "staff"){
paginationLinkGen(btntype,id);//stf_pre,stf_nextリンク作成
}
if(mobile){
floatingmenudel();//floatingmenu削除
}
}
}
break;
}
}
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(btntype){
case "b":
case "law":
var listname = "弁護士";
var btntype = "law";
break;
case "z":
case "ac":
var listname = "税理士";
var btntype = "ac";
break;
case "sr":
var listname = "社会保険労務士・社会保険労務士試験合格者";
break;
case "gs":
var listname = "行政書士・行政書士試験合格者";
break;
case "tk":
var listname = "宅地建物取引士・宅地建物取引士試験合格者";
break;
case "fp":
var listname = "FP・2級FP技能士";
break;
case "sonota":
case "staff":
var listname = "その他のスタッフ";
var btntype = "staff";
break;
default:
}
const stfListBtn = document.getElementById("stf_list_btn");
const stfSubmenu = document.getElementById("staff_submenu");
const attrurl = stfListBtn.getAttribute("href");
stfListBtn.setAttribute("href", attrurl.replace(bfswtype(attrurl), "mokuji-"+btntype));
const text = listname+"一覧";
stfListBtn.innerHTML = text;
stfListBtn.removeAttribute("class");
if( btntype === "staff"){
stfListBtn.classList.add("hidden");
} else {
stfListBtn.classList.add(btntype);
}
if(stfSubmenu.classList.contains("hidden")){
stfSubmenu.classList.remove("hidden");
stfSubmenu.classList.add("show");
}
}
function paginationLinkGen(btntype,id){//stf_pre,stf_nextリンク作成
const idData_array = Object.values(pnidData[btntype]);
console.log(idData_array);
const sdata = idData_array[0].find( (data) => data === id );
const prev = idData_array[0][idData_array[0].indexOf(sdata) - 1];
const next = idData_array[0][idData_array[0].indexOf(sdata) + 1];
const stfPrev = document.getElementById("stf_prev");
const stfNext = document.getElementById("stf_next");
const stfPagination = document.getElementById("staff_pagination");
if(stfPagination.classList.contains("hidden")){
stfPagination.classList.remove("hidden")
stfPagination.classList.add("show");
}
if(prev === undefined){
stfPrev.classList.add("hidden");
} else {
if(stfPrev.classList.contains("hidden")){
stfPrev.classList.remove("hidden");
}
const attrurl = stfPrev.getAttribute("href");
stfPrev.setAttribute("href", attrurl.replace(bfswtype(attrurl), btntype +"_"+ prev));
}
if(next === undefined){
stfNext.classList.add("hidden");
} else {
if(stfNext.classList.contains("hidden")){
stfNext.classList.remove("hidden");
}
const attrurl = stfNext.getAttribute("href");
stfNext.setAttribute("href", attrurl.replace(bfswtype(attrurl), btntype +"_"+ next));
}
}
function floatingmenudel(){//floatingmenu削除
const floatingMenu = document.querySelector(".floatingmenu");
if(floatingMenu){
floatingMenu.classList.add("hidden");
const toTopLink = document.querySelector(".to_top a");
if (toTopLink) {
toTopLink.style.paddingBottom = "";
const pagetopHeight = document.querySelector(".to_top").clientHeight;
const space = window.innerWidth * 0.005;
document.querySelector("#staff_pagination div").style.bottom = pagetopHeight + space +"px";
}
const footer = document.querySelector(".footer");
if (footer) {
footer.style.paddingBottom = "";
}
}
}
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;
if(location.href.indexOf("/staff/")!== -1){//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 = swtype !=="staff" ?btntype + "_" + swtype:swtype;
mainIf.setAttribute("src", attrurl.replace("mokuji-if","index-if").replace(bfswtype(attrurl), afswtype));
stflistLinkGen(btntype);//stf_list_btnリンク作成
if(btntype !== "staff"){
paginationLinkGen(btntype,id);//stf_pre,stf_nextリンク作成
}
if($(window).width() < 600){
floatingmenudel();//floatingmenu削除
}
}else{//?以下のid送信
win.postMessage(id,"*");
}
}
});
//選ばれる理由アコーディオン
$(function(){
$('.riyuuttl_list .continue_btn,.kouishougaishinsei_sec .continue_btn').append('');
$('.riyuuttl_list .riyuu_on,.kouishougaishinsei_sec .acd_on').hide();
$('.riyuuttl_list .continue_btn,.kouishougaishinsei_sec .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();
}
});
});
//解決実績アコーディオン
$(function(){
/*$('.jisseki_close').append('');*/
$('.jisseki_sec .acd_on').hide();
$('.jisseki_sec .acd_off').click(function(){
$(this).slideToggle();
$(this).prev().slideToggle();
});
$('.jisseki_sec .jisseki_close').click(function(){
if($(this).hasClass('ttl_close')){
$(this).parent().slideToggle();
$(this).parent().next().slideToggle();
} else {
var navHeight = $('.nav').height();
var topSpace = ($(window).width() < 600) ? $(window).width() * 0.04 : 15;
var offsetTop = $(this).parent().parent().offset().top - navHeight - topSpace;
if($(window).scrollTop() > offsetTop) {
$('html,body').animate({scrollTop:offsetTop}, 500);
$(this).parent().delay(400).slideToggle();
$(this).parent().next().delay(400).slideToggle();
}else{
$(this).parent().slideToggle();
$(this).parent().next().slideToggle();
}
}
});
});
$(function(){
$('.main_cat p.m_ttl').removeClass('toggle_btn');
$('.main_cat p.m_ttl i').remove();
});