(function(){ // Add css var sheet = document.createElement('style') sheet.innerHTML = '.adbUcpIframeFullsize{position:fixed !important; top:0px !important;left:0px !important;right:0px !important;bottom:0px !important;width:100% !important;height:100% !important;z-index:2000 !important;}'; document.body.appendChild( sheet ); // Init API var s = document.createElement("iframe"); s.id = 'adbUcpIframe'; s.src = "https://www.autopriwos.by/api/10b36cddb75a969e19d1efaa1836f7c1/parts/form/"; s.scrolling = 'no'; s.frameborder = 'no'; s.allowtransparency = 'yes'; s.style.border = 'none'; s.style.width = '100%'; s.style.overflow = 'hidden'; document.getElementById("adbUcpSearchDiv").appendChild(s); // Fullsize layers number adbUcpLayers = {}; // Frame events messages window.addEventListener( 'message', function(e) { switch( e.data[0] ) { // Set frame height case 'setHeight': if( document.getElementById('adbUcpIframe').className != 'adbUcpIframeFullsize' ) document.getElementById('adbUcpIframe').height = e.data[1] + 'px'; break; // Set full size mode case 'fullSize': // Store layer adbUcpLayers[ e.data[1] ] = 1; // Set full size if( document.getElementById('adbUcpIframe').className != 'adbUcpIframeFullsize' ) document.getElementById('adbUcpIframe').className = 'adbUcpIframeFullsize'; break; // Set normal size mode case 'normalSize': // Delete layer if( typeof adbUcpLayers[ e.data[1] ] != 'undefined' ) delete adbUcpLayers[ e.data[1] ]; // Process if( Object.keys( adbUcpLayers ).length == 0 ) { // Set normal size document.getElementById('adbUcpIframe').className = ''; // Scroll to document.getElementById('adbUcpIframe').scrollIntoView(); } break; // Scroll top case 'scrollTop': var el = document.getElementById('adbUcpIframe').getBoundingClientRect(); var y = el.top + window.scrollY; window.scrollTo( 0, e.data[1] + y ); break; } }, false ); })();