/************************************ * iFrame Wrapper ***********************************/ (function(){ var hash = new Date().getTime(); document.write(''); window['leadiaFrame' + hash] = {}; (function(lf){ lf.params = { hash: hash, form_params: "product=lawyer&template=blue&language=ru&nostats=1®ion=ru&style=default&height=370&p=lawyer&theme=default&t=blue&w=5156&banner=http%3A%2F%2Fstatic.leadia.ru%2Fbanners%2Frazvod_240x400.png&width=750", form_width: "750", form_height: "370", wmid: "5156", host: "localhost", url: "api.clloudia.com" }; lf.ready = function(fn) { if (document.readyState != 'loading'){ fn(); } else { document.addEventListener('DOMContentLoaded', fn); } }; lf.addEvent = function(elem, type, handler){ if (elem.addEventListener){ elem.addEventListener(type, handler, false) } else { elem.attachEvent("on" + type, handler) } }; lf.updatePosition = function() { var form = document.querySelector("#leadia-" + lf.params.hash), width = form.offsetWidth, height = form.offsetHeight, doc_width = window.innerWidth, doc_height = window.innerHeight; form.style.left = ((doc_width/2) - (width/2)) + "px"; form.style.top = ((doc_height/2) - (height/2)) + "px"; }; lf.runEffect = function(){ var form = document.querySelector("#leadia-" + lf.params.hash), shadow = document.querySelector("#leadiaShadow" + lf.params.hash); form.style.display = ""; shadow.style.display = ""; lf.updatePosition(); form.style.opacity = 1; shadow.style.opacity = .5; }; lf.hideIt = function(){ var form = document.querySelector("#leadia-" + lf.params.hash), shadow = document.querySelector("#leadiaShadow" + lf.params.hash); form.style.opacity = 0; shadow.style.opacity = 0; setTimeout(function(){ form.style.display = "none"; shadow.style.display = "none"; }, 300); }; lf.httpGetAsync = function(theUrl){ var iframe = document.createElement("iframe"), id = "iframe" + new Date().getTime(), el; iframe.src = theUrl; iframe.id = id; iframe.style.display = "none"; iframe.onload = function(){ el = document.querySelector("#" + id); el.parentNode.removeChild(el); }; document.querySelector("#leadiaFrame" + lf.params.hash).appendChild(iframe); }; lf.transitionGen = function(v){ return "-webkit-transition: " + v + ";" + "-moz-transition: " + v + ";" + "-ms-transition: " + v + ";" + "-o-transition: " + v + ";" + "transition: " + v + ";"; }; lf.leadiaInit = function(){ var shade, form, iframe, leadia_close_button, leadiaFrame; leadiaFrame = document.createElement("div"); leadiaFrame.id = "leadiaFrame" + lf.params.hash; lf.addEvent(window, "resize", lf.updatePosition); if(!document.querySelector("#leadiaShadow" + lf.params.hash)){ shade = document.createElement("div"); shade.id = "leadiaShadow" + lf.params.hash; shade.style.display = "none"; shade.setAttribute("style", "background:#000; position:fixed; left:0; top:0; width:100%; z-index:8888; height: 100%; opacity: 0; display: none; " + lf.transitionGen("opacity .3s")); lf.addEvent(window, "keydown", function(e){ var code = (e.keyCode ? e.keyCode : e.which); if(code == 27) lf.hideIt(); }); lf.addEvent(shade, "click", function(){ lf.hideIt(); }); leadiaFrame.appendChild(shade); } if(!document.querySelector("#leadia-" + lf.params.hash)){ form = document.createElement("div"); form.id = "leadia-" + lf.params.hash; form.setAttribute("class", "leadia-form"); form.setAttribute("style", "position: fixed; top: 10%; z-index: 9999; width: " + lf.params.form_width + "px; background-color: transparent; opacity: 0; display: none; " + lf.transitionGen("opacity .3s")); iframe = document.createElement("iframe"); iframe.setAttribute("src", "//" + lf.params.url + "/?" + lf.params.form_params); iframe.setAttribute("class", "leadia-form-iframe"); iframe.setAttribute('width', lf.params.form_width); iframe.setAttribute('height', lf.params.form_height); iframe.setAttribute("style", "width:100%; background: #fff; border: 10px solid #fff; border-radius: 10px; height:" + lf.params.form_height + "px; padding: 0px;"); leadia_close_button = document.createElement("div"); leadia_close_button.setAttribute("class", "leadia_close_button"); leadia_close_button.setAttribute("style", "width: 32px; height: 30px; margin-left: -20px; margin-top: -20px; cursor:pointer; background: url(//s3-eu-west-1.amazonaws.com/static.leadia.ru/assets/closebutton.png) no-repeat; position: absolute;"); lf.addEvent(leadia_close_button, "click", function(){ lf.hideIt(); }); form.insertBefore(leadia_close_button, form.firstChild); form.appendChild(iframe); leadiaFrame.appendChild(form); document.body.appendChild(leadiaFrame); } lf.addEvent(document.querySelector(".leadia-trigger-" + lf.params.hash), "click", function(e){ e.preventDefault(); lf.runEffect(); lf.httpGetAsync('//' + lf.params.url + '/stats/tick/form?w=' + lf.params.wmid + '&host=' + lf.params.host); }); }; lf.ready(lf.leadiaInit()); })(window['leadiaFrame' + hash]); })();