function checkSlotsView() { //$evoGptAd = $('.evo-gpt-ad:not(.refreshed)'); var $evoGptAd = jQuery(".evo-gpt-ad:not(.refreshed)").filter(function () { return (jQuery(this).data('addesktop') == undefined && jQuery(this).data('admobile') == undefined) || jQuery(this).data('addesktop') == "1"; }); if (jQuery(window).width() < 980) { $evoGptAd = jQuery(".evo-gpt-ad:not(.refreshed)").filter(function () { return (jQuery(this).data('addesktop') == undefined && jQuery(this).data('admobile') == undefined) || jQuery(this).data('admobile') == "1"; }); } if ($evoGptAd.length > 0) { var scrollTop = jQuery(window).scrollTop(); var windowHeight = window.innerHeight; var allRefreshed = true; $evoGptAd.each(function () { var element = this; var currentElementOffset = jQuery(this).offset().top; if (currentElementOffset < scrollTop + windowHeight) { // Logger.getInstance().log("GPT " + getDateTimeString() + " => show slot id " + element.slotid + // " ad unit " + element.adunitid);//+ " targeting " + element.targeting); //googletag.cmd.push(function() { googletag.display($(this).attr('id')); }); jQuery(this).html( "" ); jQuery(this).addClass('refreshed'); //console.log("Caricato intext"); } }); } } jQuery(window).on("scroll", debounceScroll(checkSlotsView, 100).bind(this)); function debounceScroll(func, distance) { var lastscroll = 0; return function() { var context = this, args = arguments; var currentScroll = jQuery(window).scrollTop(); if (currentScroll - lastscroll > 100) { lastscroll = currentScroll; func.apply(context, args); } } }; function insertBanner() { var $texte = jQuery(".content").last(); if ($texte.length > 0) { var $p = $texte.find("p"); var limit = $texte.data("banner") || 150; var currentLimit = limit; var wordCount = 0; var count = Date.now() + 1; var $pAndImg = $texte.find("p, img"); for (var i = 0; i < $pAndImg.length; i++) { var $node =jQuery( $pAndImg[i]); if ($node.is("p")) { wordCount += $node.text().split(' ').length; if (wordCount > currentLimit) { var j = i + 1; var found = false; while (j < $pAndImg.length && !found) { if (jQuery($pAndImg[j]).is("p:not(#toc_container)") && jQuery($pAndImg[j]).text().trim().length > 0 ) { found = true; jQuery($pAndImg[j]).before( "
" ); } j++; } count++; wordCount = 0; } } } } } jQuery(document).ready(function() { insertBanner(); });