(function() { var take = function() { function render(template, data){ //console.log("render",template,data) return template.replace(/{{(.*?)}}/g, (match) => { return data[match.split(/{{|}}/).filter(Boolean)[0].trim()] }) } function isMobile () { if (typeof navigator === 'undefined' || typeof navigator.userAgent !== 'string') { return false; } if( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)) { return true } } function getUserAgentData() { if ('userAgentData' in window.navigator) { //console.log("userAgentData",window.navigator.userAgentData) return window.navigator.userAgentData } else { console.log("userAgentData not isSupported") return null } } function chatformCancelButtonClick(){ let w = document.querySelector('.chatform_widget'); if(w.dataset.targetPid){ console.log(w.dataset.targetPid) } w.classList.toggle("close"); if(w.classList.contains("close")){ //console.log("A chat_open") document.body.classList.remove("chat_open"); }else{ //console.log("B chat_close") document.body.classList.add("chat_open"); } } function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); } var isMobile; const userAgentData=getUserAgentData() if(userAgentData){ isMobile = userAgentData.mobile }else{ isMobile = isMobile(); } var client=""; var target="release"; var mode="release"; var device=(isMobile)?"mobile":"pc"; switch (target) { case 'local': client="http://localhost:3333"; break; case 'release': client="https://chatform-client.herokuapp.com/"; break; case 'staging': client="https://chatform-client-staging.herokuapp.com/"; break; default: client="https://chatform-client.herokuapp.com/"; } var search = window.location.search.slice(1) var v_id_val = "" if(getCookie("utag_main_v_id")) v_id_val= getCookie("utag_main_v_id") else if(getCookie("utag_main")) v_id_val = getCookie("utag_main").split("$")[0].split("_id:")[1] else v_id_val = "" // search += (v_id_val)?"&v_id="+v_id_val:"" search += (v_id_val ? "&v_id="+v_id_val : "&v_id=null") var widget = render( ''+ '
'+ '
'+ ''+ '
'+ '
'+ '
'+ '無料体験教材・資料のお申し込み {{target}} {{modestr}}'+ '
'+ ''+ '
'+ '
', { pid :"we6986e67f", mode : mode, client : client, device : device, target : (target!="release")?target:"", modestr: (mode=="draft")?"draft":"", search : (search)?"&"+search:"", } ); const body = document.body; if(body){ //console.log(body) body.classList.add(device) body.insertAdjacentHTML('beforeend', widget); const target = document.getElementsByClassName('chatform_widget')[0]; const observer = new MutationObserver((mutations) => { mutations.forEach((mutation) => { if(!mutation.target.classList.contains("close")){ const iframe = document.getElementsByClassName('chatform_widget_iframe')[0]; var contentWindow = iframe.contentWindow; if(contentWindow){ contentWindow.postMessage("chat_open", "*"); } } }); }); const config = { characterData: true, attributes:true, subtree: true }; observer.observe(target, config); } var setWidget = function(){ let button = document.getElementById('chatform_widget_cancelbtn'); button.addEventListener('click', chatformCancelButtonClick); let chatformBtns = document.querySelectorAll('.chatformBtn'); if(chatformBtns.length>0){ chatformBtns.forEach((item, i) => { item.addEventListener('click', chatformCancelButtonClick); }); } }; setTimeout(setWidget, 1000); } setTimeout(take, 0); }())