Mercurial Hosting > nabble
view src/nabble/modules/ad/Javascript.jmp @ 62:4674ed7d56df default tip
remove n2
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 30 Sep 2023 20:25:29 -0600 |
parents | 7ecd1a4ef557 |
children |
line wrap: on
line source
<% package nabble.modules.ad; import nabble.model.Init; final class Javascript { public static String BANNER_IMG = Init.get("bannerImg", "ad_nabble.png"); public static String BANNER_URL = Init.get("bannerUrl", "https://www.nabble.com/"); public static volatile String hackAds = ""; static String text(Ad ad) { boolean isSafe = ad.isSafe(); return %> var _gaq = _gaq || []; var isA; (function() { var ab = Nabble.getCookie("ab"); if( ab == null ) { ab = Math.random() < 0.5 ? "a" : "b"; Nabble.setCookie("ab",ab); } isA = ab == "a"; })(); var isB = !isA; Nabble.isSafe = <%=isSafe%>; Nabble.adGroup = '<%= isSafe ? "SAFE" : "BAD" %>'; var lastDayWithoutAds = <%=ad.lastDayWithoutAds()%>; var daysLeft = Math.round((lastDayWithoutAds - new Date().getTime()) / (24 * 60 * 60 * 1000)); Nabble.currentCredits = <%=ad.getCredits()%>; Nabble.isPaid = <%=ad.isPaid()%>; Nabble.creditsForUsersOnly = <%=ad.isCreditsForUsersOnly()%>; Nabble.wasCreatedRecently = daysLeft > 0; Nabble.removeAdsPath = '/template/NamlServlet.jtp?macro=site_payment'; Nabble.noAds = function(location) { Nabble.noAds = function(location) {}; _gaq.push(['nabble._trackEvent', 'ad-type', 'NONE']); }; Nabble.ads = function(location) { if (Nabble.currentCredits > 0 && Nabble.creditsForUsersOnly && Nabble.userId) return; Nabble.fixAdGroup(location); Ads[Nabble.adGroup](location); }; Nabble.adbayes = function() { window.Adbayes = window.Adbayes || { properties:{} }; Adbayes.properties['domain'] = window.location.hostname; Adbayes.properties['adtype'] = Nabble.adGroup; if (Nabble.wasCreatedRecently && Nabble.adGroup == 'SAFE') Nabble.adGroup = "NEW"; if( Nabble.adGroup=='SAFE' && Adbayes.result != 'safe' ) Nabble.adGroup = 'UNSAFE'; if( Nabble.adGroup=='SAFE' ) _gaq.push(['nabble._setCustomVar', 1, 'Safe', 'x']); }; Nabble.fixAdGroup = function(location) { Nabble.fixAdGroup = function(location) {}; if (!window.Adbayes) { Nabble.adGroup = "NEW"; _gaq.push(['nabble._trackEvent', 'ad-type', Nabble.adGroup]); return; } switch(location) { case 'app_bottom': Adbayes.properties['page-type'] = 'forum'; break; case 'first_classic_message': case 'last_classic_message': Adbayes.properties['page-type'] = 'classic-view'; break; case 'list_bottom': Adbayes.properties['page-type'] = 'list-view'; break; case 'threaded_bottom': Adbayes.properties['page-type'] = 'threaded-view'; break; case 'blog_topic': Adbayes.properties['page-type'] = 'blog-topic'; break; case 'search_top': case 'search_bottom': Adbayes.properties['page-type'] = 'search'; break; case 'widget': Adbayes.properties['page-type'] = 'widget'; break; default: Adbayes.properties['page-type'] = 'unknown:' + location; break; } Nabble.realTimeAnalytics(); }; Nabble.realTimeAnalytics = function() { _gaq.push(['nabble._trackEvent', 'ad-type', Nabble.adGroup]); if (Adbayes.properties['adtype'] == 'SAFE' && window.Adbayes.listeners) { window.Adbayes.listeners.push(function() { var page = Adbayes.properties['page-type']; var status; if (Adbayes.isNew) { status = "new"; } else if (Adbayes.isCanonical) { status = "canonical"; } else if(Adbayes.isOutdated) { status = "outdated"; } else { status = "set"; } _gaq.push(['nabble._trackEvent', 'adbayes-status', page + ':' + status, Adbayes.result]); }); } }; var Ads = {}; Ads.styles = { widget: { cls: '', style: '' }, blog_topic: { cls: 'shaded-bg-color rounded', style: 'padding:.5em;' }, first_classic_message: { cls: '', style: 'text-align:left;' }, last_classic_message: { cls: '', style: 'text-align:left;padding-top:1em;' }, list_bottom: { cls: '', style: 'margin-top:1.5em;' }, threaded_bottom: { cls: '', style: 'margin-top:1.5em;' }, search_top: { cls: '', style: 'text-align:left;margin:1em 0;padding:.5em 0;' }, search_bottom: { cls: '', style: 'text-align:left;padding:.5em 0;' }, app_bottom: { cls: '', style: 'margin:2.5em auto;text-align:center;' }, topic_bottom: { cls: '', style: '' } }; Ads.NEW = function(location) { switch(location) { case 'blog_topic': case 'first_classic_message': case 'list_bottom': case 'threaded_bottom': case 'search_bottom': case 'app_bottom': } }; Ads.NABBLE = function(location) { switch(location) { case 'blog_topic': case 'first_classic_message': case 'list_bottom': case 'threaded_bottom': case 'search_bottom': Nabble.showAd( location, function() { var imgName = '<%=BANNER_IMG%>'; var url = '<%=BANNER_URL%>'; _gaq.push(['nabble._trackEvent', 'banner', imgName]); document.write('<a href="'+url+'" rel="nofollow" style="display:block !important;visibility:visible !important;height:auto !important; width: auto !important;position:static !important;top:auto !important;left:auto !important"><img src="http://static.nabble.com/images/'+imgName+'" style="border:1px solid #bbb;display:inline !important;visibility:visible !important;height:auto !important;width:auto !important"/></a>'); } ); } }; Ads.AdSense = function(location) { switch(location) { case 'blog_topic': Nabble.showAd( location, function() { google_ad_slot = "8807592501"; google_ad_width = 728; google_ad_height = 90; Nabble._adsense(); } ); break; case 'first_classic_message': Nabble.showAd( location, function() { var fn = function() { google_ad_slot = "8703015991"; google_ad_width = 336; google_ad_height = 280; Nabble._adsense(); }; document.writeln('<div style="width:336px; float:left; clear:none; display:block !important;">'); Nabble.writeFn(fn); document.writeln('</div>'); document.writeln('<div style="width:336px; float:left; clear:none; display:block !important;">'); Nabble.writeFn(fn); document.writeln('</div>'); }, "width:675px !important;" ); break; case 'last_classic_message': Nabble.showAd( location, function() { google_ad_slot = "8323336297"; google_ad_width = 728; google_ad_height = 90; Nabble._adsense(); } ); break; case 'list_bottom': Nabble.showAd( location, function() { google_ad_slot = "6508328921"; google_ad_width = 728; google_ad_height = 90; Nabble._adsense(); } ); break; case 'threaded_bottom': Nabble.showAd( location, function() { google_ad_slot = "8434893994"; google_ad_width = 728; google_ad_height = 90; Nabble._adsense(); } ); break; case 'search_top': Nabble.AdsenseSearchAds(); break; case 'search_bottom': Nabble.showAd( location, function() { google_ad_slot = "0099567777"; google_ad_width = 728; google_ad_height = 90; google_ad_type = "image"; Nabble._adsense(); } ); break; case 'app_bottom': Nabble.showAd( location, function() { var fn = function() { google_ad_slot = "1057993213"; google_ad_width = 728; google_ad_height = 90; Nabble._adsense(); }; Nabble.writeFn(fn); } ); break; } }; Ads.SAFE = function(location) { Ads.AdSense(location); }; Ads.ST = function(location) { if (Nabble.currentCredits > 0 || Nabble.isPaid) return; window.has_st = true; }; Ads.BAD = Ads.ST; Ads.UNSAFE = Ads.ST; Nabble.showAd = function(location,fn,style) { var customStyle = Ads.styles[location].style + (style == null?'':style); document.writeln('<div class="ad '+Ads.styles[location].cls+'" style="display:block !important;visibility:visible !important;height:auto !important; width: auto !important;position:static !important;top:auto !important;left:auto !important;'+customStyle+'">'); fn(); if (!Nabble.creditsForUsersOnly || Nabble.userId) { document.writeln('<div style="padding-top:.3em;font-size:90%;clear:both"><a href="'+Nabble.removeAdsPath+'">'+Ads.text.removeAds+'</a></div>'); document.writeln('</div>'); } }; Nabble.AdsenseSearchAds = function() { if (nabble_search_query && nabble_search_query != '') { (function(G,o,O,g,L,e){G[g]=G[g]||function(){(G[g]['q']=G[g]['q']||[]).push( arguments)},G[g]['t']=1*new Date;L=o.createElement(O),e=o.getElementsByTagName( O)[0];L.async=1;L.src='//www.google.com/adsense/search/async-ads.js'; e.parentNode.insertBefore(L,e)})(window,document,'script','_googCsa'); document.writeln('<div id="ad1" style="margin:0 0 1em -.3em"></div>'); var pageOptions = { 'pubId': 'pub-6703598369329977', 'query': nabble_search_query, 'hl': 'en' }; var ad = Nabble._ad(); var bg = '#'+Nabble._bgcolor(ad); var tc = '#'+Nabble._color('div.search-results-header','808080'); var lc = '#'+Nabble._linkColor(ad); var adblock1 = { 'container': 'ad1', 'width': '100%', 'fontFamily': 'verdana', 'fontSizeTitle': 15, 'fontSizeDescription': 13, 'fontSizeDomainLink': 13, 'colorTitleLink': lc, 'colorText': tc, 'colorDomainLink': tc, 'colorBackground': bg, 'colorAdBorder': bg, 'colorBorder': bg }; _googCsa('ads', pageOptions, adblock1); } }; Nabble.writeFn = function(fn) { Nabble._fn = fn; document.writeln('<script type="text/javascript">Nabble._fn()</script>'); }; Nabble._adwords = function() { google_conversion_id = 975361083; google_conversion_language = "en"; google_conversion_format = "3"; google_conversion_color = "ffffff"; google_conversion_label = "sfP9CM34nwgQu6iL0QM"; google_conversion_value = 10; google_remarketing_only = false; document.write('<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js"></script>'); }; Nabble._adsense = function() { var ad = Nabble._ad(); if( google_ad_width==728 && Nabble._narrowUnit(ad,728) ) { google_ad_slot = "1143776366"; google_ad_width = 468; google_ad_height = 60; } var bg = Nabble._bgcolor(ad); google_color_border = bg; google_color_bg = bg; google_color_text = "808080"; google_color_url = "808080"; google_color_link = Nabble._linkColor(ad); google_ad_client = "ca-pub-6703598369329977"; document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>'); var __ad = 'div'+ad.getAttribute('id').substring(2); $(ad).parent().addClass(__ad); document.write('<style type="text/css">'); document.write('.nabble .' + __ad + ' ins { display:inline-table !important; visibility: visible !important; height:' + google_ad_height + 'px !important; width: ' + google_ad_width + 'px !important; position:static !important;top:auto !important;left:auto !important; }'); document.write('.nabble .' + __ad + ' ins ins iframe { display:block !important; visibility: visible !important; height:' + google_ad_height + 'px !important; width: ' + google_ad_width + 'px !important; position:static !important;top:auto !important;left:auto !important; }'); document.write('</style>'); }; Nabble._ad = function() { var ad = "ad" + Math.round(Math.random() * 999999); document.writeln('<a id="'+ad+'" href="#" style="display:none">.</a>'); return Nabble.get(ad); }; Nabble._bgcolor = function(ad) { var $elem = $(ad); var $parent = $elem; var bg; while ($parent.size() > 0) { try { bg = $parent.css('background-color'); } catch(err) { $elem.addClass('shaded-bg-color'); bg = $elem.css('background-color'); break; } if (bg != 'transparent' && bg.indexOf('rgba') != 0) break; $parent = $parent.parent(); } if (bg.charAt(0) == '#') return bg.substring(1); else if (bg.indexOf('rgb') == 0) { bg = bg.substring(4, bg.length-1); var rgb = bg.split(','); return Nabble._hexa(rgb[0]) + Nabble._hexa(rgb[1]) + Nabble._hexa(rgb[2]); } return bg; }; Nabble._linkColor = function(ad) { var c = $(ad).css('color'); if (c.charAt(0) == '#') return c.substring(1); else if (c.indexOf('rgb') == 0) { c = c.substring(4, c.length-1); var rgb = c.split(','); return Nabble._hexa(rgb[0]) + Nabble._hexa(rgb[1]) + Nabble._hexa(rgb[2]); } return 'EEEEEE'; }; Nabble._color = function(sel,def) { var c = $(sel).css('color'); if (c.charAt(0) == '#') return c.substring(1); else if (c.indexOf('rgb') == 0) { c = c.substring(4, c.length-1); var rgb = c.split(','); return Nabble._hexa(rgb[0]) + Nabble._hexa(rgb[1]) + Nabble._hexa(rgb[2]); } return def; }; Nabble._hexa = function(c) { var n = parseInt(c).toString(16); return n.length == 1? '0' + n : n; }; Nabble._narrowUnit = function(ad,limit) { return $(ad).parent().width() < limit; }; var b = function() {}; <%=hackAds%> if(isB) b(); <%; } private Javascript() {} // never } %>