(function(d, w) { if(w.IIB_INIT) return false; w.IIB = w.IIB || { queryParams: {}, }; const pref = 'iib-widget-'; const domain = 'я-застройщик.рф'; const classNameOpened = 'iib-open'; let widget; function iinit() { console.log("iinit"); let styles = d.createElement("style"); styles.innerHTML = ".iib-wrapper{position:fixed;top:-100vh;left:0;height:100vh;width:100vw;transition:.3s}" + "." + classNameOpened + "{overflow:hidden !important}" + "." + classNameOpened + " .iib-wrapper{top:0!important}"; d.body.appendChild(styles); // if(w.IIB && w.IIB.autoInit == false) return; let ls = d.querySelectorAll('[class^="' + pref + '"]'); // console.log(ls); for(let l of ls) { let wrapper = d.createElement("div"); wrapper.classList.add("iib-wrapper"); let id = ''; l.classList.forEach(function (cl) { if(cl.indexOf(pref) >= 0) id = cl; }); let i = d.createElement('iframe'); let protocol = "https"; if (domain === "localhost") { protocol = "http"; } let srcUri = protocol + '://' + domain + '/client?cid=' + id.replace(pref, '') + location.search.replace('?', '&'); // console.log(srcUri); srcUri = new URL(srcUri); for (let p in window.IIB.queryParams) { srcUri.searchParams.append(p, window.IIB.queryParams[p]) } // alert(srcUri); i.src = srcUri; i.frameBorder = 0; i.width = '100%'; i.height = '100%'; wrapper.append(i); l.replaceChildren(wrapper); widget = i; } } function handlerMessage(e) { // if (e.origin.split('/').splice(-1)[0] !== domain) { // return false; // } if(! e.data) return false; console.log("e", e); let data = null; try { data = typeof e.data === "string"? JSON.parse(e.data) : e.data; } catch (e) { return false; } // let id = data.id; if(!data.type) return false; switch (data.type) { case 'rollUp': console.log("rollUp handler") d.body.classList.remove(classNameOpened); break; // case 'setHeight': // let lgts = d.querySelectorAll('.iib-' + id + ' > *'); // for(let l of lgts) // { // l.style.height = data.height + 'px'; // } // break; case 'openLink': location.href = data.uri; break; } } if (window.addEventListener) { w.addEventListener('message', handlerMessage); } else { w.attachEvent('message', handlerMessage); } if(d.readyState === 'ready' || d.readyState === 'complete' || d.readyState === 'interactive') iinit(); d.addEventListener('DOMContentLoaded', function () { iinit(); }); w.IIB_INIT = true; w.iib_reinit = iinit; IIB["methods"] = { open() { d.body.classList.add(classNameOpened); }, close() { d.body.classList.remove(classNameOpened); }, toggle() { d.body.classList.toggle(classNameOpened); }, // IIB.methods.postMessage("IibClientNavTo", {to: "path", params: {}}) postMessage(type, data) { widget.contentWindow.postMessage(JSON.stringify({type, data}), "*") }, navTo(navData) { window.IIB.methods.postMessage("IibClientNavTo", navData) } } }(document, window));