function flamengoBannerBase() { if (typeof window.FLAMENGO_WEBROOT === 'string' && window.FLAMENGO_WEBROOT.length) return window.FLAMENGO_WEBROOT.replace(/\/$/, ''); var p = (window.location.pathname || '/').replace(/\/+$/, ''); if (p.indexOf('.php') !== -1) p = p.replace(/\/[^/]+$/, ''); return p || ''; } $('.img-banner-tracker').each(function(){ var element = this; if (!this.complete) { $(this).load(function(){ if($(this).is(":visible")){ addBannerView($(element).attr('data-banner')); } }); } else { if($(this).is(":visible")){ addBannerView($(element).attr('data-banner')); } } }); $('.img-banner-tracker').parent().click(function(){ if($(this).attr('href') != undefined){ var bannerId = $(this).find('.img-banner-tracker').attr('data-banner'); $.ajax({ url: flamengoBannerBase() + '/add-banner-click.php', data: {banner: bannerId}, method: 'post', dataType: 'json' }); } }); function addBannerView(bannerId){ $.ajax({ url: flamengoBannerBase() + '/add-banner-view.php', data: {banner: bannerId}, method: 'post', dataType: 'json' }); }