//リンク先設定 var liberty_tools_modal_link_url = ''; //親要素の中央に小要素配置 function liberty_tools_modal_move_center(parent,child) { var top = parent.clientHeight / 2 - child.clientHeight / 2; var left = parent.clientWidth / 2 - child.clientWidth / 2; child.style.left = left + 'px'; child.style.top = top + 'px'; } //親要素の内に小要素を縮小して収める function liberty_tools_modal_change_Inner_size(parent,child,img) { var img_ratio = img.naturalHeight / img.naturalWidth if(parent.clientWidth * img_ratio > parent.clientHeight){ var height_diff = child.clientHeight - img.clientHeight; if(parent.clientHeight < img.naturalHeight + height_diff + 40) { height = parent.clientHeight - height_diff - 40; }else{ height = img.naturalHeight; } img.style.height = height + 'px'; img.style.width = height / img_ratio + 'px'; }else{ var width_diff = child.clientWidth - img.clientWidth; if(parent.clientWidth < img.naturalWidth + width_diff + 40) { width = parent.clientWidth - width_diff - 40; }else{ width = img.naturalWidth; } img.style.width = width + 'px'; img.style.height = width * img_ratio + 'px'; } } //配置&リサイズ function liberty_tools_modal_resize() { var modal_background = document.getElementsByClassName('liberty_tools_modal_modal_background')[0]; var modal_content_background = document.getElementsByClassName('liberty_tools_modal_modal_content_background')[0]; var modal_image = document.getElementsByClassName('liberty_tools_modal_modal_image')[0]; liberty_tools_modal_change_Inner_size(modal_background,modal_content_background,modal_image); child = document.getElementsByClassName('liberty_tools_modal_modal_content_background')[0]; liberty_tools_modal_move_center(modal_background,modal_content_background); } //modal_backgroundフェードイン function liberty_tools_modal_fadein() { var modal_background = document.getElementsByClassName('liberty_tools_modal_modal_background')[0]; modal_background.style.opacity = 0; modal_background.style.display = "block"; liberty_tools_modal_resize(); modal_background.classList.add('liberty_tools_modal_fadein'); } //modal_backgroundフェードアウト function liberty_tools_modal_fadeout() { var modal_background = document.getElementsByClassName('liberty_tools_modal_modal_background')[0]; modal_background.classList.add('liberty_tools_modal_fadeout'); setTimeout(function(){ modal_background.style.display = "none"; }, 500); } //モーダル表示 function liberty_tools_modal_setup(request) { if(!request['check']) { return; } liberty_tools_modal_link_url = request['link_url']; var head = document.getElementsByTagName('head').item(0); var style = document.createElement('style'); var text = liberty_tools_modal_css; var rule = document.createTextNode(text); style.media = 'screen'; style.type = 'text/css'; style.appendChild(rule); head.appendChild(style); var modal_background = document.createElement('div'); modal_background.classList.add('liberty_tools_modal_modal_background'); modal_background.style.display = "none"; var modal_content_background = document.createElement('div'); modal_content_background.classList.add('liberty_tools_modal_modal_content_background'); modal_background.appendChild(modal_content_background); var modal_content = document.createElement('div'); modal_content.classList.add('liberty_tools_modal_modal_content'); modal_content_background.appendChild(modal_content); var modal_close = document.createElement('button'); modal_close.classList.add('liberty_tools_modal_modal_close'); modal_content.appendChild(modal_close); var modal_close_svg = document.createElementNS('http://www.w3.org/2000/svg','svg'); modal_close_svg.setAttributeNS (null, "viewBox",'0 0 1279.35 1279.48'); modal_close.appendChild(modal_close_svg); modal_close_svg.innerHTML = ''; //var modal_close_svg_path = document.createElementNS('http://www.w3.org/2000/svg','path'); //modal_close_svg.setAttributeNS (null, 'd','M154.5,1.6a85.93,85.93,0,0,0-24.3,9.5C123.3,15.2,21.3,116,14.5,125.5c-10.1,14.1-14,26.3-14,44,0,16.9,3.6,29.3,12.5,42.7,2.9,4.3,70.5,72.6,214.9,217L438.5,640,227.4,851.2C91.8,987,15,1064.5,12.7,1068.1,3.9,1081.8.6,1093,.6,1110c-.1,18.1,3.7,30.2,13.9,44.5,6.8,9.5,108.8,110.3,115.7,114.4,27.3,15.9,60.4,14.3,85.3-4.2,2.2-1.7,98.6-97.6,214.3-213.1L640,841.5l210.3,210.1c115.6,115.5,212,211.4,214.2,213.1,6.9,5.1,13,8.2,22.4,11.3,20.8,7,43.1,4.4,62.9-7.1,6.9-4.1,108.9-104.9,115.7-114.4,10.1-14.1,14-26.3,14-44,0-16.6-3.6-29-12.1-42.2-2.5-3.9-74.6-76.7-214.8-217.1L841.5,640l210.7-210.8c220.7-220.8,216.2-216.1,221.9-230.3,7.5-18.7,7.7-39.2.4-57.2-5.3-13.2-7.4-15.7-61.5-70-28.9-29.1-55.2-54.8-58.5-57.2-14.1-10.1-26.3-14-44-14-16.6,0-28.9,3.5-42,12-4.1,2.6-72.4,70.2-217.2,214.9L640,438.5,428.8,227.4C283.4,82.2,215.6,15.1,211.5,12.4a90.59,90.59,0,0,0-23-10.1C180.6.1,162.7-.3,154.5,1.6Z'); //modal_close_svg.setAttributeNS (null, 'transform','translate(-0.5 -0.38)'); //modal_close_svg.appendChild(modal_close_svg_path); var modal_image = document.createElement('img'); modal_image.classList.add('liberty_tools_modal_modal_image'); modal_image.src = request['img_url']; modal_content.appendChild(modal_image); document.body.appendChild(modal_background); //リサイズ時 window.addEventListener('resize', function() { liberty_tools_modal_resize(); }); //modal_background押下時 var modal_background = document.getElementsByClassName('liberty_tools_modal_modal_background')[0]; modal_background.addEventListener('click', function(ev) { ev.stopPropagation(); liberty_tools_modal_fadeout(); }); //modal_close押下時 var modal_close = document.getElementsByClassName('liberty_tools_modal_modal_close')[0]; modal_close.addEventListener('click', function(ev) { ev.stopPropagation(); liberty_tools_modal_fadeout(); }); //modal_content_background押下時 var modal_content_background = document.getElementsByClassName('liberty_tools_modal_modal_content_background')[0]; modal_content_background.addEventListener('click', function(ev) { ev.stopPropagation(); }); //modal_imageカーソル設定 var modal_image = document.getElementsByClassName('liberty_tools_modal_modal_image')[0]; if(liberty_tools_modal_link_url != null){ modal_image.style.cursor = "pointer"; } //modal_image押下時 modal_image.addEventListener('click', function(ev) { ev.stopPropagation(); if(liberty_tools_modal_link_url != null){ window.open(liberty_tools_modal_link_url, '_blank'); modal_background.style.display = "none"; } }); modal_background.style.opacity = 0; modal_background.style.display = "block"; modal_image.onload = function() { //modal_backgroundフェードイン setTimeout(function(){ console.log("OK!!"); liberty_tools_modal_fadein(); }, 1000); } } function liberty_tools_modal_run(){ //Ajax通信 var request = new XMLHttpRequest(); request.onreadystatechange = function() { if (request.readyState == 4) { if (request.status == 200) { //成功 console.log('成功'); liberty_tools_modal_setup(eval('(' + request.responseText + ')')); }else{ //失敗 console.log('失敗'); } }else{ //通信中 console.log('通信中'); } } request.open('GET', 'https://tools.liberty-hp.com/436731134/modal/check.json', true); request.send(null); } var liberty_tools_modal_css = (function() {/* .liberty_tools_modal_modal_background { position: fixed; background-color: rgba(0, 0, 0, 0.45); width: 100%; height: 100%; z-index: 1; top: 0; left: 0; right: 0; bottom: 0; z-index: 2147483640; } .liberty_tools_modal_modal_content_background { position: fixed; display: table; top: 0; left: 0; right: 0; bottom: 0; z-index: 2147483641; } .liberty_tools_modal_modal_content{ position: static; padding: 20px; padding-bottom: 9px; } .liberty_tools_modal_modal_content > img{ width: 100%; height: 100%; } .liberty_tools_modal_modal_close{ position: absolute; width: 40px; height: 40px; border-radius: 20px; border: none; background-color: #40AAEF; top: 0px; right: 0px; padding: 9px; cursor: pointer; } .liberty_tools_modal_modal_close:hover{ background-color: #87C9F5; } .liberty_tools_modal_modal_close > svg{ width: 100%; height: 100%; fill: #fff; } .liberty_tools_modal_fadein { animation : liberty_tools_modal_fadeIn 0.5s; animation-fill-mode: both; } @keyframes liberty_tools_modal_fadeIn { 0% { opacity: 0; } 100% { opacity: 1; } } .liberty_tools_modal_fadeout { animation : liberty_tools_modal_fadeOut 0.5s; animation-fill-mode: both; } @keyframes liberty_tools_modal_fadeOut { 0% { opacity: 1; } 100% { opacity: 0; } } */}).toString().match(/\/\*\n*([^]*)\*\//)[1]; liberty_tools_modal_run();