$(function(){
//狭い画面幅でのグローバルナビゲーション
$('').appendTo('header [role="navigation"]');
$('', {
'value': '',
'text': 'メニュー',
'selected': 'selected'
}).appendTo('header [role="navigation"] > select');
$('header [role="navigation"] a').each(function() {
var el = $(this);
$('', {
'value': el.attr('href'),
'text': el.text()
}).appendTo('header [role="navigation"] > select');
});
$('header [role="navigation"] > select, .widget-archive-dropdown select').change(function() {
window.location = $(this).find('option:selected').val();
});
//トップへ戻るボタン
$(document).ready(function(){
// scroll body to 0px on click
$('#back_top a').click(function () {
$('body,html').animate({scrollTop: 0}, '400');
return false;
});
});
});
/********kokoro-blog用********/
// ハンドシェイク受付:子からの「鍵ください」に対して、そのまま鍵を返却する
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',
];
if (!trustedOrigins.includes(e.origin)) return;
console.log(e.data);
const topUrl = $("#global_home 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;
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'){//インラインフレーム間のスクロール
const 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 '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: '#'
};
id = (value === 'access')? option.replaceAll('grp_', ''):option;
const prefix = prefixMap[value];
const uri = prefix ? `${prefix}${id}` : '/';
window.location.replace(topUrl + uri);
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.slice(1));
const ifHeight = $("#main_if").offset().top ;
const scrollposition = ifHeight + ifScroll - navHeight - topSpace;
if(mobile){
$('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";
}
}
//ページデータ読み込み完了後データ送信:?anchorname形式のanchorname送信
$(window).on('load',function(){
if( 1 < window.location.search.length ){//?以下の文字数チェック
const params = window.location.search.substring(1);//substring[1]で?より後ろを取得
if( params.search(/[&=]/) === -1 ){//?以降に&も=もない場合実行
let ifname;
if (location.href.indexOf("/staff/") !== -1) { // スタッフページの場合
if (params === 'staff') {
ifname = 'staffall';
} else {
ifname = 'expertall';
}
} else {
ifname = 'main';
}
const targetIf = document.getElementById(ifname + '_if');
if (targetIf && targetIf.contentWindow) {
const win = targetIf.contentWindow;
// 子側のハンドシェイク完了(isAuthorized = true)を確実に待つために少し遅延させる
setTimeout(function(){
win.postMessage({ type: 'scr', value: params, option: 'pgNav', ifid: ifname }, '*');
}, 300);
}
}
}
});
//ページ操作・解析可能後データ処理:?key=pageid形式のpageidをiframe srcに追記
$(document).ready(function(){
if( 1 < window.location.search.length ){//?以下の文字数チェック
var params = window.location.search.substring(1);//substring[1]で?より後ろを取得
if( params.search(/[&=]/) != -1 ){//?以降に&か=がある場合実行
var param = params.split('&');
var paramArray = [];
for ( i = 0; i < param.length; i++ ) {
neet = param[i].split("=");
paramArray.push(neet[0]);
paramArray[neet[0]] = neet[1];
}
document.getElementById('main_if').src = document.getElementById('main_if').src + paramArray['page'];
}
}
});
//ページデータ読み込み完了後データ送信:?anchorname形式のanchorname送信
$(window).on('load',function(){
if( 1 < window.location.search.length ){//?以下の文字数チェック
var params = window.location.search.substring(1);//substring[1]で?より後ろを取得
if( params.search(/[&=]/) == -1 ){//?以降に&も=もない場合実行
if(location.href.indexOf("/staff/") !== -1){//スタッフページの場合
if(params === 'staff'){
var win = document.getElementById('staffall_if').contentWindow;
win.postMessage('#'+params+'&mif&staffall','*');
}else{
var win = document.getElementById('expertall_if').contentWindow;
win.postMessage('#'+params+'&mif&expertall','*');
}
}else{
var win = document.getElementById('main_if').contentWindow;
win.postMessage(params,'*');
}
}
}
});
function openparking(url) {//駐車場ポップアップ
window.open(url, "", "width=740,height=600, scrollbars=yes,resizable=yes");
}