var mySelfURL = 'http://bg.search.etargetnet.com/generic/uni.php?g=ref:86575'.replace('http://','').replace('https://',''); var mySelfOBJ = false; var xPos = 0, yPos = 0; var minViewPrc = 20; var alreadyCreated = false; var heightRatio = parseInt((9/16)*1000)/1000; var showTime = 4000; var remTime = 4000; var defaultVPAIDURL = ''; var dHeight = 0; var vaiframe = false; var alreadyPlaying = false; var etargetVideoDomain = 'bg'; var etargetVideoReferrer = parseInt('86575'); var standalone = window.navigator.standalone, userAgent = window.navigator.userAgent.toLowerCase(), safari = /safari/.test( userAgent ), ios = /ipod|ipad/.test( userAgent ); console.log('eplayaArticle: start'); var deviceType = 'web'; if(typeof(eplayaDeviceType)=='string' || typeof(eplayaDeviceType)=='number'){ var eplayaDeviceType = parseInt(eplayaDeviceType); if(eplayaDeviceType>0){ deviceType = 'mobile'; } } function playaInit(){ console.log('init'); playaFindMySelf(); playaDivCSS(); playaGetPosition(); alreadyCreated = true; playaCreate(); document.addEventListener('scroll',playaCheckPlay,false); window.addEventListener('resize',playaGetPosition,false); document.getElementById('playaClose').addEventListener('click',function(e){playaRemove(true)},false); } function playaCheckPlay(){ if(typeof(mySelfOBJ)=='object'){ if(playaInView()){ playaPlay(); }else{ playaPause(); } } } function playaPlay(){ if(typeof(vaiframe.contentWindow)=='object'){ var vac = vaiframe.contentWindow; if(typeof(vac)=='object' && vac){ if(alreadyPlaying){ if(typeof(vac.resume)=='function'){ vac.resume(true); } }else{ if(typeof(vac.start)=='function'){ vac.start(true); alreadyPlaying = true; } } } } } function playaPause(){ if(typeof(vaiframe.contentWindow)=='object'){ var vac = vaiframe.contentWindow; if(typeof(vac)=='object' && vac){ if(typeof(vac.pause)=='function'){ vac.pause(true); } } } } function playaGetPosition(){ if(typeof(mySelfOBJ)=='object'){ var el = mySelfOBJ; xPos = 0; yPos = 0; while(el){ xPos += (el.offsetLeft + el.clientLeft); yPos += (el.offsetTop + el.clientTop); el = el.offsetParent; } } } function playaInView(){ if(typeof(mySelfOBJ)=='object'){ var pixelRatio = window.devicePixelRatio || 1; var height = parseInt(playaGetHeight()); var scroll = top.pageYOffset || top.document.documentElement.scrollTop || top.document.body.scrollTop || 0; var ct_min = yPos; var ct_max = yPos+height; var st_min = scroll; var st_max = (top.screen.availHeight)+scroll+(height*(pixelRatio-1)); webConsole(yPos); webConsole(top.screen.availHeight); webConsole(ct_min+'>='+st_min+'&&'+ct_max+'<='+st_max+'-'+height+'-'+scroll); if((ct_min>=st_min && ct_max<=st_max)){ return true; } } return false; } function playaCreate(){ if(typeof(mySelfOBJ)=='object'){ console.log('create'); var height = playaGetHeight(); height = height+'px'; var inside = mySelfOBJ.childNodes[0]; if(typeof(inside)=='object'){ inside = inside.childNodes[0]; if(typeof(inside)=='object'){ buildWholeDesignVA(inside,'100%','100%','/Etarget-half.mp4','article'); } } } } function playaGetHeight(){ var height = parseInt(heightRatio*mySelfOBJ.clientWidth); webConsole(height); var maxHeight = parseInt(parseInt(top.screen.availHeight)/2); webConsole(maxHeight); var pixelRatio = window.devicePixelRatio || 1; webConsole(pixelRatio); if(maxHeight>100){ if(maxHeight0){ playaAdsClose.className = 'adsCloseDefSize'; playaAdsClose.style.cssText = eplayaXko; } } var playaAdsBanner = document.createElement('div'); playaAdsBanner.id = 'adsBanner'; var playaAdsBar = document.createElement('div'); playaAdsBar.id = 'adsBar'; playaAdsBar.appendChild(playaAdsBanner); playaAdsBar.appendChild(playaAdsClose); //subs area var playaSubsArea = document.createElement('div'); playaSubsArea.id = 'playaSubsArea'; fheight = parseInt(parseInt(playaHeight)+4); // wrap var playaWrap = document.createElement('div'); playaWrap.id = 'etargetPlayerWrap'; playaWrap.setAttribute('rel',playaID); playaWrap.appendChild(playaWrapx); playaWrap.appendChild(playaPlayPause); playaWrap.appendChild(playaSubsArea); playaWrap.appendChild(playaAdsBar); playaWrap.appendChild(skipVideo); if(true){ // seek var playaSeekShow = document.createElement('div'); playaSeekShow.id = 'seekShow'; var playaSeekShowText = document.createElement('div'); playaSeekShowText.id = 'seekShowText'; var playaSeekShowArrow = document.createElement('div'); playaSeekShowArrow.id = 'seekShowArrow'; playaSeekShow.appendChild(playaSeekShowText); playaSeekShow.appendChild(playaSeekShowArrow); var playaSeekBall = document.createElement('div'); playaSeekBall.id = 'seekBall'; var playaSeekBallIn = document.createElement('div'); playaSeekBallIn.id = 'seekBallIn'; playaSeekBall.appendChild(playaSeekBallIn); var playaSeekLine = document.createElement('div'); playaSeekLine.id = 'seekLine'; var playaSeekAds = document.createElement('div'); playaSeekAds.id = 'seekAds'; var playaSeekLoader = document.createElement('div'); playaSeekLoader.id = 'seekLoaded'; var playaSeekBar = document.createElement('div'); playaSeekBar.id = 'seekBar'; var playaSeekWrap = document.createElement('div'); playaSeekWrap.id = 'etargetSeek'; playaSeekWrap.setAttribute('rel','et_'+playaID); playaSeekWrap.appendChild(playaSeekShow); playaSeekWrap.appendChild(playaSeekBall); playaSeekWrap.appendChild(playaSeekLine); playaSeekWrap.appendChild(playaSeekAds); playaSeekWrap.appendChild(playaSeekLoader); playaSeekWrap.appendChild(playaSeekBar); //guality var playaQualityAuto = document.createElement('div'); playaQualityAuto.id = 'quality_auto'; playaQualityAuto.className = 'default'; playaQualityAuto.innerHTML = 'auto'; var playaQualitySmall = document.createElement('div'); playaQualitySmall.id = 'quality_small'; playaQualitySmall.innerHTML = '240p'; var playaQualityMedium = document.createElement('div'); playaQualityMedium.id = 'quality_medium'; playaQualityMedium.innerHTML = '360p'; var playaQualityLarge = document.createElement('div'); playaQualityLarge.id = 'quality_large'; playaQualityLarge.innerHTML = '480p'; var playaQualityHD720 = document.createElement('div'); playaQualityHD720.id = 'quality_hd720'; playaQualityHD720.innerHTML = '720p'; var playaQualityHD1080 = document.createElement('div'); playaQualityHD1080.id = 'quality_hd1080'; playaQualityHD1080.innerHTML = '1080p'; var playaQualityHighres = document.createElement('div'); playaQualityHighres.id = 'quality_highres'; playaQualityHighres.innerHTML = 'high'; var playaQuality = document.createElement('div'); playaQuality.id = 'playaQuality'; playaQuality.className = 'playaIcon'; // sets var playaSets = document.createElement('div'); playaSets.id = 'playaSets'; //volume var playaVol = document.createElement('div'); playaVol.id = 'playaVol'; playaVol.className = 'playaIcon'; var playaVolMute = document.createElement('div'); playaVolMute.id = 'playaVolMute'; var playaVolBack = document.createElement('div'); playaVolBack.id = 'playaVolBack'; var playaVolSlideOver = document.createElement('div'); playaVolSlideOver.id = 'playaVolSlideOverlay'; var playaVolSlideLine = document.createElement('div'); playaVolSlideLine.id = 'playaVolSlideLine'; var playaVolSlide = document.createElement('div'); playaVolSlide.id = 'playaVolSlide'; var playaVolSlideIn = document.createElement('div'); playaVolSlideIn.id = 'playaVolSlideIn'; playaVolSlide.appendChild(playaVolSlideIn); playaVolBack.appendChild(playaVolSlideLine); playaVolBack.appendChild(playaVolSlide); playaVol.appendChild(playaVolMute); playaVol.appendChild(playaVolBack); playaVol.appendChild(playaVolSlideOver); //subs var playaSub = document.createElement('div'); playaSub.id = 'playaSubs'; var playaSubWrap = document.createElement('div'); playaSubWrap.id = 'playaSubsWrap'; //play var playaPlayPlay = document.createElement('div'); playaPlayPlay.id = 'playaPlay'; playaPlayPlay.className = 'playaIcon'; if(deviceType=='mobile'){ //playaPlayPlay.className = 'hidden'; } //time var playaSeekTime = document.createElement('div'); playaSeekTime.id = 'seekTime'; playaSeekTime.className = 'playaIcon'; var playaSeekEnd = document.createElement('div'); playaSeekEnd.id = 'seekEnd'; playaSeekEnd.innerHTML='00:00'; var playaSeekStart = document.createElement('div'); playaSeekStart.id = 'seekStart'; playaSeekStart.innerHTML='00:00'; var playaSeekDelim = document.createElement('div'); playaSeekDelim.id = 'seekDelim'; playaSeekDelim.innerHTML='/'; playaSeekTime.appendChild(playaSeekStart); playaSeekTime.appendChild(playaSeekDelim); playaSeekTime.appendChild(playaSeekEnd); //controls var playaControls = document.createElement('div'); playaControls.id = 'playaControls'; //fullscreen if(true){ var playaFull = document.createElement('div'); playaFull.id = 'playaScreen'; playaFull.className = 'playaIcon'; playaControls.appendChild(playaFull); } playaControls.appendChild(playaPlayPlay); playaControls.appendChild(playaQuality); playaControls.appendChild(playaSets); playaControls.appendChild(playaSub); playaControls.appendChild(playaSeekTime); playaControls.appendChild(playaVol); // controls wrap var playaControlsWrap = document.createElement('div'); playaControlsWrap.id = 'playaControlsWrap'; playaControlsWrap.appendChild(playaSeekWrap); playaControlsWrap.appendChild(playaControls); // inWrap playaWrap.appendChild(playaControlsWrap); } // all wrap var playaAllWrap = document.createElement('div'); playaAllWrap.id = 'etargetPlayerWrap_eta'+playaID+'get'; // attrs-> var adsType = adsType ? 'etargetPlayerWrapAll '+adsType : 'etargetPlayerWrapAll'; var wrapClass = deviceType ? adsType+' '+deviceType : adsType; var fullscrn = 1; var related = defRelated; var controls = 1; // playaAllWrap.setAttribute('class',wrapClass); playaAllWrap.setAttribute('autoplay',autoplay); playaAllWrap.setAttribute('fs',fullscrn); playaAllWrap.setAttribute('rel',related); var csstext = 'min-width:'+playaWidth+';min-height:'+playaHeight+';'; playaAllWrap.style.cssText = csstext; playaAllWrap.appendChild(playaWrap); var notif = document.createElement('img'); notif.id = 'playaNotif'; notif.style.cssText = 'width:1px;height:1px;position:absolute;z-index:99;top:0px;right:0px;border:none;background:transparent;display:block;'; playaAllWrap.appendChild(notif); var clear = document.createElement('div'); clear.style.cssText = 'width:100%;clear:both;'; playaAllWrap.appendChild(clear); var iframe = document.createElement('iframe'); iframe.id = 'content_iframe_'+playaID; iframe.style.cssText = csstext+';border:0px;'; iframe.setAttribute('allowFullScreen',true); iframe.setAttribute('webkitAllowFullScreen',true); iframe.setAttribute('scrolling',false); vaiframe = iframe; playaAppend(iframe,beforeWhat); var style = document.createElement('link'); style.type = 'text/css'; style.rel = 'stylesheet'; style.href = '//sk.search.etargetnet.com/embed/player/eplayaV5.1.css'; var style_popup = document.createElement('link'); style_popup.type = 'text/css'; style_popup.rel = 'stylesheet'; style_popup.href = '//sk.search.etargetnet.com/embed/player/ajax_popup.css'; var jquery = document.createElement('script'); jquery.type = 'text/javascript'; jquery.async = false; jquery.src = '//sk.search.etargetnet.com/embed/player/jquery.etarget.min.js'; var popup = document.createElement('script'); popup.type = 'text/javascript'; popup.async = false; popup.src = '//sk.search.etargetnet.com/embed/player/ajax_popup.php'; var vpaid = document.createElement('script'); vpaid.type = 'text/javascript'; vpaid.async = false; vpaid.src = '//sk.search.etargetnet.com/embed/player/vpaidV3.2.js?t='+parseInt(Math.random()*1000); var handler = document.createElement('script'); handler.type = 'text/javascript'; handler.async = false; handler.src = '//sk.search.etargetnet.com/embed/player/eplayaHandlerV3.2.js?t='+parseInt(Math.random()*1000); var yuscript = document.createElement('script'); yuscript.type = 'text/javascript'; yuscript.async = false; yuscript.src = 'https://www.youtube.com/iframe_api'; var customJS = document.createElement('script'); customJS.type = 'text/javascript'; customJS.async = false; customJS.innerHTML = "var autoplayLoadOnlyVideoAds = true, skippable = false, afterVideoAdsEndDoNothing = true;"; iframe.contentWindow.document.open(); iframe.contentWindow.document.write(playaAllWrap.outerHTML); iframe.contentWindow.document.head.appendChild(style); iframe.contentWindow.document.head.appendChild(style_popup); iframe.contentWindow.document.head.appendChild(yuscript); iframe.contentWindow.document.head.appendChild(jquery); iframe.contentWindow.document.head.appendChild(customJS); iframe.contentWindow.document.head.appendChild(popup); iframe.contentWindow.document.head.appendChild(vpaid); iframe.contentWindow.document.head.appendChild(handler); iframe.contentWindow.document.close(); } function playaFindMySelf(){ if(mySelfURL){ var scripts = document.getElementsByTagName('script'); if(typeof(scripts)=='object' || typeof(scripts)=='function'){ var cnt = scripts.length; for(var k in scripts){ var script = scripts[k]; if(typeof(script)=='object'){ var src = script.src.replace('http://','').replace('https://',''); if(src){ if(src==mySelfURL){ mySelfOBJ = script; break; } } } } } } if(typeof(mySelfOBJ)=='object'){ var wrap = document.createElement('div'); wrap.id = 'eplayaWrap'; var inwrap = document.createElement('div'); inwrap.id = 'eplayaArticleWrap'; var div = document.createElement('div'); div.id = 'eplayaInArticleWrap'; var header = document.createElement('div'); header.id = 'eplayaInArticleHeader'; header.innerHTML = 'реклама ЕТАРГЕТ'; var close = document.createElement('div'); close.id = 'playaClose'; div.appendChild(header); div.appendChild(close); inwrap.appendChild(div); wrap.appendChild(inwrap); playaInsert(wrap,mySelfOBJ,false); } } function playaAppend(what,where){ if(typeof(what)=='object' && typeof(where)=='object'){ where.appendChild(what); } } function playaInsert(what,where,rem){ if(typeof(what)=='object' && typeof(where)=='object'){ mySelfOBJ = where.parentNode.insertBefore(what,where); if(typeof(rem)=='boolean'){ if(rem){ where.parentNode.removeChild(where); } } } } function playaDivCSS(){ var css = ''; css += '#eplayaWrap{width:100%;height:0px;overflow:hidden;}'; css += '#eplayaArticleWrap{width:100%;height:calc(100% - 30px);position:relative;padding:15px 0px;overflow:hidden;}'; css += '#eplayaInArticleWrap{width:90%;height:calc(100% - 33px);position:relative;padding:15px;margin:0px auto;border:dashed 1px rgb(200,200,200)}'; css += '#eplayaInArticleHeader{position:absolute;top:-10px;left:calc(50% - 80px);background:white;text-align:center;width:160px;height:20px;line-height:20px;font-size:16px;color:gray;}'; css += '#playaClose{background-color:black;width:20px;height:20px;position:absolute;z-index:1;top:-12px;right:-12px;opacity:0.3;cursor:pointer;border-radius:100%;border:solid 2px white;background-image:url(//sk.search.etargetnet.com/img/close_icon.png);background-position:center;background-size:16px;}'; css += '#playaClose:hover{opacity:1;}'; var style = document.createElement('style'); style.innerHTML = css; top.document.head.appendChild(style); } function playaRemove(slow){ console.log('remove'); if(typeof(mySelfOBJ)=='object'){ if(slow){ var speed = 1; var i = 1; var height = playaGetHeight(); var permicrotime = height/remTime*speed; var showint = setInterval(function(){ var cheight = height-(height*permicrotime*i); if(cheight<=0){ mySelfOBJ.parentNode.removeChild(mySelfOBJ); if(showint){ clearInterval(showint); } }else{ i++; mySelfOBJ.style.cssText = 'height:'+cheight+'px'; } },speed); }else{ mySelfOBJ.parentNode.removeChild(mySelfOBJ); } } } function playaShow(){ if(typeof(mySelfOBJ)=='object'){ if(true){ var speed = 1; var i = 1; var height = playaGetHeight(); var cheight = 0; var permicrotime = height/showTime*speed; var showint = setInterval(function(){ var cheight = height*(permicrotime*i); if(cheight>height){ mySelfOBJ.style.cssText = 'height:'+height+'px;visibility:visible;'; if(showint){ clearInterval(showint); playaCheckPlay(); } }else{ i++; mySelfOBJ.style.cssText = 'height:'+cheight+'px;visibility:visible;'; } },speed); } playaGetPosition(); } } function webConsole(s){ var obj = document.getElementById('web-console'); if(typeof(obj)=='object' && obj!=null){ if(obj.length>0){ var div = document.createElement('span'); div.style.cssText = 'padding:2px;display:block;border-bottom:solid 1px gray;'; if(typeof(s)=='object'){ div.append(s); }else{ div.innerHTML = s; } obj.append(div); var height = obj.scrollHeight; obj.scrollTop(height); } } } document.onreadystatechange = function(){ var state = document.readyState; if(state=='complete' || state=='interactive'){ playaInit(); } }