/** InRead Varese-Monza - v. 1.5 */ var adAgioInRead = ''; (function(){ //variables var adAgioVideoSrc = '342/91_8342_2_1__eurospin_23_1.0_BASSA.mp4', adAgioContainerWidth = '640', adAgioContainerHeight = 'auto', adAgioVolumeOn_img = '', adAgioVolumeOff_img = '', adAgioPoster_img = ''; if(adAgioVolumeOn_img === "") adAgioVolumeOn_img = "//adagiobanner.s3.amazonaws.com/img_uploads/766/91_526766_1_audio_on.png"; if(adAgioVolumeOff_img === "") adAgioVolumeOff_img = "//adagiobanner.s3.amazonaws.com/img_uploads/766/91_526766_1_audio_off.png"; //style and html var addingElement = function(){ var elemTag = '
'; return elemTag; }; //js var addingScript = function(){ var s = document.createElement('script'); s.type = "text/javascript"; var scriptCode = ''; scriptCode += 'var adAgioVideo = function(){'; scriptCode += ' var adVideo = document.createElement(\'video\'),'; scriptCode += ' adText = document.createTextNode("Your Browser doesn\'t support video tag"),'; scriptCode += ' adSource = document.createElement(\'source\');'; scriptCode += ' adSource.src = "//am91.s3.amazonaws.com/'+ adAgioVideoSrc +' ";'; scriptCode += ' adSource.type = \'video/mp4\';'; scriptCode += ' adVideo.id = \'adAgioVideo\';'; scriptCode += ' adVideo.appendChild(adSource);'; scriptCode += ' adVideo.appendChild(adText);'; scriptCode += ' adVideo.style.width = "100%";'; scriptCode += ' adVideo.style.cursor = "pointer";'; scriptCode += ' return adVideo;'; scriptCode += ' };'; scriptCode += ' var adAgioText = function(){'; scriptCode += ' var adString = document.createElement(\'p\');'; scriptCode += ' adString.insertAdjacentHTML(\'afterbegin\', \'PUBBLICITÀ\');'; scriptCode += ' adString.id = \'adAgioText\';'; scriptCode += ' adString.style.height = \'5px\'; adString.style.textAlign = \'center\'; adString.style.color = \'grey\';'; scriptCode += ' adString.style.fontWeight = \'bold\';'; scriptCode += ' return adString;'; scriptCode += ' };'; scriptCode += ' var adAgioProgress = function(){'; scriptCode += ' var adProgress = document.createElement(\'progress\'); adProgress.id = \'adProgress\';'; scriptCode += ' adProgress.value = \'0\'; adProgress.max = \'100\'; adProgress.style.position = \'relative\';'; scriptCode += ' adProgress.style.backgroundColor = \'#f3f3f3\'; adProgress.style.border = \'0\'; adProgress.style.height = \'4px\';'; scriptCode += ' adProgress.style.width = \'100%\'; adProgress.style.borderRadius = \'9px\'; adProgress.style.top = \'-29px\';'; scriptCode += ' return adProgress;'; scriptCode += ' };'; scriptCode += ' var adAgioControls = function(){'; scriptCode += ' var adControls = document.createElement(\'div\'), adVolumeOn = document.createElement(\'div\'),'; scriptCode += ' adVolumeOff = document.createElement(\'div\'), volumeOn = document.createElement(\'img\'),'; scriptCode += ' volumeOff = document.createElement(\'img\');'; scriptCode += ' volumeOn.src = "'+adAgioVolumeOn_img+'"; volumeOn.alt = \'audio_on\';'; scriptCode += ' volumeOff.src = "'+adAgioVolumeOff_img+'"; volumeOff.alt = \'audio_off\';'; scriptCode += ' volumeOn.style.border = \'0px !important\';'; scriptCode += ' volumeOff.style.border = \'0px !important\';'; scriptCode += ' adVolumeOn.appendChild(volumeOn); adVolumeOff.appendChild(volumeOff); adControls.id = \'adAgioControls\'; adControls.style.display = \'none\';'; scriptCode += ' adControls.style.display="block";adControls.style.height="34px";adControls.style.position="relative";adControls.style.marginTop="-34px";adControls.style.zIndex="50";' + 'adControls.style.width = "34px"; adControls.style.marginLeft = "auto"; adControls.style.cursor = "pointer"; '; scriptCode += ' volumeOn.setAttribute("style","width:34px;height:34px;border: 0px solid !important;");'; scriptCode += ' adVolumeOn.id = \'adAgioVolumeOn\'; adVolumeOn.style.position = \'absolute\'; adVolumeOn.style.bottom = \'10px\'; adVolumeOn.style.right = \'4px\';'; scriptCode += ' volumeOff.setAttribute("style","width:34px;height:34px;border: 0px solid !important;");'; scriptCode += ' adVolumeOff.id = \'adAgioVolumeOff\'; adVolumeOff.style.position = \'absolute\'; adVolumeOff.style.bottom = \'10px\'; adVolumeOff.style.right = \'4px\';'; scriptCode += ' adControls.appendChild(adVolumeOn); adControls.appendChild(adVolumeOff);'; scriptCode += ' return adControls;'; scriptCode += ' };'; scriptCode += ' var adExec = false;'; scriptCode += ' var getMobileOperatingSystem = function(){' + ' var userAgent = navigator.userAgent || navigator.vendor || window.opera;' + ' if(/windows phone/i.test(userAgent)){ return "w_phone"; }' + ' if(/android/i.test(userAgent)){ return "Android"; }' + ' if(/iPhone|iPod/.test(userAgent) && !window.MSStream){ return "iOS_phone"; }' + ' if(/iPad/.test(userAgent) && !window.MSStream){ return "iOS_tab"; }' + ' return "unkown";' + ' };'; scriptCode += ' var adAgioForcePlayOnIPAD = function(){ ' + ' var adAgioIpadPlayer = document.getElementById(\'adAgioVideo\');' + ' adAgioIpadPlayer.play();' + ' };'; scriptCode += ' var checkFocus = function(){'; scriptCode += ' if (adExec) return;'; scriptCode += ' var adContainer = document.getElementById(\'adAgioVideo\'), adControls = document.getElementById(\'adAgioControls\'), adParentContainer = document.getElementById(\'adAgioContainerVideo\'),'; scriptCode += ' rect = adContainer.parentNode.getBoundingClientRect(), parentN = adContainer.parentNode.getBoundingClientRect(), area = Math.round(rect.top + Math.round(parentN.width * 9/16/2));'; scriptCode += ' if (area >= 0 && area <= (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) && parentN.width > 0) {'; scriptCode += ' adExec = true; adParentContainer.insertBefore(adAgioText(),adContainer); adContainer.style.height = \''+adAgioContainerHeight+'\';'; scriptCode += ' adControls.style.display = \'block\'; adParentContainer.appendChild(adAgioProgress());' + ' var os_detected = getMobileOperatingSystem();' + ' var adVolOff = document.getElementById(\'adAgioVolumeOff\');' + ' var adVolOn = document.getElementById(\'adAgioVolumeOn\');' + ' if(os_detected === "unkown"){ ' + ' ' + ' adVolOff.style.display = "none";' + ' adContainer.muted = false; ' + ' }' + ' else if(os_detected === "iOS_tab") { ' + ' adContainer.muted = true; ' + ' adVolOn.setAttribute("style","display:none"); ' + ' adVolOff.setAttribute("style","display:block"); ' + // ' adControls.setAttribute("style","display:none !important"); ' + ' } ' + ' else{ adContainer.muted = true; adVolOn.style.display = "none"; adVolOff.style.display = "block";}' + ' if( os_detected === "iOS_tab" || os_detected === "iOS_phone" || os_detected === "w_phone"){ ' + ' window.document.addEventListener("touchstart", adAgioForcePlayOnIPAD, false);' + ' if(os_detected === "iOS_phone"){' ; if (adAgioPoster_img != "") scriptCode += ' adContainer.setAttribute("poster","' + adAgioPoster_img + '");'; scriptCode += ' adContainer.setAttribute("muted","muted"); ' + ' adContainer.muted = true;' + ' adVolOn.style.display = "none"; adVolOff.style.display = "block";' + ' } ' + ' adContainer.setAttribute("playsinline","true");' + ' adContainer.play(); ' + ' }' + ' adContainer.play();' + ' '; scriptCode += ' }'; scriptCode += ' else{ adExec = false; }'; scriptCode += ' };'; scriptCode += ' var adAgioExec = function(){'; scriptCode += ' var adContainer = document.getElementById(\'adAgioContainerVideo\'); adContainer.appendChild(adAgioVideo()); adContainer.appendChild(adAgioControls());'; scriptCode += ' var adVideo = document.getElementById(\'adAgioVideo\'), adVolumeOn = document.getElementById(\'adAgioVolumeOn\'), '; scriptCode += ' adVolumeOff = document.getElementById(\'adAgioVolumeOff\'), adControlsContainer = document.getElementById(\'adAgioControls\'), audioControls = false, value = 0;' + ' var detected_os = getMobileOperatingSystem(); '; scriptCode += ' window.addEventListener(\'scroll\', checkFocus);'; scriptCode += ' adVideo.addEventListener(\'play\',function(){'; scriptCode += ' var time = (1000/(document.getElementById(\'adProgress\').max))*(Math.round(adVideo.duration));'; scriptCode += ' var updateAdProgress = setInterval(function(){'; scriptCode += ' value = value +1;'; scriptCode += ' if(document.getElementById(\'adProgress\') !== null){'; scriptCode += ' if(value === document.getElementById(\'adProgress\').max) clearInterval(updateAdProgress);'; scriptCode += ' else document.getElementById(\'adProgress\').value = value;'; scriptCode += ' }'; scriptCode += ' else clearInterval(updateAdProgress);'; scriptCode += ' }, time); });'; scriptCode += ' adVideo.addEventListener(\'mouseover\',function(){'; scriptCode += ' if(!audioControls) { adVideo.muted = false; adVolumeOn.style.display = \'block\'; adVolumeOff.style.display = \'none\'; } });'; scriptCode += ' adVideo.addEventListener(\'mouseout\',function(){'; scriptCode += ' if(!audioControls){ adVideo.muted = true; adVolumeOff.style.display = \'block\'; adVolumeOn.style.display = \'none\'; } });'; scriptCode += ' adVideo.addEventListener(\'ended\',function(){'; scriptCode += ' adVideo.style.height = \'0px\'; adVideo.parentNode.removeChild(document.getElementById(\'adAgioText\'));'; scriptCode += ' adVideo.parentNode.removeChild(document.getElementById(\'adProgress\')); adContainer.removeChild(adContainer.childNodes[0]); adContainer.parentNode.removeChild(adContainer); ' + ' if(detected_os === "iOS_tab" || detected_os === "iOS_phone" || detected_os === "w_phone"){' + ' window.document.removeEventListener("touchstart",adAgioForcePlayOnIPAD,false);' + ' }' + ' });'; scriptCode += ' adVolumeOn.addEventListener(\'click\',function(event){ ' + ' event.stopPropagation(); ' + ' if(detected_os === "iOS_phone"){' + ' window.document.removeEventListener("touchstart",adAgioForcePlayOnIPAD,false);' + ' adVideo.setAttribute("muted","true");' + ' adVideo.muted = true;' + ' }' + ' else { adVideo.muted = true; }' + ' audioControls = true; ' + ' document.getElementById(\'adAgioVolumeOff\').style.display = \'block\';' + ' document.getElementById(\'adAgioVolumeOn\').style.display = \'none\';' + ' }); '; scriptCode += ' adVolumeOff.addEventListener(\'click\',function(event){ ' + ' event.stopPropagation(); ' + ' if(detected_os === "iOS_phone"){' + ' window.document.removeEventListener("touchstart",adAgioForcePlayOnIPAD,false);' + ' adVideo.setAttribute("muted","false");' + ' adVideo.muted = false;' + ' }' + ' else { adVideo.muted = false; }' + ' audioControls = true; ' + 'adVolumeOff.style.display = \'none\'; adVolumeOn.style.display = \'block\';' + ' }); '; scriptCode += ' adVideo.addEventListener(\'click\',function(event){' + ' if(detected_os !== "unkown" && !(audioControls) ){ ' + ' adVideo.muted = true; adVolumeOff.style.display = \'block\'; adVolumeOn.style.display = \'none\';' + ' adVideo.play();' + ' }' + ' window.open("//ad-aws-it.neodatagroup.com/ad/clk.jsp?x=399375.604324.1063.463203.-1.-1.85.91.1.10066.1.-1.-1.-1..-1.2...&link=https%3A%2F%2Fwww.eurospin.it%2F",\'_blank\');' + ' });'; /* scriptCode += ' adVolumeOn.addEventListener(\'mouseover\', function(event){' + ' if(!audioControls && detected_os != "Android") { adVideo.muted = false; adVolumeOn.style.display = \'block\'; adVolumeOff.style.display = \'none\'; }' + ' });'; scriptCode += ' adVolumeOn.addEventListener(\'mouseout\', function(event){' + ' if(!audioControls && detected_os != "Android") { adVideo.muted = true; adVolumeOn.style.display = \'none\'; adVolumeOff.style.display = \'block\'; }' + ' });'; scriptCode += ' adVolumeOff.addEventListener(\'mouseover\',function(){ '+ ' if(!audioControls && detected_os != "Android"){ adVideo.muted = false; adVolumeOff.style.display = \'none\'; adVolumeOn.style.display = \'block\'; } ' + ' });'; scriptCode += ' adVolumeOff.addEventListener(\'mouseout\',function(){'+ ' if(!audioControls && detected_os != "Android"){ adVideo.muted = true; adVolumeOff.style.display = \'block\'; adVolumeOn.style.display = \'none\'; } ' + ' });'; */ scriptCode += ' };'; scriptCode += ' adAgioExec();'; scriptCode += ''; return scriptCode; }; adAgioInRead = addingElement(); adAgioInRead += addingScript(); })(window); document.write(adAgioInRead);